Search in sources :

Example 1 with EscapingShortFormProvider

use of edu.stanford.bmir.protege.web.server.shortform.EscapingShortFormProvider in project webprotege by protegeproject.

the class GetManchesterSyntaxFrameActionHandler method execute.

@Nonnull
@Override
public GetManchesterSyntaxFrameResult execute(@Nonnull GetManchesterSyntaxFrameAction action, @Nonnull ExecutionContext executionContext) {
    StringWriter writer = new StringWriter();
    EscapingShortFormProvider entityShortFormProvider = new EscapingShortFormProvider(shortFormProvider);
    final ManchesterOWLSyntaxFrameRenderer frameRenderer = new ManchesterOWLSyntaxFrameRenderer(importsClosure.getImportsClosure(), writer, entityShortFormProvider);
    frameRenderer.setOntologyIRIShortFormProvider(ontologyIRIShortFormProvider);
    frameRenderer.setRenderExtensions(true);
    // frameRenderer.setRenderOntologyLists(true);
    // frameRenderer.setUseTabbing(true);
    // frameRenderer.setUseWrapping(true);
    frameRenderer.writeFrame(action.getSubject());
    // frameRenderer.writeRulesContainingPredicate(action.getSubject());
    return new GetManchesterSyntaxFrameResult(writer.getBuffer().toString());
}
Also used : EscapingShortFormProvider(edu.stanford.bmir.protege.web.server.shortform.EscapingShortFormProvider) StringWriter(java.io.StringWriter) ManchesterOWLSyntaxFrameRenderer(org.semanticweb.owlapi.manchestersyntax.renderer.ManchesterOWLSyntaxFrameRenderer) GetManchesterSyntaxFrameResult(edu.stanford.bmir.protege.web.shared.frame.GetManchesterSyntaxFrameResult) Nonnull(javax.annotation.Nonnull)

Example 2 with EscapingShortFormProvider

use of edu.stanford.bmir.protege.web.server.shortform.EscapingShortFormProvider 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

EscapingShortFormProvider (edu.stanford.bmir.protege.web.server.shortform.EscapingShortFormProvider)2 AutoCompletionChoice (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice)1 GetManchesterSyntaxFrameResult (edu.stanford.bmir.protege.web.shared.frame.GetManchesterSyntaxFrameResult)1 EntityNameMatchResult (edu.stanford.bmir.protege.web.shared.search.EntityNameMatchResult)1 EntityNameMatcher (edu.stanford.bmir.protege.web.shared.search.EntityNameMatcher)1 StringWriter (java.io.StringWriter)1 Nonnull (javax.annotation.Nonnull)1 ManchesterOWLSyntaxFrameRenderer (org.semanticweb.owlapi.manchestersyntax.renderer.ManchesterOWLSyntaxFrameRenderer)1 EntityType (org.semanticweb.owlapi.model.EntityType)1 OWLEntity (org.semanticweb.owlapi.model.OWLEntity)1 BidirectionalShortFormProvider (org.semanticweb.owlapi.util.BidirectionalShortFormProvider)1