Search in sources :

Example 1 with CorporaApi

use of org.corpus_tools.annis.api.CorporaApi in project ANNIS by korpling.

the class Helper method getCorpusConfig.

/**
 * Loads the corpus config of a specific corpus.
 *
 * @param corpus The name of the corpus, for which the config is fetched.
 * @return A {@link CorpusConfig} object, which wraps a {@link Properties} object. This Properties
 *         object stores the corpus configuration as simple key-value pairs.
 */
public static CorpusConfiguration getCorpusConfig(final String corpus, final UI ui) {
    if (corpus == null || corpus.isEmpty()) {
        Notification.show("no corpus is selected", "please select at least one corpus and execute query again", Notification.Type.WARNING_MESSAGE);
        return null;
    }
    CorpusConfiguration corpusConfig = new CorpusConfiguration();
    final CorporaApi api = new CorporaApi(getClient(ui));
    try {
        corpusConfig = api.corpusConfiguration(corpus);
    } catch (final ApiException ex) {
        ui.access(() -> ExceptionDialog.show(ex, ERROR_MESSAGE_CORPUS_PROPS_HEADER, ui));
    }
    return corpusConfig;
}
Also used : CorpusConfiguration(org.corpus_tools.annis.api.model.CorpusConfiguration) CorporaApi(org.corpus_tools.annis.api.CorporaApi) ApiException(org.corpus_tools.annis.ApiException)

Example 2 with CorporaApi

use of org.corpus_tools.annis.api.CorporaApi in project ANNIS by korpling.

the class Helper method getMetaAnnotationNames.

