Search in sources :

Example 11 with MatchGroup

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

the class QueryDaoImpl method graph.

@Override
@Transactional(readOnly = true)
public SaltProject graph(QueryData data) {
    SaltProject p = executeQueryFunction(data, graphSqlGenerator, saltAnnotateExtractor);
    List<MatchGroup> matchGroupExt = data.getExtensions(MatchGroup.class);
    SaltAnnotateExtractor.addMatchInformation(p, matchGroupExt.get(0));
    return p;
}
Also used : MatchGroup(annis.service.objects.MatchGroup) SaltProject(org.corpus_tools.salt.common.SaltProject) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with MatchGroup

use of annis.service.objects.MatchGroup 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)

Aggregations

MatchGroup (annis.service.objects.MatchGroup)12 Match (annis.service.objects.Match)9 SaltProject (org.corpus_tools.salt.common.SaltProject)7 LinkedList (java.util.LinkedList)5 WebResource (com.sun.jersey.api.client.WebResource)4 AnnotateQueryData (annis.sqlgen.extensions.AnnotateQueryData)3 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)3 InputStreamReader (java.io.InputStreamReader)3 ArrayList (java.util.ArrayList)3 AnnisCorpusAccessException (annis.exceptions.AnnisCorpusAccessException)2 AnnisQLSemanticsException (annis.exceptions.AnnisQLSemanticsException)2 AnnisQLSyntaxException (annis.exceptions.AnnisQLSyntaxException)2 QueryData (annis.ql.parser.QueryData)2 AnnisAttribute (annis.service.objects.AnnisAttribute)2 SubgraphFilter (annis.service.objects.SubgraphFilter)2 LimitOffsetQueryData (annis.sqlgen.extensions.LimitOffsetQueryData)2 Stopwatch (com.google.common.base.Stopwatch)2 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2