Search in sources :

Example 1 with FilteringVisualizerPlugin

use of annis.libgui.visualizers.FilteringVisualizerPlugin in project ANNIS by korpling.

the class VisualizerPanel method createInput.

private VisualizerInput createInput() {
    VisualizerInput input = new VisualizerInput();
    input.setAnnisWebServiceURL((String) VaadinSession.getCurrent().getAttribute("AnnisWebService.URL"));
    input.setContextPath(Helper.getContext());
    input.setDotPath((String) VaadinSession.getCurrent().getAttribute("DotPath"));
    input.setId(resultID);
    input.setMarkableExactMap(markersExact);
    input.setMarkableMap(markersCovered);
    input.setMarkedAndCovered(markedAndCovered);
    input.setResult(result);
    input.setVisibleTokenAnnos(visibleTokenAnnos);
    input.setSegmentationName(segmentationName);
    if (instanceConfig != null && instanceConfig.getFont() != null) {
        input.setFont(instanceConfig.getFont());
    }
    if (entry != null) {
        input.setMappings(entry.getMappings());
        input.setNamespace(entry.getNamespace());
        String template = Helper.getContext() + "/Resource/" + entry.getVisType() + "/%s";
        input.setResourcePathTemplate(template);
    }
    // getting the whole document, when plugin is using text
    if (visPlugin != null && visPlugin.isUsingText() && result != null && result.getDocumentGraph().getNodes().size() > 0) {
        List<String> nodeAnnoFilter = null;
        if (visPlugin instanceof FilteringVisualizerPlugin) {
            nodeAnnoFilter = ((FilteringVisualizerPlugin) visPlugin).getFilteredNodeAnnotationNames(corpusName, documentName, input.getMappings());
        }
        SaltProject p = getDocument(result.getGraph().getRoots().get(0).getName(), result.getName(), nodeAnnoFilter);
        SDocument wholeDocument = p.getCorpusGraphs().get(0).getDocuments().get(0);
        Helper.addMatchToDocumentGraph(match, wholeDocument);
        input.setDocument(wholeDocument);
    } else {
        input.setDocument(result);
    }
    // getting the raw text, when the visualizer wants to have it
    if (visPlugin != null && visPlugin.isUsingRawText()) {
        input.setRawText(Helper.getRawText(corpusName, documentName));
    }
    return input;
}
Also used : VisualizerInput(annis.libgui.visualizers.VisualizerInput) SDocument(org.corpus_tools.salt.common.SDocument) SaltProject(org.corpus_tools.salt.common.SaltProject) FilteringVisualizerPlugin(annis.libgui.visualizers.FilteringVisualizerPlugin)

Example 2 with FilteringVisualizerPlugin

use of annis.libgui.visualizers.FilteringVisualizerPlugin in project ANNIS by korpling.

the class ShareSingleMatchGenerator method generatorURLForVisualizer.

private URI generatorURLForVisualizer(ResolverEntry entry) {
    String appContext = Helper.getContext();
    URI appURI = UI.getCurrent().getPage().getLocation();
    UriBuilder result = UriBuilder.fromUri(appURI).replacePath(appContext).path("embeddedvis").path(Helper.encodeJersey(entry.getVisType())).fragment("");
    if (entry.getNamespace() != null) {
        result = result.queryParam("embedded_ns", Helper.encodeJersey(entry.getNamespace()));
    }
    // test if the request was made from a sub-instance
    String nonContextPath = appURI.getPath().substring(appContext.length());
    if (!nonContextPath.isEmpty()) {
        if (nonContextPath.startsWith("/")) {
            nonContextPath = nonContextPath.substring(1);
        }
        result = result.queryParam(EmbeddedVisUI.KEY_INSTANCE, nonContextPath);
    }
    UriBuilder serviceURL = UriBuilder.fromUri(Helper.getAnnisWebResource().path("query").getURI());
    VisualizerPlugin visPlugin = ps.getVisualizer(entry.getVisType());
    if (visPlugin != null && visPlugin.isUsingText()) {
        // generate a service URL that gets the whole document
        URI firstID = match.getSaltIDs().get(0);
        String pathAsString = firstID.getRawPath();
        List<String> path = Splitter.on('/').omitEmptyStrings().trimResults().splitToList(pathAsString);
        String corpusName = path.get(0);
        String documentName = path.get(path.size() - 1);
        try {
            corpusName = URLDecoder.decode(corpusName, "UTF-8");
            documentName = URLDecoder.decode(documentName, "UTF-8");
            ;
        } catch (UnsupportedEncodingException ex) {
            log.warn("Could not decode URL", ex);
        }
        // apply any node annotation filters if possible
        if (visPlugin instanceof FilteringVisualizerPlugin) {
            List<String> visAnnos = ((FilteringVisualizerPlugin) visPlugin).getFilteredNodeAnnotationNames(corpusName, documentName, entry.getMappings());
            if (visAnnos != null) {
                Set<String> annos = new HashSet<>(visAnnos);
                // always add the matched node annotation as well
                for (String matchedAnno : match.getAnnos()) {
                    if (!matchedAnno.isEmpty()) {
                        annos.add(matchedAnno);
                    }
                }
                serviceURL = serviceURL.queryParam("filternodeanno", Joiner.on(",").join(annos));
            }
        }
        serviceURL = serviceURL.path("graph").path(Helper.encodePath(corpusName)).path(Helper.encodePath(documentName));
        // add the original match so the embedded visualizer can add it
        // (since we use the graph query it will not be included in the Salt XMI itself)
        result = result.queryParam(EmbeddedVisUI.KEY_MATCH, Helper.encodeJersey(match.toString()));
    } else {
        // default to the subgraph URL for this specific match
        serviceURL = serviceURL.path("search").path("subgraph").queryParam("match", Helper.encodeJersey(match.toString())).queryParam("left", query.getLeftContext()).queryParam("right", query.getRightContext());
        if (query.getSegmentation() != null) {
            serviceURL = serviceURL.queryParam("segmentation", query.getSegmentation());
        }
    }
    // add the URL where to fetch the graph from
    result = result.queryParam(EmbeddedVisUI.KEY_SALT, Helper.encodeQueryParam(serviceURL.build().toASCIIString()));
    // add the current view as "return back" parameter
    result = result.queryParam(EmbeddedVisUI.KEY_SEARCH_INTERFACE, appURI.toASCIIString());
    if (segmentation != null) {
        result = result.queryParam(EmbeddedVisUI.KEY_BASE_TEXT, segmentation);
    }
    // add all mappings as parameter
    for (String key : entry.getMappings().stringPropertyNames()) {
        if (!key.startsWith(EmbeddedVisUI.KEY_PREFIX)) {
            String value = Helper.encodeJersey(entry.getMappings().getProperty(key));
            result = result.queryParam(key, value);
        }
    }
    return result.build();
}
Also used : FilteringVisualizerPlugin(annis.libgui.visualizers.FilteringVisualizerPlugin) VisualizerPlugin(annis.libgui.visualizers.VisualizerPlugin) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) FilteringVisualizerPlugin(annis.libgui.visualizers.FilteringVisualizerPlugin) HashSet(java.util.HashSet)

Aggregations

FilteringVisualizerPlugin (annis.libgui.visualizers.FilteringVisualizerPlugin)2 VisualizerInput (annis.libgui.visualizers.VisualizerInput)1 VisualizerPlugin (annis.libgui.visualizers.VisualizerPlugin)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 SDocument (org.corpus_tools.salt.common.SDocument)1 SaltProject (org.corpus_tools.salt.common.SaltProject)1