Search in sources :

Example 11 with SaltProject

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

the class SingleResultFetchJob method call.

@Override
public SaltProject call() throws Exception {
    WebResource subgraphRes = Helper.getAnnisWebResource().path("query/search/subgraph");
    if (Thread.interrupted()) {
        return null;
    }
    List<Match> subList = new LinkedList<>();
    subList.add(match);
    SaltProject p = executeQuery(subgraphRes, new MatchGroup(subList), query.getLeftContext(), query.getRightContext(), query.getSegmentation(), SubgraphFilter.all);
    return p;
}
Also used : MatchGroup(annis.service.objects.MatchGroup) WebResource(com.sun.jersey.api.client.WebResource) SaltProject(org.corpus_tools.salt.common.SaltProject) LinkedList(java.util.LinkedList) Match(annis.service.objects.Match)

Example 12 with SaltProject

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

the class ResultFetchJob method run.

@Override
public void run() {
    WebResource subgraphRes = Helper.getAnnisWebResource().path("query/search/subgraph");
    // holds the ids of the matches.
    MatchGroup result;
    try {
        if (Thread.interrupted()) {
            return;
        }
        // set the the progress bar, for given the user some information about the loading process
        ui.accessSynchronously(new Runnable() {

            @Override
            public void run() {
                resultPanel.showMatchSearchInProgress(query);
            }
        });
        // get the matches
        result = futureMatches.get();
        // get the subgraph for each match, when the result is not empty
        if (result.getMatches().isEmpty()) {
            // check if thread was interrupted
            if (Thread.interrupted()) {
                return;
            }
            // nothing found, so inform the user about this.
            ui.access(new Runnable() {

                @Override
                public void run() {
                    resultPanel.showNoResult();
                }
            });
        } else {
            if (Thread.interrupted()) {
                return;
            }
            // since annis found something, inform the user that subgraphs are created
            ui.access(new Runnable() {

                @Override
                public void run() {
                    resultPanel.showSubgraphSearchInProgress(query, 0.0f);
                }
            });
            // prepare fetching subgraphs
            final BlockingQueue<SaltProject> queue = new ArrayBlockingQueue<>(result.getMatches().size());
            int current = 0;
            final ArrayList<Match> matchList = new ArrayList<>(result.getMatches());
            for (Match m : matchList) {
                if (Thread.interrupted()) {
                    return;
                }
                List<Match> subList = new LinkedList<>();
                subList.add(m);
                final SaltProject p = executeQuery(subgraphRes, new MatchGroup(subList), query.getLeftContext(), query.getRightContext(), query.getSegmentation(), SubgraphFilter.all);
                queue.put(p);
                log.debug("added match {} to queue", current + 1);
                if (current == 0) {
                    ui.access(new Runnable() {

                        @Override
                        public void run() {
                            resultPanel.setQueryResultQueue(queue, query, matchList);
                        }
                    });
                }
                if (Thread.interrupted()) {
                    return;
                }
                current++;
            }
        }
    // end if no results
    } catch (InterruptedException ex) {
    // just return
    } catch (final ExecutionException root) {
        ui.accessSynchronously(new Runnable() {

            @Override
            public void run() {
                if (resultPanel != null && resultPanel.getPaging() != null) {
                    PagingComponent paging = resultPanel.getPaging();
                    Throwable cause = root.getCause();
                    if (cause instanceof UniformInterfaceException) {
                        UniformInterfaceException ex = (UniformInterfaceException) cause;
                        if (ex.getResponse().getStatus() == 400) {
                            List<AqlParseError> errors = ex.getResponse().getEntity(new GenericType<List<AqlParseError>>() {
                            });
                            String errMsg = Joiner.on(" | ").join(errors);
                            paging.setInfo("parsing error: " + errMsg);
                        } else if (ex.getResponse().getStatus() == 504) {
                            paging.setInfo("Timeout: query execution took too long");
                        } else if (ex.getResponse().getStatus() == 403) {
                            paging.setInfo("Not authorized to query this corpus.");
                        } else {
                            paging.setInfo("unknown error: " + ex);
                        }
                    } else {
                        log.error("Unexcepted ExecutionException cause", root);
                    }
                    resultPanel.showFinishedSubgraphSearch();
                }
            }
        });
    }
// end catch
}
Also used : ArrayList(java.util.ArrayList) AqlParseError(annis.model.AqlParseError) AsyncWebResource(com.sun.jersey.api.client.AsyncWebResource) WebResource(com.sun.jersey.api.client.WebResource) SaltProject(org.corpus_tools.salt.common.SaltProject) LinkedList(java.util.LinkedList) Match(annis.service.objects.Match) PagingComponent(annis.gui.paging.PagingComponent) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) MatchGroup(annis.service.objects.MatchGroup) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException)

Example 13 with SaltProject

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

the class SaltAnnotateExtractorTest method testLayerNodes.

