Search in sources :

Example 1 with AutoCompletionChoice

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));
        });
    }
}
Also used : EditorPosition(edu.stanford.bmir.gwtcodemirror.client.EditorPosition) GetUserIdCompletionsAction(edu.stanford.bmir.protege.web.shared.itemlist.GetUserIdCompletionsAction) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ArrayList(java.util.ArrayList) AutoCompletionResult(edu.stanford.bmir.gwtcodemirror.client.AutoCompletionResult) AutoCompletionChoice(edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 2 with AutoCompletionChoice

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;
}
Also used : ManchesterOWLSyntax(org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntax) ManchesterSyntaxKeywords(edu.stanford.bmir.protege.web.server.renderer.ManchesterSyntaxKeywords) AutoCompletionChoice(edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice)

Example 3 with AutoCompletionChoice

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

Example 4 with AutoCompletionChoice

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);
    });
}
Also used : EditorPosition(edu.stanford.bmir.gwtcodemirror.client.EditorPosition) LookupEntitiesAction(edu.stanford.bmir.protege.web.shared.entity.LookupEntitiesAction) ArrayList(java.util.ArrayList) AutoCompletionResult(edu.stanford.bmir.gwtcodemirror.client.AutoCompletionResult) EntityLookupResult(edu.stanford.bmir.protege.web.shared.entity.EntityLookupResult) AutoCompletionChoice(edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice)

Aggregations

AutoCompletionChoice (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice)4 AutoCompletionResult (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionResult)2 EditorPosition (edu.stanford.bmir.gwtcodemirror.client.EditorPosition)2 ArrayList (java.util.ArrayList)2 MatchResult (com.google.gwt.regexp.shared.MatchResult)1 ManchesterSyntaxKeywords (edu.stanford.bmir.protege.web.server.renderer.ManchesterSyntaxKeywords)1 EscapingShortFormProvider (edu.stanford.bmir.protege.web.server.shortform.EscapingShortFormProvider)1 EntityLookupResult (edu.stanford.bmir.protege.web.shared.entity.EntityLookupResult)1 LookupEntitiesAction (edu.stanford.bmir.protege.web.shared.entity.LookupEntitiesAction)1 GetUserIdCompletionsAction (edu.stanford.bmir.protege.web.shared.itemlist.GetUserIdCompletionsAction)1 EntityNameMatchResult (edu.stanford.bmir.protege.web.shared.search.EntityNameMatchResult)1 EntityNameMatcher (edu.stanford.bmir.protege.web.shared.search.EntityNameMatcher)1 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)1 ManchesterOWLSyntax (org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntax)1 EntityType (org.semanticweb.owlapi.model.EntityType)1 OWLEntity (org.semanticweb.owlapi.model.OWLEntity)1 BidirectionalShortFormProvider (org.semanticweb.owlapi.util.BidirectionalShortFormProvider)1