if(log.isDebugEnabled()){
log.debug("findNamedEntities model={}, language={}, text=",
new Object[]{ nameFinderModel, language,
StringUtils.abbreviate(at != null ? at.getSpan() : text, 100) });
}
LiteralFactory literalFactory = LiteralFactory.getInstance();
MGraph g = ci.getMetadata();
Map<String,List<NameOccurrence>> entityNames;
if(at != null){
entityNames = extractNameOccurrences(nameFinderModel, at, lang);
} else {
entityNames = extractNameOccurrences(nameFinderModel, text,lang);
}
//lock the ContentItem while writing the RDF data for found Named Entities
ci.getLock().writeLock().lock();
try {
Map<String,UriRef> previousAnnotations = new LinkedHashMap<String,UriRef>();
for (Map.Entry<String,List<NameOccurrence>> nameInContext : entityNames.entrySet()) {
String name = nameInContext.getKey();
List<NameOccurrence> occurrences = nameInContext.getValue();
UriRef firstOccurrenceAnnotation = null;
for (NameOccurrence occurrence : occurrences) {
UriRef textAnnotation = EnhancementEngineHelper.createTextEnhancement(ci, this);
g.add(new TripleImpl(textAnnotation, ENHANCER_SELECTED_TEXT,
new PlainLiteralImpl(name, language)));
g.add(new TripleImpl(textAnnotation, ENHANCER_SELECTION_CONTEXT,
new PlainLiteralImpl(occurrence.context, language)));
if(occurrence.type != null){
g.add(new TripleImpl(textAnnotation, DC_TYPE, occurrence.type));
}
g.add(new TripleImpl(textAnnotation, ENHANCER_CONFIDENCE, literalFactory
.createTypedLiteral(occurrence.confidence)));
if (occurrence.start != null && occurrence.end != null) {
g.add(new TripleImpl(textAnnotation, ENHANCER_START, literalFactory
.createTypedLiteral(occurrence.start)));
g.add(new TripleImpl(textAnnotation, ENHANCER_END, literalFactory
.createTypedLiteral(occurrence.end)));
}
// add the subsumption relationship among occurrences of the same
// name