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 2011/09/21 15:28:15 UTC

svn commit: r1173625 - in /incubator/clerezza/trunk/parent/uima/uima.casconsumer/src: main/java/org/apache/clerezza/uima/casconsumer/ao/ test/java/org/apache/clerezza/uima/casconsumer/ao/ test/resources/

Author: tommaso
Date: Wed Sep 21 13:28:15 2011
New Revision: 1173625

URL: http://svn.apache.org/viewvc?rev=1173625&view=rev
Log:
[CLEREZZA-632] - applying patch from Paolo Ciccarese 

Added:
    incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/apache/clerezza/uima/casconsumer/ao/
    incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/apache/clerezza/uima/casconsumer/ao/AnnotationOntologyCASConsumerTest.java
    incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/resources/TestAnnotationOntologyCASConsumerDescriptor.xml
Modified:
    incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ao/AOMappingStrategy.java

Modified: incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ao/AOMappingStrategy.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ao/AOMappingStrategy.java?rev=1173625&r1=1173624&r2=1173625&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ao/AOMappingStrategy.java (original)
+++ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/main/java/org/apache/clerezza/uima/casconsumer/ao/AOMappingStrategy.java Wed Sep 21 13:28:15 2011
@@ -18,6 +18,11 @@
  */
 package org.apache.clerezza.uima.casconsumer.ao;
 
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+
 import org.apache.clerezza.rdf.core.BNode;
 import org.apache.clerezza.rdf.core.Triple;
 import org.apache.clerezza.rdf.core.TripleCollection;
@@ -36,11 +41,6 @@ import org.apache.uima.jcas.tcas.Annotat
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.concurrent.locks.Lock;
-
 /**
  * {@link CASMappingStrategy} which maps a CAS object to the Annotation Ontology format
  */
@@ -65,14 +65,23 @@ public class AOMappingStrategy implement
       // is incase we have references between
       // annotations and need to output the appropriate RDF identifier out
       // of sequence
-      Iterator<?> annotationIter = cas.getAnnotationIndex().iterator();
       Map<Annotation, Integer> annotIndex = new HashMap<Annotation, Integer>();
       int annotCnt = 0;
