Author: tommaso
Date: Fri Feb 18 09:52:29 2011
New Revision: 1071932
URL: http://svn.apache.org/viewvc?rev=1071932&view=rev
Log:
[CLEREZZA-426][CLEREZZA-427] - fix begin, end and Sofa adds in UIMA utils while
enhancing node
Modified:
incubator/clerezza/trunk/parent/uima/uima.ontologies/src/main/resources/org/apache/clerezza/uima/ontologies/entity.rdf
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtils.java
incubator/clerezza/trunk/parent/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAUtilsTest.java
Modified:
incubator/clerezza/trunk/parent/uima/uima.ontologies/src/main/resources/org/apache/clerezza/uima/ontologies/entity.rdf
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.ontologies/src/main/resources/org/apache/clerezza/uima/ontologies/entity.rdf?rev=1071932&r1=1071931&r2=1071932&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.ontologies/src/main/resources/org/apache/clerezza/uima/ontologies/entity.rdf
(original)
+++
incubator/clerezza/trunk/parent/uima/uima.ontologies/src/main/resources/org/apache/clerezza/uima/ontologies/entity.rdf
Fri Feb 18 09:52:29 2011
@@ -46,20 +46,6 @@
<rdfs:range
rdf:resource="http://www.w3.org/2000/01/rdf-schema#Literal"/>
<rdfs:isDefinedBy
rdf:resource="http://clerezza.apache.org/2010/22/uima-entities"/>
</rdf:Property>
-
- <rdf:Property
rdf:about="http://clerezza.apache.org/2010/22/uima-entities#begin"
vs:term_status="stable" rdfs:label="begin" skos:definition="The first character
of the wrapped text.">
- <rdf:type
rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
- <rdfs:domain
rdf:resource="http://clerezza.apache.org/2010/22/uima-entities#Annotation"/>
- <rdfs:range
rdf:resource="http://www.w3.org/2000/01/rdf-schema#Literal"/>
- <rdfs:isDefinedBy
rdf:resource="http://clerezza.apache.org/2010/22/uima-entities"/>
- </rdf:Property>
-
- <rdf:Property
rdf:about="http://clerezza.apache.org/2010/22/uima-entities#end"
vs:term_status="stable" rdfs:label="end" skos:definition="The last character of
the wrapped text.">
- <rdf:type
rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
- <rdfs:domain
rdf:resource="http://clerezza.apache.org/2010/22/uima-entities#Annotation"/>
- <rdfs:range
rdf:resource="http://www.w3.org/2000/01/rdf-schema#Literal"/>
- <rdfs:isDefinedBy
rdf:resource="http://clerezza.apache.org/2010/22/uima-entities"/>
- </rdf:Property>
<rdf:Property
rdf:about="http://clerezza.apache.org/2010/22/uima-entities#coveredText"
vs:term_status="stable" rdfs:label="coveredText" skos:definition="The text span
between begin and end">
<rdf:type
rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
Modified:
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtils.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtils.java?rev=1071932&r1=1071931&r2=1071932&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtils.java
(original)
+++
incubator/clerezza/trunk/parent/uima/uima.utils/src/main/java/org/apache/clerezza/uima/utils/UIMAUtils.java
Fri Feb 18 09:52:29 2011
@@ -23,10 +23,7 @@ import org.apache.clerezza.rdf.utils.Gra
import org.apache.clerezza.uima.ontologies.ENTITY;
import
org.apache.clerezza.uima.utils.exception.FeatureStructureNotFoundException;
import
org.apache.clerezza.uima.utils.exception.NotSingletonFeatureStructureException;
-import org.apache.uima.cas.FSIterator;
-import org.apache.uima.cas.Feature;
-import org.apache.uima.cas.FeatureStructure;
-import org.apache.uima.cas.Type;
+import org.apache.uima.cas.*;
import org.apache.uima.cas.text.AnnotationIndex;
import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.tcas.Annotation;
@@ -43,7 +40,6 @@ 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 {
@@ -96,11 +92,9 @@ public class UIMAUtils {
// set Annotation specific properties for the node
if (uimaObject instanceof Annotation) {
Annotation annotation = (Annotation) uimaObject;
- annotationNode.addPropertyValue(ENTITY.begin, annotation.getBegin());
- annotationNode.addPropertyValue(ENTITY.end, annotation.getEnd());
-
annotationNode.addPropertyValue(ENTITY.coveredText,annotation.getCoveredText());
-
- log.info(new StringBuilder("Added annotation properties to node
").append(uimaObject.toString()).toString());
+ String coveredText = annotation.getCoveredText();
+ annotationNode.addPropertyValue(ENTITY.coveredText, coveredText);
+ log.info(new StringBuilder("Node wraps Annotation with
coveredText:").append(coveredText).toString());
}
//XXX : in OpenCalais the type is an URI so it maybe reasonable to put
another node here
@@ -121,9 +115,15 @@ public class UIMAUtils {
String featureValue = null;
try {
featureValue = uimaObject.getFeatureValueAsString(feature);
- } catch (Exception e) {
- // do nothing at the moment
- log.warn(new StringBuilder("Unable to create feature value -
").append(e.toString()).toString());
+ } catch (CASRuntimeException sofaEx) {
+ try {
+ // this is usually due to Sofa having a range of {2}
+ featureValue = uimaObject.getFeatureValue(feature).toString();
+ } catch (Exception ex) {
+ // do nothing at the moment
+ log.warn(new StringBuilder("Unable to create feature value -
").append(ex.toString()).append(" (").
+ append(sofaEx.toString()).append(")").toString());
+ }
}
if (featureValue != null) {
@@ -136,7 +136,7 @@ public class UIMAUtils {
annotationNode.addProperty(ENTITY.hasFeature, featureNode.getNode());
}
- // finally add the triple existingNode,ENTITY.contains,calaisNode
+ // finally add the triple to the existing node
existingNode.addProperty(ENTITY.contains, annotationNode.getNode());
}
Modified:
incubator/clerezza/trunk/parent/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAUtilsTest.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAUtilsTest.java?rev=1071932&r1=1071931&r2=1071932&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAUtilsTest.java
(original)
+++
incubator/clerezza/trunk/parent/uima/uima.utils/src/test/java/org/apache/clerezza/uima/utils/UIMAUtilsTest.java
Fri Feb 18 09:52:29 2011
@@ -47,7 +47,7 @@ import static org.junit.Assert.fail;
* Testcase for {@link UIMAUtils}
*/
public class UIMAUtilsTest {
- private static final String DOCUMENT_TEXT = "the seerver will return a \"A
concept with the same label and language already exists!\", so there are
actually 2 issues:";
+ private static final String DOCUMENT_TEXT = "the server will return a \"A
concept with the same label and language already exists!\", so there are
actually 2 issues:";
@Test
public void testGetAllFSOfAnnotationType() {