Revision: 14750
          http://gate.svn.sourceforge.net/gate/?rev=14750&view=rev
Author:   nirajaswani
Date:     2011-12-12 17:13:25 +0000 (Mon, 12 Dec 2011)
Log Message:
-----------
added two parameters segmentAnnotationFeatureName and 
segmentAnnotationFeatureValue. User can now specify an annotation type with a 
constraint on feature name and feature value and the segment PR will only run 
PR or Pipeline on a section that satisfies the constraint. The two parameters 
are optional.  Also the PR now accepts LanguageAnalyser instead of 
CorpusController

Modified Paths:
--------------
    gate/trunk/plugins/Alignment/creole.xml
    
gate/trunk/plugins/Alignment/src/gate/composite/impl/SegmentProcessingPR.java

Modified: gate/trunk/plugins/Alignment/creole.xml
===================================================================
--- gate/trunk/plugins/Alignment/creole.xml     2011-12-12 17:06:17 UTC (rev 
14749)
+++ gate/trunk/plugins/Alignment/creole.xml     2011-12-12 17:13:25 UTC (rev 
14750)
@@ -116,8 +116,10 @@
          COMMENT="The document to be processed"  
          RUNTIME="true">gate.Document</PARAMETER>  
       <PARAMETER NAME="segmentAnnotationType" RUNTIME="true" 
DEFAULT="Section">java.lang.String</PARAMETER>
+      <PARAMETER NAME="segmentAnnotationFeatureName" RUNTIME="true" 
OPTIONAL="true">java.lang.String</PARAMETER>
+      <PARAMETER NAME="segmentAnnotationFeatureValue" RUNTIME="true" 
OPTIONAL="true">java.lang.String</PARAMETER>
       <PARAMETER NAME="inputASName" RUNTIME="true" 
OPTIONAL="true">java.lang.String</PARAMETER>
-      <PARAMETER NAME="controller" 
RUNTIME="true">gate.CorpusController</PARAMETER>
+      <PARAMETER NAME="analyser" 
RUNTIME="true">gate.LanguageAnalyser</PARAMETER>
       <ICON>pr.gif</ICON>
     </RESOURCE>
   </CREOLE>

Modified: 
gate/trunk/plugins/Alignment/src/gate/composite/impl/SegmentProcessingPR.java
===================================================================
--- 
gate/trunk/plugins/Alignment/src/gate/composite/impl/SegmentProcessingPR.java   
    2011-12-12 17:06:17 UTC (rev 14749)
+++ 
gate/trunk/plugins/Alignment/src/gate/composite/impl/SegmentProcessingPR.java   
    2011-12-12 17:13:25 UTC (rev 14750)
@@ -7,6 +7,7 @@
 import gate.Factory;
 import gate.FeatureMap;
 import gate.Gate;
+import gate.LanguageAnalyser;
 import gate.ProcessingResource;
 import gate.Resource;
 import gate.composite.CombiningMethod;
@@ -17,6 +18,7 @@
 import gate.creole.AbstractLanguageAnalyser;
 import gate.creole.ExecutionException;
 import gate.creole.ResourceInstantiationException;
+import gate.util.GateRuntimeException;
 import gate.util.OffsetComparator;
 import gate.util.Out;
 
@@ -27,24 +29,22 @@
 import java.util.Map;
 
 /**
- * As the name suggests, the PR is useful processing segments of the
- * text. Given a controller, annotation type and a document, this PR
- * creates a composite documents for every annotation with type as
- * specified by the <annotation type>. Since the composite documents are
- * linked with their original documents, when the PR processing the
- * composite document, the composite document takes care of transferring
- * relevant annotations back to the original document. This is a good
- * way of processing just a segment of a document.
+ * As the name suggests, the PR is useful processing segments of the text. 
Given
+ * a analyser, annotation type and a document, this PR creates a composite
+ * documents for every annotation with type as specified by the <annotation
+ * type>. Since the composite documents are linked with their original
+ * documents, when the PR processing the composite document, the composite
+ * document takes care of transferring relevant annotations back to the 
original
+ * document. This is a good way of processing just a segment of a document.
  * 
  * @author niraj
  */
 public class SegmentProcessingPR extends AbstractLanguageAnalyser implements
                                                                  
