Search in sources :

Example 36 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class AugmentedFreshEntitiesSuggestStrategy method getSuggestion.

private Optional<FreshEntitySuggestion> getSuggestion(String query, EntityType<?> type, Optional<OWLEntityData> auxiliaryType) {
    // TODO: If query starts with a lowercase letter, suggest individual first?
    OWLEntity entity = DataFactory.getFreshOWLEntity(type, query);
    OWLEntityData entityData = DataFactory.getOWLEntityData(entity, query);
    if (auxiliaryType.isPresent()) {
        AuxiliaryTypeHandler auxiliaryTypeHandler = AuxiliaryTypeHandler.get(auxiliaryType.get());
        if (auxiliaryTypeHandler.isApplicableTo(type)) {
            Set<OWLAxiom> augmentingAxioms = auxiliaryTypeHandler.getAdditionalAxioms(entity);
            return Optional.of(new FreshEntitySuggestion(entityData, auxiliaryTypeHandler.getSuggestionText(entityData), augmentingAxioms));
        }
    }
    return Optional.empty();
}
Also used : OWLEntity(org.semanticweb.owlapi.model.OWLEntity) OWLEntityData(edu.stanford.bmir.protege.web.shared.entity.OWLEntityData) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom)

Example 37 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class AugmentedFreshEntitiesSuggestStrategy method getSuggestions.

@Override
public List<EntitySuggestion> getSuggestions(String query, List<EntityType<?>> suggestedTypes) {
    List<EntitySuggestion> result = Lists.newArrayList();
    for (EntityType<?> type : suggestedTypes) {
        for (Optional<OWLEntityData> auxiliaryType : auxiliaryTypes) {
            Optional<FreshEntitySuggestion> suggestion = getSuggestion(query, type, auxiliaryType);
            if (suggestion.isPresent()) {
                result.add(suggestion.get());
            }
        }
        OWLEntity entity = DataFactory.getFreshOWLEntity(type, query);
        OWLEntityData entityData = DataFactory.getOWLEntityData(entity, query);
        result.add(new EntitySuggestion(entityData, formatSuggestText(query, type)));
    }
    return result;
}
Also used : EntitySuggestion(edu.stanford.bmir.protege.web.client.library.suggest.EntitySuggestion) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) OWLEntityData(edu.stanford.bmir.protege.web.shared.entity.OWLEntityData)

Example 38 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class SimpleFreshEntitySuggestStrategy method getSuggestions.

@Override
public List<EntitySuggestion> getSuggestions(String query, List<EntityType<?>> suggestedTypes) {
    List<EntitySuggestion> suggestions = Lists.newArrayList();
    for (EntityType<?> allowedType : suggestedTypes) {
        OWLEntity entity = DataFactory.getFreshOWLEntity(allowedType, query);
        OWLEntityData entityData = DataFactory.getOWLEntityData(entity, query);
        suggestions.add(new EntitySuggestion(entityData, formatSuggestText(query, allowedType)));
    }
    return suggestions;
}
Also used : EntitySuggestion(edu.stanford.bmir.protege.web.client.library.suggest.EntitySuggestion) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) OWLEntityData(edu.stanford.bmir.protege.web.shared.entity.OWLEntityData)

Example 39 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity in project webprotege by protegeproject.

the class MutableFreshEntitiesHandler method getFreshEntity.

/**
 * Gets a fresh entity of the given type with the specified browser text.
 * @param browserText The browser text. Not {@code null}.
 * @param type The type.  Not {@code null}.
 * @param <E> The fresh entity type.
 * @return The fresh entity.  Not {@code null}.
 */
@Override
@SuppressWarnings("unchecked")
public <E extends OWLEntity> E getFreshEntity(String browserText, EntityType<E> type) {
    OWLEntity entity = entitiesTable.get(browserText, type);
    if (entity != null) {
        return (E) entity;
    }
    E freshEntity = DataFactory.getFreshOWLEntity(type, browserText);
    entitiesTable.put(browserText, type, freshEntity);
    return freshEntity;
}
Also used : OWLEntity(org.semanticweb.owlapi.model.OWLEntity)

Example 40 with OWLEntity

use of org.semanticweb.owlapi.model.OWLEntity 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

OWLEntity (org.semanticweb.owlapi.model.OWLEntity)45 Test (org.junit.Test)13 OWLOntologyChange (org.semanticweb.owlapi.model.OWLOntologyChange)7 OWLEntityData (edu.stanford.bmir.protege.web.shared.entity.OWLEntityData)6 ArrayList (java.util.ArrayList)6 Nonnull (javax.annotation.Nonnull)6 Inject (javax.inject.Inject)6 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)5 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)4 AccessManager (edu.stanford.bmir.protege.web.server.access.AccessManager)3 IRI (org.semanticweb.owlapi.model.IRI)3 DBObject (com.mongodb.DBObject)2 EntitySuggestion (edu.stanford.bmir.protege.web.client.library.suggest.EntitySuggestion)2 AbstractProjectActionHandler (edu.stanford.bmir.protege.web.server.dispatch.AbstractProjectActionHandler)2 ExecutionContext (edu.stanford.bmir.protege.web.server.dispatch.ExecutionContext)2 VIEW_PROJECT (edu.stanford.bmir.protege.web.shared.access.BuiltInAction.VIEW_PROJECT)2 ColumnType (edu.stanford.bmir.protege.web.shared.csv.ColumnType)2 OWLPrimitiveData (edu.stanford.bmir.protege.web.shared.entity.OWLPrimitiveData)2 ProjectEvent (edu.stanford.bmir.protege.web.shared.event.ProjectEvent)2 Comparator.comparing (java.util.Comparator.comparing)2