You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by to...@apache.org on 2010/12/29 18:11:55 UTC

svn commit: r1053676 - in /incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src: main/java/org/apache/clerezza/uima/utils/UIMAUtils.java test/java/org/apache/clerezza/uima/utils/UIMAUtilsTest.java

Author: tommaso
Date: Wed Dec 29 17:11:55 2010
New Revision: 1053676

URL: http://svn.apache.org/viewvc?rev=1053676&view=rev
Log:
[CLEREZZA-379] - fix to properly generate instances as triple subjects for UIMA annotations and features

Modified:
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtils.java
    incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAUtilsTest.java

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtils.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtils.java?rev=1053676&r1=1053675&r2=1053676&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtils.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtils.java Wed Dec 29 17:11:55 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.clerezza.uima.utils;
 
+import org.apache.clerezza.rdf.core.UriRef;
 import org.apache.clerezza.rdf.utils.GraphNode;
 import org.apache.clerezza.uima.ontologies.ENTITY;
 import org.apache.clerezza.uima.utils.exception.FeatureStructureNotFoundException;
@@ -42,6 +43,7 @@ import java.util.concurrent.locks.Lock;
 public class UIMAUtils {
 
   private final static Logger log = LoggerFactory.getLogger(UIMAUtils.class);
+  private static final String COVERED_TEXT = "coveredText";
 
   public static List<FeatureStructure> getAllFSofType(int type, JCas cas)
           throws FeatureStructureNotFoundException {
@@ -87,7 +89,8 @@ public class UIMAUtils {
       lock.lock();
       for (FeatureStructure uimaObject : uimaObjects) {
         // create a new node for the current Annotation
-        GraphNode annotationNode = new GraphNode(ENTITY.Annotation, existingNode.getGraph());
+        GraphNode annotationNode = new GraphNode(new UriRef(new StringBuilder(ENTITY.Annotation.getUnicodeString()).
+                append(uimaObject.hashCode()).toString()), existingNode.getGraph());
         log.info(new StringBuilder("Node created for Type ").append(uimaObject.getType().toString()).toString());
 
         // set Annotation specific properties for the node
@@ -95,6 +98,16 @@ public class UIMAUtils {
           Annotation annotation = (Annotation) uimaObject;
           annotationNode.addPropertyValue(ENTITY.begin, annotation.getBegin());
           annotationNode.addPropertyValue(ENTITY.end, annotation.getEnd());
+
+          GraphNode coveredTextNode = new GraphNode(new UriRef(new StringBuilder(ENTITY.Feature.getUnicodeString()).
+                  append(COVERED_TEXT.hashCode() / uimaObject.hashCode()).toString()), annotationNode.getGraph());
+          coveredTextNode.addPropertyValue(ENTITY.featureName, COVERED_TEXT);
+          log.info(new StringBuilder("Node created for Feature ").append(COVERED_TEXT).toString());
+          String coveredText = annotation.getCoveredText();
+          coveredTextNode.addPropertyValue(ENTITY.featureValue, coveredText);
+          log.info(new StringBuilder("Added feature ").append(COVERED_TEXT).append(" with value ")
+                  .append(coveredText).toString());
+
         }
 
         //XXX : in OpenCalais the type is an URI so it maybe reasonable to put another node here
@@ -105,7 +118,8 @@ public class UIMAUtils {
         for (Feature feature : type.getFeatures()) {
 
           // create a new feature node
-          GraphNode featureNode = new GraphNode(ENTITY.Feature, existingNode.getGraph());
+          GraphNode featureNode = new GraphNode(new UriRef(new StringBuilder(ENTITY.Feature.getUnicodeString()).
+                  append(feature.hashCode() / uimaObject.hashCode()).toString()), annotationNode.getGraph());
           log.info(new StringBuilder("Node created for Feature ").append(feature.getName()).toString());
 
           // set feature name and value if not null
@@ -114,8 +128,7 @@ public class UIMAUtils {
           String featureValue = null;
           try {
             featureValue = uimaObject.getFeatureValueAsString(feature);
-          }
-          catch (Exception e) {
+          } catch (Exception e) {
             // do nothing at the moment
             log.warn(new StringBuilder("Unable to create feature value - ").append(e.toString()).toString());
           }

Modified: incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAUtilsTest.java?rev=1053676&r1=1053675&r2=1053676&view=diff
==============================================================================
--- incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAUtilsTest.java (original)
+++ incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.uima/org.apache.clerezza.uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAUtilsTest.java Wed Dec 29 17:11:55 2010
@@ -18,6 +18,10 @@
  */
 package org.apache.clerezza.uima.utils;
 
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.utils.GraphNode;
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CASException;
 import org.apache.uima.cas.FeatureStructure;
@@ -131,6 +135,35 @@ public class UIMAUtilsTest {
     }
   }
 
+  @Test
+  public void testEnhanceNode() {
+
+    try {
+      JCas cas = getCAS().getJCas();
+      cas.setDocumentText(DOCUMENT_TEXT);
+
+      Annotation simpleAnnotation = new Annotation(cas);
+      simpleAnnotation.setBegin(10);
+      simpleAnnotation.setEnd(24);
+      simpleAnnotation.addToIndexes();
+
+      Annotation secondSimpleAnnotation = new Annotation(cas);
+      secondSimpleAnnotation.setBegin(32);
+      secondSimpleAnnotation.setEnd(44);
+      secondSimpleAnnotation.addToIndexes();
+
+      MGraph mGraph = new SimpleMGraph();
+      GraphNode node = new GraphNode(new UriRef(cas.toString()), mGraph);
+
+      UIMAUtils.enhanceNode(node, UIMAUtils.getAllAnnotationsOfType(Annotation.type, cas));
+
+
+    } catch (Exception e) {
+      fail(e.getLocalizedMessage());
+    }
+
+  }
+
 
   private static CAS getCAS() {
     // Create an initial CASMgr from the factory.