R Graph - RittoShadow/QCan GitHub Wiki

R-Graph

We denote the graphs that represent SPARQL queries as r-graphs. These are directed graphs where operators and variables are represented by instances of (Apache Jena) ARQ's Blank Nodes; URIs are represented by ARQ's URI nodes; and literals are represented by ARQ's Literal Nodes.

This class contains a field that is an instance of ARQ's Graph.

These r-graphs are constructed in a bottom-up fashion by the RGraphBuilder class. For instance, if we have a query:

(union
    (bgp
        (triple ?x <father> ?parent) )
    (bgp
        (triple ?x <mother> ?parent) )
)

We first construct r-graphs for both BGPs. There's a constructor in the RGraph class that takes a list of Triples.

public RGraph(List<Triple triples)

This creates an empty graph, and then adds every triple in a reified manner. i.e. If we have a triple (:Alice,:knows,:Bob), we add (_:b,:subject,:Alice), (_:b,:predicate,:knows), and (_:b,:object,:knows), where _:b is a blank node.

Then, assuming each BGP is represented by rg1 and rg2, respectively, we compute the union with:

rg1.union(rg2)

The result of this is that rg1 will be the union of rg1 and rg2. This is a void function, so it returns nothing. Instead, it operates over the RGraph that calls the function.

If you wish to extend this class, most operators follow this template:

 public void operator(RGraph arg) {
    Node root = NodeFactory.createBlankNode();
    merge(arg); // Merges both graphs
    graph.add(Triple.create(root,CommonNodes.typeNode,INSERTOPERATORTYPEHERE);
    graph.add(Triple.create(root,CommonNodes.argNode,this.root);
    graph.add(Triple.create(root,CommonNodes.argNode,arg1.root);
    this.root = root;
 }

Note:

CommonNodes is a class that contains static instances of all IRI nodes that are used repeatedly used in r-graphs such as: :type, :arg, etc.

⚠️ **GitHub.com Fallback** ⚠️