Search in sources :

Example 1 with BidirectionalShortFormProvider

use of org.semanticweb.owlapi.util.BidirectionalShortFormProvider 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());
}
Also used : EntityNameMatcher(edu.stanford.bmir.protege.web.shared.search.EntityNameMatcher) BidirectionalShortFormProvider(org.semanticweb.owlapi.util.BidirectionalShortFormProvider) EntityNameMatchResult(edu.stanford.bmir.protege.web.shared.search.EntityNameMatchResult)

Example 2 with BidirectionalShortFormProvider

use of org.semanticweb.owlapi.util.BidirectionalShortFormProvider 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;
}
Also used : EscapingShortFormProvider(edu.stanford.bmir.protege.web.server.shortform.EscapingShortFormProvider) EntityNameMatcher(edu.stanford.bmir.protege.web.shared.search.EntityNameMatcher) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) AutoCompletionChoice(edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice) EntityType(org.semanticweb.owlapi.model.EntityType) BidirectionalShortFormProvider(org.semanticweb.owlapi.util.BidirectionalShortFormProvider) EntityNameMatchResult(edu.stanford.bmir.protege.web.shared.search.EntityNameMatchResult)

Aggregations

EntityNameMatchResult (edu.stanford.bmir.protege.web.shared.search.EntityNameMatchResult)2 EntityNameMatcher (edu.stanford.bmir.protege.web.shared.search.EntityNameMatcher)2 BidirectionalShortFormProvider (org.semanticweb.owlapi.util.BidirectionalShortFormProvider)2 AutoCompletionChoice (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice)1 EscapingShortFormProvider (edu.stanford.bmir.protege.web.server.shortform.EscapingShortFormProvider)1 EntityType (org.semanticweb.owlapi.model.EntityType)1 OWLEntity (org.semanticweb.owlapi.model.OWLEntity)1