public static Set<AnnoKey> getMetaAnnotationNames(final String corpus, final UI ui) throws ApiException {
    final CorporaApi api = new CorporaApi(getClient(ui));
    final SearchApi search = new SearchApi(getClient(ui));
    final List<org.corpus_tools.annis.api.model.Annotation> nodeAnnos = api.nodeAnnotations(corpus, false, true).stream().filter(a -> !Objects.equals(a.getKey().getNs(), "annis") && !Objects.equals(a.getKey().getName(), "tok")).collect(Collectors.toList());
    final Set<AnnoKey> metaAnnos = new HashSet<>();
    // Check for each annotation if its actually a meta-annotation
    for (final org.corpus_tools.annis.api.model.Annotation a : nodeAnnos) {
        String annotationName = getQName(a.getKey());
        if (annotationIsMetadata(corpus, annotationName, search)) {
            metaAnnos.add(a.getKey());
        }
    }
    return metaAnnos;
}
Also used : Arrays(java.util.Arrays) SDominanceRelation(org.corpus_tools.salt.common.SDominanceRelation) SGraph(org.corpus_tools.salt.core.SGraph) StringUtils(org.apache.commons.lang3.StringUtils) Base64(org.apache.commons.codec.binary.Base64) InetAddress(java.net.InetAddress) JsonValue(elemental.json.JsonValue) DataSourceSequence(org.corpus_tools.salt.util.DataSourceSequence) AnnoKey(org.corpus_tools.annis.api.model.AnnoKey) Map(java.util.Map) XMLStreamException(javax.xml.stream.XMLStreamException) CorpusConfigurationContext(org.corpus_tools.annis.api.model.CorpusConfigurationContext) STextualRelation(org.corpus_tools.salt.common.STextualRelation) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) SRelation(org.corpus_tools.salt.core.SRelation) SSpan(org.corpus_tools.salt.common.SSpan) Range(com.google.common.collect.Range) Set(java.util.Set) ApiClient(org.corpus_tools.annis.ApiClient) FEAT_MATCHEDNODE(org.corpus_tools.annis.gui.objects.AnnisConstants.FEAT_MATCHEDNODE) ComparisonChain(com.google.common.collect.ComparisonChain) StandardCharsets(java.nio.charset.StandardCharsets) AnnisConstants(org.corpus_tools.annis.gui.objects.AnnisConstants) Stream(java.util.stream.Stream) SALT_TYPE(org.corpus_tools.salt.SALT_TYPE) SDocumentGraph(org.corpus_tools.salt.common.SDocumentGraph) OAuth2User(org.springframework.security.oauth2.core.user.OAuth2User) SCorpusGraph(org.corpus_tools.salt.common.SCorpusGraph) SAnnotation(org.corpus_tools.salt.core.SAnnotation) Joiner(com.google.common.base.Joiner) QueryLanguage(org.corpus_tools.annis.api.model.QueryLanguage) CorpusConfiguration(org.corpus_tools.annis.api.model.CorpusConfiguration) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) LinkedHashSet(java.util.LinkedHashSet) Properties(java.util.Properties) Files(java.nio.file.Files) GraphTraverseHandler(org.corpus_tools.salt.core.GraphTraverseHandler) SaltProject(org.corpus_tools.salt.common.SaltProject) IOException(java.io.IOException) MultiPartEmail(org.apache.commons.mail.MultiPartEmail) UnknownHostException(java.net.UnknownHostException) File(java.io.File) ANNIS_NS(org.corpus_tools.annis.gui.objects.AnnisConstants.ANNIS_NS) SCorpus(org.corpus_tools.salt.common.SCorpus) TreeMap(java.util.TreeMap) ApiException(org.corpus_tools.annis.ApiException) CorpusGraphMapper(org.corpus_tools.annis.gui.graphml.CorpusGraphMapper) CorpusConfigurationView(org.corpus_tools.annis.api.model.CorpusConfigurationView) AnnotationComponentType(org.corpus_tools.annis.api.model.AnnotationComponentType) STextualDS(org.corpus_tools.salt.common.STextualDS) JsonCodec(com.vaadin.server.JsonCodec) URLDecoder(java.net.URLDecoder) URISyntaxException(java.net.URISyntaxException) UI(com.vaadin.ui.UI) LoggerFactory(org.slf4j.LoggerFactory) ExceptionDialog(org.corpus_tools.annis.gui.components.ExceptionDialog) Match(org.corpus_tools.annis.gui.objects.Match) OrderEnum(org.corpus_tools.annis.api.model.FindQuery.OrderEnum) URI(java.net.URI) CorporaApi(org.corpus_tools.annis.api.CorporaApi) Escaper(com.google.common.escape.Escaper) Collection(java.util.Collection) SAnnotationContainer(org.corpus_tools.salt.core.SAnnotationContainer) Collectors(java.util.stream.Collectors) Label(org.corpus_tools.salt.graph.Label) Objects(java.util.Objects) List(java.util.List) SecurityContext(org.springframework.security.core.context.SecurityContext) Component(org.corpus_tools.annis.api.model.Component) SaltFactory(org.corpus_tools.salt.SaltFactory) EmailException(org.apache.commons.mail.EmailException) Optional(java.util.Optional) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) Pattern(java.util.regex.Pattern) Authentication(org.springframework.security.core.Authentication) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SToken(org.corpus_tools.salt.common.SToken) SLayer(org.corpus_tools.salt.core.SLayer) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) SNode(org.corpus_tools.salt.core.SNode) SMetaAnnotation(org.corpus_tools.salt.core.SMetaAnnotation) SSpanningRelation(org.corpus_tools.salt.common.SSpanningRelation) HashSet(java.util.HashSet) FindQuery(org.corpus_tools.annis.api.model.FindQuery) GRAPH_TRAVERSE_TYPE(org.corpus_tools.salt.core.SGraph.GRAPH_TRAVERSE_TYPE) SOrderRelation(org.corpus_tools.salt.common.SOrderRelation) Notification(com.vaadin.ui.Notification) Escapers(com.google.common.escape.Escapers) LinkedList(java.util.LinkedList) SecurityConfiguration(org.corpus_tools.annis.gui.security.SecurityConfiguration) SDocument(org.corpus_tools.salt.common.SDocument) SearchApi(org.corpus_tools.annis.api.SearchApi) StandardClaimNames(org.springframework.security.oauth2.core.oidc.StandardClaimNames) SFeature(org.corpus_tools.salt.core.SFeature) Comparator(java.util.Comparator) CorporaApi(org.corpus_tools.annis.api.CorporaApi) SAnnotation(org.corpus_tools.salt.core.SAnnotation) SMetaAnnotation(org.corpus_tools.salt.core.SMetaAnnotation) AnnoKey(org.corpus_tools.annis.api.model.AnnoKey) SearchApi(org.corpus_tools.annis.api.SearchApi) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 3 with CorporaApi

