Search in sources :

Example 31 with SaltProject

use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.

the class ResultViewPanel method addQueryResult.

private void addQueryResult(PagedResultQuery q, List<SaltProject> subgraphList) {
    if (q == null) {
        return;
    }
    List<SingleResultPanel> newPanels = new LinkedList<>();
    try {
        if (subgraphList == null || subgraphList.isEmpty()) {
            Notification.show("Could not get subgraphs", Notification.Type.TRAY_NOTIFICATION);
        } else {
            for (SaltProject p : subgraphList) {
                updateVariables(p);
                newPanels = createPanels(p, currentResults, q.getOffset() + currentResults);
                currentResults += newPanels.size();
                String strResults = numberOfResults > 1 ? "results" : "result";
                sui.getSearchView().getControlPanel().getQueryPanel().setStatus(sui.getSearchView().getControlPanel().getQueryPanel().getLastPublicStatus(), " (showing " + currentResults + "/" + numberOfResults + " " + strResults + ")");
                if (currentResults == numberOfResults) {
                    resetQueryResultQueue();
                }
                for (SingleResultPanel panel : newPanels) {
                    resultPanelList.add(panel);
                    resultLayout.addComponent(panel);
                    panel.setSegmentationLayer(sui.getQueryState().getVisibleBaseText().getValue());
                }
            }
            if (currentResults == numberOfResults) {
                showFinishedSubgraphSearch();
                if (!initialQuery.getSelectedMatches().isEmpty()) {
                    // scroll to the first selected match
                    JavaScript.eval("$(\".v-panel-content-result-view-panel\").animate({scrollTop: $(\".selected-match\").offset().top - $(\".result-view-panel\").offset().top}, 1000);");
                }
            }
            if (projectQueue != null && !newPanels.isEmpty() && currentResults < numberOfResults) {
                log.debug("adding callback for result " + currentResults);
                // add a callback so we can load the next single result
                OnLoadCallbackExtension ext = new OnLoadCallbackExtension(this, 250);
                ext.extend(newPanels.get(newPanels.size() - 1));
            }
        }
    } catch (Throwable ex) {
        log.error(null, ex);
    }
}
Also used : SaltProject(org.corpus_tools.salt.common.SaltProject) LinkedList(java.util.LinkedList) OnLoadCallbackExtension(annis.gui.components.OnLoadCallbackExtension)

Example 32 with SaltProject

use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.

the class ResultViewPanel method onCompononentLoaded.

@Override
public boolean onCompononentLoaded(AbstractClientConnector source) {
    if (source != null) {
        if (projectQueue != null && currentQuery != null) {
            LinkedList<SaltProject> subgraphs = new LinkedList<>();
            SaltProject p;
            while ((p = projectQueue.poll()) != null) {
                log.debug("Polling queue for SaltProject graph");
                subgraphs.add(p);
            }
            if (subgraphs.isEmpty()) {
                log.debug("no SaltProject graph in queue");
                return false;
            }
            log.debug("taken {} SaltProject graph(s) from queue", subgraphs.size());
            addQueryResult(currentQuery, subgraphs);
            return true;
        }
    }
    return true;
}
Also used : SaltProject(org.corpus_tools.salt.common.SaltProject) LinkedList(java.util.LinkedList)

Example 33 with SaltProject

use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.

the class VisualizerPanel method getDocument.

private SaltProject getDocument(String toplevelCorpusName, String documentName, List<String> nodeAnnoFilter) {
    SaltProject txt = null;
    try {
        toplevelCorpusName = urlPathEscape.escape(toplevelCorpusName);
        documentName = urlPathEscape.escape(documentName);
        WebResource res = Helper.getAnnisWebResource().path("query").path("graph").path(toplevelCorpusName).path(documentName);
        if (nodeAnnoFilter != null) {
            res = res.queryParam("filternodeanno", Joiner.on(",").join(nodeAnnoFilter));
        }
        txt = res.get(SaltProject.class);
    } catch (ClientHandlerException | UniformInterfaceException e) {
        log.error("General remote service exception", e);
    }
    return txt;
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) WebResource(com.sun.jersey.api.client.WebResource) SaltProject(org.corpus_tools.salt.common.SaltProject)

