Search in sources :

Example 6 with AnnotateQueryData

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;
}
Also used : AnnotateQueryData(annis.sqlgen.extensions.AnnotateQueryData) SqlConstraints.sqlString(annis.sqlgen.SqlConstraints.sqlString) Properties(java.util.Properties) LinkedList(java.util.LinkedList)

Example 7 with AnnotateQueryData

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);
}
Also used : MatchGroup(annis.service.objects.MatchGroup) AnnotateQueryData(annis.sqlgen.extensions.AnnotateQueryData) SqlConstraints.sqlString(annis.sqlgen.SqlConstraints.sqlString) URI(java.net.URI) LinkedList(java.util.LinkedList) Match(annis.service.objects.Match)

Aggregations

AnnotateQueryData (annis.sqlgen.extensions.AnnotateQueryData)7 SqlConstraints.sqlString (annis.sqlgen.SqlConstraints.sqlString)3 LinkedList (java.util.LinkedList)3 QueryNode (annis.model.QueryNode)2 QueryData (annis.ql.parser.QueryData)2 Match (annis.service.objects.Match)2 LimitOffsetQueryData (annis.sqlgen.extensions.LimitOffsetQueryData)2 ArrayList (java.util.ArrayList)2 MatchGroup (annis.service.objects.MatchGroup)1 SubgraphFilter (annis.service.objects.SubgraphFilter)1 MatrixQueryData (annis.sqlgen.MatrixQueryData)1 TestUtils.uniqueAlphaString (annis.test.TestUtils.uniqueAlphaString)1 URI (java.net.URI)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Properties (java.util.Properties)1 TreeSet (java.util.TreeSet)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Subject (org.apache.shiro.subject.Subject)1