Revision: 19673
          http://sourceforge.net/p/gate/code/19673
Author:   markagreenwood
Date:     2016-10-12 12:40:02 +0000 (Wed, 12 Oct 2016)
Log Message:
-----------
couple more fixes

Modified Paths:
--------------
    
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/annic/lucene/QueryParser.java
    
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/annic/lucene/StatsCalculator.java

Modified: 
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/annic/lucene/QueryParser.java
===================================================================
--- 
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/annic/lucene/QueryParser.java
    2016-10-12 01:23:01 UTC (rev 19672)
+++ 
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/annic/lucene/QueryParser.java
    2016-10-12 12:40:02 UTC (rev 19673)
@@ -7,13 +7,17 @@
  */
 package gate.creole.annic.lucene;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import gate.creole.annic.Constants;
-import gate.creole.annic.apache.lucene.search.*;
-import gate.creole.annic.apache.lucene.index.*;
+import gate.creole.annic.apache.lucene.index.Term;
+import gate.creole.annic.apache.lucene.search.BooleanQuery;
+import gate.creole.annic.apache.lucene.search.PhraseQuery;
+import gate.creole.annic.apache.lucene.search.Query;
+import gate.creole.annic.apache.lucene.search.TermQuery;
 import gate.creole.ir.SearchException;
 
-import java.util.*;
-
 /**
  * QueryParser parses the provided ANNIC Query and converts it into the
  * format understood to Lucene.
@@ -463,10 +467,8 @@
             areAllTermsTokens = false;
 
           terms.add(new Term(field, norm(fields.get(p)), "*"));
-          pos.add(new Integer(position));
-          if(p == 0)
-            consider.add(new Boolean(true));
-          else consider.add(new Boolean(false));
+          pos.add(position);
+          consider.add(p == 0);
 
         }
         position++;
@@ -493,21 +495,16 @@
               areAllTermsTokens = false;
             
             terms.add(new Term(field, annotText, annotType + ".string"));
-            pos.add(new Integer(position));
-            if(p == 0)
-              consider.add(new Boolean(true));
-            else consider.add(new Boolean(false));
-
+            pos.add(position);
+            consider.add(p == 0);
           }
           else {
             if(!(norm(fields.get(p))).equals(baseTokenAnnotationType))
               areAllTermsTokens = false;
             
             terms.add(new Term(field, norm(fields.get(p)), "*"));
-            pos.add(new Integer(position));
-            if(p == 0)
-              consider.add(new Boolean(true));
-            else consider.add(new Boolean(false));
+            pos.add(position);
+            consider.add(p == 0);
           }
         }
 
@@ -547,11 +544,8 @@
             if(!norm(subElems[j].trim()).equals(baseTokenAnnotationType))
               areAllTermsTokens = false;
             terms.add(new Term(field, norm(subElems[j].trim()), "*"));
-            pos.add(new Integer(position));
-            if(j == 0)
-              consider.add(new Boolean(true));
-            else consider.add(new Boolean(false));
-
+            pos.add(position);
+            consider.add(j == 0);
           }
           else if(index != -1 && index1 == -1) {
             // this is {AT=="String"}
@@ -565,11 +559,8 @@
             if(!annotType.trim().equals(baseTokenAnnotationType))
               areAllTermsTokens = false;
             terms.add(new Term(field, annotText, annotType + ".string"));
-            pos.add(new Integer(position));
-            if(j == 0)
-              consider.add(new Boolean(true));
-            else consider.add(new Boolean(false));
-
+            pos.add(position);
+            consider.add(j == 0);
           }
           else if(index == -1 && index1 != -1) {
             throw new SearchException("missing operator",
@@ -592,10 +583,8 @@
               areAllTermsTokens = false;
             terms.add(new Term(field, featureText, annotType + "."
                     + featureType));
-            pos.add(new Integer(position));
-            if(j == 0)
-              consider.add(new Boolean(true));
-            else consider.add(new Boolean(false));
+            pos.add(position);
+            consider.add(j == 0);
           }
           lengthTravelledSoFar += subElems[j].length() + 1;
         }
@@ -605,7 +594,7 @@
     else {
       // possible
       // remove all the inverted commas
-      String newString = "";
+      StringBuilder newString = new StringBuilder();
       char prev = ' ', ch = ' ';
       for(int i = 0; i < elem.length(); i++) {
         prev = ch;
@@ -614,17 +603,17 @@
           continue;
         }
         else {
-          newString += ch;
+          newString.append(ch);
         }
       }
       // there can be many tokens
-      String[] subTokens = norm(newString).split("( )+");
+      String[] subTokens = norm(newString.toString()).split("( )+");
       for(int k = 0; k < subTokens.length; k++) {
         if(subTokens[k].trim().length() > 0) {
           terms.add(new Term(field, norm(subTokens[k]), baseTokenAnnotationType
                   + ".string"));
-          pos.add(new Integer(position));
-          consider.add(new Boolean(true));
+          pos.add(position);
+          consider.add(Boolean.TRUE);
           position++;
         }
       }

Modified: 
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/annic/lucene/StatsCalculator.java
===================================================================
--- 
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/annic/lucene/StatsCalculator.java
        2016-10-12 01:23:01 UTC (rev 19672)
+++ 
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/annic/lucene/StatsCalculator.java
        2016-10-12 12:40:02 UTC (rev 19673)
@@ -1,14 +1,23 @@
 package gate.creole.annic.lucene;
 
-import java.io.*;
-import java.util.*;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import gate.creole.annic.Constants;
 import gate.creole.annic.Hit;
 import gate.creole.annic.Pattern;
 import gate.creole.annic.PatternAnnotation;
 import gate.creole.annic.SearchException;
 import gate.creole.annic.apache.lucene.index.Term;
-import gate.creole.annic.apache.lucene.search.*;
+import gate.creole.annic.apache.lucene.search.BooleanQuery;
+import gate.creole.annic.apache.lucene.search.Hits;
+import gate.creole.annic.apache.lucene.search.IndexSearcher;
+import gate.creole.annic.apache.lucene.search.PhraseQuery;
+import gate.creole.annic.apache.lucene.search.TermQuery;
 
 public class StatsCalculator {
 
@@ -59,7 +68,7 @@
 
       if(corpusToSearchIn != null) {
         PhraseQuery cq = new PhraseQuery();
-        cq.add(new Term(Constants.CORPUS_ID, corpusToSearchIn), new Integer(0),
+        cq.add(new Term(Constants.CORPUS_ID, corpusToSearchIn), 0,
                 true);
         bq.add(cq, true, false);
         useBooleanQuery = true;
@@ -68,7 +77,7 @@
       if(annotationSetToSearchIn != null) {
         PhraseQuery aq = new PhraseQuery();
         aq.add(new Term(Constants.ANNOTATION_SET_ID, annotationSetToSearchIn),
-                new Integer(0), true);
+                0, true);
         bq.add(aq, true, false);
         useBooleanQuery = true;
       }
@@ -279,11 +288,11 @@
         String uniqueKey = pa.getFeatures().get(feature);
         Integer counter = toReturn.get(uniqueKey);
         if(counter == null) {
-          counter = new Integer(1);
+          counter = 1;
           toReturn.put(uniqueKey, counter);
         }
         else {
-          counter = new Integer(counter.intValue() + 1);
+          counter = counter.intValue() + 1;
           toReturn.put(uniqueKey, counter);
         }
       }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
GATE-cvs mailing list
GATE-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to