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);
}
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, ",") + "}");
}
}
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;
}
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");
}
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);
}
}
Aggregations