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;
}
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;
}
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);
}
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;
}
Aggregations