use of org.corpus_tools.annis.api.CorporaApi in project ANNIS by korpling.

the class SearchView method evaluateFragment.

private void evaluateFragment(String fragment) {
    // do nothing if not changed
    if (fragment == null || fragment.isEmpty() || fragment.equals(lastEvaluatedFragment)) {
        return;
    }
    Map<String, String> args = Helper.parseFragment(fragment);
    if (args.containsKey("c")) {
        String[] originalCorpusNames = args.get("c").split("\\s*,\\s*");
        Set<String> corpora = new TreeSet<String>(Arrays.asList(originalCorpusNames));
        // Remove all corpora we don't have the access right to
        try {
            CorporaApi api = new CorporaApi(Helper.getClient(ui));
            Set<String> availableCorpora = new HashSet<>(api.listCorpora());
            corpora.removeIf(c -> !availableCorpora.contains(c));
        } catch (ApiException e) {
            ExceptionDialog.show(e, "Could not get corpus list", ui);
        }
        if (corpora.isEmpty()) {
            if (!Helper.getUser(ui.getSecurityContext()).isPresent() && toolbar != null) {
                // not logged in, show login window
                toolbar.showLoginWindow();
            } else {
                // already logged in or no login system available, just display a message
                new Notification("Linked corpus does not exist", "<div><p>The corpus you wanted to access unfortunally does not (yet) exist" + " in ANNIS.</p>" + "<h2>possible reasons are:</h2>" + "<ul>" + "<li>that it has not been imported yet,</li>" + "<li>you don't have the access rights to see this corpus,</li>" + "<li>or the ANNIS service is not running.</li>" + "</ul>" + "<p>Please ask the responsible person of the site that contained " + "the link to import the corpus.</p></div>", Notification.Type.WARNING_MESSAGE, true).show(Page.getCurrent());
            }
        } else // end if corpus list returned from service is empty
        {
            if (args.containsKey("c") && args.size() == 1) {
                // special case: we were called from outside and should only select,
                // but not query, the selected corpora
                Query q = new Query();
                q.setCorpora(corpora);
                q.setQuery("");
                ui.getQueryController().setQuery(q);
                ui.getQueryController().corpusSelectionChangedInBackground();
            } else if (args.get("cl") != null && args.get("cr") != null) {
                // make sure the properties are not overwritten by the background process
                getControlPanel().getSearchOptions().setUpdateStateFromConfig(false);
                DisplayedResultQuery query = QueryGenerator.displayed().left(Integer.parseInt(args.get("cl"))).right(Integer.parseInt(args.get("cr"))).offset(Integer.parseInt(args.get("s"))).limit(Integer.parseInt(args.get("l"))).segmentation(args.get("seg")).baseText(args.get("bt")).query(args.get("q")).corpora(corpora).build();
                if (query.getBaseText() == null && query.getSegmentation() != null) {
                    // if no explicit visible segmentation was given use the same as the context
                    query.setBaseText(query.getSegmentation());
                }
                if (query.getBaseText() != null && query.getBaseText().isEmpty()) {
                    // empty string means "null"
                    query.setBaseText(null);
                }
                String matchSelectionRaw = args.get("m");
                if (matchSelectionRaw != null) {
                    for (String selectedMatchNr : Splitter.on(',').omitEmptyStrings().trimResults().split(matchSelectionRaw)) {
                        try {
                            long nr = Long.parseLong(selectedMatchNr);
                            query.getSelectedMatches().add(nr);
                        } catch (NumberFormatException ex) {
                            log.warn("Invalid long provided as selected match", ex);
                        }
                    }
                }
                if (args.get("o") != null) {
                    try {
                        query.setOrder(DisplayedResultQuery.parseOrderFromCitationFragment(args.get("0")));
                    } catch (IllegalArgumentException ex) {
                        log.warn("Could not parse query fragment argument for order", ex);
                    }
                }
                if (args.get("ql") != null) {
                    try {
                        query.setQueryLanguage(QueryLanguage.valueOf(args.get("ql").toUpperCase()));
                    } catch (IllegalArgumentException ex) {
                        log.warn("Could not parse query fragment argument for the query language", ex);
                    }
                }
                // full query with given context
                ui.getQueryController().setQuery(query);
                ui.getQueryController().executeSearch(true, false);
            } else if (args.get("q") != null) {
                QueryLanguage ql = QueryLanguage.AQL;
                if (args.get("ql") != null) {
                    try {
                        ql = QueryLanguage.valueOf(args.get("ql").toUpperCase());
                    } catch (IllegalArgumentException ex) {
                        log.warn("Could not parse query fragment argument for the query language", ex);
                    }
                }
                // use default context
                ui.getQueryController().setQuery(new Query(args.get("q"), ql, corpora));
                ui.getQueryController().executeSearch(true, true);
            }
        }
    // end if corpus list from server was non-empty
    }
// end if there is a corpus definition
}
Also used : CorporaApi(org.corpus_tools.annis.api.CorporaApi) PagedResultQuery(org.corpus_tools.annis.gui.objects.PagedResultQuery) Query(org.corpus_tools.annis.gui.objects.Query) DisplayedResultQuery(org.corpus_tools.annis.gui.objects.DisplayedResultQuery) Notification(com.vaadin.ui.Notification) TreeSet(java.util.TreeSet) QueryLanguage(org.corpus_tools.annis.gui.objects.QueryLanguage) DisplayedResultQuery(org.corpus_tools.annis.gui.objects.DisplayedResultQuery) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ApiException(org.corpus_tools.annis.ApiException)

