Search in sources :

Example 1 with VisualizerInput

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

the class EmbeddedVisUI method showHtmlDoc.

private void showHtmlDoc(String corpus, String doc, Map<String, String[]> args) {
    // do nothing for empty fragments
    if (args == null || args.isEmpty()) {
        return;
    }
    if (args.get("config") != null && args.get("config").length > 0) {
        String config = args.get("config")[0];
        // get input parameters
        HTMLVis visualizer;
        visualizer = new HTMLVis();
        VisualizerInput input;
        Visualizer visConfig;
        visConfig = new Visualizer();
        visConfig.setDisplayName(" ");
        visConfig.setMappings("config:" + config);
        visConfig.setNamespace(null);
        visConfig.setType("htmldoc");
        // create input
        try {
            input = DocBrowserController.createInput(corpus, doc, visConfig, false, null);
            // create components, put in a panel
            Panel viszr = visualizer.createComponent(input, null);
            // Set the panel as the content of the UI
            setContent(viszr);
        } catch (UniformInterfaceException ex) {
            displayMessage("Could not query document", "error was \"" + ex.getMessage() + "\" (detailed error is available in the server log-files)");
            log.error("Could not get document for embedded visualizer", ex);
        }
    } else {
        displayMessage("Missing required argument for visualizer \"htmldoc\"", "The following arguments are required:" + "<ul>" + "<li><code>config</code>: the internal config file to use (same as <a href=\"http://korpling.github.io/ANNIS/doc/classannis_1_1visualizers_1_1htmlvis_1_1HTMLVis.html\">\"config\" mapping parameter)</a></li>" + "</ul>");
    }
}
Also used : Panel(com.vaadin.ui.Panel) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) VisualizerInput(annis.libgui.visualizers.VisualizerInput) Visualizer(annis.service.objects.Visualizer) HTMLVis(annis.visualizers.htmlvis.HTMLVis)

Example 2 with VisualizerInput

use of annis.libgui.visualizers.VisualizerInput 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 3 with VisualizerInput

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

the class EmbeddedVisUI method generateVisFromRemoteURL.

