Search in sources :

Example 6 with Template

use of org.apache.jena.sparql.syntax.Template in project jena by apache.

the class ParserSPARQL11 method parseTemplate.

public static Template parseTemplate(String string) {
    final Query query = new Query();
    Action action = new Action() {

        @Override
        public void exec(SPARQLParser11 parser) throws Exception {
            Template t = parser.ConstructTemplate();
            query.setConstructTemplate(t);
        }
    };
    perform(query, string, action);
    return query.getConstructTemplate();
}
Also used : SPARQLParser11(org.apache.jena.sparql.lang.sparql_11.SPARQLParser11) Query(org.apache.jena.query.Query) Template(org.apache.jena.sparql.syntax.Template)

Example 7 with Template

use of org.apache.jena.sparql.syntax.Template in project jena by apache.

the class ParserARQ method parseTemplate.

public static Template parseTemplate(String string) {
    final Query query = new Query();
    Action action = new Action() {

        @Override
        public void exec(ARQParser parser) throws Exception {
            Template t = parser.ConstructTemplate();
            query.setConstructTemplate(t);
        }
    };
    perform(query, string, action);
    return query.getConstructTemplate();
}
Also used : Query(org.apache.jena.query.Query) ARQParser(org.apache.jena.sparql.lang.arq.ARQParser) Template(org.apache.jena.sparql.syntax.Template)

Example 8 with Template

use of org.apache.jena.sparql.syntax.Template in project jena by apache.

the class ConstructHandlerTest method testAddAll.

@Test
public void testAddAll() {
    Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
    ConstructHandler handler2 = new ConstructHandler(new Query());
    handler2.addConstruct(t);
    handler.addAll(handler2);
    Template template = query.getConstructTemplate();
    assertNotNull(template);
    List<Triple> lst = template.getTriples();
    assertEquals(1, lst.size());
    assertEquals(t, lst.get(0));
}
Also used : Triple(org.apache.jena.graph.Triple) Query(org.apache.jena.query.Query) Template(org.apache.jena.sparql.syntax.Template) Test(org.junit.Test)

Example 9 with Template

use of org.apache.jena.sparql.syntax.Template in project jena by apache.

the class ConstructHandlerTest method testAddConstruct.

@Test
public void testAddConstruct() {
    Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
    handler.addConstruct(t);
    Template template = query.getConstructTemplate();
    assertNotNull(template);
    List<Triple> lst = template.getTriples();
    assertEquals(1, lst.size());
    assertEquals(t, lst.get(0));
}
Also used : Triple(org.apache.jena.graph.Triple) Template(org.apache.jena.sparql.syntax.Template) Test(org.junit.Test)

Example 10 with Template

use of org.apache.jena.sparql.syntax.Template in project jena by apache.

the class ConstructHandler method addConstruct.

/**
	 * Add a triple to the construct statement.
	 * @param t The triple to add.
	 */
public void addConstruct(Triple t) {
    constructs.add(t);
    query.setConstructTemplate(new Template(BasicPattern.wrap(constructs)));
}
Also used : Template(org.apache.jena.sparql.syntax.Template)

Aggregations

Template (org.apache.jena.sparql.syntax.Template)11 Query (org.apache.jena.query.Query)4 Triple (org.apache.jena.graph.Triple)3 Test (org.junit.Test)3 Node (org.apache.jena.graph.Node)2 HashMap (java.util.HashMap)1 AbstractRewriter (org.apache.jena.arq.querybuilder.rewriters.AbstractRewriter)1 Var (org.apache.jena.sparql.core.Var)1 ARQParser (org.apache.jena.sparql.lang.arq.ARQParser)1 SPARQLParser10 (org.apache.jena.sparql.lang.sparql_10.SPARQLParser10)1 SPARQLParser11 (org.apache.jena.sparql.lang.sparql_11.SPARQLParser11)1