Search in sources :

Example 1 with TextMatching

use of annis.model.QueryNode.TextMatching in project ANNIS by korpling.

the class AnnotationConditionProvider method addAnnotationConditions.

/**
 * Adds annotation conditions for a single node.
 * @param conditions Condition list where the conditions should be added to
 * @param index Index for a specific annotation
 * @param annotation The annotation to add
 * @param table Table to operate on
 * @param tas {@link TableAccessStrategy} for the given node.
 */
public void addAnnotationConditions(Collection<String> conditions, int index, QueryAnnotation annotation, String table, TableAccessStrategy tas) {
    TextMatching tm = annotation.getTextMatching();
    String column = annotation.getNamespace() == null ? "annotext" : "qannotext";
    Escaper escaper = tm != null && tm.isRegex() ? regexEscaper : likeEscaper;
    String val;
    if (tm == null) {
        val = "%";
    } else {
        val = escaper.escape(annotation.getValue());
    }
    String prefix;
    if (annotation.getNamespace() == null) {
        prefix = escaper.escape(annotation.getName()) + ":";
    } else {
        prefix = escaper.escape(annotation.getNamespace()) + ":" + escaper.escape(annotation.getName()) + ":";
    }
    if (tm == null || tm == TextMatching.EXACT_EQUAL) {
        conditions.add(tas.aliasedColumn(table, column, index) + " LIKE '" + prefix + val + "'");
    } else if (tm == TextMatching.EXACT_NOT_EQUAL) {
        conditions.add(tas.aliasedColumn(table, column, index) + " LIKE '" + prefix + "%'");
        conditions.add(tas.aliasedColumn(table, column, index) + " NOT LIKE '" + prefix + val + "'");
    } else if (tm == TextMatching.REGEXP_EQUAL) {
        conditions.add(tas.aliasedColumn(table, column, index) + " ~ '^(" + prefix + "(" + val + "))$'");
    } else if (tm == TextMatching.REGEXP_NOT_EQUAL) {
        conditions.add(tas.aliasedColumn(table, column, index) + " LIKE '" + prefix + "%'");
        conditions.add(tas.aliasedColumn(table, column, index) + " !~ '^(" + prefix + "(" + val + "))$'");
    }
}
Also used : TextMatching(annis.model.QueryNode.TextMatching) Escaper(com.google.common.escape.Escaper)

Example 2 with TextMatching

use of annis.model.QueryNode.TextMatching in project ANNIS by korpling.

the class DefaultWhereClauseGenerator method addSpanConditions.

@Override
protected void addSpanConditions(List<String> conditions, QueryData queryData, QueryNode node) {
    TextMatching textMatching = node.getSpanTextMatching();
    conditions.add(join(textMatching.sqlOperator(), tables(node).aliasedColumn(NODE_TABLE, "span"), sqlString(node.getSpannedText(), textMatching)));
}
Also used : TextMatching(annis.model.QueryNode.TextMatching)

Aggregations

TextMatching (annis.model.QueryNode.TextMatching)2 Escaper (com.google.common.escape.Escaper)1