Revision: 16583
          http://sourceforge.net/p/gate/code/16583
Author:   valyt
Date:     2013-03-12 13:07:53 +0000 (Tue, 12 Mar 2013)
Log Message:
-----------
Removed no-op class AbstractTermsQuery.

More default stop-words: single digits and letters.

Added support for multiple strategies when combining counts from multiple 
sub-queries.

Modified Paths:
--------------
    
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractCompoundTermsQuery.java
    
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractDocumentsBasedTermsQuery.java
    
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractIndexTermsQuery.java
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/AndTermsQuery.java
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/LimitTermsQuery.java
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/OrTermsQuery.java
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/SortedTermsQuery.java
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermTypeTermsQuery.java

Removed Paths:
-------------
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractTermsQuery.java

Modified: 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractCompoundTermsQuery.java
===================================================================
--- 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractCompoundTermsQuery.java
  2013-03-12 12:58:32 UTC (rev 16582)
+++ 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractCompoundTermsQuery.java
  2013-03-12 13:07:53 UTC (rev 16583)
@@ -23,10 +23,46 @@
  * Abstract base class for {@link TermQuery} implementations that wrap a group
  * of {@link TermQuery} sub-queries.
  */
-public abstract class AbstractCompoundTermsQuery extends AbstractTermsQuery 
-    implements CompoundTermsQuery{
+public abstract class AbstractCompoundTermsQuery implements CompoundTermsQuery{
 
   /**
+   * Enum describing different ways term counts can be calculated for a 
compound
+   * terms query.
+   * 
+   * A compound terms query produces its result set by combining the result 
sets
+   * from a set of constituent sub-queries. When each of the sub-queries 
+   * supplies potentially different counts for the same term, different
+   * strategies can be employed for deriving the output term count for the 
+   * compound query.
+   */
+  public static enum CompoundCountsStrategy {
+    
+    /**
+     * The output count is the count from the first sub-query found to supply 
a 
+     * count for each output term.
+     */
+    FIRST,
+  
+    /**
+     * The output count is the maximum count from all of the sub-queries for 
+     * each output term.
+     */
+    MAX, 
+  
+    /**
+     * The output count is the minimum count from all of the sub-queries for 
+     * each output term.
+     */    
+    MIN,
+    
+    /**
+     * The output count is the sum of the counts from all of the sub-queries 
for 
+     * each output term.
+     */
+    SUM
+  }
+
+  /**
    * The wrapped wrappedQuery
    */
   protected TermsQuery[] subQueries;
@@ -62,4 +98,66 @@
     }
     return combine(resSets);
   }
+
+  protected AbstractCompoundTermsQuery.CompoundCountsStrategy countsStrategy;  
+  
+  /**
+   * Gets the current counts strategy. See 
+   * {@link #setCountsStrategy(CompoundCountsStrategy)} for more details.
+   * @return the countsStrategy
+   */
+  public AbstractCompoundTermsQuery.CompoundCountsStrategy getCountsStrategy() 
{
+    return countsStrategy;
+  }
+
+  /**
+   * A compound terms query produces its result set by combining the result 
sets
+   * from a set of constituent sub-queries. When each of the sub-queries 
+   * supplies potentially different counts for the same term, different
+   * strategies can be employed for deriving the output term count for the 
+   * compound query. This method can be used to set what strategy should be 
used
+   * when generating output counts.
+   *  
+   * @param countsStrategy the countsStrategy to set
+   */
+  public void 
setCountsStrategy(AbstractCompoundTermsQuery.CompoundCountsStrategy 
countsStrategy) {
+    this.countsStrategy = countsStrategy;
+  }
+
+  /**
+   * Given an array of counts, compute the output count taking into account the
+   * provided {@link #countsStrategy}.
+   * @param counts an array of count values. Zero and negative values are 
+   * ignored (interpreted as count not available).
+   * @param countsStrategy the chosen counts strategy.
+   * @return the computed output count.
+   */
+  protected static int computeCompoundCount(final int[] counts,
+      final CompoundCountsStrategy countsStrategy) {
+    int count = 0;
+    counts:for(int aCount : counts) {
+      if(aCount > 0) {
+        switch(countsStrategy){
+          case FIRST:
+            if(count <= 0) count = aCount;
+            break counts;
+          case MAX:
+            if(aCount > count) count = aCount;
+            break;
+          case MIN:
+            if(aCount < count) count = aCount;
+            break;
+          case SUM:
+            count += aCount;
+            break;
+          default:
+            throw new IllegalArgumentException("Unknown count strategy " + 
+                countsStrategy.toString());
+        }
+      }
+    }
+    return count;
+  }
+  
+
 }

