Search in sources :

Example 11 with QueryAnnotation

use of annis.model.QueryAnnotation in project ANNIS by korpling.

the class TestAbstractFromClauseGenerator method setupTableAliases.

// set up table access strategy to return the requested table alias
// simulate that count copies of the table (alias) are required
private Map<String, String> setupTableAliases(QueryNode node, String table, String tableAlias, int count) {
    HashMap<String, String> tableAliases = new HashMap<>();
    tableAliases.put(table, tableAlias);
    if (count > 0) {
        tableAliases.put(TableAccessStrategy.NODE_ANNOTATION_TABLE, tableAlias);
    }
    for (int i = 0; i < count; i++) {
        // this will add new entries for the source tables
        node.addNodeAnnotation(new QueryAnnotation("dummy", "dummy" + i));
    }
    tableAccessStrategy.setTableAliases(tableAliases);
    tableAccessStrategy.setNode(node);
    Bag tables = new HashBag();
    tables.add(tableAlias, count);
    given(tableAccessStrategy.computeSourceTables()).willReturn(tables);
    return tableAliases;
}
Also used : HashBag(org.apache.commons.collections.bag.HashBag) HashMap(java.util.HashMap) QueryAnnotation(annis.model.QueryAnnotation) Bag(org.apache.commons.collections.Bag) HashBag(org.apache.commons.collections.bag.HashBag) TestUtils.uniqueString(annis.test.TestUtils.uniqueString)

Example 12 with QueryAnnotation

use of annis.model.QueryAnnotation in project ANNIS by korpling.

the class TestDefaultWhereClauseGenerator method whereClauseForNodeAnnotation.

// WHERE condition for node annotation
@Test
public void whereClauseForNodeAnnotation() {
    node23.addNodeAnnotation(new QueryAnnotation("namespace1", "name1"));
    node23.addNodeAnnotation(new QueryAnnotation("namespace2", "name2", "value2", TextMatching.EXACT_EQUAL));
    node23.addNodeAnnotation(new QueryAnnotation("namespace3", "name3", "value3", TextMatching.REGEXP_EQUAL));
    checkWhereConditions("_annotation23_1.qannotext LIKE 'namespace1:name1:%'", "_annotation23_2.qannotext LIKE 'namespace2:name2:value2'", "_annotation23_3.qannotext ~ '^(namespace3:name3:(value3))$'");
}
Also used : QueryAnnotation(annis.model.QueryAnnotation) Test(org.junit.Test)

Example 13 with QueryAnnotation

use of annis.model.QueryAnnotation in project ANNIS by korpling.

the class TestDefaultWhereClauseGenerator method whereClauseForNodeEdgeAnnotation.

// WHERE condition for node annotation
@Test
public void whereClauseForNodeEdgeAnnotation() {
    Dominance j = new Dominance(node23);
    j.addEdgeAnnotation(new QueryAnnotation("namespace1", "name1"));
    j.addEdgeAnnotation(new QueryAnnotation("namespace2", "name2", "value2", TextMatching.EXACT_EQUAL));
    j.addEdgeAnnotation(new QueryAnnotation("namespace3", "name3", "value3", TextMatching.REGEXP_EQUAL));
    node42.addOutgoingJoin(j);
    checkWhereConditions("_rank_annotation23_1.qannotext LIKE 'namespace1:name1:%'", "_rank_annotation23_2.qannotext LIKE 'namespace2:name2:value2'", "_rank_annotation23_3.qannotext ~ '^(namespace3:name3:(value3))$'");
}
Also used : QueryAnnotation(annis.model.QueryAnnotation) RightDominance(annis.sqlgen.model.RightDominance) Dominance(annis.sqlgen.model.Dominance) LeftDominance(annis.sqlgen.model.LeftDominance) Test(org.junit.Test)

Example 14 with QueryAnnotation

use of annis.model.QueryAnnotation in project ANNIS by korpling.

the class SubQueryCorpusSelectionStrategy method buildSubQuery.