-      while (annotationIter.hasNext()) {
-        Annotation annot = (Annotation) annotationIter.next();
-        log.info("annotation index " + annotCnt);
-        annotIndex.put(annot, annotCnt);
-        annotCnt++;
+      for (FeatureStructure uimaObject : UIMAUtils.getAllFSofType(TOP.type, cas.getJCas())) {
+
+          // set Annotation specific properties for the node
+          if (uimaObject instanceof Annotation) {
+        	  // If type is DocumentAnnotation I skip it
+              if (uimaObject.getType().toString().equals("uima.tcas.DocumentAnnotation")) {
+                continue;
+              }
+
+              // Get persistent URI for region in document
+              Annotation annot = (Annotation) uimaObject;
+              log.info("annotation index " + annotCnt);
+              annotIndex.put(annot, annotCnt);
+              annotCnt++;
+          }
       }
 
       UriRef annotationSetUri = new UriRef(

Added: incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/apache/clerezza/uima/casconsumer/ao/AnnotationOntologyCASConsumerTest.java
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/apache/clerezza/uima/casconsumer/ao/AnnotationOntologyCASConsumerTest.java?rev=1173625&view=auto
==============================================================================
--- incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/apache/clerezza/uima/casconsumer/ao/AnnotationOntologyCASConsumerTest.java (added)
+++ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/java/org/apache/clerezza/uima/casconsumer/ao/AnnotationOntologyCASConsumerTest.java Wed Sep 21 13:28:15 2011
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.uima.casconsumer.ao;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.clerezza.uima.casconsumer.ClerezzaCASConsumer;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.CASException;
+import org.apache.uima.cas.admin.CASFactory;
+import org.apache.uima.cas.admin.CASMgr;
+import org.apache.uima.cas.admin.FSIndexRepositoryMgr;
+import org.apache.uima.cas.admin.TypeSystemMgr;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.test.junit_extension.AnnotatorTester;
+import org.apache.uima.util.CasCreationUtils;
+import org.junit.Test;
+
+/**
+ * TestCase for {@link ClerezzaCASConsumer} using {@link AOMappingStrategy}
+ */
+public class AnnotationOntologyCASConsumerTest {
+
+  @Test
+  public void simpleRunningTest() {
+    try {
+      AnnotatorTester annotatorTester = new AnnotatorTester("src/test/resources/TestAnnotationOntologyCASConsumerDescriptor.xml");
+
+      /* create a mock CAS */
+      CAS cas = createCAS();
+
+      cas.setDocumentText("Clerezza is an Apache project");
+      cas.setDocumentLanguage("en");
+
+      AnnotationFS annotation = cas.createAnnotation(cas.getAnnotationType(), 0, 9);
+      cas.addFsToIndexes(annotation);
+
+      /* execute ClerezzaCASConsumer on the created CAS */
+      annotatorTester.performTest(cas);
+
+      MGraph createdGraph = TcManager.getInstance().getMGraph(new UriRef("mytest-clerezza-ao-graph"));
+      assertNotNull(createdGraph);
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getLocalizedMessage());
+    }
+  }
+
+  private CAS createCAS() throws ResourceInitializationException, CASException {
+    CASMgr casMgr0 = CASFactory.createCAS();
+    CASMgr casMgr = null;
+    CasCreationUtils.setupTypeSystem(casMgr0, null);
+
+    TypeSystemMgr tsa = casMgr0.getTypeSystemMgr();
+
+    ((CASImpl) casMgr0).commitTypeSystem();
+
+    casMgr = CASFactory.createCAS(tsa);
+
+    casMgr.initCASIndexes();
+    FSIndexRepositoryMgr irm = casMgr.getIndexRepositoryMgr();
+    irm.commit();
+
+    return casMgr.getCAS().getCurrentView();
+  }
+}

Added: incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/resources/TestAnnotationOntologyCASConsumerDescriptor.xml
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/resources/TestAnnotationOntologyCASConsumerDescriptor.xml?rev=1173625&view=auto
==============================================================================
--- incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/resources/TestAnnotationOntologyCASConsumerDescriptor.xml (added)
+++ incubator/clerezza/trunk/parent/uima/uima.casconsumer/src/test/resources/TestAnnotationOntologyCASConsumerDescriptor.xml Wed Sep 21 13:28:15 2011
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+-->
+<analysisEngineDescription xmlns="http://uima.apache.org/resourceSpecifier">
+  <frameworkImplementation>org.apache.uima.java</frameworkImplementation>
+  <primitive>true</primitive>
+  <annotatorImplementationName>org.apache.clerezza.uima.casconsumer.ClerezzaCASConsumer</annotatorImplementationName>
+  <analysisEngineMetaData>
+    <name>TestClerezzaCASConsumerDescriptor</name>
+    <description>CAS Consumer to produce Clerezza graphs</description>
+    <version>1.0</version>
+    <vendor/>
+    <configurationParameters>
+      <configurationParameter>
+        <name>graphName</name>
+        <type>String</type>
+        <multiValued>false</multiValued>
+        <mandatory>true</mandatory>
+      </configurationParameter>
+      <configurationParameter>
+        <name>mappingStrategy</name>
+        <type>String</type>
+        <multiValued>false</multiValued>
+        <mandatory>true</mandatory>
+      </configurationParameter>
+    </configurationParameters>
+    <configurationParameterSettings>
+      <nameValuePair>
+        <name>graphName</name>
+        <value>
+          <string>mytest-clerezza-ao-graph</string>
+        </value>
+      </nameValuePair>
+      <nameValuePair>
+        <name>mappingStrategy</name>
+        <value>
+          <string>ao</string>
+        </value>
+      </nameValuePair>
+    </configurationParameterSettings>
+    <typeSystemDescription>
+      <types>
+      </types>
+    </typeSystemDescription>
+    <typePriorities/>
+    <fsIndexCollection/>
+    <capabilities>
+      <capability>
+        <inputs/>
+        <outputs/>
+        <languagesSupported/>
+      </capability>
+    </capabilities>
+    <operationalProperties>
+      <modifiesCas>true</modifiesCas>
+      <multipleDeploymentAllowed>true</multipleDeploymentAllowed>
+      <outputsNewCASes>false</outputsNewCASes>
+    </operationalProperties>
+  </analysisEngineMetaData>
+  <resourceManagerConfiguration/>
+</analysisEngineDescription>