summaryrefslogtreecommitdiff
path: root/docs/graph_utilities.rst
diff options
context:
space:
mode:
authorGraham Higgins <gjh@bel-epa.com>2012-01-08 12:32:36 +0000
committerGraham Higgins <gjh@bel-epa.com>2012-01-08 12:32:36 +0000
commit0d1284864634c76239ff324ebd6b028cfbe08e3f (patch)
tree37129916bfc5deced77ac31aef88ab5abe67d9e8 /docs/graph_utilities.rst
parent097de8a4b0066df94a8b2d09e35ebba7d36373ac (diff)
downloadrdflib-0d1284864634c76239ff324ebd6b028cfbe08e3f.tar.gz
Remove extraneous content from docs
Diffstat (limited to 'docs/graph_utilities.rst')
-rw-r--r--docs/graph_utilities.rst68
1 files changed, 68 insertions, 0 deletions
diff --git a/docs/graph_utilities.rst b/docs/graph_utilities.rst
index fa6cef85..d0be7d90 100644
--- a/docs/graph_utilities.rst
+++ b/docs/graph_utilities.rst
@@ -46,6 +46,7 @@ Triples can be added in two ways:
:noindex:
The first argument can be a *source* of many kinds, but the most common is the serialization (in various formats: RDF/XML, Notation 3, NTriples of an RDF graph as a string. The :keyword:`format` parameter is one of ``n3``, ``xml``, or ``ntriples``. :keyword:`publicID` is the name of the graph into which the RDF serialization will be parsed.
+
* Triples can also be added with the :meth:`add` function:
.. automethod:: rdflib.graph.Graph.add
@@ -113,4 +114,71 @@ Maps Python instances to WXS datatyped Literals
Maps WXS datatyped Literals to Python. This mapping is used by the :meth:`toPython` method defined on all Literal instances.
+Merging graphs
+--------------
+
+.. note:: A merge of a set of RDF graphs is defined as follows. If the graphs in the set have no blank nodes in common, then the union of the graphs is a merge; if they do share blank nodes, then it is the union of a set of graphs that is obtained by replacing the graphs in the set by equivalent graphs that share no blank nodes. This is often described by saying that the blank nodes have been 'standardized apart'. It is easy to see that any two merges are equivalent, so we will refer to the merge, following the convention on equivalent graphs. Using the convention on equivalent graphs and identity, any graph in the original set is considered to be a subgraph of the merge.
+
+ One does not, in general, obtain the merge of a set of graphs by concatenating their corresponding N-Triples documents and constructing the graph described by the merged document. If some of the documents use the same node identifiers, the merged document will describe a graph in which some of the blank nodes have been 'accidentally' identified. To merge N-Triples documents it is necessary to check if the same nodeID is used in two or more documents, and to replace it with a distinct nodeID in each of them, before merging the documents. Similar cautions apply to merging graphs described by RDF/XML documents which contain nodeIDs
+
+(copied directly from http://www.w3.org/TR/rdf-mt/#graphdefs)
+
+.. code-block:: pycon
+
+ """
+ Tutorial 9 - demonstrate graph operations
+
+ (not really quite graph operations since rdflib cannot merge models like
+ Jena, but this examples shows you can load two different RDF files and
+ rdflib will merge the two together into one model)
+
+ Copyright (C) 2005 Sylvia Wong <sylvia at whileloop dot org>
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ """
+
+ >>> data1 = """\
+ ... @prefix vCard: <http://www.w3.org/2001/vcard-rdf/3.0#> .
+ ...
+ ... <http://somewhere/JohnSmith/> vCard:FN "John Smith";
+ ... vCard:N [ vCard:Family "Smith";
+ ... vCard:Given "John" ] .
+ ... """
+ >>> data2 = """\
+ ... @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+ ... @prefix vCard: <http://www.w3.org/2001/vcard-rdf/3.0#> .
+ ...
+ ... <http://somewhere/JohnSmith/> vCard:EMAIL [ a vCard:internet;
+ ... rdf:value "John@somewhere.com" ];
+ ... vCard:FN "John Smith" .
+ ... """
+ >>> from rdflib import Graph
+ >>> store = Graph()
+ >>> store.parse(data=data1, format="n3") #doctest :ellipsis
+ <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
+ >>> store.parse(data=data2, format="n3") #doctest :ellipsis
+ <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
+ >>> print(store.serialize(format="n3"))
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+ @prefix vCard: <http://www.w3.org/2001/vcard-rdf/3.0#> .
+
+ <http://somewhere/JohnSmith/> vCard:EMAIL [ a vCard:internet;
+ rdf:value "John@somewhere.com" ];
+ vCard:FN "John Smith";
+ vCard:N [ vCard:Family "Smith";
+ vCard:Given "John" ] .
+
+(edited for inclusion in rdflib documentation)