Search in sources :

Example 1 with MapResult

use of org.apache.jena.sdb.exprmatch.MapResult in project jena by apache.

the class RegexSqlGen method compile.

@Override
public SqlExpr compile(Scope scope) {
    // TODO Convert regex to using a string value table?
    MapResult rMap = exprPattern.match(getExpr());
    if (rMap == null)
        throw new SDBException("Couldn't compile after all: " + getExpr());
    Var var = rMap.get(Var.alloc("a1")).getExprVar().asVar();
    String pattern = rMap.get(Var.alloc("a2")).getConstant().getString();
    if (!scope.hasColumnForVar(var)) {
        LoggerFactory.getLogger(this.getClass()).error("Variable '" + var + "' not in scope");
        return null;
    }
    SqlColumn vCol = scope.findScopeForVar(var).getColumn();
    // Ensure it's the lex column
    SqlColumn lexCol = new SqlColumn(vCol.getTable(), "lex");
    SqlColumn vTypeCol = new SqlColumn(vCol.getTable(), "type");
    // "is a string"
    SqlExpr isStr = new S_Equal(vTypeCol, new SqlConstant(ValueType.STRING.getTypeId()));
    isStr.addNote("is a string");
    // regex.
    SqlExpr sCond = new S_Regex(vCol, pattern, flags);
    sCond.addNote(getExpr().toString());
    SqlExpr sqlExpr = new S_And(isStr, sCond);
    return sqlExpr;
}
Also used : Var(org.apache.jena.sparql.core.Var) ActionMatchVar(org.apache.jena.sdb.exprmatch.ActionMatchVar) SDBException(org.apache.jena.sdb.SDBException) ActionMatchString(org.apache.jena.sdb.exprmatch.ActionMatchString) MapResult(org.apache.jena.sdb.exprmatch.MapResult)

Example 2 with MapResult

use of org.apache.jena.sdb.exprmatch.MapResult in project jena by apache.

the class StringEqualsSqlGen method recognize.

//    private static ExprPattern equalsString3 = new ExprPattern("str(?a1) = ?a2",
//                                                               new Var[]{ Var.alloc("a1") , Var.alloc("a2") },
//                                                               new Action[]{ new ActionMatchVar() ,
//                                                                             new ActionMatchString()}) ;
////  As equalsString3 but reverse the arguments.
//    private static ExprPattern equalsString4 = new ExprPattern("?a1 = str(?a2)",
//                                                               new Var[]{ Var.alloc("a1") , Var.alloc("a2") },
//                                                               new Action[]{ new ActionMatchString() ,
//                                                                             new ActionMatchVar() }) ;
@Override
public SDBConstraint recognize(Expr expr) {
    MapResult rMap = null;
    if ((rMap = equalsString1.match(expr)) != null) {
        Var var = rMap.get("a1").getExprVar().asVar();
        String str = rMap.get("a2").getConstant().getString();
        return new StringEqualsSqlGen(expr, equalsString1, true);
    }
    return null;
}
Also used : Var(org.apache.jena.sparql.core.Var) ActionMatchVar(org.apache.jena.sdb.exprmatch.ActionMatchVar) ActionMatchString(org.apache.jena.sdb.exprmatch.ActionMatchString) MapResult(org.apache.jena.sdb.exprmatch.MapResult)

Example 3 with MapResult

use of org.apache.jena.sdb.exprmatch.MapResult in project jena by apache.

the class StringEqualsSqlGen method compile.

@Override
public SqlExpr compile(Scope scope) {
    MapResult rMap = exprPattern.match(getExpr());
    if (rMap == null)
        throw new SDBException("Couldn't compile after all: " + getExpr());
    //log.info("equalsString - Matched: ?a1 = "+rMap.get("a1")+" : ?a2 = "+rMap.get("a2")) ;
    Var var = rMap.get("a1").getExprVar().asVar();
    String str = rMap.get("a2").getConstant().getString();
    if (!scope.hasColumnForVar(var)) {
        LoggerFactory.getLogger(this.getClass()).error("Variable '" + var + "' not in scope");
        return null;
    }
    SqlColumn vCol = scope.findScopeForVar(var).getColumn();
    SqlColumn lexCol = new SqlColumn(vCol.getTable(), "lex");
    SqlColumn vTypeCol = new SqlColumn(vCol.getTable(), "type");
    // "is a string"
    SqlExpr isStr = new S_Equal(vTypeCol, new SqlConstant(ValueType.STRING.getTypeId()));
    isStr.addNote("is a string");
    // Equality
    SqlExpr strEquals = new S_Equal(lexCol, new SqlConstant(str));
    isStr.addNote(getExpr().toString());
    return new S_And(isStr, strEquals);
}
Also used : Var(org.apache.jena.sparql.core.Var) ActionMatchVar(org.apache.jena.sdb.exprmatch.ActionMatchVar) SDBException(org.apache.jena.sdb.SDBException) ActionMatchString(org.apache.jena.sdb.exprmatch.ActionMatchString) MapResult(org.apache.jena.sdb.exprmatch.MapResult)

Example 4 with MapResult

use of org.apache.jena.sdb.exprmatch.MapResult in project jena by apache.

the class RegexSqlGen method recognize.

@Override
public SDBConstraint recognize(Expr expr) {
    MapResult rMap = null;
    if ((rMap = regex1.match(expr)) != null) {
        Var var = rMap.get("a1").getExprVar().asVar();
        String pattern = rMap.get("a2").getConstant().getString();
        return new RegexSqlGen(expr, regex1, pattern, null, true);
    }
    if ((rMap = regex1_i.match(expr)) != null) {
        Var var = rMap.get(Var.alloc("a1")).getExprVar().asVar();
        String pattern = rMap.get(Var.alloc("a2")).getConstant().getString();
        return new RegexSqlGen(expr, regex1_i, pattern, "i", true);
    }
    return null;
}
Also used : Var(org.apache.jena.sparql.core.Var) ActionMatchVar(org.apache.jena.sdb.exprmatch.ActionMatchVar) ActionMatchString(org.apache.jena.sdb.exprmatch.ActionMatchString) MapResult(org.apache.jena.sdb.exprmatch.MapResult)

Aggregations

ActionMatchString (org.apache.jena.sdb.exprmatch.ActionMatchString)4 ActionMatchVar (org.apache.jena.sdb.exprmatch.ActionMatchVar)4 MapResult (org.apache.jena.sdb.exprmatch.MapResult)4 Var (org.apache.jena.sparql.core.Var)4 SDBException (org.apache.jena.sdb.SDBException)2