/usr/share/doc/python-rdflib-doc/html/namespaces_and_bindings.html is in python-rdflib-doc 4.1.2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Namespaces and Bindings — rdflib 4.1.2 documentation</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
<link rel="stylesheet" href="_static/rtd.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '4.1.2',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/searchtools.js"></script>
<link rel="top" title="rdflib 4.1.2 documentation" href="index.html" />
<link rel="next" title="Persistence" href="persistence.html" />
<link rel="prev" title="RDF terms in rdflib" href="rdf_terms.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="persistence.html" title="Persistence"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="rdf_terms.html" title="RDF terms in rdflib"
accesskey="P">previous</a> |</li>
<li><a href="index.html">rdflib 4.1.2 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="id1">
<h1>Namespaces and Bindings<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h1>
<p>RDFLib provides several short-cuts to working with many URIs in the same namespace.</p>
<p>The <a class="reference internal" href="apidocs/rdflib.html#module-rdflib.namespace" title="rdflib.namespace"><tt class="xref py py-mod docutils literal"><span class="pre">rdflib.namespace</span></tt></a> defines the <a class="reference internal" href="apidocs/rdflib.html#rdflib.namespace.Namespace" title="rdflib.namespace.Namespace"><tt class="xref py py-class docutils literal"><span class="pre">rdflib.namespace.Namespace</span></tt></a> class which lets you easily create URIs in a namespace:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">rdflib</span> <span class="kn">import</span> <span class="n">Namespace</span>
<span class="n">n</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">(</span><span class="s">"http://example.org/"</span><span class="p">)</span>
<span class="n">n</span><span class="o">.</span><span class="n">Person</span> <span class="c"># as attribute</span>
<span class="c"># = rdflib.term.URIRef(u'http://example.org/Person')</span>
<span class="n">n</span><span class="p">[</span><span class="s">'first%20name'</span><span class="p">]</span> <span class="c"># as item - for things that are not valid python identifiers</span>
<span class="c"># = rdflib.term.URIRef(u'http://example.org/first%20name')</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">namespace</span></tt> module also defines many common namespaces such as RDF, RDFS, OWL, FOAF, SKOS, etc.</p>
<p>Namespaces can also be associated with prefixes, in a <a class="reference internal" href="apidocs/rdflib.html#rdflib.namespace.NamespaceManager" title="rdflib.namespace.NamespaceManager"><tt class="xref py py-class docutils literal"><span class="pre">rdflib.namespace.NamespaceManager</span></tt></a>, i.e. using <tt class="docutils literal"><span class="pre">foaf</span></tt> for <tt class="docutils literal"><span class="pre">http://xmlns.com/foaf/0.1/</span></tt>. Each RDFLib graph has a <a class="reference internal" href="apidocs/rdflib.html#rdflib.graph.Graph.namespace_manager" title="rdflib.graph.Graph.namespace_manager"><tt class="xref py py-attr docutils literal"><span class="pre">namespace_manager</span></tt></a> that keeps a list of namespace to prefix mappings. The namespace manager is populated when reading in RDF, and these prefixes are used when serialising RDF, or when parsing SPARQL queries. Additional prefixes can be bound with the <tt class="xref py py-meth docutils literal"><span class="pre">rdflib.graph.bind()</span></tt> method.</p>
<div class="section" id="namespaces-in-sparql-queries">
<h2>Namespaces in SPARQL Queries<a class="headerlink" href="#namespaces-in-sparql-queries" title="Permalink to this headline">¶</a></h2>
<p>The <tt class="docutils literal"><span class="pre">initNs</span></tt> argument supplied to <a class="reference internal" href="apidocs/rdflib.html#rdflib.graph.Graph.query" title="rdflib.graph.Graph.query"><tt class="xref py py-meth docutils literal"><span class="pre">query()</span></tt></a> is a dictionary of namespaces to be expanded in the query string.
If you pass no <tt class="docutils literal"><span class="pre">initNs</span></tt> argument, the namespaces registered with the graphs namespace_manager are used:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="o">...</span>
<span class="kn">from</span> <span class="nn">rdflib.namespace</span> <span class="kn">import</span> <span class="n">FOAF</span>
<span class="n">graph</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="s">'SELECT * WHERE { ?p a foaf:Person }'</span><span class="p">,</span> <span class="n">initNs</span><span class="o">=</span><span class="p">{</span> <span class="s">'foaf'</span><span class="p">:</span> <span class="n">FOAF</span> <span class="p">})</span>
</pre></div>
</div>
<p>In order to use an empty prefix (e.g. <tt class="docutils literal"><span class="pre">?a</span> <span class="pre">:knows</span> <span class="pre">?b</span></tt>), use a <tt class="docutils literal"><span class="pre">PREFIX</span></tt> directive with no prefix in the SPARQL query to set a default namespace:</p>
<div class="highlight-sparql"><div class="highlight"><pre>PREFIX : <http://xmlns.com/foaf/0.1/>
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="index.html">
<img class="logo" src="_static/logo.svg" alt="Logo"/>
</a></p>
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Namespaces and Bindings</a><ul>
<li><a class="reference internal" href="#namespaces-in-sparql-queries">Namespaces in SPARQL Queries</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="rdf_terms.html"
title="previous chapter">RDF terms in rdflib</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="persistence.html"
title="next chapter">Persistence</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/namespaces_and_bindings.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="persistence.html" title="Persistence"
>next</a> |</li>
<li class="right" >
<a href="rdf_terms.html" title="RDF terms in rdflib"
>previous</a> |</li>
<li><a href="index.html">rdflib 4.1.2 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2009 - 2013, RDFLib Team.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2.2.
<br />Theme based on <a href="http://readthedocs.org/">Read The Docs</a>
</div>
</body>
</html>
|