ProcessingResource {
-
   /**
    * Controller that should be used to process segments.
    */
-  private CorpusController controller;
+  private LanguageAnalyser analyser;
 
   /**
    * annotation type that the segment is annotated with.
@@ -52,14 +52,28 @@
   private String segmentAnnotationType;
 
   /**
-   * Annotation set that contains the segment annotation and the
-   * annotations to be copied to the composite document.
+   * Only the annotation that has the specified feature should be considered 
for
+   * annotating.
    */
+  private String segmentAnnotationFeatureName;
+
+  /**
+   * Only the annotation that has the feature specified as
+   * segmentAnnotationFeatureName with the value of
+   * segmentAnnotaitonFeatureValue then only the annotation is considered for
+   * annotating.
+   */
+  private String segmentAnnotationFeatureValue;
+
+  /**
+   * Annotation set that contains the segment annotation and the annotations to
+   * be copied to the composite document.
+   */
   private String inputASName;
 
   /**
-   * Used internally - this is the document that will be used for
-   * holding the original document and the composite documents.
+   * Used internally - this is the document that will be used for holding the
+   * original document and the composite documents.
    */
   private CompoundDocument compoundDoc;
 
@@ -76,7 +90,6 @@
     // annotation as identified by the annotation id
     combiningMethodInst = new CombineFromAnnotID();
     compoundDoc = new CompoundDocumentImpl();
-
     // initializing an empty compound document
     compoundDoc.init();
     return this;
@@ -93,101 +106,95 @@
    */
   public void execute() throws ExecutionException {
     // if no document provided
-    if(document == null) {
-      throw new ExecutionException("Document is null!");
-    }
-
+    if(document == null) { throw new ExecutionException("Document is null!"); }
     // annotation set to use
-    AnnotationSet set = inputASName == null || inputASName.trim().length() == 0
-            ? document.getAnnotations()
-            : document.getAnnotations(inputASName);
-
+    AnnotationSet set =
+        inputASName == null || inputASName.trim().length() == 0 ? document
+            .getAnnotations() : document.getAnnotations(inputASName);
     AnnotationSet segmentSet = set.get(segmentAnnotationType);
     if(set.isEmpty()) {
-      Out.prln("Could not find annotations of type: " +  segmentAnnotationType 
+
-        " in the document: " + document.getName());
+      Out.prln("Could not find annotations of type: " + segmentAnnotationType
+          + " in the document: " + document.getName());
       return;
     }
-
     String originalDocument = document.getName();
-
     if(document instanceof CompoundDocument) {
       if(debug) {
         System.out
-                .println("Document is a compound document and using the 
memeber \""
-                        + document.getName() + "\" for processing");
+            .println("Document is a compound document and using the memeber \""
+                + document.getName() + "\" for processing");
       }
-      compoundDoc.addDocument(document.getName(), ((CompoundDocument)document)
-              .getCurrentDocument());
-    }
-    else {
+      compoundDoc.addDocument(document.getName(),
+          ((CompoundDocument)document).getCurrentDocument());
+    } else {
       if(debug) {
         System.out.println("Document is a normal GATE document with name \""
-                + document.getName() + "\"");
+            + document.getName() + "\"");
       }
-
       // add the current document as a member of the compound document
       compoundDoc.addDocument(document.getName(), document);
     }
-
     Corpus tempCorpus = null;
-
     try {
       Map<String, Object> map = new HashMap<String, Object>();
       map.put(CombineFromAnnotID.INPUT_AS_NAME_FEATURE_NAME, inputASName);
       map.put(CombineFromAnnotID.DOCUMENT_ID_FEATURE_NAME, document.getName());
       FeatureMap hideMap = Factory.newFeatureMap();
       Gate.setHiddenAttribute(hideMap, true);
-      tempCorpus = (Corpus)Factory.createResource("gate.corpora.CorpusImpl",
+      tempCorpus =
+          (Corpus)Factory.createResource("gate.corpora.CorpusImpl",
               Factory.newFeatureMap(), hideMap, "compoundDocCorpus");
       tempCorpus.add(compoundDoc);
-      controller.setCorpus(tempCorpus);
+      analyser.setDocument(compoundDoc);
+      analyser.setCorpus(tempCorpus);
       List<Annotation> segmentList = new ArrayList<Annotation>(segmentSet);
       Collections.sort(segmentList, new OffsetComparator());
       for(Annotation annotation : segmentList) {
-
         if(debug) {
           System.out.println("Processing annotation" + annotation.getType()
-                  + "=>" + annotation.getId());
+              + "=>" + annotation.getId());
         }
+        // only consider the annotation if it has a specific feature and a 
value
+        if(segmentAnnotationFeatureName != null
+            && segmentAnnotationFeatureName.length() != 0
+            && segmentAnnotationFeatureValue != null
+            && segmentAnnotationFeatureValue.length() != 0) {
+          Object value =
+              annotation.getFeatures().get(segmentAnnotationFeatureName);
+          if(value == null || !value.equals(segmentAnnotationFeatureValue)) {
+            continue;
+          }
+        }
         String nameForCompositeDoc = "Composite" + Gate.genSym();
-        map.put(CombineFromAnnotID.ANNOTATION_ID_FEATURE_NAME, annotation
-                .getId());
+        map.put(CombineFromAnnotID.ANNOTATION_ID_FEATURE_NAME,
+            annotation.getId());
         CompositeDocument compositeDoc = null;
-        
         try {
           if(debug) {
-            System.out.println("Creating temp composite 
document:"+nameForCompositeDoc);
+            System.out.println("Creating temp composite document:"
+                + nameForCompositeDoc);
           }
           compositeDoc = combiningMethodInst.combine(compoundDoc, map);
           compositeDoc.setName(nameForCompositeDoc);
           compoundDoc.addDocument(nameForCompositeDoc, compositeDoc);
-
           // change focus to composite document
           compoundDoc.setCurrentDocument(nameForCompositeDoc);
-
           // now run the application on the composite document
-          controller.execute();
+          analyser.execute();
           compoundDoc.removeDocument(nameForCompositeDoc);
-
-        }
-        catch(CombiningMethodException e) {
+        } catch(CombiningMethodException e) {
           throw new ExecutionException(e);
-        }
-        finally {
+        } finally {
           // finally get rid of the composite document
           compoundDoc.removeDocument(nameForCompositeDoc);
-
           if(compositeDoc != null) {
             gate.Factory.deleteResource(compositeDoc);
           }
         }
       }
-    }
-    catch(ResourceInstantiationException e) {
+    } catch(ResourceInstantiationException e) {
       throw new ExecutionException(e);
-    }
-    finally {
+    } finally {
       compoundDoc.removeDocument(originalDocument);
       if(tempCorpus != null) {
         gate.Factory.deleteResource(tempCorpus);
@@ -196,29 +203,42 @@
   }
 
   /**
-   * Gets the set controller. The controller is used for processing the
-   * segmented document.
+   * Gets the set analyser. The analyser is used for processing the segmented
+   * document.
    * 
    * @return
    */
-  public CorpusController getController() {
-    return controller;
+  public LanguageAnalyser getAnalyser() {
+    return analyser;
   }
 
   /**
-   * Sets the controller. The controller is used for processing the
-   * segmented document.
+   * Sets the analyser. The analyser is used for processing the segmented
+   * document.
    * 
-   * @param controller
+   * @param analyser
    */
+  public void setAnalyser(LanguageAnalyser controller) {
+    this.analyser = controller;
+  }
+
+  /**
+   * Sets the analyser. The analyser is used for processing the segmented
+   * document.
+   * 
+   * @param analyser
+   */
+  @Deprecated
   public void setController(CorpusController controller) {
-    this.controller = controller;
+    if(!(controller instanceof LanguageAnalyser)) { throw new 
GateRuntimeException(
+        "controller must be of type LanguageAnalyser"); }
+    setAnalyser((LanguageAnalyser)controller);
   }
 
   /**
-   * Annotation type that has been used for segmenting the document. The
-   * PR uses annotations of this type to create new composite documents
-   * and process them individually.
+   * Annotation type that has been used for segmenting the document. The PR 
uses
+   * annotations of this type to create new composite documents and process 
them
+   * individually.
    * 
    * @return
    */
@@ -227,9 +247,9 @@
   }
 
   /**
-   * Annotation type that has been used for segmenting the document. The
-   * PR uses annotations of this type to create new composite documents
-   * and process them individually.
+   * Annotation type that has been used for segmenting the document. The PR 
uses
+   * annotations of this type to create new composite documents and process 
them
+   * individually.
    * 
    * @param unitAnnotationType
    */
@@ -238,8 +258,8 @@
   }
 
   /**
-   * Annotation set to use for obtaining segment annotations and the
-   * annotations to copy into the composite document.
+   * Annotation set to use for obtaining segment annotations and the 
annotations
+   * to copy into the composite document.
    * 
    * @return
    */
@@ -248,12 +268,30 @@
   }
 
   /**
-   * Annotation set to use for obtaining segment annotations and the
-   * annotations to copy into the composite document.
+   * Annotation set to use for obtaining segment annotations and the 
annotations
+   * to copy into the composite document.
    * 
    * @param inputASName
    */
   public void setInputASName(String inputAS) {
     this.inputASName = inputAS;
   }
+
+  public String getSegmentAnnotationFeatureName() {
+    return segmentAnnotationFeatureName;
+  }
+
+  public void setSegmentAnnotationFeatureName(
+      String segmentAnnotationFeatureName) {
+    this.segmentAnnotationFeatureName = segmentAnnotationFeatureName;
+  }
+
+  public String getSegmentAnnotationFeatureValue() {
+    return segmentAnnotationFeatureValue;
+  }
+
+  public void setSegmentAnnotationFeatureValue(
+      String segmentAnnotationFeatureValue) {
+    this.segmentAnnotationFeatureValue = segmentAnnotationFeatureValue;
+  }
 } // class SegmentProcessingPR

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


------------------------------------------------------------------------------
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for 
developers. It will provide a great way to learn Windows Azure and what it 
provides. You can attend the event by watching it streamed LIVE online.  
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to