Graph URIs on GraphDB

703 Views Asked by At

The SPARQL graph concept is still abstract for me.

Are graphs similar to SQL Tables? Does one triple could belong to more than one graph?

Is there a way to get the URI of the graph to which belongs a triple?

Is there a way to get the URI of every graph stored in a GraphDB repository? To get the URI of the default graph?

Thanks,

2

There are 2 best solutions below

0
Sava Savov On

In addition of the answers of UninformedUser, graphs also could be listed using the following cURL command curl 'http://<host>:<port>/repositories/<your_repo>/contexts'.

One could easily explore and export the content of graphs in GraphDB repository using Workbench.enter image description here

Here could be found the value of the default graph as well.

0
jdacoello On

To understand the differences, we could refer first to the data model itself:

Relational model

SQL operates on relational databases. Relational model, in general terms, is a way to model your data and its dependencies as structured tables. If we want to query information that is built out of more than one table, then we perform what is called the join operation that retrieves the relationships between elements in different tables. The join operator often uses keys that are common among the tables. One drawback of this model is when you need to perform many of such join operations to retrieve the desired information. In this case, the response becomes very slow and the performance drops significantly.

Graph model

In contrast, SparQL is a query language that has a SQL-like syntax but operates on graph data. The graph data model does not store the data as tables. Instead, it uses the triple store (another option is to use a Property Graph, but your question refers to triple store). RDF triples are the W3C standard way for describing statements in the graph data model. It consist of Subject, Predicate, Object. Subject is the entity to which the triple refers, Predicate is the type of relationship it has, and Object is the entity or property to which is the subject connects. The subject has always a unique identifier (e.g, URI), whereas the object can be a literal or another entity with an URI.

Further comparison

You can have a look at a more detailed comparison of the models in chapter 2 (Options for Storing Connected Data) of the book: Graph Databases, 2nd Edition by Ian Robinson, Jim Webber, Emil Eifrem

Coming back to your questions

Are graphs similar to SQL Tables? Does one triple could belong to more than one graph?

No, graphs are not SQL tables. And yes, one triple could appear in different graphs (as long as the triple has the same Subject, Predicate, and Object). However, if you use different ontologies, the triple would appear in a different context.

Is there a way to get the URI of the graph to which belongs a triple? Is there a way to get the URI of every graph stored in a GraphDB repository? To get the URI of the default graph?

The SparQL queries are graph patterns. You need to specify the type of structure you are searching for.

As UninformedUser commented:

All triples

select distinct ?g {graph ?g {?s ?p ?o}}

All structures that contain an specific triple

select distinct ?g {graph ?g {:s :p :o}}