Example 34 with SaltProject

use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.

the class SaltProjectProvider method readFrom.

@Override
public SaltProject readFrom(Class<SaltProject> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    SaltProject result = SaltFactory.createSaltProject();
    SAXParser parser;
    XMLReader xmlReader;
    SAXParserFactory factory = SAXParserFactory.newInstance();
    MixedContentHandler handler = new MixedContentHandler();
    try {
        parser = factory.newSAXParser();
        xmlReader = parser.getXMLReader();
        xmlReader.setContentHandler(handler);
        InputSource source = new InputSource(entityStream);
        source.setEncoding("UTF-8");
        xmlReader.parse(source);
        for (SDocumentGraph g : handler.getDocGraphs()) {
            // create a separate corpus graph for each document
            SCorpusGraph corpusGraph = SaltFactory.createSCorpusGraph();
            SCorpus parentCorpus = null;
            SDocument doc = null;
            List<SNode> nodes = g.getNodes();
            Iterator<String> it;
            if (nodes != null && !nodes.isEmpty()) {
                // the path of each node ID is always the document/corpus path
                it = nodes.get(0).getPath().segmentsList().iterator();
            } else {
                // Old salt versions had a separate ID for the document graph
                // which was the document name with the suffix "_graph".
                // Thus this method of getting the corpus path is only the fallback.
                it = g.getPath().segmentsList().iterator();
            }
            while (it.hasNext()) {
                String name = it.next();
                if (it.hasNext()) {
                    // this is a sub-corpus
                    parentCorpus = corpusGraph.createCorpus(parentCorpus, name);
                } else {
                    // no more path elements left, must be a document
                    doc = corpusGraph.createDocument(parentCorpus, name);
                    break;
                }
            }
            if (doc != null) {
                result.addCorpusGraph(corpusGraph);
                doc.setDocumentGraph(g);
            }
        }
    } catch (ParserConfigurationException | SAXException ex) {
        log.error("Error when parsing XMI", ex);
    }
    return result;
}
Also used : InputSource(org.xml.sax.InputSource) SNode(org.corpus_tools.salt.core.SNode) SDocument(org.corpus_tools.salt.common.SDocument) SaltProject(org.corpus_tools.salt.common.SaltProject) SCorpusGraph(org.corpus_tools.salt.common.SCorpusGraph) SAXException(org.xml.sax.SAXException) SCorpus(org.corpus_tools.salt.common.SCorpus) SDocumentGraph(org.corpus_tools.salt.common.SDocumentGraph) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

SaltProject (org.corpus_tools.salt.common.SaltProject)34 Test (org.junit.Test)11 Match (annis.service.objects.Match)8 WebResource (com.sun.jersey.api.client.WebResource)8 LinkedList (java.util.LinkedList)8 SDocumentGraph (org.corpus_tools.salt.common.SDocumentGraph)8 MatchGroup (annis.service.objects.MatchGroup)7 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)6 ArrayList (java.util.ArrayList)6 SDocument (org.corpus_tools.salt.common.SDocument)6 HashMap (java.util.HashMap)4 SCorpusGraph (org.corpus_tools.salt.common.SCorpusGraph)4 SNode (org.corpus_tools.salt.core.SNode)4 VisualizerInput (annis.libgui.visualizers.VisualizerInput)3 QueryData (annis.ql.parser.QueryData)3 SubgraphFilter (annis.service.objects.SubgraphFilter)3 AnnotateQueryData (annis.sqlgen.extensions.AnnotateQueryData)3 LimitOffsetQueryData (annis.sqlgen.extensions.LimitOffsetQueryData)3 IOException (java.io.IOException)3 AnnisCorpusAccessException (annis.exceptions.AnnisCorpusAccessException)2