use of annis.service.objects.Match in project ANNIS by korpling.
the class GraphWithClauseGenerator method getMatchesWithClause.
@Override
protected List<String> getMatchesWithClause(QueryData queryData, List<QueryNode> alternative, String indent) {
TableAccessStrategy tas = createTableAccessStrategy();
List<AnnotateQueryData> extensions = queryData.getExtensions(AnnotateQueryData.class);
AnnotateQueryData annotateQueryData = extensions.isEmpty() ? new AnnotateQueryData(5, 5) : extensions.get(0);
List<MatchGroup> listOfSaltURIs = queryData.getExtensions(MatchGroup.class);
// only work with the first element
Validate.isTrue(!listOfSaltURIs.isEmpty());
List<String> subselects = new LinkedList<>();
String indent2 = indent + TABSTOP;
MatchGroup groupSet = listOfSaltURIs.get(0);
int matchNr = 1;
for (Match match : groupSet.getMatches()) {
List<URI> uriList = match.getSaltIDs();
int nodeNr = 1;
for (URI uri : uriList) {
String sub = indent2 + "(\n" + subselectForMatch(matchNr, nodeNr, uri, tas, annotateQueryData, queryData.getCorpusList(), indent2) + indent2 + ")";
subselects.add(0, sub);
nodeNr++;
}
matchNr++;
}
String result = indent + "matches AS\n" + indent + "(\n" + Joiner.on("\n" + indent2 + "UNION ALL\n").join(subselects) + "\n" + indent + ")";
return Lists.newArrayList(result);
}
use of annis.service.objects.Match 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);
}
}
use of annis.service.objects.Match in project ANNIS by korpling.
the class ResultViewPanel method createPanels.
private List<SingleResultPanel> createPanels(SaltProject p, int localMatchIndex, long globalOffset) {
List<SingleResultPanel> result = new LinkedList<>();
int i = 0;
for (SCorpusGraph corpusGraph : p.getCorpusGraphs()) {
SDocument doc = corpusGraph.getDocuments().get(0);
Match m = new Match();
if (allMatches != null && localMatchIndex >= 0 && localMatchIndex < allMatches.size()) {
m = allMatches.get(localMatchIndex);
}
SingleResultPanel panel = new SingleResultPanel(doc, m, i + globalOffset, new ResolverProviderImpl(cacheResolver), ps, sui, getVisibleTokenAnnos(), segmentationName, controller, instanceConfig, initialQuery);
i++;
panel.setWidth("100%");
panel.setHeight("-1px");
result.add(panel);
}
return result;
}
Aggregations