use of edu.stanford.bmir.protege.web.shared.search.EntityNameMatchResult in project webprotege by protegeproject.
the class LookupEntitiesActionHandler method lookupEntities.
private List<EntityLookupResult> lookupEntities(final EntityLookupRequest entityLookupRequest) {
BidirectionalShortFormProvider sfp = renderingManager.getShortFormProvider();
List<OWLEntityDataMatch> matches = new ArrayList<>();
EntityNameMatcher matcher = new EntityNameMatcher(entityLookupRequest.getSearchString());
Set<OWLEntity> addedEntities = new HashSet<>();
for (String shortForm : sfp.getShortForms()) {
Optional<EntityNameMatchResult> result = matcher.findIn(shortForm);
if (result.isPresent()) {
Set<OWLEntity> entities = sfp.getEntities(shortForm);
for (OWLEntity matchingEntity : entities) {
if (!addedEntities.contains(matchingEntity)) {
Optional<OWLEntityData> match = toOWLEntityData(matchingEntity, entityLookupRequest, renderingManager);
if (match.isPresent()) {
EntityNameMatchResult resultValue = result.get();
matches.add(new OWLEntityDataMatch(match.get(), resultValue));
addedEntities.add(matchingEntity);
}
// BAD
if (matches.size() >= 1000) {
break;
}
}
}
}
// BAD
if (matches.size() >= 10000) {
break;
}
}
return matches.stream().sorted().limit(entityLookupRequest.getSearchLimit()).map(this::toEntityLookupResult).collect(toList());
}
use of edu.stanford.bmir.protege.web.shared.search.EntityNameMatchResult in project webprotege by protegeproject.
the class GetManchesterSyntaxFrameCompletionsActionHandler method getEntityAutocompletionChoices.
private List<AutoCompletionChoice> getEntityAutocompletionChoices(GetManchesterSyntaxFrameCompletionsAction action, ParserException e, EditorPosition fromPos, EditorPosition toPos, String lastWordPrefix) {
List<AutoCompletionMatch> matches = Lists.newArrayList();
Set<EntityType<?>> expectedEntityTypes = Sets.newHashSet(ManchesterSyntaxFrameParser.getExpectedEntityTypes(e));
if (!expectedEntityTypes.isEmpty()) {
BidirectionalShortFormProvider shortFormProvider = renderingManager.getShortFormProvider();
for (String shortForm : shortFormProvider.getShortForms()) {
EntityNameMatcher entityNameMatcher = new EntityNameMatcher(lastWordPrefix);
Optional<EntityNameMatchResult> match = entityNameMatcher.findIn(shortForm);
if (match.isPresent()) {
Set<OWLEntity> entities = shortFormProvider.getEntities(shortForm);
for (OWLEntity entity : entities) {
if (expectedEntityTypes.contains(entity.getEntityType())) {
EscapingShortFormProvider escapingShortFormProvider = new EscapingShortFormProvider(shortFormProvider);
AutoCompletionChoice choice = new AutoCompletionChoice(escapingShortFormProvider.getShortForm(entity), shortForm, "", fromPos, toPos);
AutoCompletionMatch autoCompletionMatch = new AutoCompletionMatch(match.get(), choice);
matches.add(autoCompletionMatch);
}
}
}
}
}
Collections.sort(matches);
List<AutoCompletionChoice> result = Lists.newArrayList();
for (AutoCompletionMatch match : matches) {
result.add(match.getAutoCompletionChoice());
if (result.size() == action.getEntityTypeSuggestLimit()) {
break;
}
}
return result;
}
Aggregations