Search in sources :

Example 31 with WhereValidator

use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.

the class WhereClauseTest method testAddSubQuery.

@ContractTest
public void testAddSubQuery() {
    SelectBuilder sb = new SelectBuilder();
    sb.addPrefix("pfx", "urn:uri:").addVar("?x").addWhere("pfx:one", "pfx:two", "pfx:three");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addSubQuery(sb);
    Query query = builder.build();
    Query q2 = new Query();
    q2.setQuerySelectType();
    q2.addProjectVars(Arrays.asList(Var.alloc("x")));
    ElementPathBlock epb = new ElementPathBlock();
    q2.setQueryPattern(epb);
    epb.addTriplePath(new TriplePath(new Triple(NodeFactory.createURI("urn:uri:one"), NodeFactory.createURI("urn:uri:two"), NodeFactory.createURI("urn:uri:three"))));
    ElementSubQuery esq = new ElementSubQuery(q2);
    WhereValidator visitor = new WhereValidator(esq);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) FrontsTriple(org.apache.jena.graph.FrontsTriple) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) TriplePath(org.apache.jena.sparql.core.TriplePath) SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Example 32 with WhereValidator

use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.

the class WhereClauseTest method testSetVarsInWhereValues_NodeVariable.

@ContractTest
public void testSetVarsInWhereValues_NodeVariable() {
    Node v = NodeFactory.createVariable("v");
    Node value = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(10));
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addWhereValueVar("?x", "<one>", "?v");
    builder.setVar(v, value);
    Query query = builder.build();
    ElementData edat = new ElementData();
    Var x = Var.alloc("x");
    edat.add(x);
    Binding binding1 = BindingFactory.binding(x, NodeFactory.createURI("one"));
    edat.add(binding1);
    Binding binding2 = BindingFactory.binding(x, value);
    edat.add(binding2);
    WhereValidator visitor = new WhereValidator(edat);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Node(org.apache.jena.graph.Node) ElementData(org.apache.jena.sparql.syntax.ElementData) ContractTest(org.xenei.junit.contract.ContractTest)

Example 33 with WhereValidator

use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.

the class WhereClauseTest method testAddOptionalStringWithPath.

@ContractTest
public void testAddOptionalStringWithPath() {
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addOptional("<one>", "<two>/<dos>", "three");
    Path path = new P_Seq(new P_Link(NodeFactory.createURI("two")), new P_Link(NodeFactory.createURI("dos")));
    ElementPathBlock epb = new ElementPathBlock();
    ElementOptional optional = new ElementOptional(epb);
    TriplePath tp = new TriplePath(NodeFactory.createURI("one"), path, NodeFactory.createLiteral("three"));
    epb.addTriplePath(tp);
    WhereValidator visitor = new WhereValidator(optional);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : TriplePath(org.apache.jena.sparql.core.TriplePath) Path(org.apache.jena.sparql.path.Path) P_Seq(org.apache.jena.sparql.path.P_Seq) ElementOptional(org.apache.jena.sparql.syntax.ElementOptional) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) P_Link(org.apache.jena.sparql.path.P_Link) TriplePath(org.apache.jena.sparql.core.TriplePath) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Example 34 with WhereValidator

use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.

the class WhereClauseTest method testSetVarsInWhereValues.

@ContractTest
public void testSetVarsInWhereValues() {
    Var v = Var.alloc("v");
    Node value = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(10));
    Map<Var, Node> values = new HashMap<>();
    values.put(v, value);
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addWhereValueVar("?x", "<one>", "?v");
    builder.setVar(v, value);
    Query query = builder.build();
    ElementData edat = new ElementData();
    Var x = Var.alloc("x");
    edat.add(x);
    Binding binding1 = BindingFactory.binding(x, NodeFactory.createURI("one"));
    edat.add(binding1);
    Binding binding2 = BindingFactory.binding(x, value);
    edat.add(binding2);
    WhereValidator visitor = new WhereValidator(edat);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) HashMap(java.util.HashMap) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Node(org.apache.jena.graph.Node) ElementData(org.apache.jena.sparql.syntax.ElementData) ContractTest(org.xenei.junit.contract.ContractTest)

Example 35 with WhereValidator

use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.

the class WhereClauseTest method testAddWhereValueVar_var.

@ContractTest
public void testAddWhereValueVar_var() {
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addWhereValueVar("?v");
    Query query = builder.build();
    ElementData edat = new ElementData();
    edat.add(Var.alloc("v"));
    WhereValidator visitor = new WhereValidator(edat);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementData(org.apache.jena.sparql.syntax.ElementData) ContractTest(org.xenei.junit.contract.ContractTest)

Aggregations

WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)90 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)60 Triple (org.apache.jena.graph.Triple)54 TriplePath (org.apache.jena.sparql.core.TriplePath)49 Test (org.junit.Test)47 Query (org.apache.jena.query.Query)42 ElementSubQuery (org.apache.jena.sparql.syntax.ElementSubQuery)42 ContractTest (org.xenei.junit.contract.ContractTest)42 Var (org.apache.jena.sparql.core.Var)34 Node (org.apache.jena.graph.Node)30 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)22 FrontsTriple (org.apache.jena.graph.FrontsTriple)22 ExprVar (org.apache.jena.sparql.expr.ExprVar)21 ElementData (org.apache.jena.sparql.syntax.ElementData)18 ElementOptional (org.apache.jena.sparql.syntax.ElementOptional)16 HashMap (java.util.HashMap)10 ElementUnion (org.apache.jena.sparql.syntax.ElementUnion)8 LinkedHashMap (java.util.LinkedHashMap)7 Binding (org.apache.jena.sparql.engine.binding.Binding)6 E_Random (org.apache.jena.sparql.expr.E_Random)6