Search in sources :

Example 26 with Triple

use of org.apache.jena.graph.Triple in project jena by apache.

the class TriplesToQuadsConstantGraphMapperTest method generateData.

protected void generateData(MapDriver<LongWritable, TripleWritable, LongWritable, QuadWritable> driver, int num) {
    for (int i = 0; i < num; i++) {
        Triple t = new Triple(NodeFactory.createURI("http://subjects/" + i), NodeFactory.createURI("http://predicate"), NodeFactory.createLiteral(Integer.toString(i), XSDDatatype.XSDinteger));
        Quad q = new Quad(Quad.defaultGraphNodeGenerated, t);
        driver.addInput(new LongWritable(i), new TripleWritable(t));
        driver.addOutput(new LongWritable(i), new QuadWritable(q));
    }
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) TripleWritable(org.apache.jena.hadoop.rdf.types.TripleWritable) QuadWritable(org.apache.jena.hadoop.rdf.types.QuadWritable) LongWritable(org.apache.hadoop.io.LongWritable)

Example 27 with Triple

use of org.apache.jena.graph.Triple in project jena by apache.

the class WhereProcessor method list.

/**
	 * Create a list node from a list of objects as per RDF Collections.
	 * 
	 * http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#collections
	 * 
	 * @param objs
	 *            the list of objects for the list.
	 * @return the first blank node in the list.
	 */
public Node list(Object... objs) {
    Node retval = NodeFactory.createBlankNode();
    Node lastObject = retval;
    for (int i = 0; i < objs.length; i++) {
        Node n = AbstractQueryBuilder.makeNode(objs[i], prefixHandler.getPrefixes());
        addWhere(new TriplePath(new Triple(lastObject, RDF.first.asNode(), n)));
        if (i + 1 < objs.length) {
            Node nextObject = NodeFactory.createBlankNode();
            addWhere(new TriplePath(new Triple(lastObject, RDF.rest.asNode(), nextObject)));
            lastObject = nextObject;
        } else {
            addWhere(new TriplePath(new Triple(lastObject, RDF.rest.asNode(), RDF.nil.asNode())));
        }
    }
    return retval;
}
Also used : Triple(org.apache.jena.graph.Triple) Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath)

Example 28 with Triple

use of org.apache.jena.graph.Triple in project jena by apache.

the class AbstractRewriter method rewrite.

/**
	 * Rewrite a triple path.
	 * @param t The triple path to rewrite.
	 * @return the triple path after rewriting.
	 */
protected final TriplePath rewrite(TriplePath t) {
    if (t.getPath() == null) {
        return new TriplePath(new Triple(changeNode(t.getSubject()), changeNode(t.getPredicate()), changeNode(t.getObject())));
    } else {
        PathRewriter transform = new PathRewriter(values);
        t.getPath().visit(transform);
        return new TriplePath(changeNode(t.getSubject()), transform.getResult(), changeNode(t.getObject()));
    }
}
Also used : Triple(org.apache.jena.graph.Triple) TriplePath(org.apache.jena.sparql.core.TriplePath)

Example 29 with Triple

use of org.apache.jena.graph.Triple in project jena by apache.

the class StageGeneratorAlt method execute.

@Override
public QueryIterator execute(BasicPattern pattern, QueryIterator input, ExecutionContext execCxt) {
    // Test ::  execCxt.getActiveGraph() 
    if (!(execCxt.getActiveGraph() instanceof GraphBase))
        // not based on GraphBase (which most Graph implementations are). 
        return other.execute(pattern, input, execCxt);
    System.err.println("MyStageGenerator.compile:: triple patterns = " + pattern.size());
    // Stream the triple matches together, one triple matcher at a time. 
    QueryIterator qIter = input;
    for (Triple triple : pattern.getList()) qIter = new QueryIterTriplePattern(qIter, triple, execCxt);
    return qIter;
}
Also used : Triple(org.apache.jena.graph.Triple) QueryIterTriplePattern(org.apache.jena.sparql.engine.iterator.QueryIterTriplePattern) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) GraphBase(org.apache.jena.graph.impl.GraphBase)

Example 30 with Triple

use of org.apache.jena.graph.Triple in project jena by apache.

the class container method execEvaluatedConcrete.

// Ask directly.
private QueryIterator execEvaluatedConcrete(Binding binding, Node containerNode, Node predicate, Node member, ExecutionContext execCxt) {
    QueryIterator input = QueryIterSingleton.create(binding, execCxt);
    Graph graph = execCxt.getActiveGraph();
    QueryIterator qIter = new QueryIterTriplePattern(input, new Triple(containerNode, predicate, member), execCxt);
    return qIter;
}
Also used : Triple(org.apache.jena.graph.Triple) Graph(org.apache.jena.graph.Graph) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Aggregations

Triple (org.apache.jena.graph.Triple)407 Test (org.junit.Test)139 Node (org.apache.jena.graph.Node)95 BaseTest (org.apache.jena.atlas.junit.BaseTest)66 Graph (org.apache.jena.graph.Graph)54 Quad (org.apache.jena.sparql.core.Quad)25 TriplePath (org.apache.jena.sparql.core.TriplePath)22 ArrayList (java.util.ArrayList)20 StatsMatcher (org.apache.jena.sparql.engine.optimizer.StatsMatcher)19 Var (org.apache.jena.sparql.core.Var)17 TripleWritable (org.apache.jena.hadoop.rdf.types.TripleWritable)15 Model (org.apache.jena.rdf.model.Model)13 TriplePattern (org.apache.jena.reasoner.TriplePattern)13 Op (org.apache.jena.sparql.algebra.Op)13 BasicPattern (org.apache.jena.sparql.core.BasicPattern)13 TransitiveGraphCache (org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache)11 LongWritable (org.apache.hadoop.io.LongWritable)10 InfGraph (org.apache.jena.reasoner.InfGraph)10 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)10 Resource (org.apache.jena.rdf.model.Resource)9