// NOTE: the site is determined from the
// fise:TextAnnotation <-- dc:relation --
// fise:EntityAnnotation -- entityhub:ste --> "{siteName}"^^xsd:string
// data.
// TODO: add configuration to include/exclude Sites by name
Site site = siteManager.getSite(savedEntity.getSite());
Collection<String> types = null; // potential types of entities
boolean casesensitive = false; // TODO: make configurable
String savedEntityLabel =
casesensitive ? savedEntity.getName() : savedEntity.getName().toLowerCase();
// Determine the context used for disambiguation
// TODO: make this configurable options
String disambiguationContext;
// (0.a) The easiest way is to just use the selection context
// disambiguationContext = savedEntity.getContext();
// (0.b) Calculate a context based on a moving window
String window =
getDisambiguationContext(textContent, savedEntity.getName(), savedEntity.getStart(), 100);
log.info("Use Window: '{}' for '{}'", window, savedEntity.getName());
// (1) The contextSelections:
// All other selected text within the selection context
List<String> contextSelections =
getSelectionsInContext(savedEntity.getName(), disData.allSelectedTexts, window);
// savedEntity.getContext());
disambiguationContext = unionString(false, contextSelections);
// (2) I do not understand this variant (see comment for the
// EntitiesInRange(..) method
// List<String> L = EntitiesInRange(disData.directoryTextAnotation,
// (savedEntity.getStart() + savedEntity.getEnd()) / 2);
// disambiguationContext = unionString(false,contextSelections);
// (3) one can build a combination of the above
// disambiguationContext = unionString(true, //unique adds
// Collections.singleton(savedEntity.getName()), //the selected text
// Collections.singleton(context), //the context
// contextSelections); //other selected parsed in the context
// or just the name of the entity AND the context
// disambiguationContext = unionString(false,
// Collections.singleton(savedEntity.getName()),
// contextSelections);
// (4) TODO: I would also like to have the possibility to disambiguate
// using URIs of Entities suggested for other TextAnnotations
// within the context.
// make the similarity query on the Entityhub using the collected
// information
QueryResultList<Entity> results;
log.info(" - Query '{}' for {}@{} with context '{}'", new Object[] {site.getId(),
savedEntityLabel, contentLangauge, disambiguationContext});
if (!StringUtils.isBlank(disambiguationContext)) {
try {
results = query(site, savedEntityLabel, contentLangauge, disambiguationContext);
} catch (SiteException e) {
// TODO we could also try to catch those errors ...
throw new EngineException("Unable to disambiguate Mention of '" + savedEntity.getName()
+ "' on Entityhub Site '" + site.getId() + "!", e);
}
log.debug(" - {} results returned by query {}", results.size(), results.getQuery());
// match the results with the suggestions
disambiguateSuggestions(results, savedEntity);
} else {