@Override
 protected boolean accepts(Object key, QuadWritable tuple) {
   Quad q = tuple.get();
   if (!q.isConcrete()) return false;
   // Ground if all nodes are URI/Literal
   return (q.getGraph().isURI() || q.getGraph().isLiteral())
       && (q.getSubject().isURI() || q.getSubject().isLiteral())
       && (q.getPredicate().isURI() || q.getPredicate().isLiteral())
       && (q.getObject().isURI() || q.getObject().isLiteral());
 }
示例#2
0
  @Override
  public QuadBlock rewrite(SDBRequest request, QuadBlock quadBlock) {
    // Does not consider if the property slot is a variable.

    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());
      quadBlock.set(i, q1); // replace rdf:type statement
      quadBlock.add(i + 1, q2); // add subClassOf statement
      i = i + 2; // Skip the two statements.
    }
    return quadBlock;
  }