private void generateVisFromRemoteURL(final String visName, final String rawUri, Map<String, String[]> args) {
    try {
        // find the matching visualizer
        final VisualizerPlugin visPlugin = this.getVisualizer(visName);
        if (visPlugin == null) {
            displayMessage("Unknown visualizer \"" + visName + "\"", "This ANNIS instance does not know the given visualizer.");
            return;
        }
        URI uri = new URI(rawUri);
        // fetch content of the URI
        Client client = null;
        AnnisUser user = Helper.getUser();
        if (user != null) {
            client = user.getClient();
        }
        if (client == null) {
            client = Helper.createRESTClient();
        }
        final WebResource saltRes = client.resource(uri);
        displayLoadingIndicator();
        // copy the arguments for using them later in the callback
        final Map<String, String[]> argsCopy = new LinkedHashMap<>(args);
        Background.runWithCallback(new Callable<SaltProject>() {

            @Override
            public SaltProject call() throws Exception {
                return saltRes.get(SaltProject.class);
            }
        }, new FutureCallback<SaltProject>() {

            @Override
            public void onFailure(Throwable t) {
                displayMessage("Could not query the result.", t.getMessage());
            }

            @Override
            public void onSuccess(SaltProject p) {
                // TODO: allow to display several visualizers when there is more than one document
                SCorpusGraph firstCorpusGraph = null;
                SDocument doc = null;
                if (p.getCorpusGraphs() != null && !p.getCorpusGraphs().isEmpty()) {
                    firstCorpusGraph = p.getCorpusGraphs().get(0);
                    if (firstCorpusGraph.getDocuments() != null && !firstCorpusGraph.getDocuments().isEmpty()) {
                        doc = firstCorpusGraph.getDocuments().get(0);
                    }
                }
                if (doc == null) {
                    displayMessage("No documents found in provided URL.", "");
                    return;
                }
                if (argsCopy.containsKey(KEY_INSTANCE)) {
                    Map<String, InstanceConfig> allConfigs = loadInstanceConfig();
                    InstanceConfig newConfig = allConfigs.get(argsCopy.get(KEY_INSTANCE)[0]);
                    if (newConfig != null) {
                        setInstanceConfig(newConfig);
                    }
                }
                // now it is time to load the actual defined instance fonts
                loadInstanceFonts();
                // generate the visualizer
                VisualizerInput visInput = new VisualizerInput();
                visInput.setDocument(doc);
                if (getInstanceConfig() != null && getInstanceConfig().getFont() != null) {
                    visInput.setFont(getInstanceFont());
                }
                Properties mappings = new Properties();
                for (Map.Entry<String, String[]> e : argsCopy.entrySet()) {
                    if (!KEY_SALT.equals(e.getKey()) && e.getValue().length > 0) {
                        mappings.put(e.getKey(), e.getValue()[0]);
                    }
                }
                visInput.setMappings(mappings);
                String[] namespace = argsCopy.get(KEY_NAMESPACE);
                if (namespace != null && namespace.length > 0) {
                    visInput.setNamespace(namespace[0]);
                } else {
                    visInput.setNamespace(null);
                }
                String baseText = null;
                if (argsCopy.containsKey(KEY_BASE_TEXT)) {
                    String[] value = argsCopy.get(KEY_BASE_TEXT);
                    if (value.length > 0) {
                        baseText = value[0];
                    }
                }
                List<SNode> segNodes = CommonHelper.getSortedSegmentationNodes(baseText, doc.getDocumentGraph());
                if (argsCopy.containsKey(KEY_MATCH)) {
                    String[] rawMatch = argsCopy.get(KEY_MATCH);
                    if (rawMatch.length > 0) {
                        // enhance the graph with match information from the arguments
                        Match match = Match.parseFromString(rawMatch[0]);
                        Helper.addMatchToDocumentGraph(match, doc);
                    }
                }
                Map<String, String> markedColorMap = new HashMap<>();
                Map<String, String> exactMarkedMap = Helper.calculateColorsForMarkedExact(doc);
                Map<String, Long> markedAndCovered = Helper.calculateMarkedAndCoveredIDs(doc, segNodes, baseText);
                Helper.calulcateColorsForMarkedAndCovered(doc, markedAndCovered, markedColorMap);
                visInput.setMarkedAndCovered(markedAndCovered);
                visInput.setMarkableMap(markedColorMap);
                visInput.setMarkableExactMap(exactMarkedMap);
                visInput.setContextPath(Helper.getContext());
                String template = Helper.getContext() + "/Resource/" + visName + "/%s";
                visInput.setResourcePathTemplate(template);
                visInput.setSegmentationName(baseText);
                // TODO: which other thing do we have to provide?
                Component c = visPlugin.createComponent(visInput, null);
                // add the styles
                c.addStyleName("corpus-font");
                c.addStyleName("vis-content");
                Link link = new Link();
                link.setCaption("Show in ANNIS search interface");
                link.setIcon(ANNISFontIcon.LOGO);
                link.setVisible(false);
                link.addStyleName("dontprint");
                link.setTargetName("_blank");
                if (argsCopy.containsKey(KEY_SEARCH_INTERFACE)) {
                    String[] interfaceLink = argsCopy.get(KEY_SEARCH_INTERFACE);
                    if (interfaceLink.length > 0) {
                        link.setResource(new ExternalResource(interfaceLink[0]));
                        link.setVisible(true);
                    }
                }
                VerticalLayout layout = new VerticalLayout(link, c);
                layout.setComponentAlignment(link, Alignment.TOP_LEFT);
                layout.setSpacing(true);
                layout.setMargin(true);
                setContent(layout);
                IDGenerator.assignID(link);
            }
        });
    } catch (URISyntaxException ex) {
        displayMessage("Invalid URL", "The provided URL is malformed:<br />" + ex.getMessage());
    } catch (LoginDataLostException ex) {
        displayMessage("LoginData Lost", "No login data available any longer in the session:<br /> " + ex.getMessage());
    } catch (UniformInterfaceException ex) {
        if (ex.getResponse().getStatus() == Response.Status.FORBIDDEN.getStatusCode()) {
            displayMessage("Corpus access forbidden", "You are not allowed to access this corpus. " + "Please login at the <a target=\"_blank\" href=\"" + Helper.getContext() + "\">main application</a> first and then reload this page.");
        } else {
            displayMessage("Service error", ex.getMessage());
        }
    } catch (ClientHandlerException ex) {
        displayMessage("Could not generate the visualization because the ANNIS service reported an error.", ex.getMessage());
    } catch (Throwable ex) {
        displayMessage("Could not generate the visualization.", ex.getMessage() == null ? ("An unknown error of type " + ex.getClass().getSimpleName()) + " occured." : ex.getMessage());
    }
}
Also used : VisualizerPlugin(annis.libgui.visualizers.VisualizerPlugin) WebResource(com.sun.jersey.api.client.WebResource) URISyntaxException(java.net.URISyntaxException) Properties(java.util.Properties) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) SCorpusGraph(org.corpus_tools.salt.common.SCorpusGraph) Match(annis.service.objects.Match) InstanceConfig(annis.libgui.InstanceConfig) VerticalLayout(com.vaadin.ui.VerticalLayout) List(java.util.List) LinkedList(java.util.LinkedList) Client(com.sun.jersey.api.client.Client) Component(com.vaadin.ui.Component) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) SDocument(org.corpus_tools.salt.common.SDocument) SaltProject(org.corpus_tools.salt.common.SaltProject) ExternalResource(com.vaadin.server.ExternalResource) AnnisUser(annis.libgui.AnnisUser) URISyntaxException(java.net.URISyntaxException) LoginDataLostException(annis.libgui.LoginDataLostException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) VisualizerInput(annis.libgui.visualizers.VisualizerInput) LoginDataLostException(annis.libgui.LoginDataLostException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Link(com.vaadin.ui.Link)

Example 4 with VisualizerInput

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

the class DocBrowserController method createInput.

/**
 * Creates the input. It only takes the salt project or the raw text from the
 * text table, never both, since the increase the performance for large texts.
 *
 * @param corpus the name of the toplevel corpus
 * @param docName the name of the document
 * @param config the visualizer configuration
 * @param isUsingRawText indicates, whether the text from text table is taken,
 * or if the salt project is traversed.
 * @param nodeAnnoFilter A list of node annotation names for filtering the nodes or null if no filtering should be applied.
 * @return a {@link VisualizerInput} input, which is usable for rendering the
 * whole document.
 */
public static VisualizerInput createInput(String corpus, String docName, Visualizer config, boolean isUsingRawText, List<String> nodeAnnoFilter) {
    VisualizerInput input = new VisualizerInput();
    // set mappings and namespaces. some visualizer do not survive without
    input.setMappings(parseMappings(config));
    input.setNamespace(config.getNamespace());
    String encodedToplevelCorpus = urlPathEscape.escape(corpus);
    String encodedDocument = urlPathEscape.escape(docName);
    if (isUsingRawText) {
        WebResource w = Helper.getAnnisWebResource();
        w = w.path("query").path("rawtext").path(encodedToplevelCorpus).path(encodedDocument);
        RawTextWrapper rawTextWrapper = w.get(RawTextWrapper.class);
        input.setRawText(rawTextWrapper);
    } else {
        // get the whole document wrapped in a salt project
        SaltProject txt = null;
        WebResource res = Helper.getAnnisWebResource().path("query").path("graph").path(encodedToplevelCorpus).path(encodedDocument);
        if (nodeAnnoFilter != null) {
            res = res.queryParam("filternodeanno", Joiner.on(",").join(nodeAnnoFilter));
        }
        txt = res.get(SaltProject.class);
        if (txt != null) {
            SDocument sDoc = txt.getCorpusGraphs().get(0).getDocuments().get(0);
            input.setResult(sDoc);
        }
    }
    return input;
}
Also used : VisualizerInput(annis.libgui.visualizers.VisualizerInput) RawTextWrapper(annis.service.objects.RawTextWrapper) WebResource(com.sun.jersey.api.client.WebResource) SDocument(org.corpus_tools.salt.common.SDocument) SaltProject(org.corpus_tools.salt.common.SaltProject)

Example 5 with VisualizerInput

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

the class VisualizerPanel method createComponent.

private Component createComponent() {
    if (visPlugin == null) {
        return null;
    }
    final VisualizerInput input = createInput();
    Component c = visPlugin.createComponent(input, this);
    c.setVisible(false);
    c.addStyleName(Helper.CORPUS_FONT);
    c.addStyleName("vis-content");
    return c;
}
Also used : VisualizerInput(annis.libgui.visualizers.VisualizerInput) Component(com.vaadin.ui.Component)

Aggregations

VisualizerInput (annis.libgui.visualizers.VisualizerInput)5 SDocument (org.corpus_tools.salt.common.SDocument)3 SaltProject (org.corpus_tools.salt.common.SaltProject)3 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)2 WebResource (com.sun.jersey.api.client.WebResource)2 Component (com.vaadin.ui.Component)2 AnnisUser (annis.libgui.AnnisUser)1 InstanceConfig (annis.libgui.InstanceConfig)1 LoginDataLostException (annis.libgui.LoginDataLostException)1 FilteringVisualizerPlugin (annis.libgui.visualizers.FilteringVisualizerPlugin)1 VisualizerPlugin (annis.libgui.visualizers.VisualizerPlugin)1 Match (annis.service.objects.Match)1 RawTextWrapper (annis.service.objects.RawTextWrapper)1 Visualizer (annis.service.objects.Visualizer)1 HTMLVis (annis.visualizers.htmlvis.HTMLVis)1 Client (com.sun.jersey.api.client.Client)1 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)1 ExternalResource (com.vaadin.server.ExternalResource)1 Link (com.vaadin.ui.Link)1 Panel (com.vaadin.ui.Panel)1