use of annis.ql.parser.QueryData in project ANNIS by korpling.
the class QueryServiceImpl method frequency.
/**
* Frequency analysis.
*
* @param rawFields Comma seperated list of result vector elements.
* Each element has the form <node-nr>:<anno-name>. The
* annotation name can be set to "tok" to indicate that the
* span should be used instead of an annotation.
*/
@GET
@Path("search/frequency")
@Produces("application/xml")
public FrequencyTable frequency(@QueryParam("q") String query, @QueryParam("corpora") String rawCorpusNames, @QueryParam("fields") String rawFields) {
requiredParameter(query, "q", "AnnisQL query");
requiredParameter(rawCorpusNames, "corpora", "comma separated list of corpus names");
requiredParameter(rawFields, "fields", "Comma seperated list of result vector elements.");
Subject user = SecurityUtils.getSubject();
List<String> corpusNames = splitCorpusNamesFromRaw(rawCorpusNames);
for (String c : corpusNames) {
user.checkPermission("query:matrix:" + c);
}
QueryData data = queryDataFromParameters(query, rawCorpusNames);
FrequencyTableQuery ext = FrequencyTableQuery.parse(rawFields);
data.addExtension(ext);
long start = new Date().getTime();
FrequencyTable freqTable = queryDao.frequency(data);
long end = new Date().getTime();
logQuery("FREQUENCY", query, splitCorpusNamesFromRaw(rawCorpusNames), end - start);
return freqTable;
}
use of annis.ql.parser.QueryData in project ANNIS by korpling.
the class AnnisRunner method doExplain.
public void doExplain(String functionCall, boolean analyze) {
SqlGenerator<QueryData> generator = getGeneratorForQueryFunction(functionCall);
String function = getAnnisQueryFromFunctionCall(functionCall);
String annisQuery = getAnnisQueryFromFunctionCall(functionCall);
QueryData queryData = analyzeQuery(annisQuery, function);
out.println("NOTICE: left = " + left + "; right = " + right + "; limit = " + limit + "; offset = " + offset);
out.println(queryDao.explain(generator, queryData, analyze));
}
use of annis.ql.parser.QueryData in project ANNIS by korpling.
the class AnnisRunner method analyzeQuery.
/**
* Does the setup for the QueryData object.
*
* If the query function is "subgraph" or "sql_subgraph" the annisQuery string
* should contain space separated salt ids. In this case the annisQuery is not
* parsed and the {@link QueryData#getAlternatives()} method should return a
* List with dummy QueryNode entries. Instead of parsing the annisQuery it
* extracts the salt ids and put it into the extension's of {@link QueryData}.
*
* @param annisQuery should include a valid annis query
* @param queryFunction should include a method name of {@link AnnisRunner}
* which starts with do.
* @return {@link QueryData} object, which contains a parsed annis query, the
* default context {@link AnnisRunner#left} and {@link AnnisRunner#left}
* values and the default {@link AnnisRunner#limit} and
* {@link AnnisRunner#offset} values
*/
private QueryData analyzeQuery(String annisQuery, String queryFunction) {
QueryData queryData;
log.debug("analyze query for " + queryFunction + " function");
if (queryFunction != null && !queryFunction.matches("(sql_)?subgraph")) {
queryData = queryDao.parseAQL(annisQuery, corpusList);
} else {
queryData = GraphHelper.createQueryData(MatchGroup.parseString(annisQuery), queryDao);
}
queryData.setCorpusConfiguration(queryDao.getCorpusConfiguration());
// filter by meta data
queryData.setDocuments(metaDataFilter.getDocumentsForMetadata(queryData));
if (queryFunction != null && queryFunction.matches("(sql_)?(annotate|find)")) {
queryData.addExtension(new AnnotateQueryData(left, right, segmentationLayer, filter));
queryData.addExtension(new LimitOffsetQueryData(offset, limit, order));
} else if (queryFunction != null && queryFunction.matches("(sql_)?subgraph")) {
queryData.addExtension(new AnnotateQueryData(left, right, segmentationLayer, filter));
} else if (queryFunction != null && queryFunction.matches("(sql_)?frequency")) {
if (frequencyDef == null) {
out.println("You have to set the 'freq-def' property first");
} else {
queryData.addExtension(frequencyDef);
}
}
if (annisQuery != null) {
if (benchmarkName == null) {
benchmarkName = "auto_" + benchmarks.size();
}
Benchmark b = new AnnisRunner.Benchmark(queryFunction + " " + annisQuery, queryData);
b.name = benchmarkName;
benchmarks.add(b);
benchmarkName = null;
}
return queryData;
}
use of annis.ql.parser.QueryData in project ANNIS by korpling.
the class GraphHelper method createQueryData.
/**
* This is a helper function to make it easier to create a correct query data object
* from a {@link MatchGroup} for a {@link AnnisDao#graph(annis.ql.parser.QueryData) } query.
*
* @param matchGroup
* @return
*/
public static QueryData createQueryData(MatchGroup matchGroup, QueryDao annisDao) {
QueryData queryData = new QueryData();
Set<String> corpusNames = new TreeSet<>();
for (Match m : matchGroup.getMatches()) {
// collect list of used corpora and created pseudo QueryNodes for each URI
List<QueryNode> pseudoNodes = new ArrayList<>(m.getSaltIDs().size());
for (java.net.URI u : m.getSaltIDs()) {
pseudoNodes.add(new QueryNode());
corpusNames.add(CommonHelper.getCorpusPath(u).get(0));
}
queryData.addAlternative(pseudoNodes);
}
List<Long> corpusIDs = annisDao.mapCorpusNamesToIds(new LinkedList<>(corpusNames));
queryData.setCorpusList(corpusIDs);
queryData.addExtension(matchGroup);
return queryData;
}
use of annis.ql.parser.QueryData in project ANNIS by korpling.
the class TestAbstractSqlGenerator method shouldAppendOrderByClause.
/**
* Append ORDER BY clause.
*/
@Test
public void shouldAppendOrderByClause() {
// given
String selectClause = uniqueString();
String fromClause = uniqueString();
setupSelectAndFromClause(selectClause, fromClause);
String orderBy = uniqueString();
@SuppressWarnings("unchecked") OrderByClauseSqlGenerator<QueryData> orderByClauseSqlGenerator = mock(OrderByClauseSqlGenerator.class);
generator.setOrderByClauseSqlGenerator(orderByClauseSqlGenerator);
given(orderByClauseSqlGenerator.orderByClause(eq(queryData), eq(alternative), anyString())).willReturn(orderBy);
// when
String sql = generator.toSql(queryData);
// then
String expected = createMinimalSqlStatement(selectClause, fromClause);
expected += "ORDER BY " + orderBy + "\n";
assertThat(sql, is(expected));
}
Aggregations