use of annis.sqlgen.extensions.AnnotateQueryData in project ANNIS by korpling.
the class CommonAnnotateWithClauseGenerator method withClauses.
@Override
public List<String> withClauses(QueryData queryData, List<QueryNode> alternative, String indent) {
List<Long> corpusList = queryData.getCorpusList();
HashMap<Long, Properties> corpusProperties = queryData.getCorpusConfiguration();
IslandsPolicy.IslandPolicies policy = getIslandsPolicy().getMostRestrictivePolicy(corpusList, corpusProperties);
List<String> result = new LinkedList<>();
List<AnnotateQueryData> ext = queryData.getExtensions(AnnotateQueryData.class);
if (!ext.isEmpty()) {
AnnotateQueryData annoQueryData = ext.get(0);
if (annoQueryData.getSegmentationLayer() == null) {
// token index based method
// first get the raw matches
result.addAll(getMatchesWithClause(queryData, alternative, indent));
result.add(getKeyWithClause(indent));
// break the columns down in a way that every matched node has it's own
// row
result.add(getSolutionFromMatchesWithClause(policy, "matches", indent));
} else {
// segmentation layer based method
result.addAll(getMatchesWithClause(queryData, alternative, indent));
result.add(getKeyWithClause(indent));
result.add(getNearestSeqWithClause(queryData, annoQueryData, alternative, "matches", indent));
result.add(getSolutionFromNearestSegWithClause(queryData, annoQueryData, alternative, policy, "nearestseg", indent));
}
}
return result;
}
use of annis.sqlgen.extensions.AnnotateQueryData 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);
}
Aggregations