@Override
public void map(CAS cas, String graphName) throws CASMappingException {
// This is creating the Graph for the annotation in Annotation Ontology format
final TcManager tcManager = TcManager.getInstance();
final UriRef mGraphName = new UriRef(graphName);
GraphNode node = new GraphNode(new BNode(), tcManager.createMGraph(mGraphName));
Lock lock = node.writeLock();
try {
lock.lock();
SelectorRegistry selectorRegistry = new SelectorRegistry();
// Iterate the annotations to create an index of them up front, this
// is incase we have references between
// annotations and need to output the appropriate RDF identifier out
// of sequence
Map<Annotation, Integer> annotIndex = new HashMap<Annotation, Integer>();
int annotCnt = 0;
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(
new StringBuilder(AO.AnnotationSet.getUnicodeString()).toString());
log.info("AO: Annotation set uri " + annotationSetUri);
GraphNode annotationSet = new GraphNode(annotationSetUri, node.getGraph());
log.info(new StringBuilder("AO: Set created ").toString());
annotationSet.addProperty(new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
AO.AnnotationSet);
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;
UriRef selectorUri = selectorRegistry.get(annot.getBegin(), annot.getEnd());
// Annotation URI
int annotId = annotIndex.get((Annotation) uimaObject);
UriRef annotationUri = new UriRef(new StringBuilder(AO.Annotation.getUnicodeString())
.append("/").append(annotId).toString());
log.info("annotation uri " + annotationUri);
// Annotation Graph
GraphNode annotationNode = new GraphNode(annotationUri, annotationSet.getGraph());
log.info(new StringBuilder("AO: Node created for Type ").append(
uimaObject.getType().toString()).toString());
annotationNode.addProperty(new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
new UriRef("http://purl.org/ao/Annotation"));
annotationNode.addProperty(AO.context, selectorUri);
// finally add the triple to the existing node
annotationSet.addProperty(AO.item, annotationNode.getNode());
}
}
Iterator<SelectorRegistry.Selector> iterator = selectorRegistry.iterator();
while (iterator.hasNext()) {
SelectorRegistry.Selector sel = iterator.next();
// Get persistent URI for region in document
UriRef selectorUri = sel.uri;
// create a new feature node
GraphNode selectorNode = new GraphNode(selectorUri, node.getGraph());
log.info(new StringBuilder("Node created for Selector " + selectorUri).toString());
String documentText = cas.getDocumentText();
selectorNode.addProperty(new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
AO.Selector);
selectorNode.addProperty(new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
AOSELECTORS.OffsetRangeTextSelector);
selectorNode.addProperty(new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
AOSELECTORS.PrefixPostfixTextSelector);
selectorNode.addPropertyValue(AOSELECTORS.exact, getSpan(documentText, sel.start, sel.end));
selectorNode.addPropertyValue(AOSELECTORS.prefix,
getSpan(documentText, sel.start - 50, sel.start));
selectorNode.addPropertyValue(AOSELECTORS.postfix,