summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshley Sommer <ashleysommer@gmail.com>2020-03-29 09:14:39 +1000
committerGitHub <noreply@github.com>2020-03-29 09:14:39 +1000
commit5e691870d242b152a3af09c540bde576ed3aa6c7 (patch)
treed1c055eaf830e183d4f76171caf29f43df2a0373
parent5e52fa83767b88f8c83bee3e79df46d576cd5b70 (diff)
parentec4efae5b8a20d5b58682aaf246c4616267b9d79 (diff)
downloadrdflib-5e691870d242b152a3af09c540bde576ed3aa6c7.tar.gz
Merge pull request #989 from nicholascar/graph_docco
Documentation for 5.0.0
-rw-r--r--docs/_themes/armstrong/rtd-themes.conf65
-rw-r--r--docs/_themes/armstrong/theme-old.conf65
-rw-r--r--docs/_themes/armstrong/theme.conf48
-rw-r--r--docs/apidocs/examples.rst6
-rw-r--r--docs/apidocs/modules.rst4
-rw-r--r--docs/apidocs/rdflib.extras.rst62
-rw-r--r--docs/apidocs/rdflib.plugins.parsers.pyMicrodata.rst35
-rw-r--r--docs/apidocs/rdflib.plugins.parsers.pyRdfa.extras.rst19
-rw-r--r--docs/apidocs/rdflib.plugins.parsers.pyRdfa.host.rst27
-rw-r--r--docs/apidocs/rdflib.plugins.parsers.pyRdfa.rdfs.rst27
-rw-r--r--docs/apidocs/rdflib.plugins.parsers.pyRdfa.rst85
-rw-r--r--docs/apidocs/rdflib.plugins.parsers.pyRdfa.transform.rst51
-rw-r--r--docs/apidocs/rdflib.plugins.parsers.rst107
-rw-r--r--docs/apidocs/rdflib.plugins.rst55
-rw-r--r--docs/apidocs/rdflib.plugins.serializers.rst97
-rw-r--r--docs/apidocs/rdflib.plugins.sparql.results.rst85
-rw-r--r--docs/apidocs/rdflib.plugins.sparql.rst149
-rw-r--r--docs/apidocs/rdflib.plugins.stores.rst71
-rw-r--r--docs/apidocs/rdflib.rst191
-rw-r--r--docs/apidocs/rdflib.tools.rst75
-rw-r--r--docs/conf.py121
-rw-r--r--docs/faq.rst48
-rw-r--r--docs/gettingstarted.rst90
-rw-r--r--docs/index.rst96
-rw-r--r--docs/intro_to_creating_rdf.rst123
-rw-r--r--docs/intro_to_graphs.rst72
-rw-r--r--docs/intro_to_parsing.rst18
-rw-r--r--docs/univrdfstore.rst4
-rw-r--r--docs/upgrade2to3.rst60
-rw-r--r--docs/upgrade3to4.rst92
-rw-r--r--docs/upgrade4to5.rst24
-rw-r--r--examples/conjunctive_graphs.py46
-rw-r--r--examples/custom_datatype.py15
-rw-r--r--examples/custom_eval.py22
-rw-r--r--examples/film.py115
-rw-r--r--examples/foaf.n3284
-rw-r--r--examples/foaf.rdf346
-rw-r--r--examples/foafpaths.py12
-rw-r--r--examples/graph_digest_benchmark.py87
-rw-r--r--examples/prepared_query.py14
-rw-r--r--examples/rdfa_example.py14
-rw-r--r--examples/resource.py11
-rw-r--r--examples/simple_example.py19
-rw-r--r--examples/sleepycat_example.py31
-rw-r--r--examples/slice.py8
-rw-r--r--examples/smushing.py11
-rw-r--r--examples/sparql_query_example.py12
-rw-r--r--examples/sparql_update_example.py35
-rw-r--r--examples/sparqlstore_example.py22
-rw-r--r--examples/swap_primer.py68
-rw-r--r--examples/transitive.py20
-rw-r--r--rdflib/__init__.py15
-rw-r--r--rdflib/graph.py661
53 files changed, 1802 insertions, 2138 deletions
diff --git a/docs/_themes/armstrong/rtd-themes.conf b/docs/_themes/armstrong/rtd-themes.conf
deleted file mode 100644
index 5930488d..00000000
--- a/docs/_themes/armstrong/rtd-themes.conf
+++ /dev/null
@@ -1,65 +0,0 @@
-[theme]
-inherit = default
-stylesheet = rtd.css
-pygment_style = default
-show_sphinx = False
-
-[options]
-show_rtd = True
-
-white = #ffffff
-almost_white = #f8f8f8
-barely_white = #f2f2f2
-dirty_white = #eeeeee
-almost_dirty_white = #e6e6e6
-dirtier_white = #dddddd
-lighter_gray = #cccccc
-gray_a = #aaaaaa
-gray_9 = #999999
-light_gray = #888888
-gray_7 = #777777
-gray = #666666
-dark_gray = #444444
-gray_2 = #222222
-black = #111111
-light_color = #e8ecef
-light_medium_color = #DDEAF0
-medium_color = #8ca1af
-medium_color_link = #86989b
-medium_color_link_hover = #a6b8bb
-dark_color = #465158
-
-h1 = #000000
-h2 = #465158
-h3 = #6c818f
-
-link_color = #444444
-link_color_decoration = #CCCCCC
-
-medium_color_hover = #697983
-green_highlight = #8ecc4c
-
-
-positive_dark = #609060
-positive_medium = #70a070
-positive_light = #e9ffe9
-
-negative_dark = #900000
-negative_medium = #b04040
-negative_light = #ffe9e9
-negative_text = #c60f0f
-
-ruler = #abc
-
-viewcode_bg = #f4debf
-viewcode_border = #ac9
-
-highlight = #ffe080
-
-code_background = #eeeeee
-
-background = #465158
-background_link = #ffffff
-background_link_half = #ffffff
-background_text = #eeeeee
-background_text_link = #86989b
diff --git a/docs/_themes/armstrong/theme-old.conf b/docs/_themes/armstrong/theme-old.conf
new file mode 100644
index 00000000..c77da3a1
--- /dev/null
+++ b/docs/_themes/armstrong/theme-old.conf
@@ -0,0 +1,65 @@
+[theme]
+inherit = default
+stylesheet = rtd.css
+pygment_style = default
+show_sphinx = False
+
+[options]
+show_rtd = True
+
+white = #ffffff
+almost_white = #f8f8f8
+barely_white = #f2f2f2
+dirty_white = #eeeeee
+almost_dirty_white = #e6e6e6
+dirtier_white = #DAC6AF
+lighter_gray = #cccccc
+gray_a = #aaaaaa
+gray_9 = #999999
+light_gray = #888888
+gray_7 = #777777
+gray = #666666
+dark_gray = #444444
+gray_2 = #222222
+black = #111111
+light_color = #EDE4D8
+light_medium_color = #DDEAF0
+medium_color_link = #634320
+medium_color_link_hover = #261a0c
+dark_color = rgba(160, 109, 52, 1.0)
+
+h1 = #1f3744
+h2 = #335C72
+h3 = #638fa6
+
+link_color = #335C72
+link_color_decoration = #99AEB9
+
+medium_color_hover = rgba(255, 255, 255, 0.25)
+medium_color = rgba(255, 255, 255, 0.5)
+green_highlight = #8ecc4c
+
+
+positive_dark = rgba(51, 77, 0, 1.0)
+positive_medium = rgba(102, 153, 0, 1.0)
+positive_light = rgba(102, 153, 0, 0.1)
+
+negative_dark = rgba(51, 13, 0, 1.0)
+negative_medium = rgba(204, 51, 0, 1.0)
+negative_light = rgba(204, 51, 0, 0.1)
+negative_text = #c60f0f
+
+ruler = #abc
+
+viewcode_bg = #f4debf
+viewcode_border = #ac9
+
+highlight = #ffe080
+
+code_background = rgba(0, 0, 0, 0.075)
+
+background = rgba(135, 57, 34, 1.0)
+background_link = rgba(212, 195, 172, 1.0)
+background_link_half = rgba(212, 195, 172, 0.5)
+background_text = rgba(212, 195, 172, 1.0)
+background_text_link = rgba(171, 138, 93, 1.0)
diff --git a/docs/_themes/armstrong/theme.conf b/docs/_themes/armstrong/theme.conf
index c77da3a1..5930488d 100644
--- a/docs/_themes/armstrong/theme.conf
+++ b/docs/_themes/armstrong/theme.conf
@@ -12,7 +12,7 @@ almost_white = #f8f8f8
barely_white = #f2f2f2
dirty_white = #eeeeee
almost_dirty_white = #e6e6e6
-dirtier_white = #DAC6AF
+dirtier_white = #dddddd
lighter_gray = #cccccc
gray_a = #aaaaaa
gray_9 = #999999
@@ -22,31 +22,31 @@ gray = #666666
dark_gray = #444444
gray_2 = #222222
black = #111111
-light_color = #EDE4D8
+light_color = #e8ecef
light_medium_color = #DDEAF0
-medium_color_link = #634320
-medium_color_link_hover = #261a0c
-dark_color = rgba(160, 109, 52, 1.0)
+medium_color = #8ca1af
+medium_color_link = #86989b
+medium_color_link_hover = #a6b8bb
+dark_color = #465158
-h1 = #1f3744
-h2 = #335C72
-h3 = #638fa6
+h1 = #000000
+h2 = #465158
+h3 = #6c818f
-link_color = #335C72
-link_color_decoration = #99AEB9
+link_color = #444444
+link_color_decoration = #CCCCCC
-medium_color_hover = rgba(255, 255, 255, 0.25)
-medium_color = rgba(255, 255, 255, 0.5)
+medium_color_hover = #697983
green_highlight = #8ecc4c
-positive_dark = rgba(51, 77, 0, 1.0)
-positive_medium = rgba(102, 153, 0, 1.0)
-positive_light = rgba(102, 153, 0, 0.1)
+positive_dark = #609060
+positive_medium = #70a070
+positive_light = #e9ffe9
-negative_dark = rgba(51, 13, 0, 1.0)
-negative_medium = rgba(204, 51, 0, 1.0)
-negative_light = rgba(204, 51, 0, 0.1)
+negative_dark = #900000
+negative_medium = #b04040
+negative_light = #ffe9e9
negative_text = #c60f0f
ruler = #abc
@@ -56,10 +56,10 @@ viewcode_border = #ac9
highlight = #ffe080
-code_background = rgba(0, 0, 0, 0.075)
+code_background = #eeeeee
-background = rgba(135, 57, 34, 1.0)
-background_link = rgba(212, 195, 172, 1.0)
-background_link_half = rgba(212, 195, 172, 0.5)
-background_text = rgba(212, 195, 172, 1.0)
-background_text_link = rgba(171, 138, 93, 1.0)
+background = #465158
+background_link = #ffffff
+background_link_half = #ffffff
+background_text = #eeeeee
+background_text_link = #86989b
diff --git a/docs/apidocs/examples.rst b/docs/apidocs/examples.rst
index 01a9d809..d099838f 100644
--- a/docs/apidocs/examples.rst
+++ b/docs/apidocs/examples.rst
@@ -60,7 +60,7 @@ These examples all live in ``./examples`` in the source-distribution of RDFLib.
:show-inheritance:
:mod:`rdfa_example` Module
-----------------------
+--------------------------
.. automodule:: examples.rdfa_example
:members:
@@ -76,7 +76,7 @@ These examples all live in ``./examples`` in the source-distribution of RDFLib.
:show-inheritance:
:mod:`sleepycat_example` Module
------------------------------------
+--------------------------------
.. automodule:: examples.sleepycat_example
:members:
@@ -92,7 +92,7 @@ These examples all live in ``./examples`` in the source-distribution of RDFLib.
:show-inheritance:
:mod:`smushing` Module
--------------------
+----------------------
.. automodule:: examples.smushing
:members:
diff --git a/docs/apidocs/modules.rst b/docs/apidocs/modules.rst
index 6db120d1..0b1fa9e2 100644
--- a/docs/apidocs/modules.rst
+++ b/docs/apidocs/modules.rst
@@ -1,5 +1,5 @@
-rdflib API docs
-===============
+rdflib
+======
.. toctree::
:maxdepth: 10
diff --git a/docs/apidocs/rdflib.extras.rst b/docs/apidocs/rdflib.extras.rst
index 3da6f545..7cd472bb 100644
--- a/docs/apidocs/rdflib.extras.rst
+++ b/docs/apidocs/rdflib.extras.rst
@@ -1,36 +1,46 @@
-extras Package
-==============
+rdflib.extras package
+=====================
-:mod:`extras` Package
----------------------
+Submodules
+----------
-.. automodule:: rdflib.extras
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`cmdlineutils` Module
---------------------------
+rdflib.extras.cmdlineutils module
+---------------------------------
.. automodule:: rdflib.extras.cmdlineutils
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`describer` Module
------------------------
+rdflib.extras.describer module
+------------------------------
.. automodule:: rdflib.extras.describer
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
+
+rdflib.extras.external\_graph\_libs module
+------------------------------------------
+
+.. automodule:: rdflib.extras.external_graph_libs
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`infixowl` Module
-----------------------
+rdflib.extras.infixowl module
+-----------------------------
.. automodule:: rdflib.extras.infixowl
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
+
+
+Module contents
+---------------
+
+.. automodule:: rdflib.extras
+ :members:
+ :undoc-members:
+ :show-inheritance:
diff --git a/docs/apidocs/rdflib.plugins.parsers.pyMicrodata.rst b/docs/apidocs/rdflib.plugins.parsers.pyMicrodata.rst
deleted file mode 100644
index 1c0f6734..00000000
--- a/docs/apidocs/rdflib.plugins.parsers.pyMicrodata.rst
+++ /dev/null
@@ -1,35 +0,0 @@
-pyMicrodata Package
-===================
-
-:mod:`pyMicrodata` Package
---------------------------
-
-.. automodule:: rdflib.plugins.parsers.pyMicrodata
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`microdata` Module
------------------------
-
-.. automodule:: rdflib.plugins.parsers.pyMicrodata.microdata
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`registry` Module
-----------------------
-
-.. automodule:: rdflib.plugins.parsers.pyMicrodata.registry
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`utils` Module
--------------------
-
-.. automodule:: rdflib.plugins.parsers.pyMicrodata.utils
- :members:
- :undoc-members:
- :show-inheritance:
-
diff --git a/docs/apidocs/rdflib.plugins.parsers.pyRdfa.extras.rst b/docs/apidocs/rdflib.plugins.parsers.pyRdfa.extras.rst
deleted file mode 100644
index 337a1f73..00000000
--- a/docs/apidocs/rdflib.plugins.parsers.pyRdfa.extras.rst
+++ /dev/null
@@ -1,19 +0,0 @@
-extras Package
-==============
-
-:mod:`extras` Package
----------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.extras
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`httpheader` Module
-------------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.extras.httpheader
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
diff --git a/docs/apidocs/rdflib.plugins.parsers.pyRdfa.host.rst b/docs/apidocs/rdflib.plugins.parsers.pyRdfa.host.rst
deleted file mode 100644
index e0df6f06..00000000
--- a/docs/apidocs/rdflib.plugins.parsers.pyRdfa.host.rst
+++ /dev/null
@@ -1,27 +0,0 @@
-host Package
-============
-
-:mod:`host` Package
--------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.host
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`atom` Module
-------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.host.atom
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`html5` Module
--------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.host.html5
- :members:
- :undoc-members:
- :show-inheritance:
-
diff --git a/docs/apidocs/rdflib.plugins.parsers.pyRdfa.rdfs.rst b/docs/apidocs/rdflib.plugins.parsers.pyRdfa.rdfs.rst
deleted file mode 100644
index 98915eb3..00000000
--- a/docs/apidocs/rdflib.plugins.parsers.pyRdfa.rdfs.rst
+++ /dev/null
@@ -1,27 +0,0 @@
-rdfs Package
-============
-
-:mod:`rdfs` Package
--------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.rdfs
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`cache` Module
--------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.rdfs.cache
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`process` Module
----------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.rdfs.process
- :members:
- :undoc-members:
- :show-inheritance:
-
diff --git a/docs/apidocs/rdflib.plugins.parsers.pyRdfa.rst b/docs/apidocs/rdflib.plugins.parsers.pyRdfa.rst
deleted file mode 100644
index 8563debd..00000000
--- a/docs/apidocs/rdflib.plugins.parsers.pyRdfa.rst
+++ /dev/null
@@ -1,85 +0,0 @@
-pyRdfa Package
-==============
-
-:mod:`pyRdfa` Package
----------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`embeddedRDF` Module
--------------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.embeddedRDF
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`initialcontext` Module
-----------------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.initialcontext
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`options` Module
----------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.options
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`parse` Module
--------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.parse
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`property` Module
-----------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.property
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`state` Module
--------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.state
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`termorcurie` Module
--------------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.termorcurie
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`utils` Module
--------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.utils
- :members:
- :undoc-members:
- :show-inheritance:
-
-Subpackages
------------
-
-.. toctree::
-
- rdflib.plugins.parsers.pyRdfa.extras
- rdflib.plugins.parsers.pyRdfa.host
- rdflib.plugins.parsers.pyRdfa.rdfs
- rdflib.plugins.parsers.pyRdfa.transform
-
diff --git a/docs/apidocs/rdflib.plugins.parsers.pyRdfa.transform.rst b/docs/apidocs/rdflib.plugins.parsers.pyRdfa.transform.rst
deleted file mode 100644
index 7f7a357b..00000000
--- a/docs/apidocs/rdflib.plugins.parsers.pyRdfa.transform.rst
+++ /dev/null
@@ -1,51 +0,0 @@
-transform Package
-=================
-
-:mod:`transform` Package
-------------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.transform
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`DublinCore` Module
-------------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.transform.DublinCore
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`OpenID` Module
---------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.transform.OpenID
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`lite` Module
-------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.transform.lite
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`metaname` Module
-----------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.transform.metaname
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`prototype` Module
------------------------
-
-.. automodule:: rdflib.plugins.parsers.pyRdfa.transform.prototype
- :members:
- :undoc-members:
- :show-inheritance:
-
diff --git a/docs/apidocs/rdflib.plugins.parsers.rst b/docs/apidocs/rdflib.plugins.parsers.rst
index 9428ad47..e3ba5ff3 100644
--- a/docs/apidocs/rdflib.plugins.parsers.rst
+++ b/docs/apidocs/rdflib.plugins.parsers.rst
@@ -1,85 +1,70 @@
-parsers Package
-===============
+rdflib.plugins.parsers package
+==============================
-:mod:`parsers` Package
-----------------------
+Submodules
+----------
-.. automodule:: rdflib.plugins.parsers
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`hturtle` Module
----------------------
-
-.. automodule:: rdflib.plugins.parsers.hturtle
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`notation3` Module
------------------------
+rdflib.plugins.parsers.notation3 module
+---------------------------------------
.. automodule:: rdflib.plugins.parsers.notation3
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`nquads` Module
---------------------
+rdflib.plugins.parsers.nquads module
+------------------------------------
.. automodule:: rdflib.plugins.parsers.nquads
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`nt` Module
-----------------
+rdflib.plugins.parsers.nt module
+--------------------------------
.. automodule:: rdflib.plugins.parsers.nt
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`ntriples` Module
-----------------------
+rdflib.plugins.parsers.ntriples module
+--------------------------------------
.. automodule:: rdflib.plugins.parsers.ntriples
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`rdfxml` Module
---------------------
+rdflib.plugins.parsers.rdfxml module
+------------------------------------
.. automodule:: rdflib.plugins.parsers.rdfxml
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`structureddata` Module
-----------------------------
+rdflib.plugins.parsers.trig module
+----------------------------------
-.. automodule:: rdflib.plugins.parsers.structureddata
- :members:
- :undoc-members:
- :show-inheritance:
+.. automodule:: rdflib.plugins.parsers.trig
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`trix` Module
-------------------
+rdflib.plugins.parsers.trix module
+----------------------------------
.. automodule:: rdflib.plugins.parsers.trix
- :members:
- :undoc-members:
- :show-inheritance:
-
-Subpackages
------------
+ :members:
+ :undoc-members:
+ :show-inheritance:
-.. toctree::
- rdflib.plugins.parsers.pyMicrodata
- rdflib.plugins.parsers.pyRdfa
+Module contents
+---------------
+.. automodule:: rdflib.plugins.parsers
+ :members:
+ :undoc-members:
+ :show-inheritance:
diff --git a/docs/apidocs/rdflib.plugins.rst b/docs/apidocs/rdflib.plugins.rst
index 6d45026f..aa93c1bd 100644
--- a/docs/apidocs/rdflib.plugins.rst
+++ b/docs/apidocs/rdflib.plugins.rst
@@ -1,37 +1,40 @@
-plugins Package
-===============
+rdflib.plugins package
+======================
-:mod:`plugins` Package
-----------------------
+Subpackages
+-----------
-.. automodule:: rdflib.plugins
- :members:
- :undoc-members:
- :show-inheritance:
+.. toctree::
+
+ rdflib.plugins.parsers
+ rdflib.plugins.serializers
+ rdflib.plugins.sparql
+ rdflib.plugins.stores
+
+Submodules
+----------
-:mod:`memory` Module
---------------------
+rdflib.plugins.memory module
+----------------------------
.. automodule:: rdflib.plugins.memory
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`sleepycat` Module
------------------------
+rdflib.plugins.sleepycat module
+-------------------------------
.. automodule:: rdflib.plugins.sleepycat
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-Subpackages
------------
-.. toctree::
-
- rdflib.plugins.parsers
- rdflib.plugins.serializers
- rdflib.plugins.sparql
- rdflib.plugins.stores
+Module contents
+---------------
+.. automodule:: rdflib.plugins
+ :members:
+ :undoc-members:
+ :show-inheritance:
diff --git a/docs/apidocs/rdflib.plugins.serializers.rst b/docs/apidocs/rdflib.plugins.serializers.rst
index c89309dd..c5ce952c 100644
--- a/docs/apidocs/rdflib.plugins.serializers.rst
+++ b/docs/apidocs/rdflib.plugins.serializers.rst
@@ -1,67 +1,78 @@
-serializers Package
-===================
+rdflib.plugins.serializers package
+==================================
-:mod:`n3` Module
-----------------
+Submodules
+----------
+
+rdflib.plugins.serializers.n3 module
+------------------------------------
.. automodule:: rdflib.plugins.serializers.n3
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`nquads` Module
---------------------
+rdflib.plugins.serializers.nquads module
+----------------------------------------
.. automodule:: rdflib.plugins.serializers.nquads
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`nt` Module
-----------------
+rdflib.plugins.serializers.nt module
+------------------------------------
.. automodule:: rdflib.plugins.serializers.nt
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`rdfxml` Module
---------------------
+rdflib.plugins.serializers.rdfxml module
+----------------------------------------
.. automodule:: rdflib.plugins.serializers.rdfxml
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`trig` Module
-------------------
+rdflib.plugins.serializers.trig module
+--------------------------------------
.. automodule:: rdflib.plugins.serializers.trig
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`trix` Module
-------------------
+rdflib.plugins.serializers.trix module
+--------------------------------------
.. automodule:: rdflib.plugins.serializers.trix
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`turtle` Module
---------------------
+rdflib.plugins.serializers.turtle module
+----------------------------------------
.. automodule:: rdflib.plugins.serializers.turtle
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`xmlwriter` Module
------------------------
+rdflib.plugins.serializers.xmlwriter module
+-------------------------------------------
.. automodule:: rdflib.plugins.serializers.xmlwriter
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
+
+
+Module contents
+---------------
+
+.. automodule:: rdflib.plugins.serializers
+ :members:
+ :undoc-members:
+ :show-inheritance:
diff --git a/docs/apidocs/rdflib.plugins.sparql.results.rst b/docs/apidocs/rdflib.plugins.sparql.results.rst
index 41d632ff..b9ff9310 100644
--- a/docs/apidocs/rdflib.plugins.sparql.results.rst
+++ b/docs/apidocs/rdflib.plugins.sparql.results.rst
@@ -1,51 +1,70 @@
-results Package
-===============
+rdflib.plugins.sparql.results package
+=====================================
-:mod:`csvresults` Module
-------------------------
+Submodules
+----------
+
+rdflib.plugins.sparql.results.csvresults module
+-----------------------------------------------
.. automodule:: rdflib.plugins.sparql.results.csvresults
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`jsonlayer` Module
------------------------
+rdflib.plugins.sparql.results.graph module
+------------------------------------------
-.. automodule:: rdflib.plugins.sparql.results.jsonlayer
- :members:
- :undoc-members:
- :show-inheritance:
+.. automodule:: rdflib.plugins.sparql.results.graph
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`jsonresults` Module
--------------------------
+rdflib.plugins.sparql.results.jsonresults module
+------------------------------------------------
.. automodule:: rdflib.plugins.sparql.results.jsonresults
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`rdfresults` Module
-------------------------
+rdflib.plugins.sparql.results.rdfresults module
+-----------------------------------------------
.. automodule:: rdflib.plugins.sparql.results.rdfresults
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`tsvresults` Module
-------------------------
+rdflib.plugins.sparql.results.tsvresults module
+-----------------------------------------------
.. automodule:: rdflib.plugins.sparql.results.tsvresults
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
+
+rdflib.plugins.sparql.results.txtresults module
+-----------------------------------------------
+
+.. automodule:: rdflib.plugins.sparql.results.txtresults
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`xmlresults` Module
-------------------------
+rdflib.plugins.sparql.results.xmlresults module
+-----------------------------------------------
.. automodule:: rdflib.plugins.sparql.results.xmlresults
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
+
+
+Module contents
+---------------
+.. automodule:: rdflib.plugins.sparql.results
+ :members:
+ :undoc-members:
+ :show-inheritance:
diff --git a/docs/apidocs/rdflib.plugins.sparql.rst b/docs/apidocs/rdflib.plugins.sparql.rst
index 0985fd41..768f4a1d 100644
--- a/docs/apidocs/rdflib.plugins.sparql.rst
+++ b/docs/apidocs/rdflib.plugins.sparql.rst
@@ -1,116 +1,109 @@
-sparql Package
-==============
+rdflib.plugins.sparql package
+=============================
-:mod:`sparql` Package
----------------------
+Subpackages
+-----------
-.. automodule:: rdflib.plugins.sparql
- :members:
- :undoc-members:
- :show-inheritance:
+.. toctree::
-:mod:`aggregates` Module
-------------------------
+ rdflib.plugins.sparql.results
-.. automodule:: rdflib.plugins.sparql.aggregates
- :members:
- :undoc-members:
- :show-inheritance:
+Submodules
+----------
-:mod:`algebra` Module
----------------------
+rdflib.plugins.sparql.aggregates module
+---------------------------------------
-.. automodule:: rdflib.plugins.sparql.algebra
- :members:
- :undoc-members:
- :show-inheritance:
+.. automodule:: rdflib.plugins.sparql.aggregates
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`compat` Module
---------------------
+rdflib.plugins.sparql.algebra module
+------------------------------------
-.. automodule:: rdflib.plugins.sparql.compat
- :members:
- :undoc-members:
- :show-inheritance:
+.. automodule:: rdflib.plugins.sparql.algebra
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`datatypes` Module
------------------------
+rdflib.plugins.sparql.datatypes module
+--------------------------------------
.. automodule:: rdflib.plugins.sparql.datatypes
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`evaluate` Module
-----------------------
+rdflib.plugins.sparql.evaluate module
+-------------------------------------
.. automodule:: rdflib.plugins.sparql.evaluate
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`evalutils` Module
------------------------
+rdflib.plugins.sparql.evalutils module
+--------------------------------------
.. automodule:: rdflib.plugins.sparql.evalutils
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`operators` Module
------------------------
+rdflib.plugins.sparql.operators module
+--------------------------------------
.. automodule:: rdflib.plugins.sparql.operators
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`parser` Module
---------------------
+rdflib.plugins.sparql.parser module
+-----------------------------------
.. automodule:: rdflib.plugins.sparql.parser
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`parserutils` Module
--------------------------
+rdflib.plugins.sparql.parserutils module
+----------------------------------------
.. automodule:: rdflib.plugins.sparql.parserutils
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`processor` Module
------------------------
+rdflib.plugins.sparql.processor module
+--------------------------------------
.. automodule:: rdflib.plugins.sparql.processor
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`sparql` Module
---------------------
+rdflib.plugins.sparql.sparql module
+-----------------------------------
.. automodule:: rdflib.plugins.sparql.sparql
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`update` Module
---------------------
+rdflib.plugins.sparql.update module
+-----------------------------------
.. automodule:: rdflib.plugins.sparql.update
- :members:
- :undoc-members:
- :show-inheritance:
-
-Subpackages
------------
+ :members:
+ :undoc-members:
+ :show-inheritance:
-.. toctree::
- rdflib.plugins.sparql.results
+Module contents
+---------------
+.. automodule:: rdflib.plugins.sparql
+ :members:
+ :undoc-members:
+ :show-inheritance:
diff --git a/docs/apidocs/rdflib.plugins.stores.rst b/docs/apidocs/rdflib.plugins.stores.rst
index 89f4506a..7367f47b 100644
--- a/docs/apidocs/rdflib.plugins.stores.rst
+++ b/docs/apidocs/rdflib.plugins.stores.rst
@@ -1,45 +1,54 @@
-stores Package
-==============
+rdflib.plugins.stores package
+=============================
-:mod:`stores` Package
----------------------
+Submodules
+----------
-.. automodule:: rdflib.plugins.stores
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`auditable` Module
------------------------
+rdflib.plugins.stores.auditable module
+--------------------------------------
.. automodule:: rdflib.plugins.stores.auditable
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`concurrent` Module
-------------------------
+rdflib.plugins.stores.concurrent module
+---------------------------------------
.. automodule:: rdflib.plugins.stores.concurrent
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`regexmatching` Module
----------------------------
+rdflib.plugins.stores.regexmatching module
+------------------------------------------
.. automodule:: rdflib.plugins.stores.regexmatching
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
+
+rdflib.plugins.stores.sparqlconnector module
+--------------------------------------------
+
+.. automodule:: rdflib.plugins.stores.sparqlconnector
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`sparqlstore` Module
--------------------------
+rdflib.plugins.stores.sparqlstore module
+----------------------------------------
.. automodule:: rdflib.plugins.stores.sparqlstore
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
+
+Module contents
+---------------
+
+.. automodule:: rdflib.plugins.stores
+ :members:
+ :undoc-members:
+ :show-inheritance:
diff --git a/docs/apidocs/rdflib.rst b/docs/apidocs/rdflib.rst
index f279cb03..99fa6132 100644
--- a/docs/apidocs/rdflib.rst
+++ b/docs/apidocs/rdflib.rst
@@ -1,180 +1,159 @@
-rdflib Package
+rdflib package
==============
-:mod:`rdflib` Package
----------------------
+Subpackages
+-----------
+
+.. toctree::
+
+ rdflib.extras
+ rdflib.plugins
+ rdflib.tools
-.. automodule:: rdflib.__init__
- :members: NORMALIZE_LITERALS, DAWG_LITERAL_COLLATION
- :show-inheritance:
+Submodules
+----------
-:mod:`collection` Module
+rdflib.collection module
------------------------
.. automodule:: rdflib.collection
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`compare` Module
+rdflib.compare module
---------------------
.. automodule:: rdflib.compare
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`compat` Module
+rdflib.compat module
--------------------
.. automodule:: rdflib.compat
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`events` Module
+rdflib.events module
--------------------
.. automodule:: rdflib.events
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`exceptions` Module
+rdflib.exceptions module
------------------------
.. automodule:: rdflib.exceptions
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`graph` Module
+rdflib.graph module
-------------------
.. automodule:: rdflib.graph
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`namespace` Module
+rdflib.namespace module
-----------------------
.. automodule:: rdflib.namespace
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`parser` Module
+rdflib.parser module
--------------------
.. automodule:: rdflib.parser
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`paths` Module
+rdflib.paths module
-------------------
.. automodule:: rdflib.paths
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`plugin` Module
+rdflib.plugin module
--------------------
.. automodule:: rdflib.plugin
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
-
-:mod:`py3compat` Module
------------------------
+ :members:
+ :undoc-members:
+ :show-inheritance:
-.. automodule:: rdflib.py3compat
- :members:
- :undoc-members:
- :show-inheritance:
-
-:mod:`query` Module
+rdflib.query module
-------------------
.. automodule:: rdflib.query
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
-
- .. autoclass:: ResultRow
- :members:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-
-:mod:`resource` Module
+rdflib.resource module
----------------------
.. automodule:: rdflib.resource
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`serializer` Module
+rdflib.serializer module
------------------------
.. automodule:: rdflib.serializer
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`store` Module
+rdflib.store module
-------------------
.. automodule:: rdflib.store
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`term` Module
+rdflib.term module
------------------
.. automodule:: rdflib.term
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
-
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`util` Module
+rdflib.util module
------------------
.. automodule:: rdflib.util
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`void` Module
+rdflib.void module
------------------
.. automodule:: rdflib.void
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-Subpackages
------------
-
-.. toctree::
- rdflib.extras
- rdflib.plugins
- rdflib.tools
+Module contents
+---------------
+.. automodule:: rdflib
+ :members:
+ :undoc-members:
+ :show-inheritance:
diff --git a/docs/apidocs/rdflib.tools.rst b/docs/apidocs/rdflib.tools.rst
index 856991cc..eaf8edf8 100644
--- a/docs/apidocs/rdflib.tools.rst
+++ b/docs/apidocs/rdflib.tools.rst
@@ -1,55 +1,54 @@
-tools Package
-=============
+rdflib.tools package
+====================
-These commandline-tools are installed into :samp:`{INSTALL_PREFIX}/bin` by setuptools.
+Submodules
+----------
-:mod:`tools` Package
----------------------
-
-.. automodule:: rdflib.tools
- :members:
- :undoc-members:
- :show-inheritance:
-
-
-:mod:`csv2rdf` Module
----------------------
+rdflib.tools.csv2rdf module
+---------------------------
.. automodule:: rdflib.tools.csv2rdf
- :members:
- :undoc-members:
- :show-inheritance:
- :exclude-members: __dict__,__weakref__
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`graphisomorphism` Module
-------------------------------
+rdflib.tools.graphisomorphism module
+------------------------------------
.. automodule:: rdflib.tools.graphisomorphism
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`rdf2dot` Module
----------------------
+rdflib.tools.rdf2dot module
+---------------------------
.. automodule:: rdflib.tools.rdf2dot
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`rdfpipe` Module
----------------------
+rdflib.tools.rdfpipe module
+---------------------------
.. automodule:: rdflib.tools.rdfpipe
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
-:mod:`rdfs2dot` Module
-----------------------
+rdflib.tools.rdfs2dot module
+----------------------------
.. automodule:: rdflib.tools.rdfs2dot
- :members:
- :undoc-members:
- :show-inheritance:
+ :members:
+ :undoc-members:
+ :show-inheritance:
+
+Module contents
+---------------
+
+.. automodule:: rdflib.tools
+ :members:
+ :undoc-members:
+ :show-inheritance:
diff --git a/docs/conf.py b/docs/conf.py
index 814e1f54..7f60b62a 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -11,47 +11,56 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
-import sys, os, re
+import sys
+import os
+import re
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
-#sys.path.append(os.path.abspath('.'))
+# sys.path.append(os.path.abspath(".."))
+sys.path.append(os.path.abspath(".."))
# -- General configuration -----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
# extensions = ['sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.doctest']
-extensions = ['sphinx.ext.autodoc', #'sphinx.ext.autosummary',
- 'sphinx.ext.doctest', 'sphinx.ext.intersphinx',
- 'sphinx.ext.todo', 'sphinx.ext.coverage',
- 'sphinx.ext.ifconfig', 'sphinx.ext.viewcode']
+extensions = [
+ "sphinx.ext.autodoc",
+ #'sphinx.ext.autosummary',
+ "sphinx.ext.doctest",
+ "sphinx.ext.intersphinx",
+ "sphinx.ext.todo",
+ "sphinx.ext.coverage",
+ "sphinx.ext.ifconfig",
+ "sphinx.ext.viewcode",
+]
-autodoc_default_flags = [ "special-members" ]
+autodoc_default_flags = ["special-members"]
autosummary_generate = True
# Add any paths that contain templates here, relative to this directory.
-templates_path = ['_templates']
+templates_path = ["_templates"]
-#epydoc_mapping = {
+# epydoc_mapping = {
# '/_static/api/': [r'rdflib\.'],
# }
# The suffix of source filenames.
-source_suffix = '.rst'
+source_suffix = ".rst"
# The encoding of source files.
-source_encoding = 'utf-8'
+source_encoding = "utf-8"
# The master toctree document.
-master_doc = 'index'
+master_doc = "index"
# General information about the project.
-project = u'rdflib'
-copyright = u'2009 - 2013, RDFLib Team'
+project = u"rdflib"
+copyright = u"2009 - 2013, RDFLib Team"
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
@@ -66,30 +75,31 @@ def find_version(filename):
if version_match:
return version_match.group(1)
+
# The full version, including alpha/beta/rc tags.
-release = find_version('../rdflib/__init__.py')
+release = find_version("../rdflib/__init__.py")
# The short X.Y version.
version = re.sub("[0-9]+\\.[0-9]\\..*", "\1", release)
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
-#language = None
+# language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
-#today = ''
+# today = ''
# Else, today_fmt is used as the format for a strftime call.
-#today_fmt = '%B %d, %Y'
+# today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
-#unused_docs = []
+# unused_docs = []
# List of directories, relative to source directory, that shouldn't be searched
# for source files.
-exclude_trees = ['_build', 'draft']
+exclude_trees = ["_build", "draft"]
# The reST default role (used for this markup: `text`) to use for all documents.
-#default_role = None
+# default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
add_function_parentheses = True
@@ -100,125 +110,128 @@ add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
-#show_authors = False
+# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
-pygments_style = 'sphinx'
+pygments_style = "sphinx"
# A list of ignored prefixes for module index sorting.
-#modindex_common_prefix = []
+# modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
-html_theme = 'armstrong'
+html_theme = "armstrong"
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
-#html_theme_options = {}
+# html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
-html_theme_path = ["_themes", ]
+html_theme_path = [
+ "_themes",
+]
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
-#html_title = None
+# html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
-#html_short_title = None
+# html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
-#html_logo = None
-html_logo = '_static/logo.svg'
+# html_logo = None
+html_logo = "_static/rdflib.png"
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
-#html_favicon = None
+html_favicon = "_static/rdflib.ico"
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
-html_static_path = ['_static']
+html_static_path = ["_static"]
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
-#html_last_updated_fmt = '%b %d, %Y'
+# html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
-#html_use_smartypants = True
+# html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
-#html_sidebars = {}
+# html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
-#html_additional_pages = {}
+# html_additional_pages = {}
# If false, no module index is generated.
-#html_use_modindex = True
+# html_use_modindex = True
# If false, no index is generated.
-#html_use_index = True
+# html_use_index = True
# If true, the index is split into individual pages for each letter.
-#html_split_index = False
+# html_split_index = False
# If true, links to the reST sources are added to the pages.
-#html_show_sourcelink = True
+# html_show_sourcelink = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
-#html_use_opensearch = ''
+# html_use_opensearch = ''
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
-#html_file_suffix = ''
+# html_file_suffix = ''
# Output file base name for HTML help builder.
-htmlhelp_basename = 'rdflibdoc'
+htmlhelp_basename = "rdflibdoc"
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
-#latex_paper_size = 'letter'
+# latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
-#latex_font_size = '10pt'
+# latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
- ('index', 'rdflib.tex', u'rdflib Documentation',
- u'RDFLib Team', 'manual'),
+ ("index", "rdflib.tex", u"rdflib Documentation", u"RDFLib Team", "manual"),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
-#latex_logo = None
+# latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
-#latex_use_parts = False
+# latex_use_parts = False
# Additional stuff for the LaTeX preamble.
-#latex_preamble = ''
+# latex_preamble = ''
# Documents to append as an appendix to all manuals.
-#latex_appendices = []
+# latex_appendices = []
# If false, no module index is generated.
-#latex_use_modindex = True
+# latex_use_modindex = True
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
- 'python': ('http://docs.python.org/2.7', None),
+ "python": ("http://docs.python.org/3.7", None),
}
+
+html_experimental_html5_writer = True
diff --git a/docs/faq.rst b/docs/faq.rst
deleted file mode 100644
index 0bf2b9e3..00000000
--- a/docs/faq.rst
+++ /dev/null
@@ -1,48 +0,0 @@
-=============================================
-Frequently Asked Questions about using RDFLib
-=============================================
-
-Questions about parsing
-=======================
-
-Questions about manipulating
-============================
-
-Questions about serializing
-===========================
-
-Which serialization method is the most efficient?
-=================================================
-
-Currently, the "nt" output format uses the most efficient
-serialization; "rdf/xml" should also be efficient. You can
-serialize to these formats using code similar to the following::
-
- myGraph.serialize(target_nt, format="nt")
- myGraph.serialize(target_rdfxml, format="xml")
-
-How can I use some of the abbreviated RDF/XML syntax?
-=====================================================
-
-Use the "pretty-xml" `format` argument to the `serialize` method::
-
- myGraph.serialize(target_pretty, format="pretty-xml")
-
-How can I control the binding of prefixes to XML namespaces when using RDF/XML?
-===============================================================================
-
-Each graph comes with a `NamespaceManager`__ instance in the `namespace_manager` field; you can use the `bind` method of this instance to bind a prefix to a namespace URI::
-
-
- myGraph.namespace_manager.bind('prefix', URIRef('scheme:my-namespace-uri:'))
-
-__ http://rdflib.net/rdflib-2.4.0/html/public/rdflib.syntax.NamespaceManager.NamespaceManager-class.html
-
-Does RDFLib support serialization to the `TriX`__ format?
-=========================================================
-
-Yes, both parsing and serialising is supported::
-
- graph.serialize(format="trix") and graph.load(source, format="trix")
-
-__ http://www.w3.org/2004/03/trix/
diff --git a/docs/gettingstarted.rst b/docs/gettingstarted.rst
index 41d54cc1..a3637210 100644
--- a/docs/gettingstarted.rst
+++ b/docs/gettingstarted.rst
@@ -17,16 +17,27 @@ The best way to install RDFLib is to use ``pip`` (sudo as required):
$ pip install rdflib
-Support is available through the rdflib-dev group:
+If you want the latest code to run, clone the master branch of the GitHub repo and use that.
+
+Support
+=======
+Usage support is available via questions tagged with ``[rdflib]`` on `StackOverflow <https://stackoverflow.com/questions/tagged/rdflib>`__
+and development support, notifications and detailed discussion through the rdflib-dev group (mailing list):
http://groups.google.com/group/rdflib-dev
-and on the IRC channel `#rdflib <irc://irc.freenode.net/swig>`_ on the freenode.net server
+If you notice an bug or want to request an enhancement, please do so via our Issue Tracker in Github:
-The primary interface that RDFLib exposes for working with RDF is a
-:class:`~rdflib.graph.Graph`. The package uses various Python idioms
+ `<http://github.com/RDFLib/rdflib/issues>`_
+
+How it all works
+================
+*The package uses various Python idioms
that offer an appropriate way to introduce RDF to a Python programmer
-who hasn't worked with RDF before.
+who hasn't worked with RDF before.*
+
+The primary interface that RDFLib exposes for working with RDF is a
+:class:`~rdflib.graph.Graph`.
RDFLib graphs are not sorted containers; they have ordinary ``set``
operations (e.g. :meth:`~rdflib.Graph.add` to add a triple) plus
@@ -35,12 +46,12 @@ methods that search triples and return them in arbitrary order.
RDFLib graphs also redefine certain built-in Python methods in order
to behave in a predictable way; they `emulate container types
<http://docs.python.org/release/2.5.2/ref/sequence-types.html>`_ and
-are best thought of as a set of 3-item triples:
+are best thought of as a set of 3-item tuples ("triples", in RDF-speak):
.. code-block:: text
[
- (subject, predicate, object),
+ (subject0, predicate0, object0),
(subject1, predicate1, object1),
...
(subjectN, predicateN, objectN)
@@ -52,52 +63,77 @@ A tiny usage example:
import rdflib
+ # create a Graph
g = rdflib.Graph()
- result = g.parse("http://www.w3.org/People/Berners-Lee/card")
- print("graph has %s statements." % len(g))
- # prints graph has 79 statements.
+ # parse in an RDF file hosted on the Internet
+ result = g.parse("http://www.w3.org/People/Berners-Lee/card")
+ # loop through each triple in the graph (subj, pred, obj)
for subj, pred, obj in g:
- if (subj, pred, obj) not in g:
+ # check if there is at least one triple in the Graph
+ if (subj, pred, obj) not in g:
raise Exception("It better be!")
- s = g.serialize(format='n3')
+ # print the number of "triples" in the Graph
+ print("graph has {} statements.".format(len(g)))
+ # prints graph has 86 statements.
-A more extensive example:
+ # print out the entire Graph in the RDF Turtle format
+ print(g.serialize(format="turtle").decode("utf-8"))
+
+Here a :class:`~rdflib.graph.Graph` is created and then an RDF file online, Tim Berners-Lee's social network details, is
+parsed into that graph. The ``print()`` statement uses the ``len()`` function to count the number of triples in the
+graph.
+A more extensive example:
.. code-block:: python
- from rdflib import Graph, Literal, BNode, Namespace, RDF, URIRef
- from rdflib.namespace import DC, FOAF
+ from rdflib import Graph, Literal, RDF, URIRef
+ # rdflib knows about some namespaces, like FOAF
+ from rdflib.namespace import FOAF , XSD
+ # create a Graph
g = Graph()
- # Create an identifier to use as the subject for Donna.
- donna = BNode()
+ # Create an RDF URI node to use as the subject for multiple triples
+ donna = URIRef("http://example.org/donna")
+
+ # Add triples using store's add() method.
+ g.add((donna, RDF.type, FOAF.Person))
+ g.add((donna, FOAF.nick, Literal("donna", lang="ed")))
+ g.add((donna, FOAF.name, Literal("Donna Fales")))
+ g.add((donna, FOAF.mbox, URIRef("mailto:donna@example.org")))
- # Add triples using store's add method.
- g.add( (donna, RDF.type, FOAF.Person) )
- g.add( (donna, FOAF.nick, Literal("donna", lang="foo")) )
- g.add( (donna, FOAF.name, Literal("Donna Fales")) )
- g.add( (donna, FOAF.mbox, URIRef("mailto:donna@example.org")) )
+ # Add another person
+ ed = URIRef("http://example.org/edward")
+
+ # Add triples using store's add() method.
+ g.add((ed, RDF.type, FOAF.Person))
+ g.add((ed, FOAF.nick, Literal("ed", datatype=XSD.string)))
+ g.add((ed, FOAF.name, Literal("Edward Scissorhands")))
+ g.add((ed, FOAF.mbox, URIRef("mailto:e.scissorhands@example.org")))
# Iterate over triples in store and print them out.
print("--- printing raw triples ---")
for s, p, o in g:
print((s, p, o))
- # For each foaf:Person in the store print out its mbox property.
+ # For each foaf:Person in the store, print out their mbox property's value.
print("--- printing mboxes ---")
for person in g.subjects(RDF.type, FOAF.Person):
for mbox in g.objects(person, FOAF.mbox):
print(mbox)
- # Bind a few prefix, namespace pairs for more readable output
- g.bind("dc", DC)
+ # Bind the FOAF namespace to a prefix for more readable output
g.bind("foaf", FOAF)
- print( g.serialize(format='n3') )
+ # print all the data in the Notation3 format
+ print("--- printing mboxes ---")
+ print(g.serialize(format='n3').decode("utf-8"))
+
-Many more :doc:`examples <apidocs/examples>` can be found in the :file:`examples` folder in the source distribution.
+More examples
+=============
+There are many more :doc:`examples <apidocs/examples>` in the :file:`examples` folder in the source distribution.
diff --git a/docs/index.rst b/docs/index.rst
index 66d88e16..3f604729 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -4,20 +4,32 @@
rdflib |release|
================
-RDFLib is a pure Python package for working with `RDF <http://www.w3.org/RDF/>`_. RDFLib contains useful APIs for working with RDF, including:
+RDFLib is a pure Python package for working with `RDF <http://www.w3.org/RDF/>`_. RDFLib contains useful APIs for
+working with RDF, including:
-* parsers and serializers for RDF/XML, N3, NTriples, N-Quads, Turtle, TriX, RDFa and Microdata.
+* **Parsers & Serializers**
-* a Graph interface which can be backed by a number of store implementations.
+ * for RDF/XML, N3, NTriples, N-Quads, Turtle, TriX, RDFa and Microdata
+ * and JSON-LD, via a plugin module
-* store implementations for in memory storage and persistent storage on top of the Berkeley DB.
+* **Store implementations**
+
+ * for in-memory and persistent RDF storage - Berkeley DB
+
+* **Graph interface**
+
+ * to a single graph
+ * or a conjunctive graph (multiple named graphs)
+ * or a dataset of graphs
+
+* **SPARQL 1.1 implementation**
+
+ * supporting both Queries and Updates
-* a SPARQL 1.1 implementation - supporting SPARQL 1.1 Queries and Update statements.
Getting started
---------------
-
-If you have never used RDFLib, the following will help get you started
+If you have never used RDFLib, the following will help get you started:
.. toctree::
:maxdepth: 1
@@ -27,14 +39,12 @@ If you have never used RDFLib, the following will help get you started
intro_to_creating_rdf
intro_to_graphs
intro_to_sparql
-
utilities
+ Examples <apidocs/examples>
- RDFLib examples <apidocs/examples>
In depth
--------
-
If you are familiar with RDF and are looking for details on how RDFLib handles RDF, these are for you.
.. toctree::
@@ -44,37 +54,31 @@ If you are familiar with RDF and are looking for details on how RDFLib handles R
namespaces_and_bindings
persistence
merging
-
- upgrade3to4
- upgrade2to3
-
- faq
+ upgrade4to5
Reference
---------
-
The nitty-gritty details of everything.
-.. toctree::
- :maxdepth: 2
-
- plugins
+API reference:
.. toctree::
:maxdepth: 1
apidocs/modules
-* :ref:`genindex`
-* :ref:`modindex`
-
+.. toctree::
+ :maxdepth: 2
+
+ plugins
+.. * :ref:`genindex`
+.. * :ref:`modindex`
For developers
--------------
-
.. toctree::
:maxdepth: 1
@@ -83,42 +87,22 @@ For developers
univrdfstore
persisting_n3_terms
+Developers might also like to join rdflib's dev mailing list: `<https://groups.google.com/group/rdflib-dev>`__
+The Code
+--------
+The rdflib code is hosted on GitHub at `<https://github.com/RDFLib/rdflib>`__ where you lodge Issues and also Pull
+Requests to help improve this community project!
-Indices and tables
-------------------
-
-* :ref:`genindex`
-* :ref:`modindex`
-* :ref:`search`
+The RDFlib organisation on GitHub at `<https://github.com/RDFLib>`__ maintains this package and a number of other RDF
+and related packaged that you might also find useful.
-.. glossary::
- functional properties
-
- A functional property is a property that can
- have only one (unique) value y for each instance x, i.e. there
- cannot be two distinct values y1 and y2 such that the pairs
- (x,y1) and (x,y2) are both instances of this
- property. -- http://www.w3.org/TR/owl-ref/#FunctionalProperty-def
+Further help
+-----------
+If you would like more help with using rdflib, please post a question using the tag ``[rdflib]`` on StackOverflow. A list of
+existing ``[rdflib]`` tagged questions is there at:
- graph
- An RDF graph is a set of RDF triples. The set of nodes of an RDF graph
- is the set of subjects and objects of triples in the graph.
-
- named graph
- Named Graphs allow multiple RDF graphs to exist within a single
- document/repository. They can be referred to with URIs. Named graphs allow queries across multiple domains.
- -- http://www.w3.org/2004/03/trix/
+* `<https://stackoverflow.com/questions/tagged/rdflib>`__
- transitivity
- A property is transitive:
-
- if whenever an element ``a`` is related to an element
- ``b``, and ``b`` is in turn related to an element ``c``,
- then ``a`` is also related to ``c``. --
- http://en.wikipedia.org/wiki/Transitive_relation
-
- Standard examples include ``rdfs:subClassOf`` or greater-than
-
diff --git a/docs/intro_to_creating_rdf.rst b/docs/intro_to_creating_rdf.rst
index 1a2b8de5..0c05a241 100644
--- a/docs/intro_to_creating_rdf.rst
+++ b/docs/intro_to_creating_rdf.rst
@@ -7,24 +7,29 @@ Creating RDF triples
Creating Nodes
--------------
-RDF is a graph where the nodes are URI references, Blank Nodes or Literals, in RDFLib represented by the classes :class:`~rdflib.term.URIRef`, :class:`~rdflib.term.BNode`, and :class:`~rdflib.term.Literal`. ``URIRefs`` and ``BNodes`` can both be thought of as resources, such a person, a company, a web-site, etc.
-A ``BNode`` is a node where the exact URI is not known.
-``URIRefs`` are also used to represent the properties/predicates in the RDF graph.
-``Literals`` represent attribute values, such as a name, a date, a number, etc.
+RDF data is a graph where the nodes are URI references, Blank Nodes or Literals. In RDFLib, these node types are
+represented by the classes :class:`~rdflib.term.URIRef`, :class:`~rdflib.term.BNode`, and :class:`~rdflib.term.Literal`.
+``URIRefs`` and ``BNodes`` can both be thought of as resources, such a person, a company, a website, etc.
+* A ``BNode`` is a node where the exact URI is not known.
+* A ``URIRef`` is a node where the exact URI is knonw. ``URIRef``s are also used to represent the properties/predicates in the RDF graph.
+* ``Literals`` represent attribute values, such as a name, a date, a number, etc. The most common literal values are XML data types, e.g. string, int...
-Nodes can be created by the constructors of the node classes::
+
+Nodes can be created by the constructors of the node classes:
+
+.. code-block:: python
from rdflib import URIRef, BNode, Literal
bob = URIRef("http://example.org/people/Bob")
- linda = BNode() # a GUID is generated
+ linda = BNode() # a GUID is generated
- name = Literal('Bob') # passing a string
- age = Literal(24) # passing a python int
- height = Literal(76.5) # passing a python float
+ name = Literal('Bob') # passing a string
+ age = Literal(24) # passing a python int
+ height = Literal(76.5) # passing a python float
-Literals can be created from python objects, this creates ``data-typed literals``, for the details on the mapping see :ref:`rdflibliterals`.
+Literals can be created from Python objects, this creates ``data-typed literals``, for the details on the mapping see :ref:`rdflibliterals`.
For creating many ``URIRefs`` in the same ``namespace``, i.e. URIs with the same prefix, RDFLib has the :class:`rdflib.namespace.Namespace` class::
@@ -32,87 +37,102 @@ For creating many ``URIRefs`` in the same ``namespace``, i.e. URIs with the same
n = Namespace("http://example.org/people/")
- n.bob # = rdflib.term.URIRef(u'http://example.org/people/bob')
- n.eve # = rdflib.term.URIRef(u'http://example.org/people/eve')
+ n.bob # = rdflib.term.URIRef(u'http://example.org/people/bob')
+ n.eve # = rdflib.term.URIRef(u'http://example.org/people/eve')
-This is very useful for schemas where all properties and classes have the same URI prefix, RDFLib pre-defines Namespaces for the most common RDF schemas::
+This is very useful for schemas where all properties and classes have the same URI prefix. RDFLib defines Namespaces for some common RDF/OWL schemas, including most W3C ones:
+
+.. code-block:: python
+
+ from rdflib.namespace import CSVW, DC, DCAT, DCTERMS, DOAP, FOAF, ODRL2, ORG, OWL, \
+ PROF, PROV, RDF, RDFS, SDO, SH, SKOS, SOSA, SSN, TIME, \
+ VOID, XMLNS, XSD
+
+ RDF.type
+ # = rdflib.term.URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
+
+ FOAF.knows
+ # = rdflib.term.URIRef("http://xmlns.com/foaf/0.1/knows")
- from rdflib.namespace import RDF, FOAF
+ PROF.isProfileOf
+ # = rdflib.term.URIRef("http://www.w3.org/ns/dx/prof/isProfileOf")
- RDF.type
- # = rdflib.term.URIRef(u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type')
+ SOSA.Sensor
+ # = rdflib.term.URIRef("http://www.w3.org/ns/sosa/Sensor")
- FOAF.knows
- # = rdflib.term.URIRef(u'http://xmlns.com/foaf/0.1/knows')
Adding Triples
--------------
-We already saw in :doc:`intro_to_parsing`, how triples can be added with with the :meth:`~rdflib.graph.Graph.parse` function.
+We already saw in :doc:`intro_to_parsing`, how triples can be added from files and online locations with with the :meth:`~rdflib.graph.Graph.parse` function.
-Triples can also be added with the :meth:`~rdflib.graph.Graph.add` function:
+Triples can also be added within Python code directly, using the :meth:`~rdflib.graph.Graph.add` function:
.. automethod:: rdflib.graph.Graph.add
:noindex:
-:meth:`~rdflib.graph.Graph.add` takes a 3-tuple of RDFLib nodes. Try the following with the nodes and namespaces we defined previously::
+:meth:`~rdflib.graph.Graph.add` takes a 3-tuple (a "triple") of RDFLib nodes. Try the following with the nodes and namespaces we defined previously:
- from rdflib import Graph
- g = Graph()
+.. code-block:: python
+
+ from rdflib import Graph
+ g = Graph()
+ g.bind("foaf", FOAF)
- g.add( (bob, RDF.type, FOAF.Person) )
- g.add( (bob, FOAF.name, name) )
- g.add( (bob, FOAF.knows, linda) )
- g.add( (linda, RDF.type, FOAF.Person) )
- g.add( (linda, FOAF.name, Literal('Linda') ) )
+ g.add((bob, RDF.type, FOAF.Person))
+ g.add((bob, FOAF.name, name))
+ g.add((bob, FOAF.knows, linda))
+ g.add((linda, RDF.type, FOAF.Person))
+ g.add((linda, FOAF.name, Literal("Linda")))
- print g.serialize(format='turtle')
+ print(g.serialize(format="turtle").decode("utf-8"))
outputs:
.. code-block:: n3
- @prefix foaf: <http://xmlns.com/foaf/0.1/> .
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
- @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
- @prefix xml: <http://www.w3.org/XML/1998/namespace> .
+ @prefix foaf: <http://xmlns.com/foaf/0.1/> .
- <http://example.org/people/Bob> a foaf:Person ;
- foaf:knows [ a foaf:Person ;
- foaf:name "Linda" ] ;
- foaf:name "Bob" .
+ <http://example.org/people/Bob> a foaf:Person ;
+ foaf:knows [ a foaf:Person ;
+ foaf:name "Linda" ] ;
+ foaf:name "Bob" .
For some properties, only one value per resource makes sense (i.e they are *functional properties*, or have max-cardinality of 1). The :meth:`~rdflib.graph.Graph.set` method is useful for this:
.. code-block:: python
- g.add( ( bob, FOAF.age, Literal(42) ) )
- print "Bob is ", g.value( bob, FOAF.age )
- # prints: Bob is 42
-
- g.set( ( bob, FOAF.age, Literal(43) ) ) # replaces 42 set above
- print "Bob is now ", g.value( bob, FOAF.age )
- # prints: Bob is now 43
+ g.add((bob, FOAF.age, Literal(42)))
+ print("Bob is ", g.value(bob, FOAF.age))
+ # prints: Bob is 42
+
+ g.set((bob, FOAF.age, Literal(43))) # replaces 42 set above
+ print("Bob is now ", g.value(bob, FOAF.age))
+ # prints: Bob is now 43
:meth:`rdflib.graph.Graph.value` is the matching query method, it will return a single value for a property, optionally raising an exception if there are more.
You can also add triples by combining entire graphs, see :ref:`graph-setops`.
+
Removing Triples
-^^^^^^^^^^^^^^^^
+----------------
Similarly, triples can be removed by a call to :meth:`~rdflib.graph.Graph.remove`:
.. automethod:: rdflib.graph.Graph.remove
:noindex:
-When removing, it is possible to leave parts of the triple unspecified (i.e. passing ``None``), this will remove all matching triples::
+When removing, it is possible to leave parts of the triple unspecified (i.e. passing ``None``), this will remove all matching triples:
+
+.. code-block:: python
+
+ g.remove((bob, None, None)) # remove all triples about bob
- g.remove( (bob, None, None) ) # remove all triples about bob
An example
-^^^^^^^^^^
+----------
LiveJournal produces FOAF data for their users, but they seem to use
``foaf:member_name`` for a person's full name. To align with data from
@@ -124,5 +144,8 @@ for ``foaf:member_name`` (a poor man's one-way
from rdflib.namespace import FOAF
g.parse("http://danbri.livejournal.com/data/foaf")
- for s,_,n in g.triples((None, FOAF['member_name'], None)):
- g.add((s, FOAF['name'], n))
+ for s, p, o in g.triples((None, FOAF['member_name'], None)):
+ g.add((s, FOAF['name'], o))
+
+Note that since rdflib 5.0.0, using ``foaf:member_name`` is somewhat prevented in rdflib since FOAF is declared as a :meth:`~rdflib.namespace.ClosedNamespace`
+class instance that has a closed set of members and ``foaf:member_name`` isnt one of them! \ No newline at end of file
diff --git a/docs/intro_to_graphs.rst b/docs/intro_to_graphs.rst
index 0c76e6f4..aa0fecf3 100644
--- a/docs/intro_to_graphs.rst
+++ b/docs/intro_to_graphs.rst
@@ -4,7 +4,7 @@
Navigating Graphs
=================
-An RDF Graph is a set of RDF triples, and we try to mirror exactly this in RDFLib, and the graph tries to emulate a container type:
+An RDF Graph is a set of RDF triples, and we try to mirror exactly this in RDFLib. The Python :meth:`~rdflib.graph.Graph` tries to emulate a container type.
Graphs as Iterators
-------------------
@@ -13,25 +13,29 @@ RDFLib graphs override :meth:`~rdflib.graph.Graph.__iter__` in order to support
.. code-block:: python
- for subject,predicate,obj in someGraph:
- if not (subject,predicate,obj) in someGraph:
- raise Exception("Iterator / Container Protocols are Broken!!")
+ for subject, predicate, object in someGraph:
+ if not (subject, predicate, object) in someGraph:
+ raise Exception("Iterator / Container Protocols are Broken!!")
Contains check
--------------
-Graphs implement :meth:`~rdflib.graph.Graph.__contains__`, so you can check if a triple is in a graph with ``triple in graph`` syntax::
+Graphs implement :meth:`~rdflib.graph.Graph.__contains__`, so you can check if a triple is in a graph with ``triple in graph`` syntax:
- from rdflib import URIRef
- from rdflib.namespace import RDF
- bob = URIRef("http://example.org/people/bob")
- if ( bob, RDF.type, FOAF.Person ) in graph:
- print "This graph knows that Bob is a person!"
+.. code-block:: python
+
+ from rdflib import URIRef
+ from rdflib.namespace import RDF
+ bob = URIRef("http://example.org/people/bob")
+ if (bob, RDF.type, FOAF.Person) in graph:
+ print("This graph knows that Bob is a person!")
-Note that this triple does not have to be completely bound::
+Note that this triple does not have to be completely bound:
+
+.. code-block:: python
- if (bob, None, None) in graph:
- print "This graph contains triples about Bob!"
+ if (bob, None, None) in graph:
+ print("This graph contains triples about Bob!")
.. _graph-setops:
@@ -51,40 +55,41 @@ operation effect
``G1 ^ G2`` xor (triples in either G1 or G2, but not in both)
============ ==================================================
-.. warning:: Set-operations on graphs assume bnodes are shared between graphs. This may or may not do what you want. See :doc:`merging` for details.
+.. warning:: Set-operations on graphs assume Blank Nodes are shared between graphs. This may or may not do what you want. See :doc:`merging` for details.
Basic Triple Matching
---------------------
Instead of iterating through all triples, RDFLib graphs support basic triple pattern matching with a :meth:`~rdflib.graph.Graph.triples` function.
-This function is a generator of triples that match the pattern given by the arguments. The arguments of these are RDF terms that restrict the triples that are returned. Terms that are :data:`None` are treated as a wildcard. For example::
+This function is a generator of triples that match the pattern given by the arguments. The arguments of these are RDF terms that restrict the triples that are returned. Terms that are :data:`None` are treated as a wildcard. For example:
+.. code-block:: python
- g.load("some_foaf.rdf")
- for s,p,o in g.triples( (None, RDF.type, FOAF.Person) ):
- print "%s is a person"%s
-
- for s,p,o in g.triples( (None, RDF.type, None) ):
- print "%s is a %s"%(s,o)
-
- bobgraph = Graph()
+ g.load("some_foaf.rdf")
+ for s, p, o in g.triples((None, RDF.type, FOAF.Person)):
+ print("{} is a person".format(s))
- bobgraph += g.triples( (bob, None, None) )
+ for s, p, o in g.triples((None, RDF.type, None)):
+ print("{} is a {}".format(s, o))
-If you are not interested in whole triples, you can get only the bits you want with the methods :meth:`~rdflib.graph.Graph.objects`, :meth:`~rdflib.graph.Graph.subjects`, :meth:`~rdflib.graph.Graph.predicates`, :meth:`~rdflib.graph.Graph.predicate_objects`, etc. Each take parameters for the components of the triple to constraint::
+ bobgraph = Graph()
- for person in g.subjects(RDF.type, FOAF.Person):
- print "%s is a person"%person
+ bobgraph += g.triples((bob, None, None))
+If you are not interested in whole triples, you can get only the bits you want with the methods :meth:`~rdflib.graph.Graph.objects`, :meth:`~rdflib.graph.Graph.subjects`, :meth:`~rdflib.graph.Graph.predicates`, :meth:`~rdflib.graph.Graph.predicate_objects`, etc. Each take parameters for the components of the triple to constraint:
-Finally, for some properties, only one value per resource makes sense (i.e they are *functional properties*, or have max-cardinality of 1). The :meth:`~rdflib.graph.Graph.value` method is useful for this, as it returns just a single node, not a generator::
+.. code-block:: python
- name = g.value(bob, FOAF.name) # get any name of bob
- # get the one person that knows bob and raise an exception if more are found
- mbox = g.value(predicate = FOAF.name, object = bob, any = False)
+ for person in g.subjects(RDF.type, FOAF.Person):
+ print("{} is a person".format(person))
+Finally, for some properties, only one value per resource makes sense (i.e they are *functional properties*, or have max-cardinality of 1). The :meth:`~rdflib.graph.Graph.value` method is useful for this, as it returns just a single node, not a generator:
+.. code-block:: python
+ name = g.value(bob, FOAF.name) # get any name of bob
+ # get the one person that knows bob and raise an exception if more are found
+ mbox = g.value(predicate = FOAF.name, object=bob, any=False)
:class:`~rdflib.graph.Graph` methods for accessing triples
@@ -112,8 +117,3 @@ Here is a list of all convenience methods for querying Graphs:
:noindex:
.. automethod:: rdflib.graph.Graph.predicate_objects
:noindex:
-
-
-
-
-
diff --git a/docs/intro_to_parsing.rst b/docs/intro_to_parsing.rst
index fdf9a6bd..6dd16a3d 100644
--- a/docs/intro_to_parsing.rst
+++ b/docs/intro_to_parsing.rst
@@ -8,7 +8,7 @@ Reading an NT file
-------------------
RDF data has various syntaxes (``xml``, ``n3``, ``ntriples``,
-``trix``, etc) that you might want to read. The simplest format is
+``trix``, ``JSON-LD``, etc) that you might want to read. The simplest format is
``ntriples``, a line-based format. Create the file :file:`demo.nt` in
the current directory with these two lines:
@@ -24,14 +24,16 @@ either a mime-type or the name (a :doc:`list of available parsers
file will be, you can use :func:`rdflib.util.guess_format` which will
guess based on the file extension.
-In an interactive python interpreter, try this::
+In an interactive python interpreter, try this:
+
+.. code-block:: python
from rdflib import Graph
g = Graph()
g.parse("demo.nt", format="nt")
- len(g) # prints 2
+ print(len(g)) # prints 2
import pprint
for stmt in g:
@@ -40,7 +42,7 @@ In an interactive python interpreter, try this::
# prints :
(rdflib.term.URIRef('http://bigasterisk.com/foaf.rdf#drewp'),
rdflib.term.URIRef('http://example.com/says'),
- rdflib.term.Literal(u'Hello world'))
+ rdflib.term.Literal('Hello world'))
(rdflib.term.URIRef('http://bigasterisk.com/foaf.rdf#drewp'),
rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
rdflib.term.URIRef('http://xmlns.com/foaf/0.1/Person'))
@@ -52,14 +54,16 @@ subjects, predicates, and objects are all rdflib types.
Reading remote graphs
---------------------
-Reading graphs from the net is just as easy::
+Reading graphs from the net is just as easy:
+
+.. code-block:: python
g.parse("http://bigasterisk.com/foaf.rdf")
- len(g)
+ print(len(g))
# prints 42
The format defaults to ``xml``, which is the common format for .rdf
files you'll find on the net.
RDFLib will also happily read RDF from any file-like object,
-i.e. anything with a ``.read`` method.
+i.e. anything with a ``.read()`` method.
diff --git a/docs/univrdfstore.rst b/docs/univrdfstore.rst
index a1c54e90..9187935b 100644
--- a/docs/univrdfstore.rst
+++ b/docs/univrdfstore.rst
@@ -6,9 +6,9 @@ A Universal RDF Store Interface
This document attempts to summarize some fundamental components of an RDF store. The motivation is to outline a standard set of interfaces for providing the support needed to persist an `RDF Graph`_ in a way that is universal and not tied to any specific implementation.
-For the most part, the interface adheres to the core RDF model and uses terminology that is consistent with the RDF Model specifications. However, this suggested interface also extends an RDF store with additional requirements necessary to facilitate those aspects of `Notation 3`_ that go beyond the RDF model to provide a framework for `First Order Predicate Logic`_ processing and persistence.
+For the most part, the interfaces adhere to the core RDF model and use terminology that is consistent with the RDF Model specifications. However, these suggested interfaces also extends an RDF store with additional requirements necessary to facilitate those aspects of `Notation 3`_ that go beyond the RDF model to provide a framework for `First Order Predicate Logic`_ processing and persistence.
-.. _RDF Graph: http://www.w3.org/TR/rdf-concepts/#dfn-rdf-graph
+.. _RDF Graph: https://www.w3.org/TR/rdf11-concepts/#data-model
.. _Notation 3: http://www.w3.org/2000/10/swap/Primer
.. _First Order Predicate Logic: http://en.wikipedia.org/wiki/First-order_predicate_logic
diff --git a/docs/upgrade2to3.rst b/docs/upgrade2to3.rst
deleted file mode 100644
index 4773c176..00000000
--- a/docs/upgrade2to3.rst
+++ /dev/null
@@ -1,60 +0,0 @@
-.. _upgrade2to3: Upgrading from RDFLib version 2.X to 3.X
-
-========================================
-Upgrading from RDFLib version 2.X to 3.X
-========================================
-
-Introduction
-============
-This page details the changes required to upgrade from RDFLib 2.X to 3.X.
-
-Some older Linux distributions still ship 2.4.X. If needed, you can also install 2.4 using easy_install/setup tools.
-
-Version 3.0 reorganised some packages, and moved non-core parts of rdflib to the `rdfextras project <http://code.google.com/p/rdfextras/>`_
-
-
-Features moved to rdfextras
-===========================
-
- * SPARQL Support is now in rdfextras / rdflib-sparql
- * The RDF Commandline tools are now in rdfextras
-
-.. warning:: If you install packages with just distutils - you will need to register the sparql plugins manually - we strongly recommend installing with setuptools or distribute!
- To register the plugins add this somewhere in your program:
-
- .. code-block:: python
-
- rdflib.plugin.register('sparql', rdflib.query.Processor,
- 'rdfextras.sparql.processor', 'Processor')
- rdflib.plugin.register('sparql', rdflib.query.Result,
- 'rdfextras.sparql.query', 'SPARQLQueryResult')
-
-
-Unstable features that were removed
-===================================
-
- The RDBMS back stores (MySQL/PostgreSQL) were removed, but are in the process of being moved to rdfextras. The Redland, SQLite and ZODB stores were all removed.
-
-Packages/Classes that were renamed
-==================================
-
-Previously all packages and classes had colliding names, i.e. both package and the class was called "Graph"::
-
- from rdflib.Graph import Graph, ConjunctiveGraph
-
-Now all packages are lower-case, i.e::
-
- from rdflib.graph import Graph, ConjunctiveGraph
-
-Most classes you need are available from the top level rdflib package::
-
- from rdflib import Graph, URIRef, BNode, Literal
-
-Namespace classes for RDF, RDFS, OWL are now directly in the rdflib package, i.e. in 2.4::
-
- from rdflib.RDF import RDFNS as RDF
-
-in 3.0::
-
- from rdflib import RDF
-
diff --git a/docs/upgrade3to4.rst b/docs/upgrade3to4.rst
deleted file mode 100644
index 574d129a..00000000
--- a/docs/upgrade3to4.rst
+++ /dev/null
@@ -1,92 +0,0 @@
-.. _upgrade3to4: Upgrading from RDFLib version 3.X to 4.X
-
-========================================
-Upgrading from RDFLib version 3.X to 4.X
-========================================
-
-RDFLib version 4.0 introduced a small number of backwards compatible changes that you should know about when porting code from version 3 or earlier.
-
-SPARQL and SPARQLStore are now included in core
------------------------------------------------
-
-For version 4.0 we've merged the SPARQL implementation from ``rdflib-sparql``, the SPARQL(Update)Store from ``rdflib-sparqlstore`` and miscellaneous utilities from ``rdfextras``. If you used any of these previously, everything you need should now be included.
-
-
-Datatyped literals
-------------------
-
-We separate lexical and value space operations for datatyped literals.
-
-This mainly affects the way datatyped literals are compared. Lexical space comparisons are done by default for ``==`` and ``!=``, meaning the exact lexical representation and the exact data-types have to match for literals to be equal. Value space comparisons are also available through the :meth:`rdflib.term.Identifier.eq` and :meth:`rdflib.term.Identifier.neq` methods, ``< > <= >=`` are also done in value space.
-
-Most things now work in a fairly sane and sensible way, if you do not have existing stores/intermediate stored sorted lists, or hash-dependent something-or-other, you should be good to go.
-
-Things to watch out for:
-
-Literals no longer compare equal across data-types with ```==```
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-i.e.
-
-.. code-block:: python
-
- >>> Literal(2, datatype=XSD.int) == Literal(2, datatype=XSD.float)
- False
-
-
-But a new method :meth:`rdflib.term.Identifier.eq` on all Nodes has been introduced, which does semantic equality checking, i.e.:
-
-.. code-block:: python
-
- >>> Literal(2, datatype=XSD.int).eq(Literal(2, datatype=XSD.float))
- True
-
-The ``eq`` method is still limited to what data-types map to the same *value space*, i.e. all numeric types map to numbers and will compare, ``xsd:string`` and ``plain literals`` both map to strings and compare fine, but:
-
-.. code-block:: python
-
- >>> Literal(2, datatype=XSD.int).eq(Literal('2'))
- False
-
-
-
-Literals will be normalised according to datatype
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-If you care about the exact lexical representation of a literal, and not just the value. Either set :data:`rdflib.NORMALIZE_LITERALS` to ``False`` before creating your literal, or pass ``normalize=False`` to the Literal constructor
-
-Ordering of literals and nodes has changed
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Comparing literals with ``<, >, <=, >=`` now work same as in SPARQL filter expressions.
-
-Greater-than/less-than ordering comparisons are also done in value space, when compatible datatypes are used.
-Incompatible datatypes are ordered by data-type, or by lang-tag.
-For other nodes the ordering is ``None < BNode < URIRef < Literal``
-
-Any comparison with non-rdflib Node are ``NotImplemented``
-In PY2.X some stable order will be made up by python.
-In PY3 this is an error.
-
-Custom mapping of datatypes to python objects
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-You can add new mappings of datatype URIs to python objects using the :func:`rdflib.term.bind` method.
-This also allows you to specify a constructor for constructing objects from the lexical string representation, and a serialization method for generating a lexical string representation from an object.
-
-
-
-Minor Changes
---------------
-
-* :class:`rdflib.namespace.Namespace` is no longer a sub-class of :class:`rdflib.term.URIRef`
- this was changed as it makes no sense for a namespace to be a node in a graph, and was causing numerous bug. Unless you do something very special, you should not notice this change.
-
-* The identifiers for Graphs are now converted to URIRefs if they are not a :class:`rdflib.term.Node`, i.e. no more graphs with string identifiers. Again, unless you do something quite unusual, you should not notice.
-
-* String concatenation with URIRefs now returns URIRefs, not strings::
-
- >>> URIRef("http://example.org/people/") + "Bill"
- rdflib.term.URIRef(u'http://example.org/people/Bill')
-
- This is be convenient, but may cause trouble if you expected a string.
diff --git a/docs/upgrade4to5.rst b/docs/upgrade4to5.rst
new file mode 100644
index 00000000..4da26959
--- /dev/null
+++ b/docs/upgrade4to5.rst
@@ -0,0 +1,24 @@
+.. _upgrade4to5: Upgrading from RDFLib version 4.2.2 to 5.0.0
+
+============================================
+Upgrading 4.2.2 to 5.0.0
+============================================
+
+RDFLib version 5.0.0 appeared over 3 years after the previous release, 4.2.2 and contains a large number of both enhancements and bug fixes. Fundamentally though, 5.0.0 is compatible with 4.2.2.
+
+
+Major Changes
+-------------
+Paragraphs of explanation
+
+Minor heading
+^^^^^^^^^^^^^
+Paragraphs of explanation
+
+
+Minor Changes
+--------------
+This list has been assembled from Pull Request and commit information.
+
+* stuff
+* more stuff
diff --git a/examples/conjunctive_graphs.py b/examples/conjunctive_graphs.py
index 81cbab9e..80282684 100644
--- a/examples/conjunctive_graphs.py
+++ b/examples/conjunctive_graphs.py
@@ -1,57 +1,59 @@
"""
-
An RDFLib ConjunctiveGraph is an (unnamed) aggregation of all the named graphs
within a Store. The :meth:`~rdflib.graph.ConjunctiveGraph.get_context`
-method can be used to get a particular named graph, or triples can be
-added to the default graph
-
-This example shows how to create some named graphs and work with the
-conjunction of all the graphs.
+method can be used to get a particular named graph for use such as to add
+triples to, or the default graph can be used
+This example shows how to create named graphs and work with the
+conjunction (union) of all the graphs.
"""
from rdflib import Namespace, Literal, URIRef
from rdflib.graph import Graph, ConjunctiveGraph
from rdflib.plugins.memory import IOMemory
-if __name__ == '__main__':
+if __name__ == "__main__":
ns = Namespace("http://love.com#")
- mary = URIRef("http://love.com/lovers/mary#")
- john = URIRef("http://love.com/lovers/john#")
+ mary = URIRef("http://love.com/lovers/mary")
+ john = URIRef("http://love.com/lovers/john")
- cmary = URIRef("http://love.com/lovers/mary#")
- cjohn = URIRef("http://love.com/lovers/john#")
+ cmary = URIRef("http://love.com/lovers/mary")
+ cjohn = URIRef("http://love.com/lovers/john")
store = IOMemory()
g = ConjunctiveGraph(store=store)
g.bind("love", ns)
+ # add a graph for Mary's facts to the Conjunctive Graph
gmary = Graph(store=store, identifier=cmary)
+ # Mary's graph only contains the URI of the person she love, not his cute name
+ gmary.add((mary, ns["hasName"], Literal("Mary")))
+ gmary.add((mary, ns["loves"], john))
- gmary.add((mary, ns['hasName'], Literal("Mary")))
- gmary.add((mary, ns['loves'], john))
-
+ # add a graph for Mary's facts to the Conjunctive Graph
gjohn = Graph(store=store, identifier=cjohn)
- gjohn.add((john, ns['hasName'], Literal("John")))
+ # John's graph contains his cute name
+ gjohn.add((john, ns["hasCuteName"], Literal("Johnny Boy")))
# enumerate contexts
for c in g.contexts():
print("-- %s " % c)
# separate graphs
- print(gjohn.serialize(format='n3'))
+ print(gjohn.serialize(format="n3").decode("utf-8"))
print("===================")
- print(gmary.serialize(format='n3'))
+ print(gmary.serialize(format="n3").decode("utf-8"))
print("===================")
# full graph
- print(g.serialize(format='n3'))
+ print(g.serialize(format="n3").decode("utf-8"))
# query the conjunction of all graphs
-
- print('Mary loves:')
- for x in g[mary: ns.loves / ns.hasName]:
- print(x)
+ xx = None
+ for x in g[mary: ns.loves / ns.hasCuteName]:
+ xx = x
+ print("Q: Who does Mary love?")
+ print("A: Mary loves {}".format(xx))
diff --git a/examples/custom_datatype.py b/examples/custom_datatype.py
index f2d4fb28..8d73e894 100644
--- a/examples/custom_datatype.py
+++ b/examples/custom_datatype.py
@@ -1,20 +1,18 @@
"""
-
-RDFLib can map between data-typed literals and python objects.
+RDFLib can map between RDF data-typed literals and Python objects.
Mapping for integers, floats, dateTimes, etc. are already added, but
you can also add your own.
This example shows how :meth:`rdflib.term.bind` lets you register new
-mappings between literal datatypes and python objects
-
+mappings between literal datatypes and Python objects
"""
from rdflib import Graph, Literal, Namespace, XSD
from rdflib.term import bind
-if __name__ == '__main__':
+if __name__ == "__main__":
# complex numbers are not registered by default
# no custom constructor/serializer needed since
@@ -30,12 +28,11 @@ if __name__ == '__main__':
g = Graph()
g.add((ns.mysubject, ns.myprop, l))
- n3 = g.serialize(format='n3')
-
- # round-trip through n3
+ n3 = g.serialize(format="n3")
+ # round-trip through n3 serialize/parse
g2 = Graph()
- g2.parse(data=n3, format='n3')
+ g2.parse(data=n3, format="n3")
l2 = list(g2)[0][2]
diff --git a/examples/custom_eval.py b/examples/custom_eval.py
index 69cd173a..74c393a4 100644
--- a/examples/custom_eval.py
+++ b/examples/custom_eval.py
@@ -1,7 +1,6 @@
"""
-
This example shows how a custom evaluation function can be added to
-handle certain SPARQL Algebra elements
+handle certain SPARQL Algebra elements.
A custom function is added that adds ``rdfs:subClassOf`` "inference" when
asking for ``rdf:type`` triples.
@@ -15,7 +14,6 @@ i.e. in your setup.py::
'myfunc = mypackage:MyFunction',
],
}
-
"""
import rdflib
@@ -23,8 +21,7 @@ import rdflib
from rdflib.plugins.sparql.evaluate import evalBGP
from rdflib.namespace import FOAF
-inferredSubClass = \
- rdflib.RDFS.subClassOf * '*' # any number of rdfs.subClassOf
+inferredSubClass = rdflib.RDFS.subClassOf * "*" # any number of rdfs.subClassOf
def customEval(ctx, part):
@@ -32,7 +29,7 @@ def customEval(ctx, part):
Rewrite triple patterns to get super-classes
"""
- if part.name == 'BGP':
+ if part.name == "BGP":
# rewrite triples
triples = []
@@ -50,20 +47,17 @@ def customEval(ctx, part):
raise NotImplementedError()
-if __name__ == '__main__':
+if __name__ == "__main__":
# add function directly, normally we would use setuptools and entry_points
- rdflib.plugins.sparql.CUSTOM_EVALS['exampleEval'] = customEval
+ rdflib.plugins.sparql.CUSTOM_EVALS["exampleEval"] = customEval
g = rdflib.Graph()
- g.load("foaf.rdf")
+ g.load("foaf.n3")
# Add the subClassStmt so that we can query for it!
- g.add((FOAF.Person,
- rdflib.RDFS.subClassOf,
- FOAF.Agent))
+ g.add((FOAF.Person, rdflib.RDFS.subClassOf, FOAF.Agent))
# Find all FOAF Agents
- for x in g.query(
- 'PREFIX foaf: <%s> SELECT * WHERE { ?s a foaf:Agent . }' % FOAF):
+ for x in g.query("PREFIX foaf: <%s> SELECT * WHERE { ?s a foaf:Agent . }" % FOAF):
print(x)
diff --git a/examples/film.py b/examples/film.py
index 6bbda04a..fe626c08 100644
--- a/examples/film.py
+++ b/examples/film.py
@@ -4,14 +4,13 @@
film.py: a simple tool to manage your movies review
Simon Rozet, http://atonie.org/
-@@ :
-- manage directors and writers
-- manage actors
-- handle non IMDB uri
-- markdown support in comment
+ - manage directors and writers
+ - manage actors
+ - handle non IMDB uri
+ - markdown support in comment
Requires download and import of Python imdb library from
-http://imdbpy.sourceforge.net/ - (warning: installation
+https://imdbpy.github.io/ - (warning: installation
will trigger automatic installation of several other packages)
--
@@ -38,115 +37,119 @@ from rdflib import BNode, ConjunctiveGraph, URIRef, Literal, Namespace, RDF
from rdflib.namespace import FOAF, DC
from six.moves import input
-storefn = os.path.expanduser('~/movies.n3')
-#storefn = '/home/simon/codes/film.dev/movies.n3'
-storeuri = 'file://' + storefn
-title = 'Movies viewed by %s'
+storefn = os.path.expanduser("~/movies.n3")
+# storefn = '/home/simon/codes/film.dev/movies.n3'
+storeuri = "file://" + storefn
+title = "Movies viewed by %s"
-r_who = re.compile('^(.*?) <([a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9_-]+(\.[a-z0-9_-]+)+)>$')
+r_who = re.compile(
+ "^(.*?) <([a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9_-]+(\.[a-z0-9_-]+)+)>$"
+)
-IMDB = Namespace('http://www.csd.abdn.ac.uk/~ggrimnes/dev/imdb/IMDB#')
-REV = Namespace('http://purl.org/stuff/rev#')
+IMDB = Namespace("http://www.csd.abdn.ac.uk/~ggrimnes/dev/imdb/IMDB#")
+REV = Namespace("http://purl.org/stuff/rev#")
class Store:
def __init__(self):
self.graph = ConjunctiveGraph()
if os.path.exists(storefn):
- self.graph.load(storeuri, format='n3')
- self.graph.bind('dc', DC)
- self.graph.bind('foaf', FOAF)
- self.graph.bind('imdb', IMDB)
- self.graph.bind('rev', 'http://purl.org/stuff/rev#')
+ self.graph.load(storeuri, format="n3")
+ self.graph.bind("dc", DC)
+ self.graph.bind("foaf", FOAF)
+ self.graph.bind("imdb", IMDB)
+ self.graph.bind("rev", "http://purl.org/stuff/rev#")
def save(self):
- self.graph.serialize(storeuri, format='n3')
+ self.graph.serialize(storeuri, format="n3")
def who(self, who=None):
if who is not None:
name, email = (r_who.match(who).group(1), r_who.match(who).group(2))
- self.graph.add((URIRef(storeuri), DC['title'], Literal(title % name)))
- self.graph.add((URIRef(storeuri + '#author'), RDF.type, FOAF['Person']))
- self.graph.add((URIRef(storeuri + '#author'),
- FOAF['name'], Literal(name)))
- self.graph.add((URIRef(storeuri + '#author'),
- FOAF['mbox'], Literal(email)))
+ self.graph.add((URIRef(storeuri), DC["title"], Literal(title % name)))
+ self.graph.add((URIRef(storeuri + "#author"), RDF.type, FOAF["Person"]))
+ self.graph.add((URIRef(storeuri + "#author"), FOAF["name"], Literal(name)))
+ self.graph.add((URIRef(storeuri + "#author"), FOAF["mbox"], Literal(email)))
self.save()
else:
- return self.graph.objects(URIRef(storeuri + '#author'), FOAF['name'])
+ return self.graph.objects(URIRef(storeuri + "#author"), FOAF["name"])
def new_movie(self, movie):
- movieuri = URIRef('http://www.imdb.com/title/tt%s/' % movie.movieID)
- self.graph.add((movieuri, RDF.type, IMDB['Movie']))
- self.graph.add((movieuri, DC['title'], Literal(movie['title'])))
- self.graph.add((movieuri, IMDB['year'], Literal(int(movie['year']))))
+ movieuri = URIRef("http://www.imdb.com/title/tt%s/" % movie.movieID)
+ self.graph.add((movieuri, RDF.type, IMDB["Movie"]))
+ self.graph.add((movieuri, DC["title"], Literal(movie["title"])))
+ self.graph.add((movieuri, IMDB["year"], Literal(int(movie["year"]))))
self.save()
def new_review(self, movie, date, rating, comment=None):
review = BNode() # @@ humanize the identifier (something like #rev-$date)
- movieuri = URIRef('http://www.imdb.com/title/tt%s/' % movie.movieID)
- self.graph.add((movieuri, REV['hasReview'], URIRef('%s#%s' % (storeuri, review))))
- self.graph.add((review, RDF.type, REV['Review']))
- self.graph.add((review, DC['date'], Literal(date)))
- self.graph.add((review, REV['maxRating'], Literal(5)))
- self.graph.add((review, REV['minRating'], Literal(0)))
- self.graph.add((review, REV['reviewer'], URIRef(storeuri + '#author')))
- self.graph.add((review, REV['rating'], Literal(rating)))
+ movieuri = URIRef("http://www.imdb.com/title/tt%s/" % movie.movieID)
+ self.graph.add(
+ (movieuri, REV["hasReview"], URIRef("%s#%s" % (storeuri, review)))
+ )
+ self.graph.add((review, RDF.type, REV["Review"]))
+ self.graph.add((review, DC["date"], Literal(date)))
+ self.graph.add((review, REV["maxRating"], Literal(5)))
+ self.graph.add((review, REV["minRating"], Literal(0)))
+ self.graph.add((review, REV["reviewer"], URIRef(storeuri + "#author")))
+ self.graph.add((review, REV["rating"], Literal(rating)))
if comment is not None:
- self.graph.add((review, REV['text'], Literal(comment)))
+ self.graph.add((review, REV["text"], Literal(comment)))
self.save()
def movie_is_in(self, uri):
- return (URIRef(uri), RDF.type, IMDB['Movie']) in self.graph
+ return (URIRef(uri), RDF.type, IMDB["Movie"]) in self.graph
def help():
- print(__doc__.split('--')[1])
+ print(__doc__.split("--")[1])
def main(argv=None):
if not argv:
argv = sys.argv
s = Store()
- if argv[1] in ('help', '--help', 'h', '-h'):
+ if argv[1] in ("help", "--help", "h", "-h"):
help()
- elif argv[1] == 'whoami':
+ elif argv[1] == "whoami":
if os.path.exists(storefn):
print(list(s.who())[0])
else:
s.who(argv[2])
- elif argv[1].startswith('http://www.imdb.com/title/tt'):
+ elif argv[1].startswith("http://www.imdb.com/title/tt"):
if s.movie_is_in(argv[1]):
raise
else:
i = imdb.IMDb()
- movie = i.get_movie(argv[1][len('http://www.imdb.com/title/tt'):-1])
- print('%s (%s)' % (movie['title'].encode('utf-8'), movie['year']))
- for director in movie['director']:
- print('directed by: %s' % director['name'].encode('utf-8'))
- for writer in movie['writer']:
- print('written by: %s' % writer['name'].encode('utf-8'))
+ movie = i.get_movie(argv[1][len("http://www.imdb.com/title/tt") : -1])
+ print("%s (%s)" % (movie["title"].encode("utf-8"), movie["year"]))
+ for director in movie["director"]:
+ print("directed by: %s" % director["name"].encode("utf-8"))
+ for writer in movie["writer"]:
+ print("written by: %s" % writer["name"].encode("utf-8"))
s.new_movie(movie)
rating = None
while not rating or (rating > 5 or rating <= 0):
try:
- rating = int(input('Rating (on five): '))
+ rating = int(input("Rating (on five): "))
except ValueError:
rating = None
date = None
while not date:
try:
- i = input('Review date (YYYY-MM-DD): ')
- date = datetime.datetime(*time.strptime(i, '%Y-%m-%d')[:6])
+ i = input("Review date (YYYY-MM-DD): ")
+ date = datetime.datetime(*time.strptime(i, "%Y-%m-%d")[:6])
except:
date = None
- comment = input('Comment: ')
+ comment = input("Comment: ")
s.new_review(movie, date, rating, comment)
else:
help()
-if __name__ == '__main__':
+if __name__ == "__main__":
if not imdb:
- raise Exception('This example requires the IMDB library! Install with "pip install imdbpy"')
+ raise Exception(
+ 'This example requires the IMDB library! Install with "pip install imdbpy"'
+ )
main()
diff --git a/examples/foaf.n3 b/examples/foaf.n3
new file mode 100644
index 00000000..73d6712b
--- /dev/null
+++ b/examples/foaf.n3
@@ -0,0 +1,284 @@
+@prefix cc: <http://creativecommons.org/ns#> .
+@prefix con: <http://www.w3.org/2000/10/swap/pim/contact#> .
+@prefix dc: <http://purl.org/dc/elements/1.1/> .
+@prefix foaf: <http://xmlns.com/foaf/0.1/> .
+@prefix geo: <http://www.opengis.net/ont/geosparql#> .
+@prefix geo1: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
+@prefix owl: <http://www.w3.org/2002/07/owl#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix xml: <http://www.w3.org/XML/1998/namespace> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+<http://dig.csail.mit.edu/2007/01/camp/data#course> foaf:maker <http://www.w3.org/People/Berners-Lee/card#i> .
+
+<http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf> a foaf:PersonalProfileDocument ;
+ cc:license <http://creativecommons.org/licenses/by-nc/3.0/> ;
+ dc:title "Tim Berners-Lee's FOAF file" ;
+ foaf:maker <http://www.w3.org/People/Berners-Lee/card#i> ;
+ foaf:primaryTopic <http://www.w3.org/People/Berners-Lee/card#i> .
+
+<http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#dj> a foaf:Person ;
+ rdfs:seeAlso <http://www.grorg.org/dean/foaf.rdf> ;
+ foaf:homepage <http://www.grorg.org/dean/> ;
+ foaf:mbox <mailto:dean@w3.org>,
+ <mailto:dino@grorg.org> ;
+ foaf:mbox_sha1sum "6de4ff27ef927b9ba21ccc88257e41a2d7e7d293" ;
+ foaf:name "Dean Jackson" .
+
+<http://dig.csail.mit.edu/breadcrumbs/blog/4> dc:title "timbl's blog" ;
+ rdfs:seeAlso <http://dig.csail.mit.edu/breadcrumbs/blog/feed/4> ;
+ foaf:maker <http://www.w3.org/People/Berners-Lee/card#i> .
+
+<http://dig.csail.mit.edu/data#DIG> foaf:member <http://www.w3.org/People/Berners-Lee/card#i> .
+
+<http://my.opera.com/danbri/xml/foaf#me> rdfs:seeAlso <http://danbri.livejournal.com/data/foaf> ;
+ = <http://danbri.org/foaf.rdf#danbri>,
+ <http://www4.wiwiss.fu-berlin.de/dblp/resource/person/336851> ;
+ foaf:mbox_sha1sum "70c053d15de49ff03a1bcc374e4119b40798a66e" .
+
+<http://wiki.ontoworld.org/index.php/_IRW2006> dc:title "Identity, Reference and the Web workshop 2006" ;
+ con:participant <http://www.w3.org/People/Berners-Lee/card#i> .
+
+<http://www.ecs.soton.ac.uk/~dt2/dlstuff/www2006_data#panel-panelk01> rdfs:label "The Next Wave of the Web (Plenary Panel)" ;
+ con:participant <http://www.w3.org/People/Berners-Lee/card#i> .
+
+<http://www.w3.org/data#W3C> rdfs:label "W3C" ;
+ rdfs:seeAlso <http://dig.csail.mit.edu/2008/2002/01/tr-automation/tr.rdf> ;
+ con:publicHomePage <http://www.w3.org/> ;
+ foaf:homepage <http://dig.csail.mit.edu/2008/> ;
+ foaf:logo <http://dig.csail.mit.edu/2008/Icons/w3c_home> ;
+ foaf:name "World Wide Web Consortium" .
+
+<http://www4.wiwiss.fu-berlin.de/booksMeshup/books/006251587X> dc:creator <http://www.w3.org/People/Berners-Lee/card#i> ;
+ dc:title "Weaving the Web: The Original Design and Ultimate Destiny of the World Wide Web" .
+
+<http://bblfish.net/people/henry/card#me> foaf:name "Henry Story" .
+
+<http://dbpedia.org/resource/John_Gage> a foaf:Person ;
+ foaf:img <http://upload.wikimedia.org/wikipedia/commons/d/de/John_Gage.jpg> ;
+ foaf:name "John Gage" .
+
+<http://dbpedia.org/resource/John_Klensin> a foaf:Person ;
+ foaf:name "John Klensin" .
+
+<http://dbpedia.org/resource/John_Markoff> a foaf:Person ;
+ foaf:name "John Markoff" .
+
+<http://dbpedia.org/resource/John_Seely_Brown> a foaf:Person ;
+ = <http://www4.wiwiss.fu-berlin.de/bookmashup/persons/John+Seely+Brown> ;
+ foaf:homepage <http://www.johnseelybrown.com/> ;
+ foaf:img <http://transliteracies.english.ucsb.edu/images/participants/t/brown-john-seely-2.jpg> ;
+ foaf:name "John Seely Brown" .
+
+<http://dbpedia.org/resource/Tim_Bray> a foaf:Person ;
+ foaf:name "Tim Bray" .
+
+<http://dig.csail.mit.edu/2007/wiki/people/JoeLambda#JL> foaf:givenName "Joe" ;
+ foaf:name "Joe Lambda" .
+
+<http://dig.csail.mit.edu/2007/wiki/people/RobertHoffmann#RMH> a foaf:Person ;
+ foaf:name "Robert Hoffmann" .
+
+<http://dig.csail.mit.edu/2008/2002/01/tr-automation/tr.rdf> dc:title "W3C Standards and Technical Reports" .
+
+<http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#cm> a foaf:Person ;
+ rdfs:seeAlso <http://www.koalie.net/foaf.rdf> ;
+ foaf:name "Coralie Mercier" .
+
+<http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#edd> a foaf:Person ;
+ rdfs:seeAlso <http://heddley.com/edd/foaf.rdf> ;
+ foaf:homepage <http://heddley.com/edd/> ;
+ foaf:mbox <mailto:edd@usefulinc.com>,
+ <mailto:edd@xml.com>,
+ <mailto:edd@xmlhack.com> ;
+ foaf:name "Edd Dumbill" ;
+ foaf:nick "edd" .
+
+<http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#libby> a foaf:Person ;
+ = <http://swordfish.rdfweb.org/people/libby/rdfweb/webwho.xrdf#me> ;
+ foaf:img <http://swordfish.rdfweb.org/~libby/libby.jpg> ;
+ foaf:mbox <mailto:libby.miller@bristol.ac.uk> ;
+ foaf:name "Libby Miller" .
+
+<http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#ss> foaf:name "Susie Stephens" ;
+ foaf:organization <http://dbpedia.org/resource/Eli_Lilly_and_Company> .
+
+<http://eikeon.com/foaf.rdf#eikeon> foaf:name "Daniel Krech" .
+
+<http://hometown.aol.com/chbussler/foaf/chbussler.foaf#me> foaf:name "Christoph Bussler" .
+
+<http://id.ecs.soton.ac.uk/person/1269> foaf:name "Nicholas Gibbins" .
+
+<http://id.ecs.soton.ac.uk/person/1650> foaf:name "Wendy Hall" .
+
+<http://id.ecs.soton.ac.uk/person/2686> foaf:name "Nigel Shadbolt" .
+
+<http://id.ecs.soton.ac.uk/person/60> foaf:name "Les Carr" .
+
+<http://inamidst.com/sbp/foaf#Sean> a foaf:Person ;
+ foaf:name "Sean Palmer" .
+
+<http://my.opera.com/chaals/xml/foaf#me> foaf:name "Charles McCathieNevile" .
+
+<http://my.opera.com/howcome/xml/foaf#howcome> foaf:name "HÃ¥kon Wium Lie" .
+
+<http://myopenlink.net/dataspace/person/kidehen#this> a foaf:Person ;
+ foaf:name "Kingsley Idehen" .
+
+<http://norman.walsh.name/knows/who#norman-walsh> a foaf:Person ;
+ foaf:name "Norman Walsh" .
+
+<http://people.apache.org/~oshani/foaf.rdf#me> foaf:name "Oshani Seneviratne" .
+
+<http://people.csail.mit.edu/lkagal/foaf#me> a foaf:Person ;
+ foaf:mailbox <mailto:lalana@csail.mit.edu> ;
+ foaf:name "Lalana Kagal" .
+
+<http://people.csail.mit.edu/psz/foaf.rdf#me> foaf:name "Peter Szolovits" .
+
+<http://people.w3.org/simon/foaf#i> a foaf:Person ;
+ foaf:name "Simon J. Hernandez" .
+
+<http://qdos.com/people/tom.xrdf#me> a foaf:Person ;
+ foaf:name "Tom Ilube" .
+
+<http://research.microsoft.com/~henrikn/foaf.xml#me> foaf:name "Henrik Nielsen" .
+
+<http://rit.mellon.org/Members/ihf/foaf.rdf#me> a foaf:Person ;
+ foaf:homepage <http://www.mellon.org/about_foundation/staff/program-area-staff/irafuchs> ;
+ foaf:img <http://www.sun.com/products-n-solutions/edu/images/jelc/fuchs.jpg> ;
+ foaf:name "Ira Fuchs" .
+
+<http://teole.jfouffa.org/People/Teole/card.rdf#me> foaf:name "Philippe Le Hégaret" .
+
+<http://users.ecs.soton.ac.uk/mc/mcfoaf.rdf#me> foaf:name "mc schraefel" .
+
+<http://web.mit.edu/shinnyih/foaf.rdf#> foaf:name "Shinnyih Huang" .
+
+<http://www.aaronsw.com/about.xrdf#aaronsw> a foaf:Person ;
+ rdfs:seeAlso <http://www.aaronsw.com/about.xrdf> ;
+ foaf:mbox <mailto:me@aaronsw.com> ;
+ foaf:name "Aaron Swartz" .
+
+<http://www.cambridgesemantics.com/people/about/lee> foaf:name "Lee Feigenbaum" .
+
+<http://www.cs.umd.edu/~hendler/2003/foaf.rdf#jhendler> foaf:name "Jim Hendler" .
+
+<http://www.dajobe.org/foaf.rdf#i> a foaf:Person ;
+ foaf:mailbox <mailto:dave@dajobe.org> ;
+ foaf:name "Dave Beckett" .
+
+<http://www.isi.edu/~gil/foaf.rdf#me> a foaf:Person ;
+ foaf:name "Yolanda Gill" .
+
+<http://www.ivan-herman.net/foaf.rdf#me> foaf:mbox_sha1sum "5ac8032d5f6012aa1775ea2f63e1676bafd5e80b",
+ "c21b7ed00d78a35efcd8e567f8fd9cca71058c5",
+ "eccd01ba8ce2391a439e9b052a9fbf37eae9f732" ;
+ foaf:name "Ivan Herman" .
+
+<http://www.kjetil.kjernsmo.net/foaf#me> foaf:name "Kjetil Kjernsmo" .
+
+<http://www.lassila.org/ora.rdf#me> foaf:name "Ora Lassila" .
+
+<http://www.mindswap.org/2004/owl/mindswappers#Bijan.Parsia> foaf:name "Bijan Parsia" .
+
+<http://www.mindswap.org/2004/owl/mindswappers#Jennifer.Golbeck> foaf:name "Jennifer Golbeck" .
+
+<http://www.w3.org/People/Berners-Lee/card#amy> a foaf:Person ;
+ rdfs:label "Amy van der Hiel" ;
+ rdfs:seeAlso <http://people.w3.org/amy/foaf.rdf> ;
+ con:familyName "van der Hiel" ;
+ con:givenName "Amy" ;
+ foaf:mbox <mailto:amy@w3.org> ;
+ foaf:mbox_sha1sum "1839a1cc2e719a85ea7d9007f587b2899cd94064" ;
+ foaf:name "Amy van der Hiel" .
+
+<http://www.w3.org/People/Connolly/#me> a foaf:Person ;
+ rdfs:seeAlso <http://www.w3.org/People/Connolly/home-smart.rdf> ;
+ foaf:mbox <mailto:connolly@w3.org> ;
+ foaf:name "Dan Connolly" ;
+ foaf:nick "DanCon" .
+
+<http://www.w3.org/People/EM/contact#me> a foaf:Person ;
+ rdfs:seeAlso <http://www.w3.org/People/EM/contact> ;
+ foaf:homepage <http://purl.org/net/eric/> ;
+ foaf:img <http://www.ilrt.bristol.ac.uk/people/cmdjb/events/dc7/orig/eric.png>,
+ <http://www.oclc.org/~emiller/capture.jpg> ;
+ foaf:mbox <mailto:em@w3.org> ;
+ foaf:name "Eric Miller" .
+
+<http://www.w3.org/People/Jacobs/contact.rdf#IanJacobs> foaf:name "Ian Jacobs" .
+
+<http://www.w3.org/People/djweitzner/foaf#DJW> a foaf:Person ;
+ foaf:mbox_sha1sum "032c319f439f63efba54f4fa51bfb3a3fafedfbe" ;
+ foaf:name "Daniel J Weitzner" .
+
+<http://www.w3.org/People/karl/karl-foaf.xrdf#me> rdfs:seeAlso <http://www.w3.org/People/karl/karl-foaf.xrdf> ;
+ foaf:mbox <mailto:karl@w3.org> ;
+ foaf:name "Karl Dubost" .
+
+<http://www.w3.org/People/Berners-Lee/card#i> a foaf:Person ;
+ foaf:img <http://www.w3.org/Press/Stock/Berners-Lee/2001-europaeum-eighth.jpg> ;
+ foaf:knows [ a foaf:Person ;
+ rdfs:seeAlso <http://dannyayers.com/me.rdf> ;
+ foaf:mbox_sha1sum "669fe353dbef63d12ba11f69ace8acbec1ac8b17" ;
+ foaf:name "Danny Ayers" ],
+ <http://bblfish.net/people/henry/card#me>,
+ <http://danbri.org/foaf#danbri>,
+ <http://dbpedia.org/resource/John_Gage>,
+ <http://dbpedia.org/resource/John_Klensin>,
+ <http://dbpedia.org/resource/John_Markoff>,
+ <http://dbpedia.org/resource/John_Seely_Brown>,
+ <http://dbpedia.org/resource/Tim_Bray>,
+ <http://dig.csail.mit.edu/2007/wiki/people/JoeLambda#JL>,
+ <http://dig.csail.mit.edu/2007/wiki/people/RobertHoffmann#RMH>,
+ <http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#cm>,
+ <http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#edd>,
+ <http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#libby>,
+ <http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#ss>,
+ <http://dig.csail.mit.edu/People/RRS>,
+ <http://dig.csail.mit.edu/People/yosi#YES>,
+ <http://eikeon.com/foaf.rdf#eikeon>,
+ <http://heddley.com/edd/foaf.rdf#edd>,
+ <http://hometown.aol.com/chbussler/foaf/chbussler.foaf#me>,
+ <http://id.ecs.soton.ac.uk/person/1269>,
+ <http://id.ecs.soton.ac.uk/person/1650>,
+ <http://id.ecs.soton.ac.uk/person/2686>,
+ <http://id.ecs.soton.ac.uk/person/60>,
+ <http://inamidst.com/sbp/foaf#Sean>,
+ <http://my.opera.com/chaals/xml/foaf#me>,
+ <http://my.opera.com/howcome/xml/foaf#howcome>,
+ <http://myopenlink.net/dataspace/person/kidehen#this>,
+ <http://norman.walsh.name/knows/who#norman-walsh>,
+ <http://people.apache.org/~oshani/foaf.rdf#me>,
+ <http://people.csail.mit.edu/crowell/foaf.rdf#crowell>,
+ <http://people.csail.mit.edu/lkagal/foaf#me>,
+ <http://people.csail.mit.edu/psz/foaf.rdf#me>,
+ <http://people.csail.mit.edu/ryanlee/about#ryanlee>,
+ <http://people.w3.org/simon/foaf#i>,
+ <http://presbrey.mit.edu/foaf.rdf#presbrey>,
+ <http://qdos.com/people/tom.xrdf#me>,
+ <http://research.microsoft.com/~henrikn/foaf.xml#me>,
+ <http://rit.mellon.org/Members/ihf/foaf.rdf#me>,
+ <http://teole.jfouffa.org/People/Teole/card.rdf#me>,
+ <http://users.ecs.soton.ac.uk/mc/mcfoaf.rdf#me>,
+ <http://web.mit.edu/ruthdhan/www/foaf.rdf#ruthdhan>,
+ <http://web.mit.edu/shinnyih/foaf.rdf#>,
+ <http://www.aaronsw.com/about.xrdf#aaronsw>,
+ <http://www.cambridgesemantics.com/people/about/lee>,
+ <http://www.cs.umd.edu/~hendler/2003/foaf.rdf#jhendler>,
+ <http://www.dajobe.org/foaf.rdf#i>,
+ <http://www.isi.edu/~gil/foaf.rdf#me>,
+ <http://www.ivan-herman.net/foaf.rdf#me>,
+ <http://www.kjetil.kjernsmo.net/foaf#me>,
+ <http://www.lassila.org/ora.rdf#me>,
+ <http://www.mindswap.org/2004/owl/mindswappers#Bijan.Parsia>,
+ <http://www.mindswap.org/2004/owl/mindswappers#Jennifer.Golbeck>,
+ <http://www.w3.org/People/Berners-Lee/card#amy>,
+ <http://www.w3.org/People/Connolly/#me>,
+ <http://www.w3.org/People/EM/contact#me>,
+ <http://www.w3.org/People/Jacobs/contact.rdf#IanJacobs>,
+ <http://www.w3.org/People/djweitzner/foaf#DJW>,
+ <http://www.w3.org/People/karl/karl-foaf.xrdf#me> ;
+ foaf:name "Tim Berners-Lee" .
diff --git a/examples/foaf.rdf b/examples/foaf.rdf
deleted file mode 100644
index 8c9dbfcd..00000000
--- a/examples/foaf.rdf
+++ /dev/null
@@ -1,346 +0,0 @@
-<rdf:RDF
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:cc="http://creativecommons.org/ns#"
- xmlns:foaf="http://xmlns.com/foaf/0.1/"
- xmlns:s="http://www.w3.org/2000/01/rdf-schema#"
- xmlns:owl="http://www.w3.org/2002/07/owl#"
- xmlns:con="http://www.w3.org/2000/10/swap/pim/contact#"
- xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
- <rdf:Description rdf:about="http://dig.csail.mit.edu/2008/2002/01/tr-automation/tr.rdf">
- <dc:title>W3C Standards and Technical Reports</dc:title>
- </rdf:Description>
- <rdf:Description rdf:about="http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf">
- <cc:license rdf:resource="http://creativecommons.org/licenses/by-nc/3.0/"/>
- <dc:title>Tim Berners-Lee's FOAF file</dc:title>
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/PersonalProfileDocument"/>
- <foaf:maker rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
- <foaf:primaryTopic rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
- </rdf:Description>
- <rdf:Description rdf:about="http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#cm">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <s:seeAlso rdf:resource="http://www.koalie.net/foaf.rdf"/>
- <foaf:name>Coralie Mercier</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#dj">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <s:seeAlso rdf:resource="http://www.grorg.org/dean/foaf.rdf"/>
- <foaf:homepage rdf:resource="http://www.grorg.org/dean/"/>
- <foaf:mbox rdf:resource="mailto:dean@w3.org"/>
- <foaf:mbox rdf:resource="mailto:dino@grorg.org"/>
- <foaf:mbox_sha1sum>6de4ff27ef927b9ba21ccc88257e41a2d7e7d293</foaf:mbox_sha1sum>
- <foaf:name>Dean Jackson</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#edd">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <s:seeAlso rdf:resource="http://heddley.com/edd/foaf.rdf"/>
- <foaf:homepage rdf:resource="http://heddley.com/edd/"/>
- <foaf:mbox rdf:resource="mailto:edd@usefulinc.com"/>
- <foaf:mbox rdf:resource="mailto:edd@xml.com"/>
- <foaf:mbox rdf:resource="mailto:edd@xmlhack.com"/>
- <foaf:name>Edd Dumbill</foaf:name>
- <foaf:nick>edd</foaf:nick>
- </rdf:Description>
- <rdf:Description rdf:about="http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#libby">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <owl:sameAs rdf:resource="http://swordfish.rdfweb.org/people/libby/rdfweb/webwho.xrdf#me"/>
- <foaf:img rdf:resource="http://swordfish.rdfweb.org/~libby/libby.jpg"/>
- <foaf:mbox rdf:resource="mailto:libby.miller@bristol.ac.uk"/>
- <foaf:name>Libby Miller</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#ss">
- <foaf:name>Susie Stephens</foaf:name>
- <foaf:organization rdf:resource="http://dbpedia.org/resource/Eli_Lilly_and_Company"/>
- </rdf:Description>
- <rdf:Description rdf:about="http://bblfish.net/people/henry/card#me">
- <foaf:name>Henry Story</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://dbpedia.org/resource/John_Gage">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:img rdf:resource="http://upload.wikimedia.org/wikipedia/commons/d/de/John_Gage.jpg"/>
- <foaf:name>John Gage</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://dbpedia.org/resource/John_Klensin">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:name>John Klensin</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://dbpedia.org/resource/John_Markoff">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:name>John Markoff</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://dbpedia.org/resource/John_Seely_Brown">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <owl:sameAs rdf:resource="http://www4.wiwiss.fu-berlin.de/bookmashup/persons/John+Seely+Brown"/>
- <foaf:homepage rdf:resource="http://www.johnseelybrown.com/"/>
- <foaf:img rdf:resource="http://transliteracies.english.ucsb.edu/images/participants/t/brown-john-seely-2.jpg"/>
- <foaf:name>John Seely Brown</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://dbpedia.org/resource/Tim_Bray">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:name>Tim Bray</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://dig.csail.mit.edu/2007/01/camp/data#course">
- <foaf:maker rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
- </rdf:Description>
- <rdf:Description rdf:about="http://dig.csail.mit.edu/2007/wiki/people/JoeLambda#JL">
- <foaf:givenName>Joe</foaf:givenName><foaf:name>Joe Lambda</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://dig.csail.mit.edu/2007/wiki/people/RobertHoffmann#RMH">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:name>Robert Hoffmann</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://dig.csail.mit.edu/breadcrumbs/blog/4">
- <dc:title>timbl's blog</dc:title>
- <s:seeAlso rdf:resource="http://dig.csail.mit.edu/breadcrumbs/blog/feed/4"/>
- <foaf:maker rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
- </rdf:Description>
- <rdf:Description rdf:about="http://dig.csail.mit.edu/data#DIG">
- <foaf:member rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
- </rdf:Description>
- <rdf:Description rdf:about="http://eikeon.com/foaf.rdf#eikeon">
- <foaf:name>Daniel Krech</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://hometown.aol.com/chbussler/foaf/chbussler.foaf#me">
- <foaf:name>Christoph Bussler</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://id.ecs.soton.ac.uk/person/1269">
- <foaf:name>Nicholas Gibbins</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://id.ecs.soton.ac.uk/person/1650">
- <foaf:name>Wendy Hall</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://id.ecs.soton.ac.uk/person/2686">
- <foaf:name>Nigel Shadbolt</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://id.ecs.soton.ac.uk/person/60">
- <foaf:name>Les Carr</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://inamidst.com/sbp/foaf#Sean">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:name>Sean Palmer</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://my.opera.com/chaals/xml/foaf#me">
- <foaf:name>Charles McCathieNevile</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://my.opera.com/danbri/xml/foaf#me">
- <s:seeAlso rdf:resource="http://danbri.livejournal.com/data/foaf"/>
- <owl:sameAs rdf:resource="http://danbri.org/foaf.rdf#danbri"/>
- <owl:sameAs rdf:resource="http://www4.wiwiss.fu-berlin.de/dblp/resource/person/336851"/>
- <foaf:mbox_sha1sum>70c053d15de49ff03a1bcc374e4119b40798a66e</foaf:mbox_sha1sum>
- </rdf:Description>
- <rdf:Description rdf:about="http://my.opera.com/howcome/xml/foaf#howcome">
- <foaf:name>HÃ¥kon Wium Lie</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://myopenlink.net/dataspace/person/kidehen#this">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:name>Kingsley Idehen</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://norman.walsh.name/knows/who#norman-walsh">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:name>Norman Walsh</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://people.apache.org/~oshani/foaf.rdf#me">
- <foaf:name>Oshani Seneviratne</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://people.csail.mit.edu/lkagal/foaf#me">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:mailbox rdf:resource="mailto:lalana@csail.mit.edu"/>
- <foaf:name>Lalana Kagal</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://people.csail.mit.edu/psz/foaf.rdf#me">
- <foaf:name>Peter Szolovits</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://people.w3.org/simon/foaf#i">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:name>Simon J. Hernandez</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://qdos.com/people/tom.xrdf#me">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:name>Tom Ilube</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://research.microsoft.com/~henrikn/foaf.xml#me">
- <foaf:name>Henrik Nielsen</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://rit.mellon.org/Members/ihf/foaf.rdf#me">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:homepage rdf:resource="http://www.mellon.org/about_foundation/staff/program-area-staff/irafuchs"/>
- <foaf:img rdf:resource="http://www.sun.com/products-n-solutions/edu/images/jelc/fuchs.jpg"/>
- <foaf:name>Ira Fuchs</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://teole.jfouffa.org/People/Teole/card.rdf#me">
- <foaf:name>Philippe Le Hégaret</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://users.ecs.soton.ac.uk/mc/mcfoaf.rdf#me">
- <foaf:name>mc schraefel</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://web.mit.edu/shinnyih/foaf.rdf#">
- <foaf:name>Shinnyih Huang</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://wiki.ontoworld.org/index.php/_IRW2006">
- <dc:title>Identity, Reference and the Web workshop 2006</dc:title>
- <con:participant rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.aaronsw.com/about.xrdf#aaronsw">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <s:seeAlso rdf:resource="http://www.aaronsw.com/about.xrdf"/>
- <foaf:mbox rdf:resource="mailto:me@aaronsw.com"/>
- <foaf:name>Aaron Swartz</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.cambridgesemantics.com/people/about/lee">
- <foaf:name>Lee Feigenbaum</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.cs.umd.edu/~hendler/2003/foaf.rdf#jhendler">
- <foaf:name>Jim Hendler</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.dajobe.org/foaf.rdf#i">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:mailbox rdf:resource="mailto:dave@dajobe.org"/>
- <foaf:name>Dave Beckett</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.ecs.soton.ac.uk/~dt2/dlstuff/www2006_data#panel-panelk01">
- <s:label>The Next Wave of the Web (Plenary Panel)</s:label>
- <con:participant rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.isi.edu/~gil/foaf.rdf#me">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:name>Yolanda Gill</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.ivan-herman.net/foaf.rdf#me">
- <foaf:mbox_sha1sum>5ac8032d5f6012aa1775ea2f63e1676bafd5e80b</foaf:mbox_sha1sum>
- <foaf:mbox_sha1sum>c21b7ed00d78a35efcd8e567f8fd9cca71058c5</foaf:mbox_sha1sum>
- <foaf:mbox_sha1sum>eccd01ba8ce2391a439e9b052a9fbf37eae9f732</foaf:mbox_sha1sum>
- <foaf:name>Ivan Herman</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.kjetil.kjernsmo.net/foaf#me">
- <foaf:name>Kjetil Kjernsmo</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.lassila.org/ora.rdf#me">
- <foaf:name>Ora Lassila</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.mindswap.org/2004/owl/mindswappers#Bijan.Parsia">
- <foaf:name>Bijan Parsia</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.mindswap.org/2004/owl/mindswappers#Jennifer.Golbeck">
- <foaf:name>Jennifer Golbeck</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.w3.org/People/Berners-Lee/card#amy">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <s:label>Amy van der Hiel</s:label>
- <s:seeAlso rdf:resource="http://people.w3.org/amy/foaf.rdf"/>
- <con:familyName>van der Hiel</con:familyName>
- <con:givenName>Amy</con:givenName>
- <foaf:mbox rdf:resource="mailto:amy@w3.org"/>
- <foaf:mbox_sha1sum>1839a1cc2e719a85ea7d9007f587b2899cd94064</foaf:mbox_sha1sum>
- <foaf:name>Amy van der Hiel</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.w3.org/People/Berners-Lee/card#i">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:img rdf:resource="http://www.w3.org/Press/Stock/Berners-Lee/2001-europaeum-eighth.jpg"/>
- <foaf:name>Tim Berners-Lee</foaf:name>
- <foaf:knows rdf:resource="http://bblfish.net/people/henry/card#me"/>
- <foaf:knows rdf:resource="http://danbri.org/foaf#danbri"/>
- <foaf:knows rdf:resource="http://dbpedia.org/resource/John_Gage"/>
- <foaf:knows rdf:resource="http://dbpedia.org/resource/John_Klensin"/>
- <foaf:knows rdf:resource="http://dbpedia.org/resource/John_Markoff"/>
- <foaf:knows rdf:resource="http://dbpedia.org/resource/John_Seely_Brown"/>
- <foaf:knows rdf:resource="http://dbpedia.org/resource/Tim_Bray"/>
- <foaf:knows rdf:resource="http://dig.csail.mit.edu/2007/wiki/people/JoeLambda#JL"/>
- <foaf:knows rdf:resource="http://dig.csail.mit.edu/2007/wiki/people/RobertHoffmann#RMH"/>
- <foaf:knows rdf:resource="http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#cm"/>
- <foaf:knows rdf:resource="http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#edd"/>
- <foaf:knows rdf:resource="http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#libby"/>
- <foaf:knows rdf:resource="http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf#ss"/>
- <foaf:knows rdf:resource="http://dig.csail.mit.edu/People/RRS"/>
- <foaf:knows rdf:resource="http://dig.csail.mit.edu/People/yosi#YES"/>
- <foaf:knows rdf:resource="http://eikeon.com/foaf.rdf#eikeon"/>
- <foaf:knows rdf:resource="http://heddley.com/edd/foaf.rdf#edd"/>
- <foaf:knows rdf:resource="http://hometown.aol.com/chbussler/foaf/chbussler.foaf#me"/>
- <foaf:knows rdf:resource="http://id.ecs.soton.ac.uk/person/1269"/>
- <foaf:knows rdf:resource="http://id.ecs.soton.ac.uk/person/1650"/>
- <foaf:knows rdf:resource="http://id.ecs.soton.ac.uk/person/2686"/>
- <foaf:knows rdf:resource="http://id.ecs.soton.ac.uk/person/60"/>
- <foaf:knows rdf:resource="http://inamidst.com/sbp/foaf#Sean"/>
- <foaf:knows rdf:resource="http://my.opera.com/chaals/xml/foaf#me"/>
- <foaf:knows rdf:resource="http://my.opera.com/howcome/xml/foaf#howcome"/>
- <foaf:knows rdf:resource="http://myopenlink.net/dataspace/person/kidehen#this"/>
- <foaf:knows rdf:resource="http://norman.walsh.name/knows/who#norman-walsh"/>
- <foaf:knows rdf:resource="http://people.apache.org/~oshani/foaf.rdf#me"/>
- <foaf:knows rdf:resource="http://people.csail.mit.edu/crowell/foaf.rdf#crowell"/>
- <foaf:knows rdf:resource="http://people.csail.mit.edu/lkagal/foaf#me"/>
- <foaf:knows rdf:resource="http://people.csail.mit.edu/psz/foaf.rdf#me"/>
- <foaf:knows rdf:resource="http://people.csail.mit.edu/ryanlee/about#ryanlee"/>
- <foaf:knows rdf:resource="http://people.w3.org/simon/foaf#i"/>
- <foaf:knows rdf:resource="http://presbrey.mit.edu/foaf.rdf#presbrey"/>
- <foaf:knows rdf:resource="http://qdos.com/people/tom.xrdf#me"/>
- <foaf:knows rdf:resource="http://research.microsoft.com/~henrikn/foaf.xml#me"/>
- <foaf:knows rdf:resource="http://rit.mellon.org/Members/ihf/foaf.rdf#me"/>
- <foaf:knows rdf:resource="http://teole.jfouffa.org/People/Teole/card.rdf#me"/>
- <foaf:knows rdf:resource="http://users.ecs.soton.ac.uk/mc/mcfoaf.rdf#me"/>
- <foaf:knows rdf:resource="http://web.mit.edu/ruthdhan/www/foaf.rdf#ruthdhan"/>
- <foaf:knows rdf:resource="http://web.mit.edu/shinnyih/foaf.rdf#"/>
- <foaf:knows rdf:resource="http://www.aaronsw.com/about.xrdf#aaronsw"/>
- <foaf:knows rdf:resource="http://www.aaronsw.com/about.xrdf#aaronsw"/>
- <foaf:knows rdf:resource="http://www.cambridgesemantics.com/people/about/lee"/>
- <foaf:knows rdf:resource="http://www.cs.umd.edu/~hendler/2003/foaf.rdf#jhendler"/>
- <foaf:knows rdf:resource="http://www.dajobe.org/foaf.rdf#i"/>
- <foaf:knows rdf:resource="http://www.isi.edu/~gil/foaf.rdf#me"/>
- <foaf:knows rdf:resource="http://www.ivan-herman.net/foaf.rdf#me"/>
- <foaf:knows rdf:resource="http://www.kjetil.kjernsmo.net/foaf#me"/>
- <foaf:knows rdf:resource="http://www.lassila.org/ora.rdf#me"/>
- <foaf:knows rdf:resource="http://www.mindswap.org/2004/owl/mindswappers#Bijan.Parsia"/>
- <foaf:knows rdf:resource="http://www.mindswap.org/2004/owl/mindswappers#Jennifer.Golbeck"/>
- <foaf:knows rdf:resource="http://www.w3.org/People/Berners-Lee/card#amy"/>
- <foaf:knows rdf:resource="http://www.w3.org/People/Connolly/#me"/>
- <foaf:knows rdf:resource="http://www.w3.org/People/EM/contact#me"/>
- <foaf:knows rdf:resource="http://www.w3.org/People/Jacobs/contact.rdf#IanJacobs"/>
- <foaf:knows rdf:resource="http://www.w3.org/People/djweitzner/foaf#DJW"/>
- <foaf:knows rdf:resource="http://www.w3.org/People/karl/karl-foaf.xrdf#me"/>
- <foaf:knows rdf:parseType="Resource">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <s:seeAlso rdf:resource="http://dannyayers.com/me.rdf"/>
- <foaf:mbox_sha1sum>669fe353dbef63d12ba11f69ace8acbec1ac8b17</foaf:mbox_sha1sum>
- <foaf:name>Danny Ayers</foaf:name>
- </foaf:knows>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.w3.org/People/Connolly/#me">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <s:seeAlso rdf:resource="http://www.w3.org/People/Connolly/home-smart.rdf"/>
- <foaf:mbox rdf:resource="mailto:connolly@w3.org"/>
- <foaf:name>Dan Connolly</foaf:name>
- <foaf:nick>DanCon</foaf:nick>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.w3.org/People/EM/contact#me">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <s:seeAlso rdf:resource="http://www.w3.org/People/EM/contact"/>
- <foaf:homepage rdf:resource="http://purl.org/net/eric/"/>
- <foaf:img rdf:resource="http://www.ilrt.bristol.ac.uk/people/cmdjb/events/dc7/orig/eric.png"/>
- <foaf:img rdf:resource="http://www.oclc.org/~emiller/capture.jpg"/>
- <foaf:mbox rdf:resource="mailto:em@w3.org"/>
- <foaf:name>Eric Miller</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.w3.org/People/Jacobs/contact.rdf#IanJacobs">
- <foaf:name>Ian Jacobs</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.w3.org/People/djweitzner/foaf#DJW">
- <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
- <foaf:mbox_sha1sum>032c319f439f63efba54f4fa51bfb3a3fafedfbe</foaf:mbox_sha1sum>
- <foaf:name>Daniel J Weitzner</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.w3.org/People/karl/karl-foaf.xrdf#me">
- <s:seeAlso rdf:resource="http://www.w3.org/People/karl/karl-foaf.xrdf"/>
- <foaf:mbox rdf:resource="mailto:karl@w3.org"/>
- <foaf:name>Karl Dubost</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www.w3.org/data#W3C">
- <s:label>W3C</s:label>
- <s:seeAlso rdf:resource="http://dig.csail.mit.edu/2008/2002/01/tr-automation/tr.rdf"/>
- <con:publicHomePage rdf:resource="http://www.w3.org/"/>
- <foaf:homepage rdf:resource="http://dig.csail.mit.edu/2008/"/>
- <foaf:logo rdf:resource="http://dig.csail.mit.edu/2008/Icons/w3c_home"/>
- <foaf:name>World Wide Web Consortium</foaf:name>
- </rdf:Description>
- <rdf:Description rdf:about="http://www4.wiwiss.fu-berlin.de/booksMeshup/books/006251587X">
- <dc:creator rdf:resource="http://www.w3.org/People/Berners-Lee/card#i"/>
- <dc:title>Weaving the Web: The Original Design and Ultimate Destiny of the World Wide Web</dc:title>
- </rdf:Description>
-</rdf:RDF>
diff --git a/examples/foafpaths.py b/examples/foafpaths.py
index 4650d228..127b7f5e 100644
--- a/examples/foafpaths.py
+++ b/examples/foafpaths.py
@@ -1,10 +1,9 @@
"""
-
SPARQL 1.1 defines path operators for combining/repeating predicates
in triple-patterns.
-We overload some python operators on URIRefs to allow creating path
-operators directly in python.
+We overload some Python operators on URIRefs to allow creating path
+operators directly in Python.
============ =========================================
Operator Path
@@ -19,22 +18,21 @@ Operator Path
============ =========================================
-these can then be used in property position for ``s,p,o`` triple queries
+These can then be used in property position for ``s,p,o`` triple queries
for any graph method.
See the docs for :mod:`rdflib.paths` for the details.
This example shows how to get the name of friends with a single query.
-
"""
from rdflib import URIRef, Graph
from rdflib.namespace import FOAF
-if __name__ == '__main__':
+if __name__ == "__main__":
g = Graph()
- g.load("foaf.rdf")
+ g.load("foaf.n3", format="n3")
tim = URIRef("http://www.w3.org/People/Berners-Lee/card#i")
diff --git a/examples/graph_digest_benchmark.py b/examples/graph_digest_benchmark.py
index 678425d1..f0d0075c 100644
--- a/examples/graph_digest_benchmark.py
+++ b/examples/graph_digest_benchmark.py
@@ -1,10 +1,9 @@
#!/usr/bin/env python
-
-'''
+"""
This benchmark will produce graph digests for all of the
downloadable ontologies available in Bioportal.
-'''
+"""
from __future__ import print_function
@@ -22,7 +21,7 @@ from collections import defaultdict
from multiprocessing import Process, Semaphore, Queue
-bioportal_query = '''
+bioportal_query = """
PREFIX metadata: <http://data.bioontology.org/metadata/>
select distinct ?ontology ?title ?download where {
@@ -32,29 +31,29 @@ select distinct ?ontology ?title ?download where {
?links metadata:Ontology ?download.
filter(regex(?download, "/download"))
}
-'''
+"""
stat_cols = [
- 'id',
- 'ontology',
- 'download_url',
- 'tree_depth',
- 'color_count',
- 'individuations',
- 'prunings',
- 'initial_color_count',
- 'adjacent_nodes',
- 'initial_coloring_runtime',
- 'triple_count',
- 'graph_digest',
- 'to_hash_runtime',
- 'canonicalize_triples_runtime',
- 'error',
+ "id",
+ "ontology",
+ "download_url",
+ "tree_depth",
+ "color_count",
+ "individuations",
+ "prunings",
+ "initial_color_count",
+ "adjacent_nodes",
+ "initial_coloring_runtime",
+ "triple_count",
+ "graph_digest",
+ "to_hash_runtime",
+ "canonicalize_triples_runtime",
+ "error",
]
def files_benchmark(ontologies, output_file, threads):
- w = open(output_file, 'w')
+ w = open(output_file, "w")
writer = csv.DictWriter(w, stat_cols)
writer.writeheader()
tasks = Queue()
@@ -68,17 +67,18 @@ def files_benchmark(ontologies, output_file, threads):
stats = q.get()
og = Graph()
try:
- og.load(stats['download_url'])
- print(stats['ontology'], stats['id'])
+ og.load(stats["download_url"])
+ print(stats["ontology"], stats["id"])
ig = to_isomorphic(og)
graph_digest = ig.graph_digest(stats)
finished_tasks.put(stats)
except Exception as e:
- print('ERROR', stats['id'], e)
- stats['error'] = str(e)
+ print("ERROR", stats["id"], e)
+ stats["error"] = str(e)
finished_tasks.put(stats)
except queue.Empty:
pass
+
for i in range(int(threads)):
print("Starting worker", i)
t = Process(target=worker, args=[tasks, finished_tasks, dl_lock])
@@ -86,11 +86,13 @@ def files_benchmark(ontologies, output_file, threads):
t.start()
for download in ontologies:
stats = defaultdict(str)
- stats.update({
- "id": download.split("/")[-1].split(".")[0],
- "ontology": download.split("/")[-1].split(".")[0],
- "download_url": download
- })
+ stats.update(
+ {
+ "id": download.split("/")[-1].split(".")[0],
+ "ontology": download.split("/")[-1].split(".")[0],
+ "download_url": download,
+ }
+ )
tasks.put(stats)
tasks.close()
written_tasks = 0
@@ -104,13 +106,13 @@ def files_benchmark(ontologies, output_file, threads):
def bioportal_benchmark(apikey, output_file, threads):
metadata = Namespace("http://data.bioontology.org/metadata/")
- url = 'http://data.bioontology.org/ontologies?apikey=%s' % apikey
+ url = "http://data.bioontology.org/ontologies?apikey=%s" % apikey
ontology_graph = Graph()
print(url)
ontology_list_json = urlopen(url).read()
- ontology_graph.parse(StringIO(unicode(ontology_list_json)), format="json-ld")
+ ontology_graph.parse(StringIO(ontology_list_json), format="json-ld")
ontologies = ontology_graph.query(bioportal_query)
- w = open(output_file, 'w')
+ w = open(output_file, "w")
writer = csv.DictWriter(w, stat_cols)
writer.writeheader()
tasks = Queue()
@@ -126,19 +128,20 @@ def bioportal_benchmark(apikey, output_file, threads):
try:
try:
dl_lock.acquire()
- og.load(stats['download_url'] + "?apikey=%s" % apikey)
+ og.load(stats["download_url"] + "?apikey=%s" % apikey)
finally:
dl_lock.release()
- print(stats['ontology'], stats['id'])
+ print(stats["ontology"], stats["id"])
ig = to_isomorphic(og)
graph_digest = ig.graph_digest(stats)
finished_tasks.put(stats)
except Exception as e:
- print('ERROR', stats['id'], e)
- stats['error'] = str(e)
+ print("ERROR", stats["id"], e)
+ stats["error"] = str(e)
finished_tasks.put(stats)
- except Empty:
+ except:
pass
+
for i in range(int(threads)):
print("Starting worker", i)
t = Process(target=worker, args=[tasks, finished_tasks, dl_lock])
@@ -146,11 +149,7 @@ def bioportal_benchmark(apikey, output_file, threads):
t.start()
for ontology, title, download in ontologies:
stats = defaultdict(str)
- stats.update({
- "id": ontology,
- "ontology": title,
- "download_url": download
- })
+ stats.update({"id": ontology, "ontology": title, "download_url": download})
tasks.put(stats)
tasks.close()
written_tasks = 0
@@ -162,7 +161,7 @@ def bioportal_benchmark(apikey, output_file, threads):
written_tasks += 1
-if __name__ == '__main__':
+if __name__ == "__main__":
if len(sys.argv) > 4:
files_benchmark(sys.argv[1:-2], sys.argv[-2], sys.argv[-1])
else:
diff --git a/examples/prepared_query.py b/examples/prepared_query.py
index eb5f2b8c..95912e59 100644
--- a/examples/prepared_query.py
+++ b/examples/prepared_query.py
@@ -1,29 +1,25 @@
-
"""
-
SPARQL Queries be prepared (i.e parsed and translated to SPARQL algebra)
by the :meth:`rdflib.plugins.sparql.prepareQuery` method.
When executing, variables can be bound with the
``initBindings`` keyword parameter
-
-
"""
import rdflib
from rdflib.plugins.sparql import prepareQuery
from rdflib.namespace import FOAF
-if __name__ == '__main__':
+if __name__ == "__main__":
q = prepareQuery(
- 'SELECT ?s WHERE { ?person foaf:knows ?s .}',
- initNs={"foaf": FOAF})
+ "SELECT ?s WHERE { ?person foaf:knows ?s .}", initNs={"foaf": FOAF}
+ )
g = rdflib.Graph()
- g.load("foaf.rdf")
+ g.load("foaf.n3", format="n3")
tim = rdflib.URIRef("http://www.w3.org/People/Berners-Lee/card#i")
- for row in g.query(q, initBindings={'person': tim}):
+ for row in g.query(q, initBindings={"person": tim}):
print(row)
diff --git a/examples/rdfa_example.py b/examples/rdfa_example.py
index e49bebbc..30462541 100644
--- a/examples/rdfa_example.py
+++ b/examples/rdfa_example.py
@@ -1,22 +1,24 @@
"""
-
A simple example showing how to process RDFa from the web
-
"""
from rdflib import Graph
-if __name__ == '__main__':
+if __name__ == "__main__":
g = Graph()
- g.parse('http://www.worldcat.org/title/library-of-babel/oclc/44089369', format='rdfa')
+ g.parse(
+ "https://www.worldcat.org/title/library-of-babel/oclc/44089369", format="rdfa"
+ )
print("Books found:")
- for row in g.query("""SELECT ?title ?author WHERE {
+ for row in g.query(
+ """SELECT ?title ?author WHERE {
[ a schema:Book ;
schema:author [ rdfs:label ?author ] ;
schema:name ?title ]
- FILTER (LANG(?title) = 'en') } """):
+ FILTER (LANG(?title) = 'en') } """
+ ):
print("%s by %s" % (row.title, row.author))
diff --git a/examples/resource.py b/examples/resource.py
index d676ae5f..e82ad0b0 100644
--- a/examples/resource.py
+++ b/examples/resource.py
@@ -1,29 +1,26 @@
"""
-
RDFLib has a :class:`~rdflib.resource.Resource` class, for a resource-centric API.
A resource acts like a URIRef with an associated graph, and allows
quickly adding or querying for triples where this resource is the
subject.
-
-
"""
from rdflib import Graph, RDF, RDFS, Literal
from rdflib.namespace import FOAF
-if __name__ == '__main__':
+if __name__ == "__main__":
g = Graph()
- bob = g.resource('urn:bob')
+ bob = g.resource("urn:bob")
bob.set(RDF.type, FOAF.Person) # .set replaces all other values
bob.set(FOAF.name, Literal("Bob"))
- bill = g.resource('urn:bill')
+ bill = g.resource("urn:bill")
- bill.add(RDF.type, FOAF.Person) # add adds to existing values
+ bill.add(RDF.type, FOAF.Person) # adds to existing values
bill.add(RDF.type, FOAF.Agent)
bill.set(RDFS.label, Literal("Bill"))
diff --git a/examples/simple_example.py b/examples/simple_example.py
index ef5ec73a..15ae0d81 100644
--- a/examples/simple_example.py
+++ b/examples/simple_example.py
@@ -1,8 +1,7 @@
-
from rdflib import Graph, Literal, BNode, RDF
from rdflib.namespace import FOAF, DC
-if __name__ == '__main__':
+if __name__ == "__main__":
store = Graph()
@@ -24,29 +23,37 @@ if __name__ == '__main__':
print(s, p, o)
# For each foaf:Person in the store print out its mbox property.
+ print()
print("--- printing mboxes ---")
for person in store.subjects(RDF.type, FOAF["Person"]):
for mbox in store.objects(person, FOAF["mbox"]):
print(mbox)
+ print("--- saving RDF to a file (donna_foaf.rdf) ---")
# Serialize the store as RDF/XML to the file donna_foaf.rdf.
store.serialize("donna_foaf.rdf", format="pretty-xml", max_depth=3)
# Let's show off the serializers
-
+ print()
print("RDF Serializations:")
# Serialize as XML
print("--- start: rdf-xml ---")
- print(store.serialize(format="pretty-xml"))
+ print(store.serialize(format="pretty-xml").decode("utf-8"))
print("--- end: rdf-xml ---\n")
# Serialize as Turtle
print("--- start: turtle ---")
- print(store.serialize(format="turtle"))
+ print(store.serialize(format="turtle").decode("utf-8"))
print("--- end: turtle ---\n")
# Serialize as NTriples
print("--- start: ntriples ---")
- print(store.serialize(format="nt"))
+ print(store.serialize(format="nt").decode("utf-8"))
print("--- end: ntriples ---\n")
+
+ # Serialize as JSON-LD
+ # only if you have the JSON-LD plugin installed!
+ print("--- start: JSON-LD ---")
+ print(store.serialize(format="json-ld").decode("utf-8"))
+ print("--- end: JSON-LD ---\n")
diff --git a/examples/sleepycat_example.py b/examples/sleepycat_example.py
index b112717e..1130da0e 100644
--- a/examples/sleepycat_example.py
+++ b/examples/sleepycat_example.py
@@ -1,8 +1,6 @@
"""
-
A simple example showing how to use a Sleepycat store to do on-disk
persistence.
-
"""
from rdflib import ConjunctiveGraph, Namespace, Literal
@@ -10,33 +8,33 @@ from rdflib.store import NO_STORE, VALID_STORE
from tempfile import mktemp
-if __name__ == '__main__':
+if __name__ == "__main__":
path = mktemp()
# Open previously created store, or create it if it doesn't exist yet
- graph = ConjunctiveGraph('Sleepycat')
+ graph = ConjunctiveGraph("Sleepycat")
rt = graph.open(path, create=False)
if rt == NO_STORE:
- # There is no underlying Sleepycat infrastructure, create it
+ # There is no underlying Sleepycat infrastructure, so create it
graph.open(path, create=True)
else:
- assert rt == VALID_STORE, 'The underlying store is corrupt'
+ assert rt == VALID_STORE, "The underlying store is corrupt"
- print('Triples in graph before add: ', len(graph))
+ print("Triples in graph before add: ", len(graph))
# Now we'll add some triples to the graph & commit the changes
- rdflib = Namespace('http://rdflib.net/test/')
- graph.bind('test', 'http://rdflib.net/test/')
+ rdflib = Namespace("http://rdflib.net/test/")
+ graph.bind("test", "http://rdflib.net/test/")
- graph.add((rdflib['pic:1'], rdflib.name, Literal('Jane & Bob')))
- graph.add((rdflib['pic:2'], rdflib.name, Literal('Squirrel in Tree')))
+ graph.add((rdflib["pic:1"], rdflib.name, Literal("Jane & Bob")))
+ graph.add((rdflib["pic:2"], rdflib.name, Literal("Squirrel in Tree")))
- print('Triples in graph after add: ', len(graph))
+ print("Triples in graph after add: ", len(graph))
# display the graph in RDF/XML
- print(graph.serialize(format='n3'))
+ print(graph.serialize(format="n3"))
# close when done, otherwise sleepycat will leak lock entries.
graph.close()
@@ -45,16 +43,17 @@ if __name__ == '__main__':
# reopen the graph
- graph = ConjunctiveGraph('Sleepycat')
+ graph = ConjunctiveGraph("Sleepycat")
graph.open(path, create=False)
- print('Triples still in graph: ', len(graph))
+ print("Triples still in graph: ", len(graph))
graph.close()
# Clean up the temp folder to remove the Sleepycat database files...
import os
+
for f in os.listdir(path):
- os.unlink(path + '/' + f)
+ os.unlink(path + "/" + f)
os.rmdir(path)
diff --git a/examples/slice.py b/examples/slice.py
index 525edb95..eaab1540 100644
--- a/examples/slice.py
+++ b/examples/slice.py
@@ -1,5 +1,4 @@
"""
-
RDFLib Graphs (and Resources) can be "sliced" with [] syntax
This is a short-hand for iterating over triples
@@ -8,21 +7,20 @@ Combined with SPARQL paths (see ``foafpaths.py``) - quite complex queries
can be realised.
See :meth:`rdflib.graph.Graph.__getitem__` for details
-
"""
from rdflib import Graph, RDF
from rdflib.namespace import FOAF
-if __name__ == '__main__':
+if __name__ == "__main__":
graph = Graph()
- graph.load("foaf.rdf")
+ graph.load("foaf.n3", format="n3")
for person in graph[: RDF.type: FOAF.Person]:
- friends = list(graph[person:FOAF.knows * '+' / FOAF.name])
+ friends = list(graph[person: FOAF.knows * "+" / FOAF.name])
if friends:
print("%s's circle of friends:" % graph.value(person, FOAF.name))
for name in friends:
diff --git a/examples/smushing.py b/examples/smushing.py
index 3b174f83..c1c3cb8b 100644
--- a/examples/smushing.py
+++ b/examples/smushing.py
@@ -4,7 +4,7 @@ A FOAF smushing example.
Filter a graph by normalizing all ``foaf:Persons`` into URIs based on
their ``mbox_sha1sum``.
-Suppose I got two `FOAF <http://xmlns.com/foaf/0.1>`_ documents each
+Suppose I get two `FOAF <http://xmlns.com/foaf/0.1>`_ documents each
talking about the same person (according to ``mbox_sha1sum``) but they
each used a :class:`rdflib.term.BNode` for the subject. For this demo
I've combined those two documents into one file:
@@ -19,7 +19,6 @@ without having to access my ever-growing archive. Even if another
``65b983bb397fb71849da910996741752ace8369b`` document comes in next
year, I would still give it the same stable subject URI that merges
with my existing data.
-
"""
from rdflib import Graph, Namespace
@@ -27,20 +26,20 @@ from rdflib.namespace import FOAF
STABLE = Namespace("http://example.com/person/mbox_sha1sum/")
-if __name__ == '__main__':
+if __name__ == "__main__":
g = Graph()
g.parse("smushingdemo.n3", format="n3")
newURI = {} # old subject : stable uri
- for s, p, o in g.triples((None, FOAF['mbox_sha1sum'], None)):
+ for s, p, o in g.triples((None, FOAF["mbox_sha1sum"], None)):
newURI[s] = STABLE[o]
out = Graph()
- out.bind('foaf', FOAF)
+ out.bind("foaf", FOAF)
for s, p, o in g:
s = newURI.get(s, s)
o = newURI.get(o, o) # might be linked to another person
out.add((s, p, o))
- print(out.serialize(format="n3").decode('utf-8'))
+ print(out.serialize(format="n3").decode("utf-8"))
diff --git a/examples/sparql_query_example.py b/examples/sparql_query_example.py
index b1ffff5f..ce84b17d 100644
--- a/examples/sparql_query_example.py
+++ b/examples/sparql_query_example.py
@@ -1,6 +1,4 @@
-
"""
-
SPARQL Query using :meth:`rdflib.graph.Graph.query`
The method returns a :class:`~rdflib.query.Result`, iterating over
@@ -11,20 +9,18 @@ For variable names that are not valid python identifiers, dict access
(i.e. with ``row[var] / __getitem__``) is also possible.
:attr:`~rdflib.query.ResultRow.vars` contains the variables
-
"""
import rdflib
-if __name__ == '__main__':
+if __name__ == "__main__":
g = rdflib.Graph()
- g.load("foaf.rdf")
+ g.load("foaf.n3", format="n3")
# the QueryProcessor knows the FOAF prefix from the graph
- # which in turn knows it from reading the RDF/XML file
- for row in g.query(
- 'select ?s where { [] foaf:knows ?s .}'):
+ # which in turn knows it from reading the N3 RDF file
+ for row in g.query("SELECT ?s WHERE { [] foaf:knows ?s .}"):
print(row.s)
# or row["s"]
# or row[rdflib.Variable("s")]
diff --git a/examples/sparql_update_example.py b/examples/sparql_update_example.py
index a604eebd..fd7bce4e 100644
--- a/examples/sparql_update_example.py
+++ b/examples/sparql_update_example.py
@@ -1,26 +1,25 @@
-
"""
-
SPARQL Update statements can be applied with :meth:`rdflib.graph.Graph.update`
-
"""
import rdflib
-if __name__ == '__main__':
+if __name__ == "__main__":
g = rdflib.Graph()
- g.load("foaf.rdf")
-
- g.update('''
- PREFIX foaf: <http://xmlns.com/foaf/0.1/>
- PREFIX dbpedia: <http://dbpedia.org/resource/>
- INSERT
- { ?s a dbpedia:Human . }
- WHERE
- { ?s a foaf:Person . }
- ''')
-
- for x in g.subjects(
- rdflib.RDF.type, rdflib.URIRef('http://dbpedia.org/resource/Human')):
- print(x)
+ g.load("foaf.n3", format="n3")
+
+ print("Initially there are {} triples in the graph".format(len(g)))
+
+ g.update(
+ """
+ PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+ PREFIX dbpedia: <http://dbpedia.org/resource/>
+ INSERT
+ { ?s a dbpedia:Human . }
+ WHERE
+ { ?s a foaf:Person . }
+ """
+ )
+
+ print("After the UPDATE, there are {} triples in the graph".format(len(g)))
diff --git a/examples/sparqlstore_example.py b/examples/sparqlstore_example.py
index afef011d..874d6183 100644
--- a/examples/sparqlstore_example.py
+++ b/examples/sparqlstore_example.py
@@ -1,23 +1,29 @@
"""
-
A simple example showing how to use the SPARQLStore
-
"""
+import locale
from rdflib import Graph, URIRef, Namespace
+from rdflib.plugins.stores.sparqlstore import SPARQLStore
-if __name__ == '__main__':
-
- dbo = Namespace('http://dbpedia.org/ontology/')
+if __name__ == "__main__":
- graph = Graph('SPARQLStore', identifier="http://dbpedia.org")
+ dbo = Namespace("http://dbpedia.org/ontology/")
+ # using a Graph with the Store type string set to "SPARQLStore"
+ graph = Graph("SPARQLStore", identifier="http://dbpedia.org")
graph.open("http://dbpedia.org/sparql")
pop = graph.value(
URIRef("http://dbpedia.org/resource/Berlin"),
dbo.populationTotal)
- print(graph.store.queryString)
+ print("According to DBPedia, Berlin has a population of {0:,}".format(int(pop), ',d').replace(",", "."))
- print("According to DBPedia Berlin has a population of", pop)
+ # using a SPARQLStore object directly
+ s = SPARQLStore(endpoint="http://dbpedia.org/sparql")
+ s.open(None)
+ pop = graph.value(
+ URIRef("http://dbpedia.org/resource/Brisbane"),
+ dbo.populationTotal)
+ print("According to DBPedia, Brisbane has a population of " "{0:,}".format(int(pop), ',d'))
diff --git a/examples/swap_primer.py b/examples/swap_primer.py
index dacb92e4..e3adc298 100644
--- a/examples/swap_primer.py
+++ b/examples/swap_primer.py
@@ -1,65 +1,70 @@
"""
-
This is a simple primer using some of the
example stuff in the Primer on N3:
http://www.w3.org/2000/10/swap/Primer
-
"""
-# Load up RDFLib
-
-from rdflib import ConjunctiveGraph, Namespace, Literal
+from rdflib import ConjunctiveGraph, Namespace, Literal, URIRef
from rdflib.namespace import OWL, DC
-if __name__ == '__main__':
+if __name__ == "__main__":
# Firstly, it doesn't have to be so complex.
# Here we create a "Graph" of our work.
# Think of it as a blank piece of graph paper!
primer = ConjunctiveGraph()
- myNS = Namespace('#')
+ myNS = Namespace("#")
primer.add((myNS.pat, myNS.knows, myNS.jo))
# or:
- primer.add((myNS['pat'], myNS['age'], Literal(24)))
+ primer.add((myNS["pat"], myNS["age"], Literal(24)))
# Now, with just that, lets see how the system
# recorded *way* too many details about what
# you just asserted as fact.
- #
from pprint import pprint
+
+ print("All the things in the Graph:")
pprint(list(primer))
# just think .whatever((s, p, o))
# here we report on what we know
+ print("==================")
+
+ print("Subjects:")
pprint(list(primer.subjects()))
+ print("Predicates:")
pprint(list(primer.predicates()))
+ print("Objects:")
pprint(list(primer.objects()))
+ print("==================")
# and other things that make sense
- # what do we know about pat?
+ print("What we know about pat:")
pprint(list(primer.predicate_objects(myNS.pat)))
- # who is what age?
+ print("Who is what age?")
pprint(list(primer.subject_objects(myNS.age)))
+ print("==================")
+ print("==================")
+
# Okay, so lets now work with a bigger
# dataset from the example, and start
# with a fresh new graph.
+ del(primer)
primer = ConjunctiveGraph()
# Lets start with a verbatim string straight from the primer text:
mySource = """
-
-
- @prefix : <http://www.w3.org/2000/10/swap/Primer#>.
+ @prefix : <#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@@ -92,9 +97,6 @@ if __name__ == '__main__':
:Woman = foo:FemaleAdult .
:Title a rdf:Property; = dc:title .
-
-
-
""" # --- End of primer code
# To make this go easier to spit back out...
@@ -103,28 +105,38 @@ if __name__ == '__main__':
# By default, your main namespace is the URI of your
# current working directory, so lets make that simpler:
- myNS = Namespace('http://www.w3.org/2000/10/swap/Primer#')
- primer.bind('', myNS)
- primer.bind('owl', OWL)
- primer.bind('dc', DC)
- primer.bind('swap', 'http://www.w3.org/2000/10/swap/')
+ primer.bind("owl", OWL)
+ primer.bind("dc", DC)
+ primer.bind("swap", "http://www.w3.org/2000/10/swap/")
# Lets load it up!
- primer.parse(data=mySource, format='n3')
+ primer.parse(data=mySource, format="n3")
# Now you can query, either directly straight into a list:
- [(x, y, z) for x, y, z in primer]
+ print()
+ print("Printing bigger example's triples:")
+ for i in [(x, y, z) for x, y, z in primer]:
+ print(i)
# or spit it back out (mostly) the way we created it:
- print(primer.serialize(format='n3'))
+ print()
+ print("Printing bigger example as N3:")
+ print(primer.serialize(format="n3").decode("utf-8"))
# for more insight into things already done, lets see the namespaces
- list(primer.namespaces())
+ print()
+ print("Printing bigger example's namespaces:")
+ for n in list(primer.namespaces()):
+ print(n)
- # lets ask something about the data
+ # lets ask something about the data, using a SPARQL query
- list(primer.objects(myNS.pat, myNS.child))
+ print()
+ print("Who are pat's children?")
+ q = "SELECT ?child WHERE { :pat :child ?child }"
+ for r in primer.query(q):
+ print(r)
diff --git a/examples/transitive.py b/examples/transitive.py
index 5251ea79..432b3723 100644
--- a/examples/transitive.py
+++ b/examples/transitive.py
@@ -1,5 +1,4 @@
"""
-
An example illustrating how to use the
:meth:`~rdflib.graph.Graph.transitive_subjects` and
:meth:`~rdflib.graph.Graph.transitive_objects` graph methods
@@ -42,21 +41,20 @@ User-defined transitive closures
The method :meth:`~rdflib.graph.Graph.transitiveClosure` returns
transtive closures of user-defined functions.
-
"""
-if __name__ == '__main__':
+if __name__ == "__main__":
from rdflib import ConjunctiveGraph, URIRef
- person = URIRef('ex:person')
- dad = URIRef('ex:d')
- mom = URIRef('ex:m')
- momOfDad = URIRef('ex:gm0')
- momOfMom = URIRef('ex:gm1')
- dadOfDad = URIRef('ex:gf0')
- dadOfMom = URIRef('ex:gf1')
+ person = URIRef("ex:person")
+ dad = URIRef("ex:d")
+ mom = URIRef("ex:m")
+ momOfDad = URIRef("ex:gm0")
+ momOfMom = URIRef("ex:gm1")
+ dadOfDad = URIRef("ex:gf0")
+ dadOfMom = URIRef("ex:gf1")
- parent = URIRef('ex:parent')
+ parent = URIRef("ex:parent")
g = ConjunctiveGraph()
g.add((person, parent, dad))
diff --git a/rdflib/__init__.py b/rdflib/__init__.py
index 29cc681c..3256f12d 100644
--- a/rdflib/__init__.py
+++ b/rdflib/__init__.py
@@ -45,8 +45,8 @@ A tiny example:
__docformat__ = "restructuredtext en"
# The format of the __version__ line is matched by a regex in setup.py
-__version__ = "5.0.0-dev"
-__date__ = "2017/01/29"
+__version__ = "5.0.0"
+__date__ = "2020-04-03"
__all__ = [
'URIRef',
@@ -60,10 +60,9 @@ __all__ = [
'Graph',
'ConjunctiveGraph',
- 'RDF',
- 'RDFS',
- 'OWL',
- 'XSD',
+ 'CSVW', 'DC', 'DCAT', 'DCTERMS', 'DOAP', 'FOAF', 'ODRL2', 'ORG', 'OWL',
+ 'PROF', 'PROV', 'RDF', 'RDFS', 'SDO', 'SH', 'SKOS', 'SOSA', 'SSN', 'TIME',
+ 'VOID', 'XMLNS', 'XSD',
'util',
]
@@ -163,7 +162,9 @@ from rdflib.namespace import Namespace
from rdflib.graph import Dataset, Graph, ConjunctiveGraph
-from rdflib.namespace import RDF, RDFS, OWL, XSD
+from rdflib.namespace import CSVW, DC, DCAT, DCTERMS, DOAP, FOAF, ODRL2, ORG, OWL, \
+ PROF, PROV, RDF, RDFS, SDO, SH, SKOS, SOSA, SSN, TIME, \
+ VOID, XMLNS, XSD
from rdflib import plugin
from rdflib import query
diff --git a/rdflib/graph.py b/rdflib/graph.py
index 4a27e6de..efd58eba 100644
--- a/rdflib/graph.py
+++ b/rdflib/graph.py
@@ -3,9 +3,11 @@ from __future__ import division
from __future__ import print_function
from rdflib.term import Literal # required for doctests
-assert Literal # avoid warning
+
+assert Literal # avoid warning
from rdflib.namespace import Namespace # required for doctests
-assert Namespace # avoid warning
+
+assert Namespace # avoid warning
__doc__ = """\
@@ -88,13 +90,13 @@ Instantiating Graphs with a IOMemory store and an identifier -
>>> g = Graph('IOMemory', URIRef("http://rdflib.net"))
>>> g.identifier
- rdflib.term.URIRef(u'http://rdflib.net')
- >>> str(g) # doctest: +NORMALIZE_WHITESPACE
+ rdflib.term.URIRef('http://rdflib.net')
+ >>> str(g) # doctest: +NORMALIZE_WHITESPACE
"<http://rdflib.net> a rdfg:Graph;rdflib:storage
[a rdflib:Store;rdfs:label 'IOMemory']."
Creating a ConjunctiveGraph - The top level container for all named Graphs
-in a 'database':
+in a "database":
>>> g = ConjunctiveGraph()
>>> str(g.default_context)
@@ -109,7 +111,7 @@ via triple pattern:
0
>>> g.add((statementId, RDF.type, RDF.Statement))
>>> g.add((statementId, RDF.subject,
- ... URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
+ ... URIRef("http://rdflib.net/store/ConjunctiveGraph")))
>>> g.add((statementId, RDF.predicate, RDFS.label))
>>> g.add((statementId, RDF.object, Literal("Conjunctive Graph")))
>>> print(len(g))
@@ -145,11 +147,11 @@ by RDFLib they are UUIDs and unique.
>>> g1 = Graph()
>>> g2 = Graph()
- >>> u = URIRef(u'http://example.com/foo')
- >>> g1.add([u, RDFS.label, Literal('foo')])
- >>> g1.add([u, RDFS.label, Literal('bar')])
- >>> g2.add([u, RDFS.label, Literal('foo')])
- >>> g2.add([u, RDFS.label, Literal('bing')])
+ >>> u = URIRef("http://example.com/foo")
+ >>> g1.add([u, RDFS.label, Literal("foo")])
+ >>> g1.add([u, RDFS.label, Literal("bar")])
+ >>> g2.add([u, RDFS.label, Literal("foo")])
+ >>> g2.add([u, RDFS.label, Literal("bing")])
>>> len(g1 + g2) # adds bing as label
3
>>> len(g1 - g2) # removes foo
@@ -162,7 +164,7 @@ by RDFLib they are UUIDs and unique.
Graph Aggregation - ConjunctiveGraphs and ReadOnlyGraphAggregate within
the same store:
- >>> store = plugin.get('IOMemory', Store)()
+ >>> store = plugin.get("IOMemory", Store)()
>>> g1 = Graph(store)
>>> g2 = Graph(store)
>>> g3 = Graph(store)
@@ -171,21 +173,21 @@ the same store:
>>> stmt3 = BNode()
>>> g1.add((stmt1, RDF.type, RDF.Statement))
>>> g1.add((stmt1, RDF.subject,
- ... URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
+ ... URIRef('http://rdflib.net/store/ConjunctiveGraph')))
>>> g1.add((stmt1, RDF.predicate, RDFS.label))
- >>> g1.add((stmt1, RDF.object, Literal("Conjunctive Graph")))
+ >>> g1.add((stmt1, RDF.object, Literal('Conjunctive Graph')))
>>> g2.add((stmt2, RDF.type, RDF.Statement))
>>> g2.add((stmt2, RDF.subject,
- ... URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
+ ... URIRef('http://rdflib.net/store/ConjunctiveGraph')))
>>> g2.add((stmt2, RDF.predicate, RDF.type))
>>> g2.add((stmt2, RDF.object, RDFS.Class))
>>> g3.add((stmt3, RDF.type, RDF.Statement))
>>> g3.add((stmt3, RDF.subject,
- ... URIRef(u'http://rdflib.net/store/ConjunctiveGraph')))
+ ... URIRef('http://rdflib.net/store/ConjunctiveGraph')))
>>> g3.add((stmt3, RDF.predicate, RDFS.comment))
>>> g3.add((stmt3, RDF.object, Literal(
- ... "The top-level aggregate graph - The sum " +
- ... "of all named graphs within a Store")))
+ ... 'The top-level aggregate graph - The sum ' +
+ ... 'of all named graphs within a Store')))
>>> len(list(ConjunctiveGraph(store).subjects(RDF.type, RDF.Statement)))
3
>>> len(list(ReadOnlyGraphAggregate([g1,g2]).subjects(
@@ -219,41 +221,31 @@ Parsing N3 from a string
... rdf:predicate rdfs:label;
... rdf:object "Conjunctive Graph" ] .
... '''
- >>> g2 = g2.parse(data=src, format='n3')
+ >>> g2 = g2.parse(data=src, format="n3")
>>> print(len(g2))
4
Using Namespace class:
- >>> RDFLib = Namespace('http://rdflib.net/')
+ >>> RDFLib = Namespace("http://rdflib.net/")
>>> RDFLib.ConjunctiveGraph
- rdflib.term.URIRef(u'http://rdflib.net/ConjunctiveGraph')
- >>> RDFLib['Graph']
- rdflib.term.URIRef(u'http://rdflib.net/Graph')
+ rdflib.term.URIRef('http://rdflib.net/ConjunctiveGraph')
+ >>> RDFLib["Graph"]
+ rdflib.term.URIRef('http://rdflib.net/Graph')
"""
import logging
+
logger = logging.getLogger(__name__)
-# import md5
import random
-import warnings
-
-from hashlib import md5
-
-
from rdflib.namespace import RDF, RDFS, SKOS
-
from rdflib import plugin, exceptions, query
-
from rdflib.term import Node, URIRef, Genid
from rdflib.term import BNode
-
import rdflib.term
-
from rdflib.paths import Path
-
from rdflib.store import Store
from rdflib.serializer import Serializer
from rdflib.parser import Parser
@@ -271,16 +263,22 @@ from six import b
from six.moves.urllib.parse import urlparse
__all__ = [
- 'Graph', 'ConjunctiveGraph', 'QuotedGraph', 'Seq',
- 'ModificationException', 'Dataset',
- 'UnSupportedAggregateOperation', 'ReadOnlyGraphAggregate']
+ "Graph",
+ "ConjunctiveGraph",
+ "QuotedGraph",
+ "Seq",
+ "ModificationException",
+ "Dataset",
+ "UnSupportedAggregateOperation",
+ "ReadOnlyGraphAggregate",
+]
class Graph(Node):
"""An RDF Graph
- The constructor accepts one argument, the 'store'
- that will be used to store the graph data (see the 'store'
+ The constructor accepts one argument, the "store"
+ that will be used to store the graph data (see the "store"
package for stores currently shipped with rdflib).
Stores can be context-aware or unaware. Unaware stores take up
@@ -291,12 +289,11 @@ class Graph(Node):
The Graph constructor can take an identifier which identifies the Graph
by name. If none is given, the graph is assigned a BNode for its
identifier.
- For more on named graphs, see: http://www.w3.org/2004/03/trix/
+ For more on named graphs, see: http://www.w3.org/2004/03/trix/
"""
- def __init__(self, store='default', identifier=None,
- namespace_manager=None):
+ def __init__(self, store="default", identifier=None, namespace_manager=None):
super(Graph, self).__init__()
self.__identifier = identifier or BNode()
@@ -315,10 +312,12 @@ class Graph(Node):
def __get_store(self):
return self.__store
+
store = property(__get_store) # read-only attr
def __get_identifier(self):
return self.__identifier
+
identifier = property(__get_identifier) # read-only attr
def _get_namespace_manager(self):
@@ -329,23 +328,24 @@ class Graph(Node):
def _set_namespace_manager(self, nm):
self.__namespace_manager = nm
- namespace_manager = property(_get_namespace_manager,
- _set_namespace_manager,
- doc="this graph's namespace-manager")
+ namespace_manager = property(
+ _get_namespace_manager,
+ _set_namespace_manager,
+ doc="this graph's namespace-manager",
+ )
def __repr__(self):
return "<Graph identifier=%s (%s)>" % (self.identifier, type(self))
def __str__(self):
if isinstance(self.identifier, URIRef):
- return ("%s a rdfg:Graph;rdflib:storage " +
- "[a rdflib:Store;rdfs:label '%s'].") % (
- self.identifier.n3(),
- self.store.__class__.__name__)
+ return (
+ "%s a rdfg:Graph;rdflib:storage " + "[a rdflib:Store;rdfs:label '%s']."
+ ) % (self.identifier.n3(), self.store.__class__.__name__)
else:
- return ("[a rdfg:Graph;rdflib:storage " +
- "[a rdflib:Store;rdfs:label '%s']].") % (
- self.store.__class__.__name__)
+ return (
+ "[a rdfg:Graph;rdflib:storage " + "[a rdflib:Store;rdfs:label '%s']]."
+ ) % self.store.__class__.__name__
def toPython(self):
return self
@@ -377,28 +377,26 @@ class Graph(Node):
Might be necessary for stores that require closing a connection to a
database or releasing some resource.
"""
- self.__store.close(
- commit_pending_transaction=commit_pending_transaction)
+ self.__store.close(commit_pending_transaction=commit_pending_transaction)
def add(self, triple):
"""Add a triple with self as context"""
s, p, o = triple
- assert isinstance(s, Node), \
- "Subject %s must be an rdflib term" % (s,)
- assert isinstance(p, Node), \
- "Predicate %s must be an rdflib term" % (p,)
- assert isinstance(o, Node), \
- "Object %s must be an rdflib term" % (o,)
+ assert isinstance(s, Node), "Subject %s must be an rdflib term" % (s,)
+ assert isinstance(p, Node), "Predicate %s must be an rdflib term" % (p,)
+ assert isinstance(o, Node), "Object %s must be an rdflib term" % (o,)
self.__store.add((s, p, o), self, quoted=False)
def addN(self, quads):
"""Add a sequence of triple with context"""
- self.__store.addN((s, p, o, c) for s, p, o, c in quads
- if isinstance(c, Graph) and
- c.identifier is self.identifier and
- _assertnode(s, p, o)
- )
+ self.__store.addN(
+ (s, p, o, c)
+ for s, p, o, c in quads
+ if isinstance(c, Graph)
+ and c.identifier is self.identifier
+ and _assertnode(s, p, o)
+ )
def remove(self, triple):
"""Remove a triple from the graph
@@ -417,10 +415,10 @@ class Graph(Node):
s, p, o = triple
if isinstance(p, Path):
for _s, _o in p.eval(self, s, o):
- yield (_s, p, _o)
+ yield _s, p, _o
else:
for (s, p, o), cg in self.__store.triples((s, p, o), context=self):
- yield (s, p, o)
+ yield s, p, o
def __getitem__(self, item):
"""
@@ -431,16 +429,16 @@ class Graph(Node):
>>> import rdflib
>>> g = rdflib.Graph()
- >>> g.add((rdflib.URIRef('urn:bob'), rdflib.RDFS.label, rdflib.Literal('Bob')))
+ >>> g.add((rdflib.URIRef("urn:bob"), rdflib.RDFS.label, rdflib.Literal("Bob")))
- >>> list(g[rdflib.URIRef('urn:bob')]) # all triples about bob
- [(rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'), rdflib.term.Literal(u'Bob'))]
+ >>> list(g[rdflib.URIRef("urn:bob")]) # all triples about bob
+ [(rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'), rdflib.term.Literal('Bob'))]
>>> list(g[:rdflib.RDFS.label]) # all label triples
- [(rdflib.term.URIRef(u'urn:bob'), rdflib.term.Literal(u'Bob'))]
+ [(rdflib.term.URIRef('urn:bob'), rdflib.term.Literal('Bob'))]
- >>> list(g[::rdflib.Literal('Bob')]) # all triples with bob as object
- [(rdflib.term.URIRef(u'urn:bob'), rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'))]
+ >>> list(g[::rdflib.Literal("Bob")]) # all triples with bob as object
+ [(rdflib.term.URIRef('urn:bob'), rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'))]
Combined with SPARQL paths, more complex queries can be
written concisely:
@@ -455,7 +453,7 @@ class Graph(Node):
All friends and friends of friends of Bob
- g[bob : FOAF.knows * '+']
+ g[bob : FOAF.knows * "+"]
etc.
@@ -489,7 +487,9 @@ class Graph(Node):
return self.predicate_objects(item)
else:
- raise TypeError("You can only index a graph by a single rdflib term or path, or a slice of rdflib terms.")
+ raise TypeError(
+ "You can only index a graph by a single rdflib term or path, or a slice of rdflib terms."
+ )
def __len__(self):
"""Returns the number of triples in the graph
@@ -516,7 +516,9 @@ class Graph(Node):
if other is None:
return -1
elif isinstance(other, Graph):
- return cmp(self.identifier, other.identifier)
+ return (self.identifier > other.identifier) - (
+ self.identifier < other.identifier
+ )
else:
# Note if None is considered equivalent to owl:Nothing
# Then perhaps a graph with length 0 should be considered
@@ -524,21 +526,20 @@ class Graph(Node):
return 1
def __eq__(self, other):
- return isinstance(other, Graph) \
- and self.identifier == other.identifier
+ return isinstance(other, Graph) and self.identifier == other.identifier
def __lt__(self, other):
- return (other is None) \
- or (isinstance(other, Graph) and
- self.identifier < other.identifier)
+ return (other is None) or (
+ isinstance(other, Graph) and self.identifier < other.identifier
+ )
def __le__(self, other):
return self < other or self == other
def __gt__(self, other):
- return (isinstance(other, Graph) and
- self.identifier > other.identifier) \
- or (other is not None)
+ return (isinstance(other, Graph) and self.identifier > other.identifier) or (
+ other is not None
+ )
def __ge__(self, other):
return self > other or self == other
@@ -560,8 +561,7 @@ class Graph(Node):
"""Set-theoretic union
BNode IDs are not changed."""
retval = Graph()
- for (prefix, uri) in set(
- list(self.namespaces()) + list(other.namespaces())):
+ for (prefix, uri) in set(list(self.namespaces()) + list(other.namespaces())):
retval.bind(prefix, uri)
for x in self:
retval.add(x)
@@ -583,7 +583,7 @@ class Graph(Node):
BNode IDs are not changed."""
retval = Graph()
for x in self:
- if not x in other:
+ if x not in other:
retval.add(x)
return retval
@@ -604,10 +604,12 @@ class Graph(Node):
(subject, predicate, object).
"""
(subject, predicate, object_) = triple
- assert subject is not None, \
- "s can't be None in .set([s,p,o]), as it would remove (*, p, *)"
- assert predicate is not None, \
- "p can't be None in .set([s,p,o]), as it would remove (s, *, *)"
+ assert (
+ subject is not None
+ ), "s can't be None in .set([s,p,o]), as it would remove (*, p, *)"
+ assert (
+ predicate is not None
+ ), "p can't be None in .set([s,p,o]), as it would remove (s, *, *)"
self.remove((subject, predicate, None))
self.add((subject, predicate, object_))
@@ -644,11 +646,13 @@ class Graph(Node):
def triples_choices(self, triple, context=None):
subject, predicate, object_ = triple
for (s, p, o), cg in self.store.triples_choices(
- (subject, predicate, object_), context=self):
- yield (s, p, o)
+ (subject, predicate, object_), context=self
+ ):
+ yield s, p, o
- def value(self, subject=None, predicate=RDF.value, object=None,
- default=None, any=True):
+ def value(
+ self, subject=None, predicate=RDF.value, object=None, default=None, any=True
+ ):
"""Get a value for a pair of two criteria
Exactly one of subject, predicate, object must be None. Useful if one
@@ -665,9 +669,11 @@ class Graph(Node):
"""
retval = default
- if (subject is None and predicate is None) or \
- (subject is None and object is None) or \
- (predicate is None and object is None):
+ if (
+ (subject is None and predicate is None)
+ or (subject is None and object is None)
+ or (predicate is None and object is None)
+ ):
return None
if object is None:
@@ -685,20 +691,25 @@ class Graph(Node):
if any is False:
try:
next(values)
- msg = ("While trying to find a value for (%s, %s, %s) the"
- " following multiple values where found:\n" %
- (subject, predicate, object))
- triples = self.store.triples(
- (subject, predicate, object), None)
+ msg = (
+ "While trying to find a value for (%s, %s, %s) the"
+ " following multiple values where found:\n"
+ % (subject, predicate, object)
+ )
+ triples = self.store.triples((subject, predicate, object), None)
for (s, p, o), contexts in triples:
msg += "(%s, %s, %s)\n (contexts: %s)\n" % (
- s, p, o, list(contexts))
+ s,
+ p,
+ o,
+ list(contexts),
+ )
raise exceptions.UniquenessError(msg)
except StopIteration:
pass
return retval
- def label(self, subject, default=''):
+ def label(self, subject, default=""):
"""Query for the RDFS.label of the subject
Return default if no label exists or any label if multiple exist.
@@ -707,14 +718,19 @@ class Graph(Node):
return default
return self.value(subject, RDFS.label, default=default, any=True)
- def preferredLabel(self, subject, lang=None, default=None,
- labelProperties=(SKOS.prefLabel, RDFS.label)):
+ def preferredLabel(
+ self,
+ subject,
+ lang=None,
+ default=None,
+ labelProperties=(SKOS.prefLabel, RDFS.label),
+ ):
"""
Find the preferred label for subject.
By default prefers skos:prefLabels over rdfs:labels. In case at least
one prefLabel is found returns those, else returns labels. In case a
- language string (e.g., 'en', 'de' or even '' for no lang-tagged
+ language string (e.g., "en", "de" or even "" for no lang-tagged
literals) is given, only such labels will be considered.
Return a list of (labelProp, label) pairs, where labelProp is either
@@ -724,30 +740,30 @@ class Graph(Node):
>>> from rdflib.namespace import SKOS
>>> from pprint import pprint
>>> g = ConjunctiveGraph()
- >>> u = URIRef(u'http://example.com/foo')
- >>> g.add([u, RDFS.label, Literal('foo')])
- >>> g.add([u, RDFS.label, Literal('bar')])
+ >>> u = URIRef("http://example.com/foo")
+ >>> g.add([u, RDFS.label, Literal("foo")])
+ >>> g.add([u, RDFS.label, Literal("bar")])
>>> pprint(sorted(g.preferredLabel(u)))
- [(rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'),
- rdflib.term.Literal(u'bar')),
- (rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'),
- rdflib.term.Literal(u'foo'))]
- >>> g.add([u, SKOS.prefLabel, Literal('bla')])
+ [(rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'),
+ rdflib.term.Literal('bar')),
+ (rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'),
+ rdflib.term.Literal('foo'))]
+ >>> g.add([u, SKOS.prefLabel, Literal("bla")])
>>> pprint(g.preferredLabel(u))
- [(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'),
- rdflib.term.Literal(u'bla'))]
- >>> g.add([u, SKOS.prefLabel, Literal('blubb', lang='en')])
+ [(rdflib.term.URIRef('http://www.w3.org/2004/02/skos/core#prefLabel'),
+ rdflib.term.Literal('bla'))]
+ >>> g.add([u, SKOS.prefLabel, Literal("blubb", lang="en")])
>>> sorted(g.preferredLabel(u)) #doctest: +NORMALIZE_WHITESPACE
- [(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'),
- rdflib.term.Literal(u'bla')),
- (rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'),
- rdflib.term.Literal(u'blubb', lang='en'))]
- >>> g.preferredLabel(u, lang='') #doctest: +NORMALIZE_WHITESPACE
- [(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'),
- rdflib.term.Literal(u'bla'))]
- >>> pprint(g.preferredLabel(u, lang='en'))
- [(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'),
- rdflib.term.Literal(u'blubb', lang='en'))]
+ [(rdflib.term.URIRef('http://www.w3.org/2004/02/skos/core#prefLabel'),
+ rdflib.term.Literal('bla')),
+ (rdflib.term.URIRef('http://www.w3.org/2004/02/skos/core#prefLabel'),
+ rdflib.term.Literal('blubb', lang='en'))]
+ >>> g.preferredLabel(u, lang="") #doctest: +NORMALIZE_WHITESPACE
+ [(rdflib.term.URIRef('http://www.w3.org/2004/02/skos/core#prefLabel'),
+ rdflib.term.Literal('bla'))]
+ >>> pprint(g.preferredLabel(u, lang="en"))
+ [(rdflib.term.URIRef('http://www.w3.org/2004/02/skos/core#prefLabel'),
+ rdflib.term.Literal('blubb', lang='en'))]
"""
if default is None:
@@ -755,12 +771,20 @@ class Graph(Node):
# setup the language filtering
if lang is not None:
- if lang == '': # we only want not language-tagged literals
- def langfilter(l): return l.language is None
+ if lang == "": # we only want not language-tagged literals
+
+ def langfilter(l):
+ return l.language is None
+
else:
- def langfilter(l): return l.language == lang
+
+ def langfilter(l):
+ return l.language == lang
+
else: # we don't care about language tags
- def langfilter(l): return True
+
+ def langfilter(l):
+ return True
for labelProp in labelProperties:
labels = list(filter(langfilter, self.objects(subject, labelProp)))
@@ -770,7 +794,7 @@ class Graph(Node):
return [(labelProp, l) for l in labels]
return default
- def comment(self, subject, default=''):
+ def comment(self, subject, default=""):
"""Query for the RDFS.comment of the subject
Return default if no comment exists
@@ -801,9 +825,9 @@ class Graph(Node):
>>> from rdflib.collection import Collection
>>> g=Graph()
- >>> a=BNode('foo')
- >>> b=BNode('bar')
- >>> c=BNode('baz')
+ >>> a=BNode("foo")
+ >>> b=BNode("bar")
+ >>> c=BNode("baz")
>>> g.add((a,RDF.first,RDF.type))
>>> g.add((a,RDF.rest,b))
>>> g.add((b,RDF.first,RDFS.label))
@@ -811,12 +835,12 @@ class Graph(Node):
>>> g.add((c,RDF.first,RDFS.comment))
>>> g.add((c,RDF.rest,RDF.nil))
>>> def topList(node,g):
- ... for s in g.subjects(RDF.rest,node):
+ ... for s in g.subjects(RDF.rest, node):
... yield s
>>> def reverseList(node,g):
- ... for f in g.objects(node,RDF.first):
+ ... for f in g.objects(node, RDF.first):
... print(f)
- ... for s in g.subjects(RDF.rest,node):
+ ... for s in g.subjects(RDF.rest, node):
... yield s
>>> [rt for rt in g.transitiveClosure(
@@ -901,11 +925,12 @@ class Graph(Node):
if replace, replace any existing prefix with the new namespace
- for example: graph.bind('foaf', 'http://xmlns.com/foaf/0.1/')
+ for example: graph.bind("foaf", "http://xmlns.com/foaf/0.1/")
"""
return self.namespace_manager.bind(
- prefix, namespace, override=override, replace=replace)
+ prefix, namespace, override=override, replace=replace
+ )
def namespaces(self):
"""Generator over all the prefix, namespace tuples"""
@@ -916,15 +941,16 @@ class Graph(Node):
"""Turn uri into an absolute URI if it's not one already"""
return self.namespace_manager.absolutize(uri, defrag)
- def serialize(self, destination=None, format="xml",
- base=None, encoding=None, **args):
+ def serialize(
+ self, destination=None, format="xml", base=None, encoding=None, **args
+ ):
"""Serialize the Graph to destination
If destination is None serialize method returns the serialization as a
string. Format defaults to xml (AKA rdf/xml).
Format support can be extended with plugins,
- but 'xml', 'n3', 'turtle', 'nt', 'pretty-xml', 'trix', 'trig' and 'nquads' are built in.
+ but "xml", "n3", "turtle", "nt", "pretty-xml", "trix", "trig" and "nquads" are built in.
"""
serializer = plugin.get(format, Serializer)(self)
if destination is None:
@@ -938,8 +964,9 @@ class Graph(Node):
location = destination
scheme, netloc, path, params, _query, fragment = urlparse(location)
if netloc != "":
- print("WARNING: not saving as location" +
- "is not a local file reference")
+ print(
+ "WARNING: not saving as location" + "is not a local file reference"
+ )
return
fd, name = tempfile.mkstemp()
stream = os.fdopen(fd, "wb")
@@ -951,8 +978,16 @@ class Graph(Node):
shutil.copy(name, path)
os.remove(name)
- def parse(self, source=None, publicID=None, format=None,
- location=None, file=None, data=None, **args):
+ def parse(
+ self,
+ source=None,
+ publicID=None,
+ format=None,
+ location=None,
+ file=None,
+ data=None,
+ **args
+ ):
"""
Parse source adding the resulting triples to the Graph.
@@ -970,7 +1005,7 @@ class Graph(Node):
- `data`: A string containing the data to be parsed.
- `format`: Used if format can not be determined from source.
Defaults to rdf/xml. Format support can be extended with plugins,
- but 'xml', 'n3', 'nt', 'trix', 'rdfa' are built in.
+ but "xml", "n3", "nt" & "trix" are built in.
- `publicID`: the logical URI to use as the document base. If None
specified the document location is used (at least in the case where
there is a document location).
@@ -983,8 +1018,8 @@ class Graph(Node):
>>> my_data = '''
... <rdf:RDF
- ... xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
- ... xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'
+ ... xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ ... xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
... >
... <rdf:Description>
... <rdfs:label>Example</rdfs:label>
@@ -994,7 +1029,7 @@ class Graph(Node):
... '''
>>> import tempfile
>>> fd, file_name = tempfile.mkstemp()
- >>> f = os.fdopen(fd, 'w')
+ >>> f = os.fdopen(fd, "w")
>>> dummy = f.write(my_data) # Returns num bytes written on py3
>>> f.close()
@@ -1018,9 +1053,14 @@ class Graph(Node):
"""
- source = create_input_source(source=source, publicID=publicID,
- location=location, file=file,
- data=data, format=format)
+ source = create_input_source(
+ source=source,
+ publicID=publicID,
+ location=location,
+ file=file,
+ data=data,
+ format=format,
+ )
if format is None:
format = source.content_type
if format is None:
@@ -1038,9 +1078,16 @@ class Graph(Node):
def load(self, source, publicID=None, format="xml"):
self.parse(source, publicID, format)
- def query(self, query_object, processor='sparql',
- result='sparql', initNs=None, initBindings=None,
- use_store_provided=True, **kwargs):
+ def query(
+ self,
+ query_object,
+ processor="sparql",
+ result="sparql",
+ initNs=None,
+ initBindings=None,
+ use_store_provided=True,
+ **kwargs
+ ):
"""
Query this graph.
@@ -1061,11 +1108,12 @@ class Graph(Node):
if hasattr(self.store, "query") and use_store_provided:
try:
return self.store.query(
- query_object, initNs, initBindings,
- self.default_union and
- '__UNION__' or
- self.identifier,
- **kwargs)
+ query_object,
+ initNs,
+ initBindings,
+ self.default_union and "__UNION__" or self.identifier,
+ **kwargs
+ )
except NotImplementedError:
pass # store has no own implementation
@@ -1074,12 +1122,17 @@ class Graph(Node):
if not isinstance(processor, query.Processor):
processor = plugin.get(processor, query.Processor)(self)
- return result(processor.query(
- query_object, initBindings, initNs, **kwargs))
-
- def update(self, update_object, processor='sparql',
- initNs=None, initBindings=None,
- use_store_provided=True, **kwargs):
+ return result(processor.query(query_object, initBindings, initNs, **kwargs))
+
+ def update(
+ self,
+ update_object,
+ processor="sparql",
+ initNs=None,
+ initBindings=None,
+ use_store_provided=True,
+ **kwargs
+ ):
"""Update this graph with the given update query."""
initBindings = initBindings or {}
initNs = initNs or dict(self.namespaces())
@@ -1087,11 +1140,12 @@ class Graph(Node):
if hasattr(self.store, "update") and use_store_provided:
try:
return self.store.update(
- update_object, initNs, initBindings,
- self.default_union and
- '__UNION__' or
- self.identifier,
- **kwargs)
+ update_object,
+ initNs,
+ initBindings,
+ self.default_union and "__UNION__" or self.identifier,
+ **kwargs
+ )
except NotImplementedError:
pass # store has no own implementation
@@ -1222,7 +1276,7 @@ class Graph(Node):
s = s.skolemize(authority=authority, basepath=basepath)
if o == bnode:
o = o.skolemize(authority=authority, basepath=basepath)
- return (s, p, o)
+ return s, p, o
def do_skolemize2(t):
(s, p, o) = t
@@ -1230,15 +1284,14 @@ class Graph(Node):
s = s.skolemize(authority=authority, basepath=basepath)
if isinstance(o, BNode):
o = o.skolemize(authority=authority, basepath=basepath)
- return (s, p, o)
+ return s, p, o
retval = Graph() if new_graph is None else new_graph
if bnode is None:
self._process_skolem_tuples(retval, do_skolemize2)
elif isinstance(bnode, BNode):
- self._process_skolem_tuples(
- retval, lambda t: do_skolemize(bnode, t))
+ self._process_skolem_tuples(retval, lambda t: do_skolemize(bnode, t))
return retval
@@ -1249,7 +1302,7 @@ class Graph(Node):
s = s.de_skolemize()
if o == uriref:
o = o.de_skolemize()
- return (s, p, o)
+ return s, p, o
def do_de_skolemize2(t):
(s, p, o) = t
@@ -1257,23 +1310,20 @@ class Graph(Node):
s = s.de_skolemize()
if isinstance(o, Genid):
o = o.de_skolemize()
- return (s, p, o)
+ return s, p, o
retval = Graph() if new_graph is None else new_graph
if uriref is None:
self._process_skolem_tuples(retval, do_de_skolemize2)
elif isinstance(uriref, Genid):
- self._process_skolem_tuples(
- retval, lambda t: do_de_skolemize(uriref, t))
+ self._process_skolem_tuples(retval, lambda t: do_de_skolemize(uriref, t))
return retval
class ConjunctiveGraph(Graph):
-
- """
- A ConjunctiveGraph is an (unnamed) aggregation of all the named
+ """A ConjunctiveGraph is an (unnamed) aggregation of all the named
graphs in a store.
It has a ``default`` graph, whose name is associated with the
@@ -1284,21 +1334,22 @@ class ConjunctiveGraph(Graph):
All methods that add triples work against this default graph.
All queries are carried out against the union of all graphs.
-
"""
- def __init__(self, store='default', identifier=None):
+ def __init__(self, store="default", identifier=None):
super(ConjunctiveGraph, self).__init__(store, identifier=identifier)
- assert self.store.context_aware, ("ConjunctiveGraph must be backed by"
- " a context aware store.")
+ assert self.store.context_aware, (
+ "ConjunctiveGraph must be backed by" " a context aware store."
+ )
self.context_aware = True
self.default_union = True # Conjunctive!
- self.default_context = Graph(store=self.store,
- identifier=identifier or BNode())
+ self.default_context = Graph(store=self.store, identifier=identifier or BNode())
def __str__(self):
- pattern = ("[a rdflib:ConjunctiveGraph;rdflib:storage "
- "[a rdflib:Store;rdfs:label '%s']]")
+ pattern = (
+ "[a rdflib:ConjunctiveGraph;rdflib:storage "
+ "[a rdflib:Store;rdfs:label '%s']]"
+ )
return pattern % self.store.__class__.__name__
def _spoc(self, triple_or_quad, default=False):
@@ -1348,8 +1399,7 @@ class ConjunctiveGraph(Graph):
"""Add a sequence of triples with context"""
self.store.addN(
- (s, p, o, self._graph(c)) for s, p, o, c in quads if
- _assertnode(s, p, o)
+ (s, p, o, self._graph(c)) for s, p, o, c in quads if _assertnode(s, p, o)
)
def remove(self, triple_or_quad):
@@ -1389,7 +1439,7 @@ class ConjunctiveGraph(Graph):
context = self
for s, o in p.eval(context, s, o):
- yield (s, p, o)
+ yield s, p, o
else:
for (s, p, o), cg in self.store.triples((s, p, o), context=context):
yield s, p, o
@@ -1412,9 +1462,8 @@ class ConjunctiveGraph(Graph):
else:
context = self._graph(context)
- for (s1, p1, o1), cg in self.store.triples_choices((s, p, o),
- context=context):
- yield (s1, p1, o1)
+ for (s1, p1, o1), cg in self.store.triples_choices((s, p, o), context=context):
+ yield s1, p1, o1
def __len__(self):
"""Number of triples in the entire conjunctive graph"""
@@ -1439,8 +1488,7 @@ class ConjunctiveGraph(Graph):
identifier must be a URIRef or BNode.
"""
- return Graph(store=self.store, identifier=identifier,
- namespace_manager=self)
+ return Graph(store=self.store, identifier=identifier, namespace_manager=self)
def remove_context(self, context):
"""Removes the given context from the graph"""
@@ -1453,8 +1501,16 @@ class ConjunctiveGraph(Graph):
context_id = "#context"
return URIRef(context_id, base=uri)
- def parse(self, source=None, publicID=None, format="xml",
- location=None, file=None, data=None, **args):
+ def parse(
+ self,
+ source=None,
+ publicID=None,
+ format="xml",
+ location=None,
+ file=None,
+ data=None,
+ **args
+ ):
"""
Parse source adding the resulting triples to its own context
(sub graph of this graph).
@@ -1468,8 +1524,13 @@ class ConjunctiveGraph(Graph):
"""
source = create_input_source(
- source=source, publicID=publicID, location=location,
- file=file, data=data, format=format)
+ source=source,
+ publicID=publicID,
+ location=location,
+ file=file,
+ data=data,
+ format=format,
+ )
g_id = publicID and publicID or source.getPublicId()
if not isinstance(g_id, Node):
@@ -1481,10 +1542,10 @@ class ConjunctiveGraph(Graph):
return context
def __reduce__(self):
- return (ConjunctiveGraph, (self.store, self.identifier))
+ return ConjunctiveGraph, (self.store, self.identifier)
-DATASET_DEFAULT_GRAPH_ID = URIRef('urn:x-rdflib:default')
+DATASET_DEFAULT_GRAPH_ID = URIRef("urn:x-rdflib:default")
class Dataset(ConjunctiveGraph):
@@ -1501,68 +1562,68 @@ class Dataset(ConjunctiveGraph):
>>> # Create a new Dataset
>>> ds = Dataset()
>>> # simple triples goes to default graph
- >>> ds.add((URIRef('http://example.org/a'),
- ... URIRef('http://www.example.org/b'),
- ... Literal('foo')))
+ >>> ds.add((URIRef("http://example.org/a"),
+ ... URIRef("http://www.example.org/b"),
+ ... Literal("foo")))
>>>
>>> # Create a graph in the dataset, if the graph name has already been
>>> # used, the corresponding graph will be returned
>>> # (ie, the Dataset keeps track of the constituent graphs)
- >>> g = ds.graph(URIRef('http://www.example.com/gr'))
+ >>> g = ds.graph(URIRef("http://www.example.com/gr"))
>>>
>>> # add triples to the new graph as usual
>>> g.add(
- ... (URIRef('http://example.org/x'),
- ... URIRef('http://example.org/y'),
- ... Literal('bar')) )
+ ... (URIRef("http://example.org/x"),
+ ... URIRef("http://example.org/y"),
+ ... Literal("bar")) )
>>> # alternatively: add a quad to the dataset -> goes to the graph
>>> ds.add(
- ... (URIRef('http://example.org/x'),
- ... URIRef('http://example.org/z'),
- ... Literal('foo-bar'),g) )
+ ... (URIRef("http://example.org/x"),
+ ... URIRef("http://example.org/z"),
+ ... Literal("foo-bar"),g) )
>>>
>>> # querying triples return them all regardless of the graph
>>> for t in ds.triples((None,None,None)): # doctest: +SKIP
... print(t) # doctest: +NORMALIZE_WHITESPACE
- (rdflib.term.URIRef(u'http://example.org/a'),
- rdflib.term.URIRef(u'http://www.example.org/b'),
- rdflib.term.Literal(u'foo'))
- (rdflib.term.URIRef(u'http://example.org/x'),
- rdflib.term.URIRef(u'http://example.org/z'),
- rdflib.term.Literal(u'foo-bar'))
- (rdflib.term.URIRef(u'http://example.org/x'),
- rdflib.term.URIRef(u'http://example.org/y'),
- rdflib.term.Literal(u'bar'))
+ (rdflib.term.URIRef("http://example.org/a"),
+ rdflib.term.URIRef("http://www.example.org/b"),
+ rdflib.term.Literal("foo"))
+ (rdflib.term.URIRef("http://example.org/x"),
+ rdflib.term.URIRef("http://example.org/z"),
+ rdflib.term.Literal("foo-bar"))
+ (rdflib.term.URIRef("http://example.org/x"),
+ rdflib.term.URIRef("http://example.org/y"),
+ rdflib.term.Literal("bar"))
>>>
>>> # querying quads return quads; the fourth argument can be unrestricted
>>> # or restricted to a graph
>>> for q in ds.quads((None, None, None, None)): # doctest: +SKIP
... print(q) # doctest: +NORMALIZE_WHITESPACE
- (rdflib.term.URIRef(u'http://example.org/a'),
- rdflib.term.URIRef(u'http://www.example.org/b'),
- rdflib.term.Literal(u'foo'),
+ (rdflib.term.URIRef("http://example.org/a"),
+ rdflib.term.URIRef("http://www.example.org/b"),
+ rdflib.term.Literal("foo"),
None)
- (rdflib.term.URIRef(u'http://example.org/x'),
- rdflib.term.URIRef(u'http://example.org/y'),
- rdflib.term.Literal(u'bar'),
- rdflib.term.URIRef(u'http://www.example.com/gr'))
- (rdflib.term.URIRef(u'http://example.org/x'),
- rdflib.term.URIRef(u'http://example.org/z'),
- rdflib.term.Literal(u'foo-bar'),
- rdflib.term.URIRef(u'http://www.example.com/gr'))
+ (rdflib.term.URIRef("http://example.org/x"),
+ rdflib.term.URIRef("http://example.org/y"),
+ rdflib.term.Literal("bar"),
+ rdflib.term.URIRef("http://www.example.com/gr"))
+ (rdflib.term.URIRef("http://example.org/x"),
+ rdflib.term.URIRef("http://example.org/z"),
+ rdflib.term.Literal("foo-bar"),
+ rdflib.term.URIRef("http://www.example.com/gr"))
>>>
>>> for q in ds.quads((None,None,None,g)): # doctest: +SKIP
... print(q) # doctest: +NORMALIZE_WHITESPACE
- (rdflib.term.URIRef(u'http://example.org/x'),
- rdflib.term.URIRef(u'http://example.org/y'),
- rdflib.term.Literal(u'bar'),
- rdflib.term.URIRef(u'http://www.example.com/gr'))
- (rdflib.term.URIRef(u'http://example.org/x'),
- rdflib.term.URIRef(u'http://example.org/z'),
- rdflib.term.Literal(u'foo-bar'),
- rdflib.term.URIRef(u'http://www.example.com/gr'))
+ (rdflib.term.URIRef("http://example.org/x"),
+ rdflib.term.URIRef("http://example.org/y"),
+ rdflib.term.Literal("bar"),
+ rdflib.term.URIRef("http://www.example.com/gr"))
+ (rdflib.term.URIRef("http://example.org/x"),
+ rdflib.term.URIRef("http://example.org/z"),
+ rdflib.term.Literal("foo-bar"),
+ rdflib.term.URIRef("http://www.example.com/gr"))
>>> # Note that in the call above -
- >>> # ds.quads((None,None,None,'http://www.example.com/gr'))
+ >>> # ds.quads((None,None,None,"http://www.example.com/gr"))
>>> # would have been accepted, too
>>>
>>> # graph names in the dataset can be queried:
@@ -1590,26 +1651,30 @@ class Dataset(ConjunctiveGraph):
.. versionadded:: 4.0
"""
- def __init__(self, store='default', default_union=False):
+ def __init__(self, store="default", default_union=False):
super(Dataset, self).__init__(store=store, identifier=None)
if not self.store.graph_aware:
raise Exception("DataSet must be backed by a graph-aware store!")
- self.default_context = Graph(store=self.store, identifier=DATASET_DEFAULT_GRAPH_ID)
+ self.default_context = Graph(
+ store=self.store, identifier=DATASET_DEFAULT_GRAPH_ID
+ )
self.default_union = default_union
def __str__(self):
- pattern = ("[a rdflib:Dataset;rdflib:storage "
- "[a rdflib:Store;rdfs:label '%s']]")
+ pattern = (
+ "[a rdflib:Dataset;rdflib:storage " "[a rdflib:Store;rdfs:label '%s']]"
+ )
return pattern % self.store.__class__.__name__
def graph(self, identifier=None):
if identifier is None:
from rdflib.term import rdflib_skolem_genid
+
self.bind(
- "genid", "http://rdflib.net" + rdflib_skolem_genid,
- override=False)
+ "genid", "http://rdflib.net" + rdflib_skolem_genid, override=False
+ )
identifier = BNode().skolemize()
g = self._graph(identifier)
@@ -1617,9 +1682,19 @@ class Dataset(ConjunctiveGraph):
self.store.add_graph(g)
return g
- def parse(self, source=None, publicID=None, format="xml",
- location=None, file=None, data=None, **args):
- c = ConjunctiveGraph.parse(self, source, publicID, format, location, file, data, **args)
+ def parse(
+ self,
+ source=None,
+ publicID=None,
+ format="xml",
+ location=None,
+ file=None,
+ data=None,
+ **args
+ ):
+ c = ConjunctiveGraph.parse(
+ self, source, publicID, format, location, file, data, **args
+ )
self.graph(c)
return c
@@ -1650,9 +1725,9 @@ class Dataset(ConjunctiveGraph):
def quads(self, quad):
for s, p, o, c in super(Dataset, self).quads(quad):
if c.identifier == self.default_context:
- yield (s, p, o, None)
+ yield s, p, o, None
else:
- yield (s, p, o, c.identifier)
+ yield s, p, o, c.identifier
class QuotedGraph(Graph):
@@ -1669,12 +1744,9 @@ class QuotedGraph(Graph):
def add(self, triple):
"""Add a triple with self as context"""
s, p, o = triple
- assert isinstance(s, Node), \
- "Subject %s must be an rdflib term" % (s,)
- assert isinstance(p, Node), \
- "Predicate %s must be an rdflib term" % (p,)
- assert isinstance(o, Node), \
- "Object %s must be an rdflib term" % (o,)
+ assert isinstance(s, Node), "Subject %s must be an rdflib term" % (s,)
+ assert isinstance(p, Node), "Predicate %s must be an rdflib term" % (p,)
+ assert isinstance(o, Node), "Object %s must be an rdflib term" % (o,)
self.store.add((s, p, o), self, quoted=True)
@@ -1682,10 +1754,11 @@ class QuotedGraph(Graph):
"""Add a sequence of triple with context"""
self.store.addN(
- (s, p, o, c) for s, p, o, c in quads
- if isinstance(c, QuotedGraph) and
- c.identifier is self.identifier and
- _assertnode(s, p, o)
+ (s, p, o, c)
+ for s, p, o, c in quads
+ if isinstance(c, QuotedGraph)
+ and c.identifier is self.identifier
+ and _assertnode(s, p, o)
)
def n3(self):
@@ -1695,12 +1768,14 @@ class QuotedGraph(Graph):
def __str__(self):
identifier = self.identifier.n3()
label = self.store.__class__.__name__
- pattern = ("{this rdflib.identifier %s;rdflib:storage "
- "[a rdflib:Store;rdfs:label '%s']}")
+ pattern = (
+ "{this rdflib.identifier %s;rdflib:storage "
+ "[a rdflib:Store;rdfs:label '%s']}"
+ )
return pattern % (identifier, label)
def __reduce__(self):
- return (QuotedGraph, (self.store, self.identifier))
+ return QuotedGraph, (self.store, self.identifier)
# Make sure QuotedGraph is ordered correctly
@@ -1735,7 +1810,7 @@ class Seq(object):
LI_INDEX = URIRef(str(RDF) + "_")
for (p, o) in graph.predicate_objects(subject):
if p.startswith(LI_INDEX): # != RDF.Seq: #
- i = int(p.replace(LI_INDEX, ''))
+ i = int(p.replace(LI_INDEX, ""))
_list.append((i, o))
# here is the trick: the predicates are _1, _2, _3, etc. Ie,
@@ -1761,23 +1836,22 @@ class Seq(object):
class ModificationException(Exception):
-
def __init__(self):
pass
def __str__(self):
- return ("Modifications and transactional operations not allowed on "
- "ReadOnlyGraphAggregate instances")
+ return (
+ "Modifications and transactional operations not allowed on "
+ "ReadOnlyGraphAggregate instances"
+ )
class UnSupportedAggregateOperation(Exception):
-
def __init__(self):
pass
def __str__(self):
- return ("This operation is not supported by ReadOnlyGraphAggregate "
- "instances")
+ return "This operation is not supported by ReadOnlyGraphAggregate " "instances"
class ReadOnlyGraphAggregate(ConjunctiveGraph):
@@ -1787,16 +1861,17 @@ class ReadOnlyGraphAggregate(ConjunctiveGraph):
ConjunctiveGraph over an explicit subset of the entire store.
"""
- def __init__(self, graphs, store='default'):
+ def __init__(self, graphs, store="default"):
if store is not None:
super(ReadOnlyGraphAggregate, self).__init__(store)
Graph.__init__(self, store)
self.__namespace_manager = None
- assert isinstance(graphs, list) \
- and graphs \
- and [g for g in graphs if isinstance(g, Graph)], \
- "graphs argument must be a list of Graphs!!"
+ assert (
+ isinstance(graphs, list)
+ and graphs
+ and [g for g in graphs if isinstance(g, Graph)]
+ ), "graphs argument must be a list of Graphs!!"
self.graphs = graphs
def __repr__(self):
@@ -1838,7 +1913,7 @@ class ReadOnlyGraphAggregate(ConjunctiveGraph):
yield s, p, o
else:
for s1, p1, o1 in graph.triples((s, p, o)):
- yield (s1, p1, o1)
+ yield s1, p1, o1
def __contains__(self, triple_or_quad):
context = None
@@ -1855,7 +1930,7 @@ class ReadOnlyGraphAggregate(ConjunctiveGraph):
s, p, o = triple
for graph in self.graphs:
for s1, p1, o1 in graph.triples((s, p, o)):
- yield (s1, p1, o1, graph)
+ yield s1, p1, o1, graph
def __len__(self):
return sum(len(g) for g in self.graphs)
@@ -1869,7 +1944,7 @@ class ReadOnlyGraphAggregate(ConjunctiveGraph):
elif isinstance(other, Graph):
return -1
elif isinstance(other, ReadOnlyGraphAggregate):
- return cmp(self.graphs, other.graphs)
+ return (self.graphs > other.graphs) - (self.graphs < other.graphs)
else:
return -1
@@ -1886,15 +1961,15 @@ class ReadOnlyGraphAggregate(ConjunctiveGraph):
for graph in self.graphs:
choices = graph.triples_choices((subject, predicate, object_))
for (s, p, o) in choices:
- yield (s, p, o)
+ yield s, p, o
def qname(self, uri):
- if hasattr(self, 'namespace_manager') and self.namespace_manager:
+ if hasattr(self, "namespace_manager") and self.namespace_manager:
return self.namespace_manager.qname(uri)
raise UnSupportedAggregateOperation()
def compute_qname(self, uri, generate=True):
- if hasattr(self, 'namespace_manager') and self.namespace_manager:
+ if hasattr(self, "namespace_manager") and self.namespace_manager:
return self.namespace_manager.compute_qname(uri, generate)
raise UnSupportedAggregateOperation()
@@ -1902,7 +1977,7 @@ class ReadOnlyGraphAggregate(ConjunctiveGraph):
raise UnSupportedAggregateOperation()
def namespaces(self):
- if hasattr(self, 'namespace_manager'):
+ if hasattr(self, "namespace_manager"):
for prefix, namespace in self.namespace_manager.namespaces():
yield prefix, namespace
else:
@@ -1925,15 +2000,15 @@ class ReadOnlyGraphAggregate(ConjunctiveGraph):
def _assertnode(*terms):
for t in terms:
- assert isinstance(t, Node), \
- 'Term %s must be an rdflib term' % (t,)
+ assert isinstance(t, Node), "Term %s must be an rdflib term" % (t,)
return True
def test():
import doctest
+
doctest.testmod()
-if __name__ == '__main__':
+if __name__ == "__main__":
test()