Search in sources :

Example 6 with ExampleQuery

use of annis.examplequeries.ExampleQuery in project ANNIS by korpling.

the class ListExampleQueriesHelper method mapRow.

@Override
public ExampleQuery mapRow(ResultSet rs, int i) throws SQLException {
    ExampleQuery exampleQuery = new ExampleQuery();
    exampleQuery.setType(rs.getString("type"));
    exampleQuery.setUsedOperators(rs.getString("used_ops"));
    exampleQuery.setExampleQuery(rs.getString("example_query"));
    exampleQuery.setDescription(rs.getString("description"));
    exampleQuery.setCorpusName(rs.getString("corpus_name"));
    return exampleQuery;
}
Also used : ExampleQuery(annis.examplequeries.ExampleQuery)

Example 7 with ExampleQuery

use of annis.examplequeries.ExampleQuery in project ANNIS by korpling.

the class AbstractAutoQuery method getExampleQuery.

@Override
public ExampleQuery getExampleQuery() {
    ExampleQuery exampleQuery = new ExampleQuery();
    exampleQuery.setNodes(getNodes());
    exampleQuery.setType(getType());
    exampleQuery.setDescription(getDescription());
    exampleQuery.setUsedOperators(getOperators());
    exampleQuery.setExampleQuery(getFinalAQLQuery());
    return exampleQuery;
}
Also used : ExampleQuery(annis.examplequeries.ExampleQuery)

Example 8 with ExampleQuery

use of annis.examplequeries.ExampleQuery 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

ExampleQuery (annis.examplequeries.ExampleQuery)8 QueryData (annis.ql.parser.QueryData)2 QueryNode (annis.model.QueryNode)1 Match (annis.service.objects.Match)1 MatchGroup (annis.service.objects.MatchGroup)1 AnnotateQueryData (annis.sqlgen.extensions.AnnotateQueryData)1 LimitOffsetQueryData (annis.sqlgen.extensions.LimitOffsetQueryData)1 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)1 GenericType (com.sun.jersey.api.client.GenericType)1 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)1 WebResource (com.sun.jersey.api.client.WebResource)1 Label (com.vaadin.ui.Label)1 Table (com.vaadin.ui.Table)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 SaltProject (org.corpus_tools.salt.common.SaltProject)1