}
}
// now write the results (requires write lock)
ci.getLock().writeLock().lock();
try {
RdfValueFactory factory = RdfValueFactory.getInstance();
Map<String,Representation> entityData = new HashMap<String,Representation>();
for (Entry<NamedEntity,List<Suggestion>> entitySuggestions : suggestions.entrySet()) {
List<UriRef> subsumed = textAnnotations.get(entitySuggestions.getKey());
List<NonLiteral> annotationsToRelate = new ArrayList<NonLiteral>(subsumed);
annotationsToRelate.add(entitySuggestions.getKey().getEntity());
for (Suggestion suggestion : entitySuggestions.getValue()) {
log.debug("Add Suggestion {} for {}", suggestion.getEntity().getId(),
entitySuggestions.getKey());
EnhancementRDFUtils.writeEntityAnnotation(this, literalFactory, graph, ci.getUri(),
annotationsToRelate, suggestion, nameField,
// TODO: maybe we want labels in a different
// language than the
// language of the content (e.g. Accept-Language
// header)?!
contentLangauge == null ? DEFAULT_LANGUAGE : contentLangauge);
if (dereferenceEntities) {
entityData.put(suggestion.getEntity().getId(), suggestion.getEntity()
.getRepresentation());
}
}
}
// if dereferneceEntities is true the entityData will also contain
// all
// Representations to add! If false entityData will be empty
for (Representation rep : entityData.values()) {
graph.addAll(factory.toRdfRepresentation(rep).getRdfGraph());
}
} finally {
ci.getLock().writeLock().unlock();
}