java.util.function.Functionjava.util.function.Predicate



Project stanfordnlp/CoreNLP in file ...p.ling.tokensregex.CoreMapExpressionExtractor.java (2015-03-12)
@@ -13,7 +13,7 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.StringReader;
 import java.util.*;
-import java.util.function.Function;
+import java.util.function.Predicate;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -67,7 +67,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
     /** Rules to extract composite expressions (grouped in stages) */
     SequenceMatchRules.ExtractRule<List<? extends CoreMap>, T> compositeExtractRule;
     /** Filtering rule */
-    Filter<T> filterRule;
+    Predicate<T> filterRule;
 
     private static <I,O> SequenceMatchRules.ExtractRule<I,O> addRule(SequenceMatchRules.ExtractRule<I, O> origRule,
                                                                      SequenceMatchRules.ExtractRule<I, O> rule)
@@ -94,7 +94,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
       basicExtractRule = addRule(basicExtractRule, rule);
     }
 
-    private void addFilterRule(Filter<T> rule)
+    private void addFilterRule(Predicate<T> rule)
     {
       Filters.DisjFilter<T> r;
       if (filterRule instanceof Filters.DisjFilter) {
@@ -124,7 +124,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
    * @param env Environment to use for binding variables and applying rules
    */
   public CoreMapExpressionExtractor(Env env) {
-    this.stages = Generics.newHashMap();
+    this.stages = new HashMap<Integer, Stage<T>>();//Generics.newHashMap();
     this.env = env;
     this.tokensAnnotationKey = EnvLookup.getDefaultTokensAnnotationKey(env);
   }
@@ -194,7 +194,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
 
   public void setExtractRules(SequenceMatchRules.ExtractRule<CoreMap, T> basicExtractRule,
                               SequenceMatchRules.ExtractRule<List<? extends CoreMap>, T> compositeExtractRule,
-                              Filter<T> filterRule)
+                              Predicate<T> filterRule)
   {
     Stage<T> stage = new Stage<T>();
     stage.basicExtractRule = basicExtractRule;
@@ -494,14 +494,14 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
     expressions.removeAll(toDiscard);
   }
 
-  private List<T> filterInvalidExpressions(Filter<T> filterRule, List<T> expressions)
+  private List<T> filterInvalidExpressions(Predicate<T> filterRule, List<T> expressions)
   {
     if (filterRule == null) return expressions;
     if (expressions.size() == 0) return expressions;
     int nfiltered = 0;
     List<T> kept = new ArrayList<T>(expressions.size());   // Approximate size
     for (T expr:expressions) {
-      if (!filterRule.accept(expr)) {
+      if (!filterRule.test(expr)) {
         kept.add(expr);
       } else {
         nfiltered++;
Project stanfordnlp/CoreNLP in file ...p.ling.tokensregex.CoreMapExpressionExtractor.java (2014-11-06)
@@ -13,7 +13,7 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.StringReader;
 import java.util.*;
-import java.util.function.Function;
+import java.util.function.Predicate;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -67,7 +67,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
     /** Rules to extract composite expressions (grouped in stages) */
     SequenceMatchRules.ExtractRule<List<? extends CoreMap>, T> compositeExtractRule;
     /** Filtering rule */
-    Filter<T> filterRule;
+    Predicate<T> filterRule;
 
     private static <I,O> SequenceMatchRules.ExtractRule<I,O> addRule(SequenceMatchRules.ExtractRule<I, O> origRule,
                                                                      SequenceMatchRules.ExtractRule<I, O> rule)
@@ -94,7 +94,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
       basicExtractRule = addRule(basicExtractRule, rule);
     }
 
-    private void addFilterRule(Filter<T> rule)
+    private void addFilterRule(Predicate<T> rule)
     {
       Filters.DisjFilter<T> r;
       if (filterRule instanceof Filters.DisjFilter) {
@@ -194,7 +194,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
 
   public void setExtractRules(SequenceMatchRules.ExtractRule<CoreMap, T> basicExtractRule,
                               SequenceMatchRules.ExtractRule<List<? extends CoreMap>, T> compositeExtractRule,
-                              Filter<T> filterRule)
+                              Predicate<T> filterRule)
   {
     Stage<T> stage = new Stage<T>();
     stage.basicExtractRule = basicExtractRule;
@@ -494,14 +494,14 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
     expressions.removeAll(toDiscard);
   }
 
-  private List<T> filterInvalidExpressions(Filter<T> filterRule, List<T> expressions)
+  private List<T> filterInvalidExpressions(Predicate<T> filterRule, List<T> expressions)
   {
     if (filterRule == null) return expressions;
     if (expressions.size() == 0) return expressions;
     int nfiltered = 0;
     List<T> kept = new ArrayList<T>(expressions.size());   // Approximate size
     for (T expr:expressions) {
-      if (!filterRule.accept(expr)) {
+      if (!filterRule.test(expr)) {
         kept.add(expr);
       } else {
         nfiltered++;
Project stanfordnlp/CoreNLP in file ...p.ling.tokensregex.CoreMapExpressionExtractor.java (2015-03-14)
@@ -13,7 +13,7 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.StringReader;
 import java.util.*;
-import java.util.function.Function;
+import java.util.function.Predicate;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -67,7 +67,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
     /** Rules to extract composite expressions (grouped in stages) */
     SequenceMatchRules.ExtractRule<List<? extends CoreMap>, T> compositeExtractRule;
     /** Filtering rule */
-    Filter<T> filterRule;
+    Predicate<T> filterRule;
 
     private static <I,O> SequenceMatchRules.ExtractRule<I,O> addRule(SequenceMatchRules.ExtractRule<I, O> origRule,
                                                                      SequenceMatchRules.ExtractRule<I, O> rule)
@@ -94,7 +94,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
       basicExtractRule = addRule(basicExtractRule, rule);
     }
 
-    private void addFilterRule(Filter<T> rule)
+    private void addFilterRule(Predicate<T> rule)
     {
       Filters.DisjFilter<T> r;
       if (filterRule instanceof Filters.DisjFilter) {
@@ -124,7 +124,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
    * @param env Environment to use for binding variables and applying rules
    */
   public CoreMapExpressionExtractor(Env env) {
-    this.stages = Generics.newHashMap();
+    this.stages = new HashMap<Integer, Stage<T>>();//Generics.newHashMap();
     this.env = env;
     this.tokensAnnotationKey = EnvLookup.getDefaultTokensAnnotationKey(env);
   }
@@ -194,7 +194,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
 
   public void setExtractRules(SequenceMatchRules.ExtractRule<CoreMap, T> basicExtractRule,
                               SequenceMatchRules.ExtractRule<List<? extends CoreMap>, T> compositeExtractRule,
-                              Filter<T> filterRule)
+                              Predicate<T> filterRule)
   {
     Stage<T> stage = new Stage<T>();
     stage.basicExtractRule = basicExtractRule;
@@ -494,14 +494,14 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
     expressions.removeAll(toDiscard);
   }
 
-  private List<T> filterInvalidExpressions(Filter<T> filterRule, List<T> expressions)
+  private List<T> filterInvalidExpressions(Predicate<T> filterRule, List<T> expressions)
   {
     if (filterRule == null) return expressions;
     if (expressions.size() == 0) return expressions;
     int nfiltered = 0;
     List<T> kept = new ArrayList<T>(expressions.size());   // Approximate size
     for (T expr:expressions) {
-      if (!filterRule.accept(expr)) {
+      if (!filterRule.test(expr)) {
         kept.add(expr);
       } else {
         nfiltered++;
Project stanfordnlp/CoreNLP in file ...p.ling.tokensregex.CoreMapExpressionExtractor.java (2015-02-18)
@@ -13,7 +13,7 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.StringReader;
 import java.util.*;
-import java.util.function.Function;
+import java.util.function.Predicate;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -22,14 +22,15 @@ import java.util.logging.Logger;
  *    See {@link SequenceMatchRules} for syntax of rules.
  * </p>
  *
- * <p>Assignment rules are used to assign value to variable for later use in
+ * <p>Assignment rules are used to assign a value to a variable for later use in
  * extraction rules or for expansions in patterns.</p>
  * <p>Extraction rules are used to extract text/tokens matching regular expressions.
- * Extraction rules are grouped into stages, with each stage consisting of the following.
+ * Extraction rules are grouped into stages, with each stage consisting of the following:
  * <ol>
- *   <li>Matching of rules over <b>text</b> and <b>tokens</b>.  These rules are applied directly on the <b>text</b> and <b>tokens</b> fields of the <code>CoreMap</code></li>
- *   <li>Matching of <b>composite</b> rules.  Matched expression are merged, and composite rules are applied recursively until no more changes to the matched expressions are detected.</li>
- *   <li><b>Filtering</b> of invalid expression.  In the final phase, a final filtering stage filters out invalid expressions.</li>
+ *   <li>Matching of rules over <b>text</b> and <b>tokens</b>.  These rules are applied directly on the <b>text</b> and <b>tokens</b> fields of the <code>CoreMap</code>.</li>
+ *   <li>Matching of <b>composite</b> rules.  Matched expression are merged, and composite rules
+ *       are applied recursively until no more changes to the matched expressions are detected.</li>
+ *   <li><b>Filtering</b> of an invalid expression.  In the final phase, a final filtering stage filters out invalid expressions.</li>
  * </ol>
  * The different stages are numbered and are applied in numeric order.
  * </p>
@@ -38,16 +39,18 @@ import java.util.logging.Logger;
  * @see SequenceMatchRules
  */
 public class CoreMapExpressionExtractor<T extends MatchedExpression> {
+
   // TODO: Remove templating of MatchedExpressions<?>  (keep for now until TimeExpression rules can be decoupled)
+
   private Logger logger = Logger.getLogger(CoreMapExpressionExtractor.class.getName());
-  Env env;
+  private final Env env;
   /* Keeps temporary tags created by extractor */
-  boolean keepTags = false;
-  Class tokensAnnotationKey;
-  Map<Integer, Stage<T>> stages;
+  private boolean keepTags = false;
+  private final Class tokensAnnotationKey;
+  private final Map<Integer, Stage<T>> stages;
 
   /**
-   * Describes one stage of extraction
+   * Describes one stage of extraction.
    * @param <T>
    */
   public static class Stage<T> {
@@ -67,7 +70,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
     /** Rules to extract composite expressions (grouped in stages) */
     SequenceMatchRules.ExtractRule<List<? extends CoreMap>, T> compositeExtractRule;
     /** Filtering rule */
-    Filter<T> filterRule;
+    Predicate<T> filterRule;
 
     private static <I,O> SequenceMatchRules.ExtractRule<I,O> addRule(SequenceMatchRules.ExtractRule<I, O> origRule,
                                                                      SequenceMatchRules.ExtractRule<I, O> rule)
@@ -94,7 +97,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
       basicExtractRule = addRule(basicExtractRule, rule);
     }
 
-    private void addFilterRule(Filter<T> rule)
+    private void addFilterRule(Predicate<T> rule)
     {
       Filters.DisjFilter<T> r;
       if (filterRule instanceof Filters.DisjFilter) {
@@ -112,7 +115,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
   }
 
   /**
-   * Creates an empty instance with no rules
+   * Creates an empty instance with no rules.
    */
   public CoreMapExpressionExtractor() {
     this(null);
@@ -124,7 +127,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
    * @param env Environment to use for binding variables and applying rules
    */
   public CoreMapExpressionExtractor(Env env) {
-    this.stages = Generics.newHashMap();
+    this.stages = new HashMap<Integer, Stage<T>>();//Generics.newHashMap();
     this.env = env;
     this.tokensAnnotationKey = EnvLookup.getDefaultTokensAnnotationKey(env);
   }
@@ -194,7 +197,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
 
   public void setExtractRules(SequenceMatchRules.ExtractRule<CoreMap, T> basicExtractRule,
                               SequenceMatchRules.ExtractRule<List<? extends CoreMap>, T> compositeExtractRule,
-                              Filter<T> filterRule)
+                              Predicate<T> filterRule)
   {
     Stage<T> stage = new Stage<T>();
     stage.basicExtractRule = basicExtractRule;
@@ -494,14 +497,14 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
     expressions.removeAll(toDiscard);
   }
 
-  private List<T> filterInvalidExpressions(Filter<T> filterRule, List<T> expressions)
+  private List<T> filterInvalidExpressions(Predicate<T> filterRule, List<T> expressions)
   {
     if (filterRule == null) return expressions;
     if (expressions.size() == 0) return expressions;
     int nfiltered = 0;
     List<T> kept = new ArrayList<T>(expressions.size());   // Approximate size
     for (T expr:expressions) {
-      if (!filterRule.accept(expr)) {
+      if (!filterRule.test(expr)) {
         kept.add(expr);
       } else {
         nfiltered++;
Project stanfordnlp/CoreNLP in file ...p.ling.tokensregex.CoreMapExpressionExtractor.java (2014-10-24)
@@ -13,7 +13,7 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.StringReader;
 import java.util.*;
-import java.util.function.Function;
+import java.util.function.Predicate;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -67,7 +67,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
     /** Rules to extract composite expressions (grouped in stages) */
     SequenceMatchRules.ExtractRule<List<? extends CoreMap>, T> compositeExtractRule;
     /** Filtering rule */
-    Filter<T> filterRule;
+    Predicate<T> filterRule;
 
     private static <I,O> SequenceMatchRules.ExtractRule<I,O> addRule(SequenceMatchRules.ExtractRule<I, O> origRule,
                                                                      SequenceMatchRules.ExtractRule<I, O> rule)
@@ -94,7 +94,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
       basicExtractRule = addRule(basicExtractRule, rule);
     }
 
-    private void addFilterRule(Filter<T> rule)
+    private void addFilterRule(Predicate<T> rule)
     {
       Filters.DisjFilter<T> r;
       if (filterRule instanceof Filters.DisjFilter) {
@@ -194,7 +194,7 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
 
   public void setExtractRules(SequenceMatchRules.ExtractRule<CoreMap, T> basicExtractRule,
                               SequenceMatchRules.ExtractRule<List<? extends CoreMap>, T> compositeExtractRule,
-                              Filter<T> filterRule)
+                              Predicate<T> filterRule)
   {
     Stage<T> stage = new Stage<T>();
     stage.basicExtractRule = basicExtractRule;
@@ -494,14 +494,14 @@ public class CoreMapExpressionExtractor<T extends MatchedExpression> {
     expressions.removeAll(toDiscard);
   }
 
-  private List<T> filterInvalidExpressions(Filter<T> filterRule, List<T> expressions)
+  private List<T> filterInvalidExpressions(Predicate<T> filterRule, List<T> expressions)
   {
     if (filterRule == null) return expressions;
     if (expressions.size() == 0) return expressions;
     int nfiltered = 0;
     List<T> kept = new ArrayList<T>(expressions.size());   // Approximate size
     for (T expr:expressions) {
-      if (!filterRule.accept(expr)) {
+      if (!filterRule.test(expr)) {
         kept.add(expr);
       } else {
         nfiltered++;