Search in sources :

Example 1 with AnonId

use of com.hp.hpl.jena.rdf.model.AnonId in project stanbol by apache.

the class RdfIndexingSource method listObjects.

/* ----------------------------------------------------------------------
     *     RDF Backend implementation
     * ----------------------------------------------------------------------
     */
@Override
public Collection<Node> listObjects(Node subject, Node property) {
    Collection<Node> nodes = new ArrayList<Node>();
    if (bnodePrefix != null && subject.isURI() && subject.getURI().startsWith(bnodePrefix)) {
        subject = NodeFactory.createAnon(new AnonId(subject.getURI().substring(bnodePrefix.length())));
    }
    ExtendedIterator<Triple> it = indexingDataset.getDefaultGraph().find(subject, property, null);
    while (it.hasNext()) {
        //STANBOL-765: we need also to transform bnodes to URIs for the
        //RDFBackend implementation
        Node object = it.next().getObject();
        if (bnodePrefix != null && object.isBlank()) {
            StringBuilder sb = new StringBuilder(bnodePrefix);
            sb.append(object.getBlankNodeId().getLabelString());
            object = NodeFactory.createURI(sb.toString());
        }
        nodes.add(object);
    }
    it.close();
    return nodes;
}
Also used : Triple(com.hp.hpl.jena.graph.Triple) Node(com.hp.hpl.jena.graph.Node) RDFNode(com.hp.hpl.jena.rdf.model.RDFNode) ArrayList(java.util.ArrayList) AnonId(com.hp.hpl.jena.rdf.model.AnonId)

Example 2 with AnonId

use of com.hp.hpl.jena.rdf.model.AnonId in project stanbol by apache.

the class RdfIndexingSource method listSubjects.

@Override
public Collection<Node> listSubjects(Node property, Node object) {
    Collection<Node> nodes = new ArrayList<Node>();
    if (bnodePrefix != null && object.isURI() && object.getURI().startsWith(bnodePrefix)) {
        object = NodeFactory.createAnon(new AnonId(object.getURI().substring(bnodePrefix.length())));
    }
    ExtendedIterator<Triple> it = indexingDataset.getDefaultGraph().find(null, property, object);
    while (it.hasNext()) {
        Node subject = it.next().getSubject();
        //RDFBackend implementation
        if (bnodePrefix != null && subject.isBlank()) {
            StringBuilder sb = new StringBuilder(bnodePrefix);
            sb.append(subject.getBlankNodeId().getLabelString());
            subject = NodeFactory.createURI(sb.toString());
        }
        nodes.add(subject);
    }
    it.close();
    return nodes;
}
Also used : Triple(com.hp.hpl.jena.graph.Triple) Node(com.hp.hpl.jena.graph.Node) RDFNode(com.hp.hpl.jena.rdf.model.RDFNode) ArrayList(java.util.ArrayList) AnonId(com.hp.hpl.jena.rdf.model.AnonId)

Aggregations

Node (com.hp.hpl.jena.graph.Node)2 Triple (com.hp.hpl.jena.graph.Triple)2 AnonId (com.hp.hpl.jena.rdf.model.AnonId)2 RDFNode (com.hp.hpl.jena.rdf.model.RDFNode)2 ArrayList (java.util.ArrayList)2