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();
}
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;
}
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;
}
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;
}
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;
}
Aggregations