Search in sources :

Example 11 with TriplePath

use of org.apache.jena.sparql.core.TriplePath in project jena by apache.

the class WhereHandlerTest method testSetVarsInTriple.

@Test
public void testSetVarsInTriple() {
    Var v = Var.alloc("v");
    handler.addWhere(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v)));
    assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + var("v") + OPT_SPACE + CLOSE_CURLY, query.toString());
    Map<Var, Node> values = new HashMap<>();
    values.put(v, NodeFactory.createURI("three"));
    handler.setVars(values);
    assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY, query.toString());
}
Also used : Triple(org.apache.jena.graph.Triple) HashMap(java.util.HashMap) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath) Test(org.junit.Test)

Example 12 with TriplePath

use of org.apache.jena.sparql.core.TriplePath in project jena by apache.

the class ElementTransformSubst method transform.

@Override
public Element transform(ElementPathBlock el) {
    ElementPathBlock epb = new ElementPathBlock();
    boolean changed = false;
    for (TriplePath p : el.getPattern()) {
        TriplePath p2 = transform(p);
        changed = changed || p != p2;
        epb.addTriplePath(p2);
    }
    if (changed)
        return epb;
    return el;
}
Also used : TriplePath(org.apache.jena.sparql.core.TriplePath) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock)

Example 13 with TriplePath

use of org.apache.jena.sparql.core.TriplePath in project jena by apache.

the class WhereHandlerTest method testAddOptionalObjects.

@Test
public void testAddOptionalObjects() {
    handler.addOptional(new TriplePath(new Triple(NodeFactory.createURI("one"), ResourceFactory.createResource("two").asNode(), ResourceFactory.createLangLiteral("three", "en-US").asNode())));
    assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + quote("three") + "@en-US" + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
}
Also used : Triple(org.apache.jena.graph.Triple) TriplePath(org.apache.jena.sparql.core.TriplePath) Test(org.junit.Test)

Example 14 with TriplePath

use of org.apache.jena.sparql.core.TriplePath 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"))));
    assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
}
Also used : Triple(org.apache.jena.graph.Triple) TriplePath(org.apache.jena.sparql.core.TriplePath) Test(org.junit.Test)

Example 15 with TriplePath

use of org.apache.jena.sparql.core.TriplePath in project jena by apache.

the class WhereHandlerTest method testSetVarsInOptional.

@Test
public void testSetVarsInOptional() {
    Var v = Var.alloc("v");
    handler.addOptional(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v)));
    assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + var("v") + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
    Map<Var, Node> values = new HashMap<>();
    values.put(v, NodeFactory.createURI("three"));
    handler.setVars(values);
    assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
}
Also used : Triple(org.apache.jena.graph.Triple) HashMap(java.util.HashMap) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath) Test(org.junit.Test)

Aggregations

TriplePath (org.apache.jena.sparql.core.TriplePath)33 Triple (org.apache.jena.graph.Triple)22 Test (org.junit.Test)18 Node (org.apache.jena.graph.Node)10 WhereHandler (org.apache.jena.arq.querybuilder.handlers.WhereHandler)4 Query (org.apache.jena.query.Query)4 Path (org.apache.jena.sparql.path.Path)4 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)3 PrefixMapping (org.apache.jena.shared.PrefixMapping)3 PrefixMappingImpl (org.apache.jena.shared.impl.PrefixMappingImpl)3 Var (org.apache.jena.sparql.core.Var)3 HashMap (java.util.HashMap)2 Op (org.apache.jena.sparql.algebra.Op)2 OpPath (org.apache.jena.sparql.algebra.op.OpPath)2 BasicPattern (org.apache.jena.sparql.core.BasicPattern)2 ContractTest (org.xenei.junit.contract.ContractTest)2 FrontsTriple (org.apache.jena.graph.FrontsTriple)1 PathBlock (org.apache.jena.sparql.core.PathBlock)1 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)1