Lock lock = existingNode.writeLock();
try {
lock.lock();
for (FeatureStructure uimaObject : uimaObjects) {
// create a new node for the current Annotation
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
if (uimaObject instanceof Annotation) {
Annotation annotation = (Annotation) uimaObject;
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
annotationNode.addPropertyValue(ENTITY.uimaType, uimaObject.getType().getName());
/* inspect features of the annotation */
Type type = uimaObject.getType();
for (Feature feature : type.getFeatures()) {
// create a new feature node
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
featureNode.addPropertyValue(ENTITY.featureName, feature.getName());
String featureValue = null;
try {
featureValue = uimaObject.getFeatureValueAsString(feature);
} 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) {
featureNode.addPropertyValue(ENTITY.featureValue, featureValue);
log.info(new StringBuilder("Added feature ").append(feature.getName()).append(" with value ")
.append(featureValue.toString()).toString());
}
// add feature to the annotation node
annotationNode.addProperty(ENTITY.hasFeature, featureNode.getNode());
}
// finally add the triple to the existing node
existingNode.addProperty(ENTITY.contains, annotationNode.getNode());