@Test
public void testLayerNodes() throws SQLException {
    SaltProject project = instance.extractData(resultSetProviderSingleText.getResultSet());
    assertNotNull(project);
    SDocumentGraph g = project.getCorpusGraphs().get(0).getDocuments().get(0).getDocumentGraph();
    List<SNode> n = new ArrayList<>(g.getLayerByName("exmaralda").get(0).getNodes());
    Collections.sort(n, new NameComparator());
    assertEquals(9, n.size());
    assertEquals("Focus_newInfSeg_10", n.get(0).getName());
    assertEquals("Focus_newInfSeg_9", n.get(1).getName());
    assertEquals("Inf-StatSeg_29", n.get(2).getName());
    assertEquals("Inf-StatSeg_30", n.get(3).getName());
    assertEquals("NPSeg_29", n.get(4).getName());
    assertEquals("NPSeg_30", n.get(5).getName());
    assertEquals("PPSeg_7", n.get(6).getName());
    assertEquals("SentSeg_10", n.get(7).getName());
    assertEquals("SentSeg_9", n.get(8).getName());
    n = new ArrayList<>(g.getLayerByName("mmax").get(0).getNodes());
    Collections.sort(n, new NameComparator());
    assertEquals(5, n.size());
    assertEquals("primmarkSeg_1000154", n.get(0).getName());
    assertEquals("primmarkSeg_60", n.get(1).getName());
    assertEquals("sentenceSeg_50010", n.get(2).getName());
    assertEquals("sentenceSeg_50011", n.get(3).getName());
    assertEquals("sentenceSeg_5009", n.get(4).getName());
    n = new ArrayList<>(g.getLayerByName("tiger").get(0).getNodes());
    Collections.sort(n, new NameComparator());
    assertEquals(10, n.size());
    assertEquals("const_50", n.get(0).getName());
    assertEquals("const_52", n.get(1).getName());
    assertEquals("const_54", n.get(2).getName());
    assertEquals("const_55", n.get(3).getName());
    assertEquals("const_56", n.get(4).getName());
    assertEquals("const_57", n.get(5).getName());
    assertEquals("const_58", n.get(6).getName());
    assertEquals("const_59", n.get(7).getName());
    assertEquals("const_60", n.get(8).getName());
    assertEquals("const_61", n.get(9).getName());
    n = new ArrayList<>(g.getLayerByName("default_ns").get(0).getNodes());
    Collections.sort(n, new NameComparator());
    assertEquals(12, n.size());
    assertEquals("tok_150", n.get(0).getName());
    assertEquals("tok_151", n.get(1).getName());
    assertEquals("tok_152", n.get(2).getName());
    assertEquals("tok_153", n.get(3).getName());
    assertEquals("tok_154", n.get(4).getName());
    assertEquals("tok_155", n.get(5).getName());
    assertEquals("tok_156", n.get(6).getName());
    assertEquals("tok_157", n.get(7).getName());
    assertEquals("tok_158", n.get(8).getName());
    assertEquals("tok_159", n.get(9).getName());
    assertEquals("tok_160", n.get(10).getName());
    assertEquals("tok_161", n.get(11).getName());
    n = new ArrayList<>(g.getLayerByName("rst").get(0).getNodes());
    Collections.sort(n, new NameComparator());
    assertEquals(9, n.size());
    assertEquals("u0", n.get(0).getName());
    assertEquals("u10", n.get(1).getName());
    assertEquals("u11", n.get(2).getName());
    assertEquals("u12", n.get(3).getName());
    assertEquals("u20", n.get(4).getName());
    assertEquals("u23", n.get(5).getName());
    assertEquals("u24", n.get(6).getName());
    assertEquals("u27", n.get(7).getName());
    assertEquals("u28", n.get(8).getName());
    assertEquals(0, g.getLayerByName("dep").get(0).getNodes().size());
}
Also used : SNode(org.corpus_tools.salt.core.SNode) SDocumentGraph(org.corpus_tools.salt.common.SDocumentGraph) ArrayList(java.util.ArrayList) SaltProject(org.corpus_tools.salt.common.SaltProject) Test(org.junit.Test)

Example 14 with SaltProject

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

the class SaltAnnotateExtractorTest method testMultipleTextGeneration.

@Test
public void testMultipleTextGeneration() throws SQLException {
    SaltProject project = instance.extractData(resultSetProviderMultiText.getResultSet());
    assertNotNull(project);
    SDocumentGraph g = project.getCorpusGraphs().get(0).getDocuments().get(0).getDocumentGraph();
    assertEquals(3, g.getTextualDSs().size());
}
Also used : SDocumentGraph(org.corpus_tools.salt.common.SDocumentGraph) SaltProject(org.corpus_tools.salt.common.SaltProject) Test(org.junit.Test)

Example 15 with SaltProject

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

the class QueryController method changeContext.

public void changeContext(PagedResultQuery originalQuery, Match match, long offset, int newContext, final VisualizerContextChanger visCtxChange, boolean left) {
    try {
        final PagedResultQuery newQuery = (PagedResultQuery) originalQuery.clone();
        if (left) {
            newQuery.setLeftContext(newContext);
        } else {
            newQuery.setRightContext(newContext);
        }
        newQuery.setOffset(offset);
        Background.runWithCallback(new SingleResultFetchJob(match, newQuery), new FutureCallback<SaltProject>() {

            @Override
            public void onSuccess(SaltProject result) {
                visCtxChange.updateResult(result, newQuery);
            }

            @Override
            public void onFailure(Throwable t) {
                ExceptionDialog.show(t, "Could not extend context.");
            }
        });
    } catch (CloneNotSupportedException ex) {
        log.error("Can't clone the query", ex);
    }
}
Also used : PagedResultQuery(annis.gui.objects.PagedResultQuery) SaltProject(org.corpus_tools.salt.common.SaltProject) SingleResultFetchJob(annis.gui.resultfetch.SingleResultFetchJob)

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