Search in sources :

Example 16 with Match

use of annis.service.objects.Match in project ANNIS by korpling.

the class GraphWithClauseGenerator method getMatchesWithClause.

@Override
protected List<String> getMatchesWithClause(QueryData queryData, List<QueryNode> alternative, String indent) {
    TableAccessStrategy tas = createTableAccessStrategy();
    List<AnnotateQueryData> extensions = queryData.getExtensions(AnnotateQueryData.class);
    AnnotateQueryData annotateQueryData = extensions.isEmpty() ? new AnnotateQueryData(5, 5) : extensions.get(0);
    List<MatchGroup> listOfSaltURIs = queryData.getExtensions(MatchGroup.class);
    // only work with the first element
    Validate.isTrue(!listOfSaltURIs.isEmpty());
    List<String> subselects = new LinkedList<>();
    String indent2 = indent + TABSTOP;
    MatchGroup groupSet = listOfSaltURIs.get(0);
    int matchNr = 1;
    for (Match match : groupSet.getMatches()) {
        List<URI> uriList = match.getSaltIDs();
        int nodeNr = 1;
        for (URI uri : uriList) {
            String sub = indent2 + "(\n" + subselectForMatch(matchNr, nodeNr, uri, tas, annotateQueryData, queryData.getCorpusList(), indent2) + indent2 + ")";
            subselects.add(0, sub);
            nodeNr++;
        }
        matchNr++;
    }
    String result = indent + "matches AS\n" + indent + "(\n" + Joiner.on("\n" + indent2 + "UNION ALL\n").join(subselects) + "\n" + indent + ")";
    return Lists.newArrayList(result);
}
Also used : MatchGroup(annis.service.objects.MatchGroup) AnnotateQueryData(annis.sqlgen.extensions.AnnotateQueryData) SqlConstraints.sqlString(annis.sqlgen.SqlConstraints.sqlString) URI(java.net.URI) LinkedList(java.util.LinkedList) Match(annis.service.objects.Match)

Example 17 with Match

use of annis.service.objects.Match in project ANNIS by korpling.

the class QueriesGenerator method generateQuery.

private void generateQuery(QueryBuilder queryBuilder) {
    try {
        // retrieve the aql query for analyzing purposes
        String aql = queryBuilder.getAQL();
        // set some necessary extensions for generating complete sql
        QueryData queryData = getQueryDao().parseAQL(aql, this.corpusIds);
        queryData.addExtension(queryBuilder.getLimitOffsetQueryData());
        // retrieve the salt project to analyze
        List<Match> matches = getQueryDao().find(queryData);
        if (matches.isEmpty()) {
            return;
        }
        QueryData matchQueryData = GraphHelper.createQueryData(new MatchGroup(matches), queryDao);
        matchQueryData.addExtension(queryBuilder.getAnnotateQueryData());
        SaltProject saltProject = getQueryDao().graph(matchQueryData);
        queryBuilder.analyzingQuery(saltProject);
        // set the corpus name
        ExampleQuery exampleQuery = queryBuilder.getExampleQuery();
        exampleQuery.setCorpusName(corpusName);
        // copy the example query to the database
        if (exampleQuery.getExampleQuery() != null && !"".equals(exampleQuery.getExampleQuery())) {
            if (getTableInsertSelect().containsKey("example_queries")) {
                Object[] values = new Object[] { exampleQuery.getExampleQuery(), exampleQuery.getDescription(), exampleQuery.getType() == null ? "" : exampleQuery.getType(), exampleQuery.getNodes(), "{}", corpusIds.get(0) };
                int[] argTypes = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.VARCHAR, Types.INTEGER };
                getJdbcTemplate().update("INSERT INTO example_queries(" + getTableInsertSelect().get("example_queries") + ") VALUES(?, ?, ?, ?, ?::text[], ?)", values, argTypes);
                log.info("generated example query: {}", exampleQuery.getExampleQuery());
            }
        } else {
            log.warn("could not generating auto query with {}", queryBuilder.getClass().getName());
        }
    } catch (Exception ex) {
        log.warn("Cannot generate example query", ex);
    }
}
Also used : QueryData(annis.ql.parser.QueryData) LimitOffsetQueryData(annis.sqlgen.extensions.LimitOffsetQueryData) AnnotateQueryData(annis.sqlgen.extensions.AnnotateQueryData) MatchGroup(annis.service.objects.MatchGroup) ExampleQuery(annis.examplequeries.ExampleQuery) SaltProject(org.corpus_tools.salt.common.SaltProject) Match(annis.service.objects.Match)

Example 18 with Match

use of annis.service.objects.Match in project ANNIS by korpling.

the class ResultViewPanel method createPanels.

private List<SingleResultPanel> createPanels(SaltProject p, int localMatchIndex, long globalOffset) {
    List<SingleResultPanel> result = new LinkedList<>();
    int i = 0;
    for (SCorpusGraph corpusGraph : p.getCorpusGraphs()) {
        SDocument doc = corpusGraph.getDocuments().get(0);
        Match m = new Match();
        if (allMatches != null && localMatchIndex >= 0 && localMatchIndex < allMatches.size()) {
            m = allMatches.get(localMatchIndex);
        }
        SingleResultPanel panel = new SingleResultPanel(doc, m, i + globalOffset, new ResolverProviderImpl(cacheResolver), ps, sui, getVisibleTokenAnnos(), segmentationName, controller, instanceConfig, initialQuery);
        i++;
        panel.setWidth("100%");
        panel.setHeight("-1px");
        result.add(panel);
    }
    return result;
}
Also used : ResolverProviderImpl(annis.libgui.ResolverProviderImpl) SDocument(org.corpus_tools.salt.common.SDocument) LinkedList(java.util.LinkedList) SCorpusGraph(org.corpus_tools.salt.common.SCorpusGraph) Match(annis.service.objects.Match)

Aggregations

Match (annis.service.objects.Match)18 MatchGroup (annis.service.objects.MatchGroup)9 LinkedList (java.util.LinkedList)8 SaltProject (org.corpus_tools.salt.common.SaltProject)8 WebResource (com.sun.jersey.api.client.WebResource)5 ArrayList (java.util.ArrayList)5 QueryData (annis.ql.parser.QueryData)4 AnnotateQueryData (annis.sqlgen.extensions.AnnotateQueryData)4 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)4 URI (java.net.URI)4 HashMap (java.util.HashMap)4 SubgraphFilter (annis.service.objects.SubgraphFilter)3 LimitOffsetQueryData (annis.sqlgen.extensions.LimitOffsetQueryData)3 AnnisCorpusAccessException (annis.exceptions.AnnisCorpusAccessException)2 AnnisQLSemanticsException (annis.exceptions.AnnisQLSemanticsException)2 AnnisQLSyntaxException (annis.exceptions.AnnisQLSyntaxException)2 AnnotationGraph (annis.model.AnnotationGraph)2 QueryNode (annis.model.QueryNode)2 AnnisAttribute (annis.service.objects.AnnisAttribute)2 MatrixQueryData (annis.sqlgen.MatrixQueryData)2