Modified: 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractDocumentsBasedTermsQuery.java
===================================================================
--- 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractDocumentsBasedTermsQuery.java
    2013-03-12 12:58:32 UTC (rev 16582)
+++ 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractDocumentsBasedTermsQuery.java
    2013-03-12 13:07:53 UTC (rev 16583)
@@ -20,7 +20,7 @@
  * search. 
  */
 public abstract class AbstractDocumentsBasedTermsQuery 
-    extends AbstractTermsQuery implements DocumentsBasedTermsQuery {
+    implements DocumentsBasedTermsQuery {
 
   /**
    * Serialization ID.

Modified: 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractIndexTermsQuery.java
===================================================================
--- 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractIndexTermsQuery.java 
    2013-03-12 12:58:32 UTC (rev 16582)
+++ 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractIndexTermsQuery.java 
    2013-03-12 13:07:53 UTC (rev 16583)
@@ -41,7 +41,9 @@
    */
   private static final long serialVersionUID = 8382919427152317859L;
 
-  private static final Logger logger = 
Logger.getLogger(AbstractIndexTermsQuery.class);
+  private static final Logger logger = Logger
+    .getLogger(AbstractIndexTermsQuery.class);
+
   /**
    * The name of the subindex in which the terms are sought. Each Mímir index
    * includes multiple sub-indexes (some storing tokens, other storing
@@ -111,47 +113,50 @@
    */
   public static final String[] DEFAULT_STOP_WORDS = new String[]{",", ".", "?",
     "!", ":", ";", "#", "~", "^", "@", "%", "&", "(", ")", "[", "]", "{", "}",
-    "|", "\\", "<", ">", "-", "+", "*", "/", "=", "a", "about", "above",
-    "above", "across", "after", "afterwards", "again", "against", "all",
-    "almost", "alone", "along", "already", "also", "although", "always", "am",
-    "among", "amongst", "amoungst", "amount", "an", "and", "another", "any",
-    "anyhow", "anyone", "anything", "anyway", "anywhere", "are", "around",
-    "as", "at", "back", "be", "became", "because", "become", "becomes",
-    "becoming", "been", "before", "beforehand", "behind", "being", "below",
-    "beside", "besides", "between", "beyond", "bill", "both", "bottom", "but",
-    "by", "call", "can", "cannot", "cant", "co", "con", "could", "couldnt",
-    "cry", "de", "describe", "detail", "do", "done", "down", "due", "during",
-    "each", "eg", "eight", "either", "eleven", "else", "elsewhere", "empty",
-    "enough", "etc", "even", "ever", "every", "everyone", "everything",
-    "everywhere", "except", "few", "fifteen", "fify", "fill", "find", "fire",
-    "first", "five", "for", "former", "formerly", "forty", "found", "four",
-    "from", "front", "full", "further", "get", "give", "go", "had", "has",
-    "hasnt", "have", "he", "hence", "her", "here", "hereafter", "hereby",
-    "herein", "hereupon", "hers", "herself", "him", "himself", "his", "how",
-    "however", "hundred", "ie", "if", "in", "inc", "indeed", "interest",
-    "into", "is", "it", "its", "itself", "keep", "last", "latter", "latterly",
-    "least", "less", "ltd", "made", "many", "may", "me", "meanwhile", "might",
-    "mill", "mine", "more", "moreover", "most", "mostly", "move", "much",
-    "must", "my", "myself", "name", "namely", "neither", "never",
-    "nevertheless", "next", "nine", "no", "nobody", "none", "noone", "nor",
-    "not", "nothing", "now", "nowhere", "of", "off", "often", "on", "once",
-    "one", "only", "onto", "or", "other", "others", "otherwise", "our", "ours",
-    "ourselves", "out", "over", "own", "part", "per", "perhaps", "please",
-    "put", "rather", "re", "same", "see", "seem", "seemed", "seeming", "seems",
-    "serious", "several", "she", "should", "show", "side", "since", "sincere",
-    "six", "sixty", "so", "some", "somehow", "someone", "something",
-    "sometime", "sometimes", "somewhere", "still", "such", "system", "take",
-    "ten", "than", "that", "the", "their", "them", "themselves", "then",
-    "thence", "there", "thereafter", "thereby", "therefore", "therein",
+    "|", "\\", "<", ">", "-", "+", "*", "/", "=", "'", "\"", "'s", "1", "2",
+    "3", "4", "5", "6", "7", "8", "9", "0", "a", "about", "above", "above",
+    "across", "after", "afterwards", "again", "against", "all", "almost",
+    "alone", "along", "already", "also", "although", "always", "am", "among",
+    "amongst", "amoungst", "amount", "an", "and", "another", "any", "anyhow",
+    "anyone", "anything", "anyway", "anywhere", "are", "around", "as", "at",
+    "b", "back", "be", "became", "because", "become", "becomes", "becoming",
+    "been", "before", "beforehand", "behind", "being", "below", "beside",
+    "besides", "between", "beyond", "bill", "both", "bottom", "but", "by", "c",
+    "call", "can", "cannot", "cant", "co", "con", "could", "couldnt", "cry",
+    "d", "de", "describe", "detail", "do", "done", "down", "due", "during",
+    "e", "each", "eg", "eight", "either", "eleven", "else", "elsewhere",
+    "empty", "enough", "etc", "even", "ever", "every", "everyone",
+    "everything", "everywhere", "except", "f", "few", "fifteen", "fify",
+    "fill", "find", "fire", "first", "five", "for", "former", "formerly",
+    "forty", "found", "four", "from", "front", "full", "further", "g", "get",
+    "give", "go", "h", "had", "has", "hasnt", "have", "he", "hence", "her",
+    "here", "hereafter", "hereby", "herein", "hereupon", "hers", "herself",
+    "him", "himself", "his", "how", "however", "hundred", "i", "ie", "if",
+    "in", "inc", "indeed", "interest", "into", "is", "it", "its", "itself",
+    "j", "k", "keep", "l", "last", "latter", "latterly", "least", "less",
+    "ltd", "m", "made", "many", "may", "me", "meanwhile", "might", "mill",
+    "mine", "more", "moreover", "most", "mostly", "move", "much", "must", "my",
+    "myself", "n", "name", "namely", "neither", "never", "nevertheless",
+    "next", "nine", "no", "nobody", "none", "noone", "nor", "not", "nothing",
+    "now", "nowhere", "o", "of", "off", "often", "on", "once", "one", "only",
+    "onto", "or", "other", "others", "otherwise", "our", "ours", "ourselves",
+    "out", "over", "own", "p", "part", "per", "perhaps", "please", "put", "q",
+    "r", "rather", "re", "s", "same", "see", "seem", "seemed", "seeming",
+    "seems", "serious", "several", "she", "should", "show", "side", "since",
+    "sincere", "six", "sixty", "so", "some", "somehow", "someone", "something",
+    "sometime", "sometimes", "somewhere", "still", "such", "system", "t",
+    "take", "ten", "than", "that", "the", "their", "them", "themselves",
+    "then", "thence", "there", "thereafter", "thereby", "therefore", "therein",
     "thereupon", "these", "they", "thickv", "thin", "third", "this", "those",
     "though", "three", "through", "throughout", "thru", "thus", "to",
     "together", "too", "top", "toward", "towards", "twelve", "twenty", "two",
-    "un", "under", "until", "up", "upon", "us", "very", "via", "was", "we",
-    "well", "were", "what", "whatever", "when", "whence", "whenever", "where",
-    "whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever",
-    "whether", "which", "while", "whither", "who", "whoever", "whole", "whom",
-    "whose", "why", "will", "with", "within", "without", "would", "yet", "you",
-    "your", "yours", "yourself", "yourselves"};
+    "u", "un", "under", "until", "up", "upon", "us", "v", "very", "via", "w",
+    "was", "we", "well", "were", "what", "whatever", "when", "whence",
+    "whenever", "where", "whereafter", "whereas", "whereby", "wherein",
+    "whereupon", "wherever", "whether", "which", "while", "whither", "who",
+    "whoever", "whole", "whom", "whose", "why", "will", "with", "within",
+    "without", "would", "x", "y", "yet", "you", "your", "yours", "yourself",
+    "yourselves", "z"};
 
   /**
    * @param indexName
@@ -170,7 +175,7 @@
    *          URIs whose format depends on the actual implementation of the
    *          index. These strings make little sense outside of the index. If
    *          this is set to <code>true</code>, then term descriptions are also
-   *          included in the results set. See 
+   *          included in the results set. See
    *          {@link TermsResultSet#termDescriptions} and
    *          {@link SemanticAnnotationHelper#describeMention(String)}. Setting
    *          this to <code>true</code> has no effect if the index being
@@ -184,8 +189,8 @@
     this.indexName = indexName;
     this.indexType = indexType;
     this.countsEnabled = countsEnabled;
-    this.describeAnnotations = describeAnnotations && 
-        (indexType == IndexType.ANNOTATIONS);
+    this.describeAnnotations =
+      describeAnnotations && (indexType == IndexType.ANNOTATIONS);
   }
 
   /**
@@ -226,8 +231,8 @@
     throws IOException {
     // prepare local data
     ObjectArrayList<String> termStrings = new ObjectArrayList<String>();
-    ObjectArrayList<String> termDescriptions = describeAnnotations ? 
-        new ObjectArrayList<String>() : null;
+    ObjectArrayList<String> termDescriptions =
+      describeAnnotations ? new ObjectArrayList<String>() : null;
     IntArrayList termCounts = countsEnabled ? new IntArrayList() : null;
     TermCollectionVisitor termCollectionVisitor = null;
     CounterSetupVisitor counterSetupVisitor = null;
@@ -258,10 +263,11 @@
       }
       String termString = null;
       // get the term string
-      try{
+      try {
         termString = indirectIndexPool.getTerm(termId);
-      } catch (Exception e) {
-        System.err.println("Error reading indirect index term with ID " + 
termId);
+      } catch(Exception e) {
+        System.err.println("Error reading indirect index term with ID " +
+          termId);
         e.printStackTrace();
         termId = documentIterator.nextDocument();
         continue terms;
@@ -278,10 +284,9 @@
           continue terms;
         }
         if(describeAnnotations) {
-          termDescriptions.add(annotationHelper.describeMention(termString));  
+          termDescriptions.add(annotationHelper.describeMention(termString));
         }
       }
-
       termStrings.add(termString);
       if(countsEnabled) {
         termCounts.add(termCount);
@@ -289,12 +294,12 @@
       termId = documentIterator.nextDocument();
     }
     // construct the result
-    TermsResultSet res = new TermsResultSet(
-      termStrings.toArray(new String[termStrings.size()]),
-      null, 
-      countsEnabled ? termCounts.toIntArray() : null,
-      describeAnnotations ? 
-        termDescriptions.toArray(new String[termDescriptions.size()]) : null);
+    TermsResultSet res =
+      new TermsResultSet(termStrings.toArray(new String[termStrings.size()]),
+        null, countsEnabled ? termCounts.toIntArray() : null,
+        describeAnnotations
+          ? termDescriptions.toArray(new String[termDescriptions.size()])
+          : null);
     if(describeAnnotations) res = TermsResultSet.groupByDescription(res);
     return res;
   }
@@ -350,5 +355,4 @@
     for(String sw : stopWords)
       this.stopWords.add(sw);
   }
-
 }

Deleted: 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractTermsQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractTermsQuery.java  
2013-03-12 12:58:32 UTC (rev 16582)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractTermsQuery.java  
2013-03-12 13:07:53 UTC (rev 16583)
@@ -1,42 +0,0 @@
-/*
- *  AbstractTermsQuery.java
- *
- *  Copyright (c) 2007-2011, The University of Sheffield.
- *
- *  This file is part of GATE Mímir (see http://gate.ac.uk/family/mimir.html), 
- *  and is free software, licenced under the GNU Lesser General Public License,
- *  Version 3, June 2007 (also included with this distribution as file
- *  LICENCE-LGPL3.html).
- *
- *  Valentin Tablan, 13 Jul 2012
- *
- *  $Id$
- */
-package gate.mimir.search.terms;
-
-import java.io.IOException;
-
-import gate.mimir.search.QueryEngine;
-
-
-/**
- * Base class for term queries.
- */
-public abstract class AbstractTermsQuery implements TermsQuery{
-  
-  /**
-   * Serialization ID.
-   */
-  private static final long serialVersionUID = -8448110711378800097L;
-  
-  public AbstractTermsQuery() {
-  }
-  
-  
-  
-  @Override
-  public TermsResultSet execute(QueryEngine engine) throws IOException {
-    // TODO Auto-generated method stub
-    return null;
-  }
-}

Modified: mimir/trunk/mimir-core/src/gate/mimir/search/terms/AndTermsQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/AndTermsQuery.java       
2013-03-12 12:58:32 UTC (rev 16582)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/AndTermsQuery.java       
2013-03-12 13:07:53 UTC (rev 16583)
@@ -14,6 +14,7 @@
  */
 package gate.mimir.search.terms;
 
+import 
gate.mimir.search.terms.AbstractCompoundTermsQuery.CompoundCountsStrategy;
 import it.unimi.dsi.fastutil.Arrays;
 import it.unimi.dsi.fastutil.Swapper;
 import it.unimi.dsi.fastutil.ints.IntArrayList;
@@ -22,6 +23,8 @@
 
 /**
  * Performs Boolean AND between multiple {@link TermsQuery} instances.
+ * The default count strategy used is 
+ * {@link AbstractCompoundTermsQuery.CompoundCountsStrategy#FIRST}.
  */
 public class AndTermsQuery extends AbstractCompoundTermsQuery {
   
@@ -42,6 +45,7 @@
    */
   public AndTermsQuery(TermsQuery... subQueries) {
     super(subQueries);
+    setCountsStrategy(AbstractCompoundTermsQuery.CompoundCountsStrategy.FIRST);
   }
   
   /* (non-Javadoc)
@@ -49,10 +53,12 @@
    */
   @Override
   public TermsResultSet combine(TermsResultSet... resSets) {
-    return andResultSets(resSets);
+    return andResultSets(resSets, countsStrategy);
   }
 
-  public static TermsResultSet andResultSets(final TermsResultSet[] resSets) {
+  public static TermsResultSet andResultSets(final TermsResultSet[] resSets,
+      AbstractCompoundTermsQuery.CompoundCountsStrategy countsStrategy) {
+    if(countsStrategy == null) countsStrategy = 
AbstractCompoundTermsQuery.CompoundCountsStrategy.FIRST;
     boolean lengthsAvailable = false;
     boolean countsAvailable = true;
     boolean descriptionsAvaialble = false;
@@ -71,25 +77,28 @@
       // all sub-queries must provide counts, for us to be able to
       if(resSets[i].termCounts == null) countsAvailable = false;
     }
-    // optimisation: sort sub-runners by increasing sizes
-    Arrays.quickSort(0, resSets.length, new IntComparator() {
-      @Override
-      public int compare(Integer o1, Integer o2) { 
-        return compare(o1.intValue(), o2.intValue());
-      }
-      @Override
-      public int compare(int k1, int k2) {
-        return resSets[k1].termStrings.length - 
resSets[k2].termStrings.length; 
-      }
-    }, new Swapper() {
-      @Override
-      public void swap(int a, int b) {
-        TermsResultSet trs = resSets[a];
-        resSets[a] = resSets[b];
-        resSets[b] = trs;
-      }
-    });
-    
+    if(!countsAvailable || countsStrategy != 
AbstractCompoundTermsQuery.CompoundCountsStrategy.FIRST) {
+      // the sorting of sub-queries is irrelevant
+      // optimisation: sort sub-runners by increasing sizes
+      Arrays.quickSort(0, resSets.length, new IntComparator() {
+        @Override
+        public int compare(Integer o1, Integer o2) { 
+          return compare(o1.intValue(), o2.intValue());
+        }
+        @Override
+        public int compare(int k1, int k2) {
+          return resSets[k1].termStrings.length - 
resSets[k2].termStrings.length; 
+        }
+      }, new Swapper() {
+        @Override
+        public void swap(int a, int b) {
+          TermsResultSet trs = resSets[a];
+          resSets[a] = resSets[b];
+          resSets[b] = trs;
+        }
+      });      
+    }
+
     // prepare local data
     ObjectArrayList<String> termStrings = new ObjectArrayList<String>();
     ObjectArrayList<String> termDescriptions = descriptionsAvaialble ? 
@@ -114,13 +123,12 @@
         termStrings.add(termString);
         // calculate the term count
         if(countsAvailable) {
-          int count = 0;
+          int[] counts = new int[resSets.length];
           for(int i = 0; i < resSets.length; i++) {
-            if(resSets[i].termCounts != null) {
-              count += resSets[i].termCounts[indexes[i]];
-            }
+            counts[i] = (resSets[i].termCounts != null) ? 
+              (resSets[i].termCounts[indexes[i]]): -1;
           }
-          termCounts.add(count);
+          
termCounts.add(AbstractCompoundTermsQuery.computeCompoundCount(counts, 
countsStrategy));
         }
         // calculate the term length
         if(lengthsAvailable) {

Modified: 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java
===================================================================
--- 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java    
    2013-03-12 12:58:32 UTC (rev 16582)
+++ 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java    
    2013-03-12 13:07:53 UTC (rev 16583)
@@ -32,7 +32,7 @@
  * Given an {@link AnnotationQuery}, this finds the set of terms that satisfy 
  * it.
  */
-public class AnnotationTermsQuery extends AbstractTermsQuery {
+public class AnnotationTermsQuery implements TermsQuery {
   
   /**
    * Serialization ID.

Modified: 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/LimitTermsQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/LimitTermsQuery.java     
2013-03-12 12:58:32 UTC (rev 16582)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/LimitTermsQuery.java     
2013-03-12 13:07:53 UTC (rev 16583)
@@ -84,4 +84,13 @@
       return trs;  
     }
   }
+
+
+  /**
+   * This method has no effect, as the number of sub-queries is always 1.
+   */
+  @Override
+  public void 
setCountsStrategy(AbstractCompoundTermsQuery.CompoundCountsStrategy 
countsStrategy) {
+    super.setCountsStrategy(countsStrategy);
+  }
 }

Modified: mimir/trunk/mimir-core/src/gate/mimir/search/terms/OrTermsQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/OrTermsQuery.java        
2013-03-12 12:58:32 UTC (rev 16582)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/OrTermsQuery.java        
2013-03-12 13:07:53 UTC (rev 16583)
@@ -20,6 +20,8 @@
 
 /**
  * Boolean OR operator for term queries.
+ * The default count strategy used is 
+ * {@link AbstractCompoundTermsQuery.CompoundCountsStrategy#FIRST}. 
  */
 public class OrTermsQuery extends AbstractCompoundTermsQuery {
   
@@ -40,6 +42,7 @@
    */
   public OrTermsQuery(TermsQuery... subQueries) {
     super(subQueries);
+    setCountsStrategy(AbstractCompoundTermsQuery.CompoundCountsStrategy.FIRST);
   }
   
   /* (non-Javadoc)
@@ -47,7 +50,7 @@
    */
   @Override
   public TermsResultSet combine(TermsResultSet... resSets) {
-    return orResultsSets(resSets);
+    return orResultsSets(resSets, countsStrategy);
   }
 
   /**
@@ -57,7 +60,9 @@
    * @param resSets 
    * @return
    */
-  public static TermsResultSet orResultsSets(TermsResultSet... resSets) {
+  public static TermsResultSet orResultsSets(TermsResultSet[] resSets, 
+      AbstractCompoundTermsQuery.CompoundCountsStrategy countsStrategy) {
+    if(countsStrategy == null) countsStrategy = 
AbstractCompoundTermsQuery.CompoundCountsStrategy.FIRST;
     String[] currentTerm = new String[resSets.length];
     ObjectHeapSemiIndirectPriorityQueue<String> queue = 
         new ObjectHeapSemiIndirectPriorityQueue<String>(currentTerm);
@@ -109,12 +114,12 @@
       if(countsAvailable) {
         // sum all counts
         int frontSize = queue.front(front);
-        int count = 0;
+        int[] counts = new int[frontSize];
         for(int i = 0;  i < frontSize; i++) {
           int subRunnerId = front[i];
-          count += resSets[subRunnerId].termCounts[termIndex[subRunnerId]];
+          counts[i]= resSets[subRunnerId].termCounts[termIndex[subRunnerId]];
         }
-        termCounts.add(count);
+        termCounts.add(AbstractCompoundTermsQuery.computeCompoundCount(counts, 
countsStrategy));
       }
       // consume all equal terms
       while(resSets[first].termStrings[termIndex[first]].equals(termString)) {

Modified: 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/SortedTermsQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/SortedTermsQuery.java    
2013-03-12 12:58:32 UTC (rev 16582)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/SortedTermsQuery.java    
2013-03-12 13:07:53 UTC (rev 16583)
@@ -14,6 +14,7 @@
  */
 package gate.mimir.search.terms;
 
+import 
gate.mimir.search.terms.AbstractCompoundTermsQuery.CompoundCountsStrategy;
 import it.unimi.dsi.fastutil.Arrays;
 import it.unimi.dsi.fastutil.ints.IntComparator;
 
@@ -148,4 +149,12 @@
     }, new TermsResultSet.Swapper(trs));
     return trs;
   }
+  
+  /**
+   * This method has no effect, as the number of sub-queries is always 1.
+   */
+  @Override
+  public void 
setCountsStrategy(AbstractCompoundTermsQuery.CompoundCountsStrategy 
countsStrategy) {
+    super.setCountsStrategy(countsStrategy);
+  }  
 }

Modified: 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermTypeTermsQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermTypeTermsQuery.java  
2013-03-12 12:58:32 UTC (rev 16582)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermTypeTermsQuery.java  
2013-03-12 13:07:53 UTC (rev 16583)
@@ -32,7 +32,7 @@
  * A {@link TermsQuery} that enumerates all terms of a given type. The type of
  * a term is the name of a token feature, or an annotation type. 
  */
-public class TermTypeTermsQuery extends AbstractTermsQuery {
+public class TermTypeTermsQuery implements TermsQuery {
 
   
   /**

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


------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to