0

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,

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Jean-Baptiste
  • 201
  • 1
  • 7
  • 2
    get all graphs: `select distinct ?g {graph ?g {?s ?p ?o}}` – UninformedUser Apr 22 '20 at 10:31
  • 2
    get all graphs that contain a triple: `select distinct ?g {graph ?g {:s :p :o}}` – UninformedUser Apr 22 '20 at 10:32
  • 2
    and don't compare graphs with SQL tables. An RDF graph is nothing more than a set of RDF triples, that's it – UninformedUser Apr 22 '20 at 10:33
  • Thank you for this answer, but it get 0 results with those queries applied to a repository where I only imported to the default graph the ex012.ttl file from Bob Ducharme's [Learning SPARQL](http://learningsparql.com/2ndeditionexamples/index.html). – Jean-Baptiste Apr 23 '20 at 08:39
  • 1
    what do you mean by 0 results? If you just load to the default graph, then there are obviously no named graphs. `graph ?g` always refers to named graphs. A default graph has no URI, why should it? – UninformedUser Apr 23 '20 at 09:39
  • 1
    In SPARQL, `SELECT ?g { GRAPH ?g {}}` lists the graph URIs. – AndyS Apr 23 '20 at 11:42
  • I mean that the request gives no result, no URI. It surprised me as I thought than a default graph was still a graph with a URI. But I should missing the concept of "default graph". – Jean-Baptiste Apr 23 '20 at 14:10

2 Answers2

1

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.

Sava Savov
  • 551
  • 2
  • 4
0

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}}
jdacoello
  • 11
  • 2