Author: pkluegl
Date: Wed Oct 19 16:10:42 2011
New Revision: 1186298

URL: http://svn.apache.org/viewvc?rev=1186298&view=rev
Log:
UIMA-2268
- added method to remove debug annotation before query

Additionally:
- removed descriptors, using descriptors in engine project now
- removed speed bottleneck when updating the result viewer

Removed:
    
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-addons/src/main/java/org/apache/uima/textmarker/query/ui/BasicEngine.xml
    
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-addons/src/main/java/org/apache/uima/textmarker/query/ui/BasicTypeSystem.xml
    
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-addons/src/main/java/org/apache/uima/textmarker/query/ui/InternalTypeSystem.xml
Modified:
    
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-addons/src/main/java/org/apache/uima/textmarker/query/ui/QueryActionHandler.java

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-addons/src/main/java/org/apache/uima/textmarker/query/ui/QueryActionHandler.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-addons/src/main/java/org/apache/uima/textmarker/query/ui/QueryActionHandler.java?rev=1186298&r1=1186297&r2=1186298&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-addons/src/main/java/org/apache/uima/textmarker/query/ui/QueryActionHandler.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-addons/src/main/java/org/apache/uima/textmarker/query/ui/QueryActionHandler.java
 Wed Oct 19 16:10:42 2011
@@ -37,6 +37,7 @@ import org.apache.uima.cas.FeatureStruct
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.impl.XmiCasDeserializer;
 import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.text.AnnotationIndex;
 import org.apache.uima.jcas.cas.FSArray;
 import org.apache.uima.resource.ResourceManager;
 import org.apache.uima.resource.ResourceSpecifier;
@@ -142,7 +143,7 @@ public class QueryActionHandler implemen
       // script += "TYPESYSTEM " + typeSystemFileText.getText();
       script += rules;
       try {
-        URL aedesc = getClass().getResource("BasicEngine.xml");
+        URL aedesc = TextMarkerEngine.class.getResource("BasicEngine.xml");
         XMLInputSource inae = new XMLInputSource(aedesc);
         ResourceSpecifier specifier = 
UIMAFramework.getXMLParser().parseResourceSpecifier(inae);
         ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();
@@ -213,8 +214,6 @@ public class QueryActionHandler implemen
             cas.setDocumentText(getText(each));
           }
 
-          ae.process(cas);
-
           Type matchedType = cas.getTypeSystem().getType(
                   "org.apache.uima.textmarker.type.DebugMatchedRuleMatch");
           Type ruleApplyType = cas.getTypeSystem().getType(
@@ -222,6 +221,10 @@ public class QueryActionHandler implemen
           Type blockApplyType = cas.getTypeSystem().getType(
                   "org.apache.uima.textmarker.type.DebugBlockApply");
 
+          removeDebugAnnotations(cas, matchedType, ruleApplyType, 
blockApplyType);
+
+          ae.process(cas);
+
           Feature innerApplyFeature = 
blockApplyType.getFeatureByBaseName("innerApply");
           Feature ruleApplyFeature = 
blockApplyType.getFeatureByBaseName("rules");
           FSIterator<AnnotationFS> iterator = 
cas.getAnnotationIndex(blockApplyType).iterator();
@@ -241,12 +244,14 @@ public class QueryActionHandler implemen
 
             final int constFound = found;
             final int constFiles = files;
-            queryComposite.getDisplay().asyncExec(new Runnable() {
+            queryComposite.getDisplay().syncExec(new Runnable() {
               @Override
               public void run() {
+                queryComposite.setResult(result);
                 queryComposite.setResultInfo(constFound, constFiles);
               }
             });
+
           }
 
           monitor.worked(1);
@@ -261,6 +266,26 @@ public class QueryActionHandler implemen
 
     }
 
+    private void removeDebugAnnotations(CAS cas, Type matchedType, Type 
ruleApplyType,
+            Type blockApplyType) {
+      Collection<AnnotationFS> toRemove = new ArrayList<AnnotationFS>();
+      AnnotationIndex<AnnotationFS> annotationIndex = 
cas.getAnnotationIndex(blockApplyType);
+      for (AnnotationFS annotationFS : annotationIndex) {
+        toRemove.add(annotationFS);
+      }
+      annotationIndex = cas.getAnnotationIndex(ruleApplyType);
+      for (AnnotationFS annotationFS : annotationIndex) {
+        toRemove.add(annotationFS);
+      }
+      annotationIndex = cas.getAnnotationIndex(matchedType);
+      for (AnnotationFS annotationFS : annotationIndex) {
+        toRemove.add(annotationFS);
+      }
+      for (AnnotationFS annotationFS : toRemove) {
+        cas.removeFsFromIndexes(annotationFS);
+      }
+    }
+
     public int findRuleMatches(final List<QueryResult> result, AnnotationFS 
fs, File file,
             final QueryComposite queryComposite, Type matchedType, Type 
ruleApplyType,
             Type blockApplyType, Feature innerApplyFeature, Feature 
ruleApplyFeature) {
@@ -285,12 +310,6 @@ public class QueryActionHandler implemen
         String text = fs.getCoveredText();
         result.add(new QueryResult(text, file));
         ret += 1;
-        queryComposite.getDisplay().asyncExec(new Runnable() {
-          @Override
-          public void run() {
-            queryComposite.setResult(result);
-          }
-        });
 
       }
       return ret;


Reply via email to