public String buildSubQuery(List<Long> corpusList, List<QueryAnnotation> metaData) {
    StringBuffer sb = new StringBuffer();
    sb.append("SELECT DISTINCT c1.id FROM corpus AS c1");
    if (!corpusList.isEmpty()) {
        sb.append(", ");
        sb.append("corpus AS c2");
    }
    for (int i = 1; i <= metaData.size(); ++i) {
        sb.append(", ");
        sb.append("corpus_annotation AS corpus_annotation");
        sb.append(i);
    }
    if (hasCorpusSelection(corpusList, metaData))
        sb.append(" WHERE ");
    List<String> conditions = new ArrayList<>();
    if (!corpusList.isEmpty()) {
        conditions.add("c1.pre >= c2.pre");
        conditions.add("c1.post <= c2.post");
        conditions.add("c2.id IN ( :corpusList )".replace(":corpusList", StringUtils.join(corpusList, ", ")));
    }
    for (int i = 1; i <= metaData.size(); ++i) {
        QueryAnnotation annotation = metaData.get(i - 1);
        if (annotation.getNamespace() != null)
            conditions.add("corpus_annotation" + i + ".namespace = '" + annotation.getNamespace() + "'");
        conditions.add("corpus_annotation" + i + ".name = '" + annotation.getName() + "'");
        if (annotation.getValue() != null) {
            String value = annotation.getValue();
            if (annotation.getTextMatching() == QueryNode.TextMatching.REGEXP_EQUAL || annotation.getTextMatching() == QueryNode.TextMatching.REGEXP_NOT_EQUAL) {
                value = "^" + value + "$";
            }
            conditions.add("corpus_annotation" + i + ".value " + annotation.getTextMatching().sqlOperator() + " '" + value + "'");
        }
        conditions.add("corpus_annotation" + i + ".corpus_ref = c1.id");
    }
    sb.append(StringUtils.join(conditions, " AND "));
    return sb.toString();
}
Also used : QueryAnnotation(annis.model.QueryAnnotation) ArrayList(java.util.ArrayList)

Example 15 with QueryAnnotation

use of annis.model.QueryAnnotation in project ANNIS by korpling.

the class AbstractWhereClauseGenerator method whereConditions.

