Search in sources :

Example 76 with WhereValidator

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

the class WhereHandlerTest method testMakeSubQueryFromConstruct.

@Test
public void testMakeSubQueryFromConstruct() {
    AbstractQueryBuilder<?> sb = new ConstructBuilder().addConstruct("?x", RDF.type, NodeFactory.createURI("foo")).addWhere("?x", RDF.type, RDF.Alt);
    ElementSubQuery esq = handler.makeSubQuery(sb);
    Triple t1 = new Triple(NodeFactory.createVariable("x"), RDF.type.asNode(), RDF.Alt.asNode());
    TriplePath tp = new TriplePath(t1);
    ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(tp);
    Query q = new Query();
    q.setQuerySelectType();
    q.setQueryResultStar(true);
    q.setQueryPattern(epb);
    ElementSubQuery esq2 = new ElementSubQuery(q);
    WhereValidator wv = new WhereValidator(esq2);
    esq.visit(wv);
    assertTrue(wv.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) 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) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ConstructBuilder(org.apache.jena.arq.querybuilder.ConstructBuilder) Test(org.junit.Test)

Example 77 with WhereValidator

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

the class WhereHandlerTest method testAddOptionalStrings.

@Test
public void testAddOptionalStrings() {
    handler.addOptional(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"))));
    handler.build();
    TriplePath tp = new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
    ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(tp);
    ElementOptional opt = new ElementOptional(epb);
    WhereValidator wv = new WhereValidator(opt);
    query.getQueryPattern().visit(wv);
    assertTrue(wv.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) ElementOptional(org.apache.jena.sparql.syntax.ElementOptional) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) TriplePath(org.apache.jena.sparql.core.TriplePath) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 78 with WhereValidator

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

the class WhereHandlerTest method addGraph.

@Test
public void addGraph() {
    WhereHandler handler2 = new WhereHandler(new Query());
    handler2.addWhere(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"))));
    handler.addGraph(NodeFactory.createURI("graph"), handler2);
    handler.build();
    TriplePath tp = new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
    ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(tp);
    ElementNamedGraph eng = new ElementNamedGraph(NodeFactory.createURI("graph"), epb);
    WhereValidator visitor = new WhereValidator(eng);
    handler.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) ElementNamedGraph(org.apache.jena.sparql.syntax.ElementNamedGraph) 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) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 79 with WhereValidator

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

the class WhereHandlerTest method testAddOptionalObjectsWithPath.

@Test
public void testAddOptionalObjectsWithPath() {
    PrefixMapping pmap = new PrefixMappingImpl();
    pmap.setNsPrefix("ts", "urn:test:");
    Path path = PathParser.parse("ts:two/ts:dos", pmap);
    handler.addOptional(new TriplePath(NodeFactory.createURI("one"), path, ResourceFactory.createLangLiteral("three", "en-US").asNode()));
    handler.build();
    ElementPathBlock epb = new ElementPathBlock();
    ElementOptional optional = new ElementOptional(epb);
    TriplePath tp = new TriplePath(NodeFactory.createURI("one"), path, ResourceFactory.createLangLiteral("three", "en-US").asNode());
    epb.addTriplePath(tp);
    WhereValidator visitor = new WhereValidator(optional);
    handler.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : TriplePath(org.apache.jena.sparql.core.TriplePath) Path(org.apache.jena.sparql.path.Path) PrefixMapping(org.apache.jena.shared.PrefixMapping) ElementOptional(org.apache.jena.sparql.syntax.ElementOptional) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) TriplePath(org.apache.jena.sparql.core.TriplePath) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 80 with WhereValidator

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

the class WhereHandlerTest method testAddValueVars.

@Test
public void testAddValueVars() {
    final Var v = Var.alloc("v");
    Map<Object, List<?>> map = new LinkedHashMap<Object, List<?>>();
    map.put(Var.alloc("v"), Arrays.asList("<one>", "<two>"));
    map.put("?x", Arrays.asList("three", "four"));
    handler.addValueVars(query.getPrefixMapping(), map);
    handler.build();
    Var x = Var.alloc("x");
    ElementData edat = new ElementData();
    edat.add(v);
    edat.add(x);
    setupBindings(edat, x, v);
    WhereValidator visitor = new WhereValidator(edat);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) List(java.util.List) ElementData(org.apache.jena.sparql.syntax.ElementData) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

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