Example 4 with CorporaApi

use of org.corpus_tools.annis.api.CorporaApi in project ANNIS by korpling.

the class CorpusBrowserPanel method fetchAnnotationsInBackground.

private void fetchAnnotationsInBackground(UI ui) {
    CorporaApi api = new CorporaApi(Helper.getClient(ui));
    try {
        final List<Annotation> nodeAnnos = api.nodeAnnotations(corpus, true, true).stream().filter(a -> !Objects.equals(a.getKey().getNs(), "annis") && !Objects.equals(a.getKey().getName(), "tok")).collect(Collectors.toList());
        final List<Annotation> metaAnnos = new LinkedList<>(nodeAnnos);
        final Set<AnnoKey> metaAnnoKeys = Helper.getMetaAnnotationNames(corpus, ui);
        nodeAnnos.removeIf(anno -> metaAnnoKeys.contains(anno.getKey()));
        metaAnnos.removeIf(anno -> !metaAnnoKeys.contains(anno.getKey()));
        final List<Component> components = api.components(corpus, "Dominance", null);
        final List<Annotation> allEdgeAnnos = new LinkedList<>();
        final Map<Component, List<Annotation>> edgeAnnosByComponent = new LinkedHashMap<>();
        components.addAll(api.components(corpus, "Pointing", null));
        for (Component c : components) {
            try {
                List<Annotation> annos = api.edgeAnnotations(corpus, c.getType().getValue(), c.getLayer(), c.getName(), true, true);
                edgeAnnosByComponent.put(c, annos);
                allEdgeAnnos.addAll(annos);
            } catch (ApiException ex) {
            // Ignore any not found errors
            }
        }
        getUI().access(() -> {
            TreeSet<CorpusBrowserEntry> nodeAnnoItems = new TreeSet<>();
            TreeSet<CorpusBrowserEntry> edgeAnnoItems = new TreeSet<>();
            TreeSet<CorpusBrowserEntry> edgeTypeItems = new TreeSet<>();
            TreeSet<CorpusBrowserEntry> metaAnnoItems = new TreeSet<>();
            progress.setVisible(false);
            accordion.setVisible(true);
            boolean stripNodeAnno = canExcludeNamespace(nodeAnnos);
            boolean stripEdgeName = canExcludeNamespace(allEdgeAnnos);
            boolean stripEdgeAnno = true;
            HashSet<String> nodeAnnoNames = new HashSet<>();
            HashSet<String> edgeAnnoNames = new HashSet<>();
            HashSet<String> edgeNames = new HashSet<>();
            boolean hasDominance = false;
            boolean hasEmptyDominance = false;
            // do some preparations first
            for (Annotation a : nodeAnnos) {
                // check for ambiguous names
                if (!nodeAnnoNames.add(a.getKey().getName())) {
                    stripNodeAnno = false;
                }
            }
            for (Component c : components) {
                // check if collected edge names are unique
                if (!edgeNames.add(Helper.getQName(c))) {
                    stripEdgeName = false;
                }
                // check if we need to add the general dominance example edge
                if (c.getType() == AnnotationComponentType.DOMINANCE) {
                    hasDominance = true;
                    if (c.getName() == null || c.getName().isEmpty()) {
                        hasEmptyDominance = true;
                    }
                }
            }
            for (List<Annotation> annos : edgeAnnosByComponent.values()) {
                for (Annotation a : annos) {
                    // check for ambiguous names
                    if (!edgeAnnoNames.add(a.getKey().getName())) {
                        stripEdgeAnno = false;
                    }
                }
            }
            // fill the actual containers
            for (Annotation a : nodeAnnos) {
                String name = stripNodeAnno ? a.getKey().getName() : Helper.getQName(a.getKey());
                CorpusBrowserEntry cbe = new CorpusBrowserEntry();
                cbe.setName(name);
                cbe.setExample(name + "=\"" + a.getVal() + "\"");
                cbe.setCorpus(corpus);
                nodeAnnoItems.add(cbe);
            }
            // edge type entry
            if (hasDominance && !hasEmptyDominance) {
                CorpusBrowserEntry cbe = new CorpusBrowserEntry();
                cbe.setName("(dominance)");
                cbe.setCorpus(corpus);
                cbe.setExample("node & node & #1 > #2");
                edgeTypeItems.add(cbe);
            }
            for (Component c : components) {
                CorpusBrowserEntry cbeEdgeType = new CorpusBrowserEntry();
                String name = stripEdgeName ? c.getName() : Helper.getQName(c);
                if ((name == null || name.isEmpty()) && c.getType() == AnnotationComponentType.DOMINANCE) {
                    cbeEdgeType.setName("(dominance)");
                } else {
                    cbeEdgeType.setName(name);
                }
                cbeEdgeType.setCorpus(corpus);
                if (c.getType() == AnnotationComponentType.POINTING) {
                    cbeEdgeType.setExample("node & node & #1 ->" + c.getName() + " #2");
                } else if (c.getType() == AnnotationComponentType.DOMINANCE) {
                    cbeEdgeType.setExample("node & node & #1 >" + c.getName() + " #2");
                }
                edgeTypeItems.add(cbeEdgeType);
            }
            // edge annotation entries
            for (Map.Entry<Component, List<Annotation>> entry : edgeAnnosByComponent.entrySet()) {
                Component c = entry.getKey();
                for (Annotation a : entry.getValue()) {
                    CorpusBrowserEntry cbeEdgeAnno = new CorpusBrowserEntry();
                    String edgeAnno = stripEdgeAnno ? a.getKey().getName() : Helper.getQName(a.getKey());
                    cbeEdgeAnno.setName(edgeAnno);
                    cbeEdgeAnno.setCorpus(corpus);
                    if (c.getType() == AnnotationComponentType.POINTING) {
                        cbeEdgeAnno.setExample("node & node & #1 ->" + c.getName() + "[" + a.getKey().getName() + "=\"" + a.getVal() + "\"] #2");
                    } else if (c.getType() == AnnotationComponentType.DOMINANCE) {
                        cbeEdgeAnno.setExample("node & node & #1 >[" + a.getKey().getName() + "=\"" + a.getVal() + "\"] #2");
                    }
                    edgeAnnoItems.add(cbeEdgeAnno);
                }
            }
            boolean stripMetaName = canExcludeNamespace(metaAnnos);
            for (Annotation a : nodeAnnos) {
                String name = stripMetaName ? a.getKey().getName() : Helper.getQName(a.getKey());
                CorpusBrowserEntry cbe = new CorpusBrowserEntry();
                cbe.setName(name);
                cbe.setExample(name + "=\"" + a.getVal() + "\"");
                cbe.setCorpus(corpus);
                nodeAnnoItems.add(cbe);
            }
            for (Annotation a : metaAnnos) {
                String name = stripNodeAnno ? a.getKey().getName() : Helper.getQName(a.getKey());
                CorpusBrowserEntry cbe = new CorpusBrowserEntry();
                cbe.setName(name);
                cbe.setExample(name + "=\"" + a.getVal() + "\"");
                cbe.setCorpus(corpus);
                metaAnnoItems.add(cbe);
            }
            lblNoNodeAnno.setVisible(nodeAnnoItems.isEmpty());
            tblNodeAnno.setVisible(!nodeAnnoItems.isEmpty());
            tblNodeAnno.setItems(new ArrayList<>(nodeAnnoItems));
            lblNoEdgeAnno.setVisible(edgeAnnoItems.isEmpty());
            tblEdgeAnno.setVisible(!edgeAnnoItems.isEmpty());
            tblEdgeAnno.setItems(edgeAnnoItems);
            lblNoEdgeTypes.setVisible(edgeTypeItems.isEmpty());
            tblEdgeTypes.setVisible(!edgeTypeItems.isEmpty());
            tblEdgeTypes.setItems(edgeTypeItems);
            lblNoMetaAnno.setVisible(metaAnnoItems.isEmpty());
            tblMetaAnno.setVisible(!metaAnnoItems.isEmpty());
            tblMetaAnno.setItems(metaAnnoItems);
        });
    } catch (ApiException e) {
        getUI().access(() -> {
            ExceptionDialog.show(e, "Error fetching corpus annotations", getUI());
        });
    }
}
Also used : Panel(com.vaadin.ui.Panel) SelectionListener(com.vaadin.event.selection.SelectionListener) VerticalLayout(com.vaadin.ui.VerticalLayout) SelectionEvent(com.vaadin.event.selection.SelectionEvent) Alignment(com.vaadin.ui.Alignment) UI(com.vaadin.ui.UI) ExceptionDialog(org.corpus_tools.annis.gui.components.ExceptionDialog) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) AnnoKey(org.corpus_tools.annis.api.model.AnnoKey) CorpusBrowserEntry(org.corpus_tools.annis.gui.beans.CorpusBrowserEntry) Accordion(com.vaadin.ui.Accordion) Label(com.vaadin.ui.Label) Map(java.util.Map) LinkedList(java.util.LinkedList) ProgressBar(com.vaadin.ui.ProgressBar) CorporaApi(org.corpus_tools.annis.api.CorporaApi) Query(org.corpus_tools.annis.gui.objects.Query) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) QueryLanguage(org.corpus_tools.annis.gui.objects.QueryLanguage) Component(org.corpus_tools.annis.api.model.Component) ApiException(org.corpus_tools.annis.ApiException) Optional(java.util.Optional) Annotation(org.corpus_tools.annis.api.model.Annotation) AnnotationComponentType(org.corpus_tools.annis.api.model.AnnotationComponentType) CorpusBrowserEntry(org.corpus_tools.annis.gui.beans.CorpusBrowserEntry) CorporaApi(org.corpus_tools.annis.api.CorporaApi) Annotation(org.corpus_tools.annis.api.model.Annotation) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) TreeSet(java.util.TreeSet) AnnoKey(org.corpus_tools.annis.api.model.AnnoKey) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Component(org.corpus_tools.annis.api.model.Component) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ApiException(org.corpus_tools.annis.ApiException) HashSet(java.util.HashSet)

