use of edu.stanford.bmir.protege.web.server.mansyntax.ManchesterSyntaxFrameParser 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());
}
Aggregations