Search in sources :

Example 1 with ExampleQuery

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

the class AdministrationDao method analyzeAutoGeneratedQueries.

/**
 * Counts nodes and operators of the AQL example query and writes it back to
 * the staging area.
 *
 * @param corpusID specifies the corpus, the analyze things.
 */
private void analyzeAutoGeneratedQueries(long corpusID) {
    // read the example queries from the staging area
    List<ExampleQuery> exampleQueries = getJdbcTemplate().query("SELECT * FROM _" + EXAMPLE_QUERIES_TAB, new RowMapper<ExampleQuery>() {

        @Override
        public ExampleQuery mapRow(ResultSet rs, int i) throws SQLException {
            ExampleQuery eQ = new ExampleQuery();
            eQ.setExampleQuery(rs.getString("example_query"));
            return eQ;
        }
    });
    // count the nodes of the aql Query
    countExampleQueryNodes(exampleQueries);
    // fetch the operators
    getOperators(exampleQueries, "\\.(\\*)?|\\>|\\>\\*|_i_");
    writeAmountOfNodesBack(exampleQueries);
}
Also used : SQLException(java.sql.SQLException) ExampleQuery(annis.examplequeries.ExampleQuery) ResultSet(java.sql.ResultSet)

Example 2 with ExampleQuery

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

the class AdministrationDao method getOperators.

/**
 * Fetches operators used in the {@link ExampleQuery#getExampleQuery()} with a
 * given regex.
 *
 * @param exQueries Set the used operators property of each member.
 * @param regex The regex to search operators.
 */
private void getOperators(List<ExampleQuery> exQueries, String regex) {
    Pattern opsRegex = Pattern.compile(regex);
    for (ExampleQuery eQ : exQueries) {
        List<String> ops = new ArrayList<>();
        Matcher m = opsRegex.matcher(eQ.getExampleQuery().replaceAll("\\s", ""));
        while (m.find()) {
            ops.add(m.group());
        }
        eQ.setUsedOperators("{" + StringUtils.join(ops, ",") + "}");
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ExampleQuery(annis.examplequeries.ExampleQuery) ArrayList(java.util.ArrayList)

Example 3 with ExampleQuery

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

the class ExampleQueriesPanel method loadExamplesFromRemote.

/**
 * Loads the available example queries for a specific corpus.
 *
 * @param corpusNames Specifies the corpora example queries are fetched for.
 * If it is null or empty all available example queries are fetched.
 */
private static List<ExampleQuery> loadExamplesFromRemote(Set<String> corpusNames) {
    List<ExampleQuery> result = new LinkedList<>();
    WebResource service = Helper.getAnnisWebResource();
    try {
        if (corpusNames == null || corpusNames.isEmpty()) {
            result = service.path("query").path("corpora").path("example-queries").get(new GenericType<List<ExampleQuery>>() {
            });
        } else {
            String concatedCorpusNames = StringUtils.join(corpusNames, ",");
            result = service.path("query").path("corpora").path("example-queries").queryParam("corpora", concatedCorpusNames).get(new GenericType<List<ExampleQuery>>() {
            });
        }
    } catch (UniformInterfaceException ex) {
    // ignore
    } catch (ClientHandlerException ex) {
        log.error("problems with getting example queries from remote for {}", corpusNames, ex);
    }
    return result;
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) GenericType(com.sun.jersey.api.client.GenericType) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) ExampleQuery(annis.examplequeries.ExampleQuery) WebResource(com.sun.jersey.api.client.WebResource) LinkedList(java.util.LinkedList)

Example 4 with ExampleQuery

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

the class ExampleQueriesPanel method setUpTable.

/**
 * Sets some layout properties.
 */
private void setUpTable() {
    setSizeFull();
    // expand the table
    table.setSizeFull();
    // Allow selecting items from the table.
    table.setSelectable(false);
    // Send changes in selection immediately to server.
    table.setImmediate(true);
    // set custom style
    table.addStyleName("example-queries-table");
    // put stripes to the table
    table.addStyleName(ChameleonTheme.TABLE_STRIPED);
    // configure columns
    table.addGeneratedColumn(COLUMN_OPEN_CORPUS_BROWSER, new ShowCorpusBrowser());
    table.addGeneratedColumn(COLUMN_EXAMPLE_QUERY, new QueryColumn());
    table.addGeneratedColumn(COLUMN_DESCRIPTION, new Table.ColumnGenerator() {

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            ExampleQuery eQ = (ExampleQuery) itemId;
            Label l = new Label(eQ.getDescription());
            l.setContentMode(ContentMode.TEXT);
            l.addStyleName(Helper.CORPUS_FONT_FORCE);
            return l;
        }
    });
    table.setVisibleColumns(new Object[] { COLUMN_EXAMPLE_QUERY, COLUMN_DESCRIPTION, COLUMN_OPEN_CORPUS_BROWSER });
    table.setColumnExpandRatio(table.getVisibleColumns()[0], 0.40f);
    table.setColumnExpandRatio(table.getVisibleColumns()[1], 0.40f);
    table.setColumnHeader(table.getVisibleColumns()[0], "Example Query");
    table.setColumnHeader(table.getVisibleColumns()[1], "Description");
    table.setColumnHeader(table.getVisibleColumns()[2], "open corpus browser");
}
Also used : Table(com.vaadin.ui.Table) ExampleQuery(annis.examplequeries.ExampleQuery) Label(com.vaadin.ui.Label)

Example 5 with ExampleQuery

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

the class AdministrationDao method countExampleQueryNodes.

/**
 * Maps example queries to integer, which represents the amount of nodes of
 * the aql query.
 */
private void countExampleQueryNodes(List<ExampleQuery> exampleQueries) {
    for (ExampleQuery eQ : exampleQueries) {
        QueryData query = getQueryDao().parseAQL(eQ.getExampleQuery(), null);
        int count = 0;
        for (List<QueryNode> qNodes : query.getAlternatives()) {
            count += qNodes.size();
        }
        eQ.setNodes(count);
    }
}
Also used : QueryData(annis.ql.parser.QueryData) QueryNode(annis.model.QueryNode) ExampleQuery(annis.examplequeries.ExampleQuery)

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