Example 5 with CorporaApi

use of org.corpus_tools.annis.api.CorporaApi in project ANNIS by korpling.

the class EmbeddedVisUI method generateVisFromParameters.

private void generateVisFromParameters(final String visName, Map<String, String[]> args) {
    // find the matching visualizer
    final Optional<VisualizerPlugin> visPlugin = visualizers.stream().filter(vis -> Objects.equal(vis.getShortName(), visName)).findAny();
    if (!visPlugin.isPresent()) {
        displayMessage("Unknown visualizer \"" + visName + "\"", "This ANNIS instance does not know the given visualizer.");
        return;
    }
    ApiClient client = getClient();
    displayLoadingIndicator();
    // Create a subgraph query
    CorporaApi api = new CorporaApi(client);
    Match match = Match.parseFromString(args.get(KEY_MATCH)[0]);
    List<String> corpusPath = Helper.getCorpusPath(match.getSaltIDs().get(0));
    if (args.containsKey(KEY_FULLTEXT)) {
        boolean isUsingRawText = visPlugin.get().isUsingRawText();
        String aql = Helper.buildDocumentQuery(corpusPath, null, isUsingRawText);
        Background.runWithCallback(() -> api.subgraphForQuery(corpusPath.get(0), aql, QueryLanguage.AQL, isUsingRawText ? AnnotationComponentType.ORDERING : null), new GraphMLLoaderCallback(corpusPath, visPlugin.get(), args));
    } else {
        SubgraphWithContext subgraphQuery = new SubgraphWithContext();
        subgraphQuery.setLeft(Integer.parseInt(args.get(KEY_LEFT)[0]));
        subgraphQuery.setRight(Integer.parseInt(args.get(KEY_RIGHT)[0]));
        subgraphQuery.setNodeIds(match.getSaltIDs());
        if (args.containsKey(KEY_SEGMENTATION)) {
            subgraphQuery.setSegmentation(args.get(KEY_SEGMENTATION)[0]);
        } else {
            subgraphQuery.setSegmentation(null);
        }
        Background.runWithCallback(() -> api.subgraphForNodes(corpusPath.get(0), subgraphQuery), new GraphMLLoaderCallback(corpusPath, visPlugin.get(), args));
    }
}
Also used : Panel(com.vaadin.ui.Panel) URISyntaxException(java.net.URISyntaxException) Alignment(com.vaadin.ui.Alignment) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) VaadinRequest(com.vaadin.server.VaadinRequest) Match(org.corpus_tools.annis.gui.objects.Match) Transport(com.vaadin.shared.ui.ui.Transport) Map(java.util.Map) XMLStreamException(javax.xml.stream.XMLStreamException) OAuth2ClientProperties(org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties) URI(java.net.URI) ANNISFontIcon(org.corpus_tools.annis.gui.util.ANNISFontIcon) Objects(com.google.common.base.Objects) DocBrowserController(org.corpus_tools.annis.gui.docbrowser.DocBrowserController) Splitter(com.google.common.base.Splitter) CorporaApi(org.corpus_tools.annis.api.CorporaApi) DocumentGraphMapper(org.corpus_tools.annis.gui.graphml.DocumentGraphMapper) Request(okhttp3.Request) Link(com.vaadin.ui.Link) ApiClient(org.corpus_tools.annis.ApiClient) SubgraphWithContext(org.corpus_tools.annis.api.model.SubgraphWithContext) VisualizerPlugin(org.corpus_tools.annis.gui.visualizers.VisualizerPlugin) IOUtils(org.apache.commons.io.IOUtils) Theme(com.vaadin.annotations.Theme) ExternalResource(com.vaadin.server.ExternalResource) List(java.util.List) SDocumentGraph(org.corpus_tools.salt.common.SDocumentGraph) SaltFactory(org.corpus_tools.salt.SaltFactory) AuthenticationSuccessListener(org.corpus_tools.annis.gui.security.AuthenticationSuccessListener) Optional(java.util.Optional) SCorpusGraph(org.corpus_tools.salt.common.SCorpusGraph) Joiner(com.google.common.base.Joiner) QueryLanguage(org.corpus_tools.annis.api.model.QueryLanguage) VerticalLayout(com.vaadin.ui.VerticalLayout) HashMap(java.util.HashMap) SpringUI(com.vaadin.spring.annotation.SpringUI) SNode(org.corpus_tools.salt.core.SNode) VisualizerRule(org.corpus_tools.annis.api.model.VisualizerRule) LinkedHashMap(java.util.LinkedHashMap) Label(com.vaadin.ui.Label) Response(okhttp3.Response) LinkedList(java.util.LinkedList) PushMode(com.vaadin.shared.communication.PushMode) ContentMode(com.vaadin.shared.ui.ContentMode) Logger(org.slf4j.Logger) HTMLVis(org.corpus_tools.annis.gui.visualizers.htmlvis.HTMLVis) SaltProject(org.corpus_tools.salt.common.SaltProject) FileOutputStream(java.io.FileOutputStream) SDocument(org.corpus_tools.salt.common.SDocument) IOException(java.io.IOException) FutureCallback(com.google.common.util.concurrent.FutureCallback) File(java.io.File) Push(com.vaadin.annotations.Push) VisualizerInput(org.corpus_tools.annis.gui.visualizers.VisualizerInput) RawTextWrapper(org.corpus_tools.annis.gui.objects.RawTextWrapper) ServletContext(javax.servlet.ServletContext) Widgetset(com.vaadin.annotations.Widgetset) Component(com.vaadin.ui.Component) AnnotationComponentType(org.corpus_tools.annis.api.model.AnnotationComponentType) VisualizerPlugin(org.corpus_tools.annis.gui.visualizers.VisualizerPlugin) CorporaApi(org.corpus_tools.annis.api.CorporaApi) SubgraphWithContext(org.corpus_tools.annis.api.model.SubgraphWithContext) ApiClient(org.corpus_tools.annis.ApiClient) Match(org.corpus_tools.annis.gui.objects.Match)

Aggregations

CorporaApi (org.corpus_tools.annis.api.CorporaApi)33 ApiException (org.corpus_tools.annis.ApiException)26 File (java.io.File)14 IOException (java.io.IOException)11 SCorpusGraph (org.corpus_tools.salt.common.SCorpusGraph)9 SDocument (org.corpus_tools.salt.common.SDocument)9 SaltProject (org.corpus_tools.salt.common.SaltProject)8 TreeSet (java.util.TreeSet)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 LinkedList (java.util.LinkedList)6 XMLStreamException (javax.xml.stream.XMLStreamException)6 SearchApi (org.corpus_tools.annis.api.SearchApi)5 FileInputStream (java.io.FileInputStream)4 Map (java.util.Map)4 Annotation (org.corpus_tools.annis.api.model.Annotation)4 FindQuery (org.corpus_tools.annis.api.model.FindQuery)4 AnnisBaseUI (org.corpus_tools.annis.gui.AnnisBaseUI)4 Test (org.junit.jupiter.api.Test)4