This turorial is part of the RAP - Rdf API for PHP documentation.
Daniel Westphal, Chris Bizer
This section gives an introduction into the ideas behind Named Graphs and RAP's RDF datset API.
The Semantic Web can be seen as a collection of RDF graphs. The RDF recommendation explains the meaning of any one graph, and how to merge a set of graphs into one, but does not provide suitable mechanisms for talking about graphs or relations between graphs. But the ability to express metainformation about graphs is required for:
RDF reification has well-known problems in addressing these use cases. To avoid these problems several authors propose quads, consisting of an RDF triple and a further URIref or blank node or ID. The proposals vary widely in the semantic of the fourth element, using it to refer to information sources, to model IDs or statement IDs or more generally to contexts. Named Graphs propose a general and simple variation on RDF, using sets of named RDF graphs.
A set of Named Graphs is a collection of RDF graphs. Each one is named with a URIref.
The name of a graph may occur either in the graph itself, in other graphs, or not at all. Graphs may share URIrefs but not blank nodes. Named Graphs can be seen as a reformulation of quads in which the fourth elements distinct syntactic and semantic properties are clearly distinguished, and the relationship to RDFs triples, abstract syntax and semantics is clearer.
Named Graphs has been adopted by W3C Data Access Working Group as data model for the SPARQL query language.
Further details about Named Graphs are found in:
RAP's quad- and named graph-centric Dataset API is an implementation of DAWG's RDF dataset. It provides methods for parsing, manipulating and serializing RDF datasets and pure sets of Named Graphs. It also provides an implementation of the TriX syntax for exchanging RDF datasets.
The basic idea of the Dataset API is to have a set of Named Graphs plus one additional unnamed default graph. The dataset can be manipulated by adding and removing entire Named Graphs, or by working with individual Quads.API Overview
The tables below give an overview about RAPs main interfaces and their most important methods. See PHPDoc for details about all methods.
|A collection of RDF triples which is named by a URI. The NamedGraph object wraps RAP models, meaning that MemModel and DbModel can be reused.|
||Sets the name of the graph.|
||Returns the URI of the named graph.|
|plus all other methods from statement-centric model API.|
|An RDF datset is a collection of named RDF graphs plus one additional unnamed default graph. RDF datsets can be accessed and modified by adding and removing NamedGraph instances, by adding, removing and finding Quads (RDF triples with an additional graph name) and by adding triple to the background graph. RDF datasets can be serialized using TriX.|
|addNamedGraph(namedgraph)||Adds a NamedGraph to the set.|
|addQuad(quad)||Adds a quad to the set of Named Graphs in the RDF dataset. A new NamedGraph will automatically be created if necessary.|
|addDefaultGraph(graph)||Adds the default graph to the RDF dataset.|
||Creates a new NamedGraph and adds it to the set. An existing graph with the same name will be replaced.|
|getNamedGraph(graphName)||Returns the NamedGraph with a specific name from the Dataset.|
|getDefaultGraph()||Returns a reference to the default graph of the Dataset.|
|removeNamedGraph(graphName)||Removes a NamedGraph from the set.|
|findInNamedGraphs(quad)||Finds Quads that match a quad pattern.|
|listNamedGraphs()||Returns an iterator over all NamedGraphs in the set.|
|serializeToFile()||Saves RDF datset as TriX file.|
|sparqlQuery(query [, resultForm])||Executes a SPARQL query against the dataset.|
//create a Quad
//add the Quad to the dataset (the needed namedGraph (http://rap/NamedGraph2) is created automatically)
//print out all saved statements