Search in sources :

Example 1 with QuadBlock

use of org.apache.jena.sdb.compiler.QuadBlock in project jena by apache.

the class QBR_SubProperty method rewrite.

@Override
public QuadBlock rewrite(SDBRequest request, QuadBlock quadBlock) {
    if (!quadBlock.contains(null, null, rdfType, null))
        return quadBlock;
    quadBlock = new QuadBlock(quadBlock);
    int i = 0;
    // Better/clearer : do as copy over from one block to another. 
    while ((i = quadBlock.findFirst(i, null, null, rdfType, null)) != -1) {
        // { :s rdf:type :C } => { :s rdf:type ?V . ?V rdfs:subClassOf :C } 
        Quad rdfTypeQuad = quadBlock.get(i);
        Var var = request.genVar();
        Quad q1 = new Quad(rdfTypeQuad.getGraph(), rdfTypeQuad.getSubject(), rdfType, var);
        Quad q2 = new Quad(rdfTypeQuad.getGraph(), var, RDFS.subClassOf.asNode(), rdfTypeQuad.getObject());
        // replace rdf:type statement
        quadBlock.set(i, q1);
        // add subClassOf statement
        quadBlock.add(i + 1, q2);
        // Skip the two statements.
        i = i + 2;
    }
    return quadBlock;
}
Also used : QuadBlock(org.apache.jena.sdb.compiler.QuadBlock) Quad(org.apache.jena.sparql.core.Quad) Var(org.apache.jena.sparql.core.Var)

Example 2 with QuadBlock

use of org.apache.jena.sdb.compiler.QuadBlock in project jena by apache.

the class QBR_SubType method rewrite.

@Override
public QuadBlock rewrite(SDBRequest request, QuadBlock quadBlock) {
    if (!quadBlock.contains(null, null, rdfType, null))
        return quadBlock;
    quadBlock = new QuadBlock(quadBlock);
    int i = 0;
    // Better/clearer : do as copy over from one block to another. 
    while ((i = quadBlock.findFirst(i, null, null, rdfType, null)) != -1) {
        // { :s rdf:type :C } => { :s rdf:type ?V . ?V rdfs:subClassOf :C } 
        Quad rdfTypeQuad = quadBlock.get(i);
        Var var = request.genVar();
        Quad q1 = new Quad(rdfTypeQuad.getGraph(), rdfTypeQuad.getSubject(), rdfType, var);
        Quad q2 = new Quad(rdfTypeQuad.getGraph(), var, RDFS.subClassOf.asNode(), rdfTypeQuad.getObject());
        // replace rdf:type statement
        quadBlock.set(i, q1);
        // add subClassOf statement
        quadBlock.add(i + 1, q2);
        // Skip the two statements.
        i = i + 2;
    }
    return quadBlock;
}
Also used : QuadBlock(org.apache.jena.sdb.compiler.QuadBlock) Quad(org.apache.jena.sparql.core.Quad) Var(org.apache.jena.sparql.core.Var)

Aggregations

QuadBlock (org.apache.jena.sdb.compiler.QuadBlock)2 Quad (org.apache.jena.sparql.core.Quad)2 Var (org.apache.jena.sparql.core.Var)2