Revision: 19452
          http://sourceforge.net/p/gate/code/19452
Author:   ian_roberts
Date:     2016-07-05 16:48:40 +0000 (Tue, 05 Jul 2016)
Log Message:
-----------
Added an option whereby annotations (or documents in document mode) which have 
no values for any of the configured features can be completely omitted from the 
index rather than being indexed as a generic {AnnotationType} instance.  This 
only really makes sense for document-mode helpers, where we might want to index 
features that are only present on some documents and want to avoid creating a 
pssudo-annotation when the feature is missing.

Modified Paths:
--------------
    mimir/trunk/plugins/db-h2/src/gate/mimir/db/DBSemanticAnnotationHelper.java

Modified: 
mimir/trunk/plugins/db-h2/src/gate/mimir/db/DBSemanticAnnotationHelper.java
===================================================================
--- mimir/trunk/plugins/db-h2/src/gate/mimir/db/DBSemanticAnnotationHelper.java 
2016-07-05 01:23:05 UTC (rev 19451)
+++ mimir/trunk/plugins/db-h2/src/gate/mimir/db/DBSemanticAnnotationHelper.java 
2016-07-05 16:48:40 UTC (rev 19452)
@@ -231,6 +231,11 @@
   private static final long serialVersionUID = 2734946594117068194L;
 
   /**
+   * Empty array to return when there are no mention URIs.
+   */
+  private static final String[] EMPTY_STRING_ARRAY = new String[0];
+
+  /**
    * The directory name for the database data (relative to the top level index
    * directory).
    */
@@ -274,6 +279,34 @@
   protected int level1CacheSize = -1;
   protected int level2CacheSize = -1;
   protected int level3CacheSize = -1;
+
+  /**
+   * Should we index "null" instances where all the configured features are
+   * null or missing?  Normally this would be true for a normal annotation-mode
+   * helper but false for a document-mode helper.
+   */
+  protected boolean indexNulls = true;
+
+  /**
+   * Should this helper index "null" instances, where none of the configured
+   * features has a value set in the target (annotation or document) feature
+   * map?  Default is true, both for backwards compatibility and because this
+   * is the only value that makes sense for normal annotation-mode helpers, but
+   * it may be useful to set it to false for document-mode helpers where not
+   * every document has the target feature(s).
+   */
+  public void setIndexNulls(boolean indexNulls) {
+    this.indexNulls = indexNulls;
+  }
+
+  /**
+   * Should this helper index "null" instances, where none of the configured
+   * features has a value set in the target (annotation or document) feature
+   * map?
+   */
+  public boolean isIndexNulls() {
+    return indexNulls;
+  }
   
   /**
    * Prepared statement used to obtain the Level-1 ID based on the values of 
@@ -326,13 +359,11 @@
 
   /**
    * The set of feature names for all the nominal features. 
-   * Only used at search time.
    */
   protected transient Set<String> nominalFeatureNameSet;  
   
   /**
    * The set of feature names for all the non-nominal features. 
-   * Only used at search time.
    */
   protected transient Set<String> nonNominalFeatureNameSet;
   
@@ -707,6 +738,31 @@
     } else {
       featuresToIndex = ann.getFeatures();
     }
+
+    if(!indexNulls) {
+      // we don't want to index instances where all the features are null, so
+      // check to see whether this is the case
+      boolean allFeaturesNull = true;
+      shortCircuit:do {
+        for(String featureName : nominalFeatureNameSet) {
+          if(featuresToIndex.get(featureName) != null) {
+            allFeaturesNull = false;
+            break shortCircuit;
+          }
+        }
+        for(String featureName : nonNominalFeatureNameSet) {
+          if(featuresToIndex.get(featureName) != null) {
+            allFeaturesNull = false;
+            break shortCircuit;
+          }
+        }
+      } while(false);
+
+      // no value found for any of the features, so drop this instance
+      if(allFeaturesNull) {
+        return EMPTY_STRING_ARRAY;
+      }
+    }
     
     try {
       // find the level 1 ID
@@ -740,7 +796,7 @@
     } catch(Exception e) {
       // something went bad: we can't fix it :(
       logger.error("Error while interogating database. Annotation was lost!", 
e);
-      return new String[]{};
+      return EMPTY_STRING_ARRAY;
     }
   }
 

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


------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to