Search in sources :

Example 1 with GetManchesterSyntaxFrameCompletionsResult

use of edu.stanford.bmir.protege.web.shared.frame.GetManchesterSyntaxFrameCompletionsResult in project webprotege by protegeproject.

the class GetManchesterSyntaxFrameCompletionsActionHandler method execute.

@Nonnull
@Override
public GetManchesterSyntaxFrameCompletionsResult execute(@Nonnull GetManchesterSyntaxFrameCompletionsAction action, @Nonnull ExecutionContext executionContext) {
    String syntax = action.getSyntax();
    int from = action.getFrom();
    String triggerText = syntax.substring(0, from) + "\u0000";
    ManchesterSyntaxFrameParser parser = manchesterSyntaxFrameParserProvider.get();
    try {
        parser.parse(triggerText, action);
    } catch (ParserException e) {
        // ManchesterOWLSyntaxTokenizer tokenizer = new ManchesterOWLSyntaxTokenizer(syntax);
        // List<ManchesterOWLSyntaxTokenizer.Token> tokens = tokenizer.tokenize();
        // ManchesterOWLSyntaxTokenizer.Token intersectingToken;
        // for(ManchesterOWLSyntaxTokenizer.Token token : tokens) {
        // int tokenPos = token.getPos();
        // if(tokenPos <= from && from <= tokenPos + token.getToken().length()) {
        // intersectingToken = token;
        // break;
        // }
        // }
        int lastWordStartIndex = getLastWordIndex(syntax, from);
        int lastWordEndIndex = getWordEnd(syntax, from);
        int fromLineNumber = action.getFromPos().getLineNumber();
        int fromColumnNumber = (action.getFromPos().getColumnNumber() - (from - lastWordStartIndex));
        EditorPosition fromPos = new EditorPosition(fromLineNumber, fromColumnNumber);
        EditorPosition toPos = new EditorPosition(fromLineNumber, action.getFromPos().getColumnNumber() + (lastWordEndIndex - from));
        String lastWordPrefix = syntax.substring(lastWordStartIndex, from).toLowerCase();
        List<AutoCompletionChoice> choices = Lists.newArrayList();
        List<AutoCompletionChoice> entityChoices = getEntityAutocompletionChoices(action, e, fromPos, toPos, lastWordPrefix);
        choices.addAll(entityChoices);
        List<AutoCompletionChoice> expectedKeywordChoices = getKeywordAutoCompletionChoices(e, fromPos, toPos, lastWordPrefix);
        choices.addAll(expectedKeywordChoices);
        List<AutoCompletionChoice> ontologyNameChoices = getNameOntologyAutocompletionChoices(e, fromPos, toPos, lastWordPrefix);
        choices.addAll(ontologyNameChoices);
        return new GetManchesterSyntaxFrameCompletionsResult(new AutoCompletionResult(choices, fromPos));
    }
    return new GetManchesterSyntaxFrameCompletionsResult(AutoCompletionResult.emptyResult());
}
Also used : ParserException(org.semanticweb.owlapi.manchestersyntax.renderer.ParserException) GetManchesterSyntaxFrameCompletionsResult(edu.stanford.bmir.protege.web.shared.frame.GetManchesterSyntaxFrameCompletionsResult) ManchesterSyntaxFrameParser(edu.stanford.bmir.protege.web.server.mansyntax.ManchesterSyntaxFrameParser) EditorPosition(edu.stanford.bmir.gwtcodemirror.client.EditorPosition) AutoCompletionResult(edu.stanford.bmir.gwtcodemirror.client.AutoCompletionResult) Nonnull(javax.annotation.Nonnull)

Aggregations

AutoCompletionResult (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionResult)1 EditorPosition (edu.stanford.bmir.gwtcodemirror.client.EditorPosition)1 ManchesterSyntaxFrameParser (edu.stanford.bmir.protege.web.server.mansyntax.ManchesterSyntaxFrameParser)1 GetManchesterSyntaxFrameCompletionsResult (edu.stanford.bmir.protege.web.shared.frame.GetManchesterSyntaxFrameCompletionsResult)1 Nonnull (javax.annotation.Nonnull)1 ParserException (org.semanticweb.owlapi.manchestersyntax.renderer.ParserException)1