@Override
public Set<String> whereConditions(QueryData queryData, List<QueryNode> alternative, String indent) {
    List<String> conditions = new ArrayList<>();
    for (QueryNode node : alternative) {
        // node constraints
        if (node.getSpannedText() != null) {
            addSpanConditions(conditions, queryData, node);
        }
        if (node.isToken()) {
            addIsTokenConditions(conditions, queryData, node);
        }
        if (node.isRoot()) {
            addIsRootConditions(conditions, queryData, node);
        }
        if (node.getArity() != null) {
            addNodeArityConditions(conditions, queryData, node);
        }
        if (node.getTokenArity() != null) {
            addTokenArityConditions(conditions, queryData, node);
        }
        // node joins
        for (Join join : node.getOutgoingJoins()) {
            QueryNode target = join.getTarget();
            if (join instanceof SameSpan) {
                addSameSpanConditions(conditions, node, target, (SameSpan) join, queryData);
            } else if (join instanceof Identical) {
                addIdenticalConditions(conditions, node, target, (Identical) join, queryData);
            } else if (join instanceof LeftAlignment) {
                addLeftAlignmentConditions(conditions, node, target, (LeftAlignment) join, queryData);
            } else if (join instanceof RightAlignment) {
                addRightAlignmentConditions(conditions, node, target, (RightAlignment) join, queryData);
            } else if (join instanceof Inclusion) {
                addInclusionConditions(conditions, node, target, (Inclusion) join, queryData);
            } else if (join instanceof Overlap) {
                addOverlapConditions(conditions, node, target, (Overlap) join, queryData);
            } else if (join instanceof LeftOverlap) {
                addLeftOverlapConditions(conditions, target, node, (LeftOverlap) join, queryData);
            } else if (join instanceof RightOverlap) {
                addRightOverlapConditions(conditions, target, node, (RightOverlap) join, queryData);
            } else if (join instanceof Precedence) {
                addPrecedenceConditions(conditions, node, target, (Precedence) join, queryData);
            } else if (join instanceof Near) {
                addNearConditions(conditions, node, target, (Near) join, queryData);
            } else if (join instanceof Sibling) {
                addSiblingConditions(conditions, node, target, (Sibling) join, queryData);
            } else if (join instanceof CommonAncestor) {
                addCommonAncestorConditions(conditions, node, target, (CommonAncestor) join, queryData);
            } else if (join instanceof LeftDominance) {
                addLeftDominanceConditions(conditions, node, target, (LeftDominance) join, queryData);
            } else if (join instanceof RightDominance) {
                addRightDominanceConditions(conditions, node, target, (RightDominance) join, queryData);
            } else if (join instanceof Dominance) {
                addDominanceConditions(conditions, node, target, (Dominance) join, queryData);
            } else if (join instanceof PointingRelation) {
                addPointingRelationConditions(conditions, node, target, (PointingRelation) join, queryData);
            } else if (join instanceof EqualValue) {
                addEqualValueConditions(conditions, node, target, (EqualValue) join, queryData);
            } else if (join instanceof NotEqualValue) {
                addNotEqualValueConditions(conditions, node, target, (NotEqualValue) join, queryData);
            }
        }
        // node annotations
        int i = 0;
        for (QueryAnnotation annotation : node.getNodeAnnotations()) {
            ++i;
            addAnnotationConditions(conditions, node, i, annotation, NODE_ANNOTATION_TABLE, queryData);
        }
        // relation annotations
        int j = 0;
        for (QueryAnnotation annotation : node.getEdgeAnnotations()) {
            ++j;
            addAnnotationConditions(conditions, node, j, annotation, EDGE_ANNOTATION_TABLE, queryData);
        }
    }
    return new HashSet<>(conditions);
}
Also used : Identical(annis.sqlgen.model.Identical) Inclusion(annis.sqlgen.model.Inclusion) SameSpan(annis.sqlgen.model.SameSpan) RightAlignment(annis.sqlgen.model.RightAlignment) ArrayList(java.util.ArrayList) LeftAlignment(annis.sqlgen.model.LeftAlignment) RightOverlap(annis.sqlgen.model.RightOverlap) Overlap(annis.sqlgen.model.Overlap) LeftOverlap(annis.sqlgen.model.LeftOverlap) Sibling(annis.sqlgen.model.Sibling) CommonAncestor(annis.sqlgen.model.CommonAncestor) NotEqualValue(annis.sqlgen.model.NotEqualValue) HashSet(java.util.HashSet) PointingRelation(annis.sqlgen.model.PointingRelation) EqualValue(annis.sqlgen.model.EqualValue) NotEqualValue(annis.sqlgen.model.NotEqualValue) QueryAnnotation(annis.model.QueryAnnotation) RightOverlap(annis.sqlgen.model.RightOverlap) Join(annis.model.Join) RightDominance(annis.sqlgen.model.RightDominance) Dominance(annis.sqlgen.model.Dominance) LeftDominance(annis.sqlgen.model.LeftDominance) RightDominance(annis.sqlgen.model.RightDominance) Near(annis.sqlgen.model.Near) LeftDominance(annis.sqlgen.model.LeftDominance) QueryNode(annis.model.QueryNode) LeftOverlap(annis.sqlgen.model.LeftOverlap) Precedence(annis.sqlgen.model.Precedence)

Aggregations

QueryAnnotation (annis.model.QueryAnnotation)20 QueryNode (annis.model.QueryNode)9 Test (org.junit.Test)7 Dominance (annis.sqlgen.model.Dominance)5 LeftDominance (annis.sqlgen.model.LeftDominance)5 RightDominance (annis.sqlgen.model.RightDominance)5 Join (annis.model.Join)4 PointingRelation (annis.sqlgen.model.PointingRelation)2 Precedence (annis.sqlgen.model.Precedence)2 TestUtils.uniqueString (annis.test.TestUtils.uniqueString)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 AnnisQLSemanticsException (annis.exceptions.AnnisQLSemanticsException)1 AqlParseError (annis.model.AqlParseError)1 AqlParser (annis.ql.AqlParser)1 AnnisAttribute (annis.service.objects.AnnisAttribute)1 SqlConstraints.numberJoin (annis.sqlgen.SqlConstraints.numberJoin)1 SqlConstraints.sqlString (annis.sqlgen.SqlConstraints.sqlString)1 CommonAncestor (annis.sqlgen.model.CommonAncestor)1