use of edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice in project webprotege by protegeproject.
the class CommentAutoCompleter method handleAutocomplete.
public void handleAutocomplete(@Nonnull String query, @Nonnull EditorPosition caretPosition, int caretPos, @Nonnull AutoCompletionCallback callback) {
String upToCarent = query.substring(0, caretPos);
MatchResult result = nameRegExp.exec(upToCarent);
if (result == null) {
handleAttemptAtEntityCompletions(upToCarent, caretPosition, callback);
} else {
String matchedPartialName = result.getGroup(NAME_GROUP);
EditorPosition replaceTextFrom = new EditorPosition(caretPosition.getLineNumber(), caretPosition.getColumnNumber() - result.getGroup(0).length());
dispatchServiceManager.execute(new GetUserIdCompletionsAction(matchedPartialName), userIdsResult -> {
List<AutoCompletionChoice> suggestions = new ArrayList<>();
List<UserId> userIds = userIdsResult.getPossibleItemCompletions();
for (UserId userId : userIds) {
String userName = userId.getUserName();
String replacement = getReplacementStringFromUserName(userName);
EditorPosition replaceTextTo = new EditorPosition(caretPosition.getLineNumber(), caretPosition.getColumnNumber());
suggestions.add(new AutoCompletionChoice(replacement, userName, "", replaceTextFrom, replaceTextTo));
}
callback.completionsReady(new AutoCompletionResult(suggestions, replaceTextFrom));
});
}
}
use of edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice in project webprotege by protegeproject.
the class GetManchesterSyntaxFrameCompletionsActionHandler method getKeywordAutoCompletionChoices.
private List<AutoCompletionChoice> getKeywordAutoCompletionChoices(ParserException e, EditorPosition fromPos, EditorPosition toPos, String lastWordPrefix) {
Set<String> expectedKeywords = e.getExpectedKeywords();
List<AutoCompletionChoice> expectedKeywordChoices = Lists.newArrayList();
for (String expectedKeyword : expectedKeywords) {
if (lastWordPrefix.isEmpty() || expectedKeyword.toLowerCase().contains(lastWordPrefix)) {
Optional<ManchesterOWLSyntax> kw = syntaxStyles.getKeyword(expectedKeyword);
String style = "";
if (kw.isPresent()) {
style = syntaxStyles.getStyleName(kw.get());
}
expectedKeywordChoices.add(new AutoCompletionChoice(expectedKeyword, expectedKeyword, style, fromPos, toPos));
}
}
expectedKeywordChoices.sort(new Comparator<AutoCompletionChoice>() {
private ManchesterSyntaxKeywords.KeywordComparator keywordComparator = new ManchesterSyntaxKeywords.KeywordComparator();
@Override
public int compare(AutoCompletionChoice autoCompletionChoice, AutoCompletionChoice autoCompletionChoice2) {
return keywordComparator.compare(autoCompletionChoice.getDisplayText(), autoCompletionChoice2.getDisplayText());
}
});
return expectedKeywordChoices;
}
use of edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice 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;
}
use of edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice in project webprotege by protegeproject.
the class CommentAutoCompleter method handleAttemptAtEntityCompletions.
private void handleAttemptAtEntityCompletions(String queryUpToCaret, EditorPosition caretPos, AutoCompletionCallback callback) {
// Last index of space or 0 if there are not spaces
int wordStart = queryUpToCaret.lastIndexOf(" ") + 1;
int wordFragmentLen = queryUpToCaret.length() - wordStart;
String wordFragment = queryUpToCaret.substring(wordStart);
if (wordFragment.isEmpty()) {
callback.completionsReady(new AutoCompletionResult());
return;
}
dispatchServiceManager.execute(new LookupEntitiesAction(projectId, lookUpEntities(wordFragment)), result -> {
List<AutoCompletionChoice> choices = new ArrayList<>();
EditorPosition pos = new EditorPosition(caretPos.getLineNumber(), caretPos.getColumnNumber() - wordFragmentLen);
for (final EntityLookupResult entity : result.getEntityLookupResults()) {
choices.add(new AutoCompletionChoice(formatReplacementTest(entity), entity.getOWLEntityData().getBrowserText(), "", pos, caretPos));
}
AutoCompletionResult autoCompletionResult = new AutoCompletionResult(choices, pos);
callback.completionsReady(autoCompletionResult);
});
}
Aggregations