diff options
Diffstat (limited to 'docs')
100 files changed, 16499 insertions, 0 deletions
diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 00000000..8b235251 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,88 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d _build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest + +help: + @echo "Please use \`make <target>' where <target> is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + -rm -rf _build/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) _build/html + @echo + @echo "Build finished. The HTML pages are in _build/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) _build/dirhtml + @echo + @echo "Build finished. The HTML pages are in _build/dirhtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) _build/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) _build/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) _build/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in _build/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) _build/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in _build/qthelp, like this:" + @echo "# qcollectiongenerator _build/qthelp/rdflib.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile _build/qthelp/rdflib.qhc" + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) _build/latex + @echo + @echo "Build finished; the LaTeX files are in _build/latex." + @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \ + "run these through (pdf)latex." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) _build/changes + @echo + @echo "The overview file is in _build/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) _build/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in _build/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) _build/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in _build/doctest/output.txt." diff --git a/docs/_build/html/_images/ContextHierarchy.png b/docs/_build/html/_images/ContextHierarchy.png Binary files differnew file mode 100644 index 00000000..28b4977e --- /dev/null +++ b/docs/_build/html/_images/ContextHierarchy.png diff --git a/docs/_build/html/_sources/addons.txt b/docs/_build/html/_sources/addons.txt new file mode 100644 index 00000000..1005e423 --- /dev/null +++ b/docs/_build/html/_sources/addons.txt @@ -0,0 +1,364 @@ +.. _addons: Additions + +========= +Additions +========= + +TriXSerializer +============== + +John L. Clark jlc6 at po.cwru.edu + +Tue Aug 7 01:55:07 EDT 2007 + +.. note:: Devs, + + I've taken a first pass at implementing a simple TriX serializer. I + should have attached the new file (which goes in + `.../rdflib/syntax/serializers/TriXSerializer.py`) to this email, + along with a crazy little test script. The test script exercises + round tripping, but it turned out parsing was broken, so I fixed it; + the patch for that (and adding the new serializer to the plugin list) + should be attached as well. Finally, does anyone mind if I clean up + the TriX parser a bit? + + Take care, + + John L. Clark + + +TriXSerializer.py +----------------- + +.. code-block:: python + + from rdflib.syntax.serializers import Serializer + + from rdflib.URIRef import URIRef + from rdflib.Literal import Literal + from rdflib.BNode import BNode + + from rdflib.Graph import Graph, ConjunctiveGraph + + from Ft.Xml import MarkupWriter, XML_NAMESPACE + + TRIX_NS = u"http://www.w3.org/2004/03/trix/trix-1/" + + class TriXSerializer(Serializer): + def __init__(self, store): + super(TriXSerializer, self).__init__(store) + + def serialize(self, stream, base=None, encoding=None, **args): + self.writer = MarkupWriter(stream=stream, encoding=encoding, + indent="yes") + self.writer.startDocument() + self.writer.startElement(u"TriX", TRIX_NS) + + if isinstance(self.store, ConjunctiveGraph): + for subgraph in self.store.contexts(): + self._writeGraph(subgraph) + elif isinstance(self.store, Graph): + self._writeGraph(self.store) + else: + pass + + self.writer.endElement(u"TriX", TRIX_NS) + self.writer.endDocument() + + def _writeGraph(self, graph): + self.writer.startElement(u"graph", TRIX_NS) + if isinstance(graph.identifier, URIRef): + self.writer.simpleElement(u"uri", TRIX_NS, + content=unicode(graph.identifier)) + + for triple in graph.triples((None,None,None)): + self._writeTriple(triple) + self.writer.endElement(u"graph", TRIX_NS) + + def _writeTriple(self, triple): + self.writer.startElement(u"triple", TRIX_NS) + for component in triple: + if isinstance(component, URIRef): + self.writer.simpleElement(u"uri", TRIX_NS, + content=unicode(component)) + elif isinstance(component, BNode): + self.writer.simpleElement(u"id", TRIX_NS, + content=unicode(component)) + elif isinstance(component, Literal): + if component.datatype: + self.writer.simpleElement(u"typedLiteral", TRIX_NS, + content=unicode(component), + attributes={u"datatype": unicode(component.datatype)}) + elif component.language: + self.writer.simpleElement(u"plainLiteral", TRIX_NS, + content=unicode(component), + attributes={ + (u"xml:lang", XML_NAMESPACE): unicode(component.language)}) + else: + self.writer.simpleElement(u"plainLiteral", TRIX_NS, + content=unicode(component)) + self.writer.endElement(u"triple", TRIX_NS) + +trixserializer.diff +------------------- + +.. code-block:: text + + Index: rdflib/plugin.py + =================================================================== + --- rdflib/plugin.py (revision 1239) + +++ rdflib/plugin.py (working copy) + @@ -49,6 +49,9 @@ + register('pretty-xml', serializers.Serializer, + 'rdflib.syntax.serializers.PrettyXMLSerializer', 'PrettyXMLSerializer') + + +register('TriX', serializers.Serializer, + + 'rdflib.syntax.serializers.TriXSerializer', 'TriXSerializer') + + + register('nt', serializers.Serializer, + 'rdflib.syntax.serializers.NTSerializer', 'NTSerializer') + + Index: rdflib/syntax/parsers/TriXHandler.py + =================================================================== + --- rdflib/syntax/parsers/TriXHandler.py (revision 1239) + +++ rdflib/syntax/parsers/TriXHandler.py (working copy) + @@ -33,6 +33,7 @@ + """ + from rdflib import RDF, RDFS, Namespace + from rdflib import URIRef, BNode, Literal + +from rdflib.Namespace import Namespace + from rdflib.Graph import Graph + from rdflib.exceptions import ParserError, Error + from rdflib.syntax.xml_names import is_ncname + @@ -42,7 +43,7 @@ + + RDFNS = RDF.RDFNS + + -TRIXNS=Namespace.Namespace("http://www.w3.org/2004/03/trix/trix-1/") + +TRIXNS=u"http://www.w3.org/2004/03/trix/trix-1/" + + + class TriXHandler(handler.ContentHandler): + @@ -200,6 +201,7 @@ + self.error("This should never happen if the SAX parser ensures XML syntax correctness") + + if name[1]=="graph": + + self.graph = Graph(store = self.store.store) + self.state=1 + + if name[1]=="TriX": + +test_trixserializer.py +---------------------- + +.. code-block:: python + + from rdflib.Graph import ConjunctiveGraph + from rdflib import URIRef, Literal + from rdflib.Graph import Graph + + s1 = URIRef('store:1') + r1 = URIRef('resource:1') + r2 = URIRef('resource:2') + + label = URIRef('predicate:label') + + g1 = Graph(identifier = s1) + g1.add((r1, label, Literal("label 1", lang="en"))) + g1.add((r1, label, Literal("label 2"))) + + s2 = URIRef('store:2') + g2 = Graph(identifier = s2) + g2.add((r2, label, Literal("label 3"))) + + g = ConjunctiveGraph() + + for s,p,o in g1.triples((None, None, None)): + g.addN([(s,p,o,g1)]) + + for s,p,o in g2.triples((None, None, None)): + g.addN([(s,p,o,g2)]) + + r3 = URIRef('resource:3') + + g.add((r3, label, Literal(4))) + #g.addN([(r1, label, Literal("label 1"), s1), + # (r1, label, Literal("label 2"), s1), + # (r2, label, Literal("label 3"), s2)]) + + for c in g.contexts(): + pass + #s = Graph(g.store, identifier=c) + #print c, c.identifier.__class__, c.identifier, len(c) + + r = g.serialize(format='TriX') + print r + + g3 = ConjunctiveGraph() + from rdflib.StringInputSource import StringInputSource + g3.parse(StringInputSource(r, None), format='trix') + for c in g3.contexts(): + print c, c.identifier.__class__, c.identifier, len(c) + + +test output +----------- + +.. code-block:: xml + + <?xml version="1.0" encoding="UTF-8"?> + <TriX xmlns="http://www.w3.org/2004/03/trix/trix-1/"> + <graph> + <uri>store:2</uri> + <triple> + <uri>resource:2</uri> + <uri>predicate:label</uri> + <plainLiteral>label 3</plainLiteral> + </triple> + </graph> + <graph> + <uri>store:1</uri> + <triple> + <uri>resource:1</uri> + <uri>predicate:label</uri> + <plainLiteral>label 2</plainLiteral> + </triple> + <triple> + <uri>resource:1</uri> + <uri>predicate:label</uri> + <plainLiteral xml:lang="en">label 1</plainLiteral> + </triple> + </graph> + <graph> + <triple> + <uri>resource:3</uri> + <uri>predicate:label</uri> + <typedLiteral datatype="http://www.w3.org/2001/XMLSchema#integer">4</typedLiteral> + </triple> + </graph> + </TriX> + +.. code-block:: n3 + + [a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']]. + <class 'rdflib.BNode.BNode'> QeDIviuA11 1 + <store:2> a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']. + <class 'rdflib.URIRef.URIRef'> store:2 1 + <store:1> a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']. + <class 'rdflib.URIRef.URIRef'> store:1 2 + +SPARQL-XML Serializer +===================== + +.. code-block:: python + + # -*- coding: iso-8859-15 -*- + # (c) Mikael Högqvist, ZIB, AstroGrid-D + # This software is licensed under the software license specified at + # http://www.gac-grid.org/ + + # this is a work-around of the SPARQL XML-serialization in rdflib which does + # not work on all installation due to a bug in the python sax-parser + # We rely on ElementTree which is only available in Python 2.5 + + from cStringIO import StringIO + + try: + from xml.etree.cElementTree import Element, SubElement, ElementTree, ProcessingInstruction + import xml.etree.cElementTree as ET + except ImportError: + from cElementTree import Element, SubElement, ElementTree + import cElementTree as ET + + from rdflib import URIRef, BNode, Literal + + SPARQL_XML_NAMESPACE = u'http://www.w3.org/2005/sparql-results#' + XML_NAMESPACE = "http://www.w3.org/2001/XMLSchema#" + + name = lambda elem: u'{%s}%s' % (SPARQL_XML_NAMESPACE, elem) + xml_name = lambda elem: u'{%s}%s' % (XML_NAMESPACE, elem) + + def variables(results): + # don't include any variables which are not part of the + # result set + #res_vars = set(results.selectionF).intersection(set(results.allVariables)) + + + # this means select *, use all variables from the result-set + if len(results.selectionF) == 0: + res_vars = results.allVariables + else: + res_vars = [v for v in results.selectionF if v in results.allVariables] + + return res_vars + + def header(results, root): + head = SubElement(root, name(u'head')) + + res_vars = variables(results) + for var in res_vars: + v = SubElement(head, name(u'variable')) + # remove the ? + v.attrib[u'name'] = var[1:] + + + def binding(val, var, elem): + bindingElem = SubElement(elem, name(u'binding')) + bindingElem.attrib[u'name'] = var + + if isinstance(val,URIRef): + varElem = SubElement(bindingElem, name(u'uri')) + elif isinstance(val,BNode) : + varElem = SubElement(bindingElem, name(u'bnode')) + elif isinstance(val,Literal): + varElem = SubElement(bindingElem, name(u'literal')) + + if val.language != "" and val.language != None: + varElem.attrib[xml_name(u'lang')] = str(val.language) + elif val.datatype != "" and val.datatype != None: + varElem.attrib[name(u'datatype')] = str(val.datatype) + + varElem.text = str(val) + + def res_iter(results): + res_vars = variables(results) + + for row in results.selected: + if len(res_vars) == 1: + row = (row, ) + + yield zip(row, res_vars) + + def result_list(results, root): + resultsElem = SubElement(root, name(u'results')) + + ordered = results.orderBy + + if ordered == None: + ordered = False + + # removed according to the new working draft (2007-06-14) + # resultsElem.attrib[u'ordered'] = str(ordered) + # resultsElem.attrib[u'distinct'] = str(results.distinct) + + for row in res_iter(results): + resultElem = SubElement(resultsElem, name(u'result')) + # remove the ? from the variable name + [binding(val, var[1:], resultElem) for (val, var) in row] + + def serializeXML(results): + root = Element(name(u'sparql')) + + header(results, root) + result_list(results, root) + + out = StringIO() + tree = ElementTree(root) + + # xml declaration must be written by hand + # http://www.nabble.com/Writing-XML-files-with-ElementTree-t3433325.html + out.write('<?xml version="1.0" encoding="utf-8"?>') + out.write('<?xml-stylesheet type="text/xsl" href="/static/sparql-xml-to-html.xsl"?>') + tree.write(out, encoding='utf-8') + + return out.getvalue() diff --git a/docs/_build/html/_sources/assorted_examples.txt b/docs/_build/html/_sources/assorted_examples.txt new file mode 100644 index 00000000..344e7e11 --- /dev/null +++ b/docs/_build/html/_sources/assorted_examples.txt @@ -0,0 +1,629 @@ +.. _assorted_examples: + +================= +Assorted examples +================= + +Conjunctive Graphs +================== + +.. code-block:: python + + from rdflib import Namespace, BNode, Literal, URIRef + from rdflib.Graph import Graph, ConjunctiveGraph + from rdflib.store.IOMemory import IOMemory + + ns = Namespace("http://love.com#") + + 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#") + + store = IOMemory() + + g = ConjunctiveGraph(store=store) + g.bind("love",ns) + + gmary = Graph(store=store, identifier=cmary) + + gmary.add((mary, ns['hasName'], Literal("Mary"))) + gmary.add((mary, ns['loves'], john)) + + gjohn = Graph(store=store, identifier=cjohn) + gjohn.add((john, ns['hasName'], Literal("John"))) + + #enumerate contexts + for c in g.contexts(): + print "-- %s " % c + + #separate graphs + print gjohn.serialize(format='n3') + print "===================" + print gmary.serialize(format='n3') + print "===================" + + #full graph + print g.serialize(format='n3') + + +Two-finger exercises +==================== + +.. code-block:: python + + import logging + + # Configure how we want rdflib logger to log messages + _logger = logging.getLogger("rdflib") + _logger.setLevel(logging.DEBUG) + _hdlr = logging.StreamHandler() + _hdlr.setFormatter(logging.Formatter('%(name)s %(levelname)s: %(message)s')) + _logger.addHandler(_hdlr) + + from rdflib.Graph import Graph + from rdflib import URIRef, Literal, BNode, Namespace + from rdflib import RDF + + store = Graph() + + # Bind a few prefix, namespace pairs. + store.bind("dc", "http://http://purl.org/dc/elements/1.1/") + store.bind("foaf", "http://xmlns.com/foaf/0.1/") + + # Create a namespace object for the Friend of a friend namespace. + FOAF = Namespace("http://xmlns.com/foaf/0.1/") + + # Create an identifier to use as the subject for Donna. + donna = BNode() + + # Add triples using store's add method. + store.add((donna, RDF.type, FOAF["Person"])) + store.add((donna, FOAF["nick"], Literal("donna", lang="foo"))) + store.add((donna, FOAF["name"], Literal("Donna Fales"))) + + # Iterate over triples in store and print them out. + print "--- printing raw triples ---" + for s, p, o in store: + print s, p, o + + # For each foaf:Person in the store print out its mbox property. + print "--- printing mboxes ---" + for person in store.subjects(RDF.type, FOAF["Person"]): + for mbox in store.objects(person, FOAF["mbox"]): + print mbox + + # Serialize the store as RDF/XML to the file foaf.rdf. + store.serialize("foaf.rdf", format="pretty-xml", max_depth=3) + + # Let's show off the serializers + + print "RDF Serializations:" + + # Serialize as XML + print "--- start: rdf-xml ---" + print store.serialize(format="pretty-xml") + print "--- end: rdf-xml ---\n" + + # Serialize as NTriples + print "--- start: ntriples ---" + print store.serialize(format="nt") + print "--- end: ntriples ---\n" + + + + +Update namespace +================ + +.. code-block:: python + + #OLD = "http://www.mindswap.org/2004/terrorOnt.owl#" + #OLD = "http://wang-desktop/TerrorOrgInstances#" + OLD = "http://localhost/" + NEW = "http://profilesinterror.mindswap.org/" + + redfoot.bind("terror", "http://counterterror.mindswap.org/2005/terrorism.owl#") + redfoot.bind("terror_old", "http://www.mindswap.org/2004/terrorOnt.owl#") + redfoot.bind("tech", "http://www.mindswap.org/~glapizco/technical.owl#") + redfoot.bind("wang-desk", "http://wang-desktop/TerrorOrgInstances#") + redfoot.bind("foaf", 'http://xmlns.com/foaf/0.1/') + redfoot.bind("dc", 'http://purl.org/dc/elements/1.1/') + + + REDFOOT = redfoot.namespace("http://redfoot.net/2005/redfoot#") + + for cid, _, source in redfoot.triples((None, REDFOOT.source, None)): + if source: + print "updating %s" % source + try: + context = redfoot.get_context(cid) + + for s, p, o in context: + context.remove((s, p, o)) + if isinstance(s, URIRef) and OLD in s: + s = URIRef(s.replace(OLD, NEW)) + if isinstance(p, URIRef) and OLD in p: + p = URIRef(p.replace(OLD, NEW)) + if isinstance(o, URIRef) and OLD in o: + o = URIRef(o.replace(OLD, NEW)) + context.add((s, p, o)) + + context.save(source, format="pretty-xml") + except Exception, e: + print e + + +SPARQL query +============ + +.. code-block:: python + + from rdflib import Literal, ConjunctiveGraph, Namespace, BNode, URIRef + + DC = Namespace(u"http://purl.org/dc/elements/1.1/";) + FOAF = Namespace(u"http://xmlns.com/foaf/0.1/";) + + graph = ConjunctiveGraph() + s = BNode() + graph.add((s, FOAF['givenName'], Literal('Alice'))) + b = BNode() + graph.add((b, FOAF['givenName'], Literal('Bob'))) + graph.add((b, DC['date'], Literal("2005-04-04T04:04:04Z"))) + + print graph.query("""PREFIX foaf: <http://xmlns.com/foaf/0.1/> + PREFIX dc: <http://purl.org/dc/elements/1.1/> + PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> + SELECT ?name + WHERE { ?x foaf:givenName ?name . + OPTIONAL { ?x dc:date ?date } . + FILTER ( bound(?date) ) }""").serialize('python') + + +Data reading exercise +===================== + +.. code-block:: python + + #!/usr/bin/env python + # -*- coding: utf-8 -*- + + """Demo script to show the different ways to read information + from an RDF file using rdflib, as found at http://rdflib.net/. + + The tree main methods are: + 1. Simple lookup in a list of triplets (SimpleLookup), + 2. SPARQL query, created with rdflib.sparql.* objects (CustomSparql), + 3. SPARQL query, created with bison (BisonSparql). + + The main function reads a file, xfn-example.rdf, and displays all resource + pairs with a symmetrical "xfn:met" relation (e.g. A met B and B met A) + Uses the rdfs:label of the resources to display the name. + + This demo file has been tested with the following versions of RDFlib: + rdflib 2.0.6 -- unsupported (since it has no "Graph" modules) + rdflib 2.1.3 -- methods 1, and 2 work fine + rdflib 2.1.4 -- methods 1, and 2 work fine + rdflib 2.2.3 -- methods 1, and 2 work fine + rdflib 2.3.0 -- methods 1, and 2 work fine + rdflib 2.3.1 -- methods 1, and 2 work fine + rdflib 2.3.2 -- methods 1, and 2 work fine + rdflib 2.3.3 -- methods 1, 2, and 3 work fine + rdflib 2.4.0 -- methods 1, 2, and 3 work fine (but function call for method 2 was changed) + """ + + __copyright__ = "rdflibdemo written by Freek Dijkstra, Universiteit van Amsterdam, april 2007, contributed to the public domain (feel free to attribute me, but it's not needed)." + + import os + import sys + import distutils.version + # semi-standard modules + try: + import rdflib + except ImportError: + raise ImportError("Module rdflib is not available. It can be downloaded from http://rdflib.net/\n") + if distutils.version.StrictVersion(rdflib.__version__) < "2.0.9": + raise ImportError("The installed version of rdflib, %s, is too old. 2.1 or higher is required" % rdflib.__version__) + from rdflib.Graph import Graph + from rdflib.sparql.sparqlGraph import SPARQLGraph + from rdflib.sparql.graphPattern import GraphPattern + if distutils.version.StrictVersion(rdflib.__version__) > "2.3.2": + from rdflib.sparql.bison import Parse # available in 2.3.3 and up + if distutils.version.StrictVersion(rdflib.__version__) > "2.3.9": + from rdflib.sparql import Query # available in 2.4.0 and up + + + + + def SimpleLookup(graph): + """ + Extracts information form a rdflib Graph object + using a simple list lookup. E.g.: + result = list(graph.subject_objects(self.xfn["met"])): + """ + assert(isinstance(graph, Graph)) + xfn = rdflib.Namespace("http://gmpg.org/xfn/1#") + rdf = rdflib.Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#") + rdfs = rdflib.Namespace("http://www.w3.org/2000/01/rdf-schema#") + meetings = [] + # Get a list of (subject, object) tuples in the graph with the xfn:met predicate + relations = list(graph.subject_objects(xfn["met"])) + for (person, peer) in relations: + if not (peer, person) in relations: + # person says he/she has met peer, but peer doesn't say he/she has met person. Skip. + continue + # since we're processing (person, peer), we can skip (peer, person) later + relations.remove((peer, person)) + personname = list(graph.objects(person, rdfs["label"])) + if len(personname) == 0: + continue # skip persons with no name + peername = list(graph.objects(peer, rdfs["label"])) + if len(peername) == 0: + continue # skip peers with no name + personname = list(graph.objects(person, rdfs["label"])) + # Add the name of the person and peer to list of people who've met. + meetings.append((personname[0], peername[0])) + + # Print the results + print "Simple Lookup (%d meetings found)" % len(meetings) + print 40*"-" + for (person, peer) in meetings: + print "%s and %s have met" % (person, peer) + print + + + def CustomSparql(graph): + """ + Extracts information form a rdflib Graph object + using a SPARQL query, put together using GraphPattern objects. E.g.: + select = ("?ifA","?ifB") + where = GraphPattern([("?ifA", xfn["met"], "?ifB")]) + result = graph.query(select,where) + See http://dev.w3.org/cvsweb/~checkout~/2004/PythonLib-IH/Doc/sparqlDesc.html for more information. + """ + assert(isinstance(graph, Graph)) + xfn = rdflib.Namespace("http://gmpg.org/xfn/1#") + rdf = rdflib.Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#") + rdfs = rdflib.Namespace("http://www.w3.org/2000/01/rdf-schema#") + select = ("?personname","?peername") + where = GraphPattern([ + ("?person", xfn["met"], "?peer"), + ("?peer", xfn["met"], "?person"), + ("?person", rdfs["label"], "?personname"), + ("?peer", rdfs["label"], "?peername"), + ]) + # Create a SPARQLGraph wrapper object out of the normal Graph + sparqlGrph = SPARQLGraph(graph) + # Make the query + if distutils.version.StrictVersion(rdflib.__version__) <= "2.3.9": + relations = sparqlGrph.query(select, where) + else: + # graph.query() function was changed in RDFlib 2.4.0 + bindings = { u"xfn": xfn, u"rdf": rdf, u"rdfs": rdfs } + relations = Query.query(sparqlGrph, select, where, initialBindings=bindings) + + for (person, peer) in relations: + # since we're processing (person, peer), we can skip (peer, person) later + relations.remove((peer, person)) + + # Print the results + print "Manual formatted SPARQL query (%d meetings found)" % len(relations) + print 40*"-" + for (person, peer) in relations: + print "%s and %s have met" % (person, peer) + print + + + def BisonSparql(graph): + """ + Extracts information form a rdflib Graph object + using a SPARQL query, parsed by the bison parser in RDFlib. + graphpattern = Parse('SELECT ?ifA ?ifB WHERE { ?ifA xfn:met ?ifB . ?ifB xfn:met ?ifA }') + result = graph.query(graphpattern, initNs=bindings) + """ + assert(isinstance(graph, Graph)) + if distutils.version.StrictVersion(rdflib.__version__) <= "2.3.2": + print "Skipping Bison SPARQL query (requires RDFlib 2.3.3 or higher; version %s detected)" % (rdflib.__version__) + print + return + xfn = rdflib.Namespace("http://gmpg.org/xfn/1#") + rdf = rdflib.Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#") + rdfs = rdflib.Namespace("http://www.w3.org/2000/01/rdf-schema#") + bindings = { u"xfn": xfn, u"rdf": rdf, u"rdfs": rdfs } + query = Parse('SELECT ?personname ?peername WHERE \ + { ?person xfn:met ?peer . ?peer xfn:met ?person . \ + ?person rdfs:label ?personname . ?peer rdfs:label ?peername }') + # Make the query, and serialize the result as python objects (as opposed to for example XML) + relations = graph.query(query, initNs=bindings).serialize('python') + for (person, peer) in relations: + # since we're processing (person, peer), we can skip (peer, person) later + relations.remove((peer, person)) + + # Print the results + print "Bison SPARQL query (%d meetings found)" % len(relations) + print 40*"-" + for (person, peer) in relations: + print "%s and %s have met" % (person, peer) + print + + def ReadFile(filename="xfn-example.rdf"): + """Read a RDF and returns the objects in a rdflib Graph object""" + graph = Graph() + print "Read RDF data from %s" % filename + print + graph.parse(filename) + return graph + + if __name__=="__main__": + print "RDFlib version %s detected" % rdflib.__version__ + print + graph = ReadFile() + SimpleLookup(graph) + CustomSparql(graph) + BisonSparql(graph) + +Example Foaf Smushing +===================== + +Filter a graph by normalizing all foaf persons into URIs based on their mbox_sha1sum. + +Suppose I got two FOAF documents each talking about the same person (according to mbox_sha1sum) but they each used a BNode for the subject. For this demo I've combined those two documents into one file: + +demo.n3 +------- + +.. code-block:: n3 + + @prefix foaf: <http://xmlns.com/foaf/0.1/> . + + # from one document + :p0 a foaf:Person; + foaf:mbox_sha1sum "65b983bb397fb71849da910996741752ace8369b"; + foaf:nick "mortenf"; + foaf:weblog <http://www.wasab.dk/morten/blog/archives/author/mortenf/> . + + # from another document + :p1 a foaf:Person; + foaf:mbox_sha1sum "65b983bb397fb71849da910996741752ace8369b"; + foaf:nick "mortenf"; + foaf:homepage <http://www.wasab.dk/morten/>; + foaf:interest <http://en.wikipedia.org/wiki/Atom_(standard)>, + +Now I'll use rdflib to transform all the incoming FOAF data to new data that lies about the subjects. It might be easier to do some queries on this resulting graph, although you wouldn't want to actually publish the result anywhere since it loses some information about FOAF people who really had a meaningful URI. + +fold_sha1.py +------------ + +.. code-block:: python + + """filter a graph by changing every subject with a foaf:mbox_sha1sum + into a new subject whose URI is based on the sha1sum. This new graph + might be easier to do some operations on. + """ + + from rdflib.Graph import Graph + from rdflib import Namespace + + FOAF = Namespace("http://xmlns.com/foaf/0.1/") + STABLE = Namespace("http://example.com/person/mbox_sha1sum/") + + g = Graph() + g.parse("demo.n3", format="n3") + + newURI = {} # old subject : stable uri + for s,p,o in g.triples((None, FOAF['mbox_sha1sum'], None)): + newURI[s] = STABLE[o] + + + out = Graph() + 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") + +Output +------ +note how all of the data has come together under one subject: + +.. code-block:: n3 + + @prefix _5: <http://example.com/person/mbox_sha1sum/65>. + @prefix foaf: <http://xmlns.com/foaf/0.1/>. + @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. + + _5:b983bb397fb71849da910996741752ace8369b a foaf:Person; + foaf:homepage <http://www.wasab.dk/morten/>; + foaf:interest <http://en.wikipedia.org/wiki/Atom_(standard)>; + foaf:mbox_sha1sum "65b983bb397fb71849da910996741752ace8369b"; + foaf:nick "mortenf"; + foaf:weblog <http://www.wasab.dk/morten/blog/archives/author/mortenf/>. + +An advantage of this approach over other methods for collapsing BNodes is that I can incrementally process new FOAF documents as they come in 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. + +Transitive traversal +==================== + +How to use the `transitive_objects` and `transitive_subjects` graph methods + +Formal definition +----------------- +The :meth:`transitive_objects` method finds all nodes such that there is a path from subject to one of those nodes using only the predicate property in the triples. The :meth:`transitive_subjects` method is similar; it finds all nodes such that there is a path from the node to the object using only the predicate property. + +Informal description, with an example +------------------------------------- +In brief, :meth:`transitive_objects` walks forward in a graph using a particular property, and :meth:`transitive_subjects` walks backward. A good example uses a property ``ex:parent``, the semantics of which are biological parentage. The :meth:`transitive_objects` method would get all the ancestors of a particular person (all nodes such that there is a parent path between the person and the object). The :meth:`transitive_subjects` method would get all the descendants of a particular person (all nodes such that there is a parent path between the node and the person). So, say that your URI is ``ex:person``. + +The following code would get all of your (known) ancestors, and then get all the (known) descendants of your maternal grandmother: + +.. code-block:: python + + 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') + + parent = URIRef('ex:parent') + + g = ConjunctiveGraph() + g.add((person, parent, dad)) + g.add((person, parent, mom)) + g.add((dad, parent, momOfDad)) + g.add((dad, parent, dadOfDad)) + g.add((mom, parent, momOfMom)) + g.add((mom, parent, dadOfMom)) + + print "Parents, forward from `ex:person`:" + for i in g.transitive_objects(person, parent): + print i + + print "Parents, *backward* from `ex:gm1`:" + for i in g.transitive_subjects(parent, momOfMom): + print i + +.. warning:: The :meth:`transitive_objects` method has the start node as the *first* argument, but the :meth:`transitive_subjects` method has the start node as the *second* argument. + +film.py +======= + +.. code-block:: python + + #!/usr/bin/env python + """ 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 + + -- + Usage: + film.py whoami "John Doe <john@doe.org>" + Initialize the store and set your name and email. + film.py whoami + Tell you who you are + film.py http://www.imdb.com/title/tt0105236/ + Review the movie "Reservoir Dogs" + """ + import datetime, os, sys, re, time, imdb + from rdflib import BNode, ConjunctiveGraph, URIRef, Literal, Namespace, RDF + + #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_-]+)+)>$') + + DC = Namespace('http://purl.org/dc/elements/1.1/') + FOAF = Namespace('http://xmlns.com/foaf/0.1/') + 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', 'http://purl.org/dc/elements/1.1/') + self.graph.bind('foaf', 'http://xmlns.com/foaf/0.1/') + self.graph.bind('imdb', 'http://www.csd.abdn.ac.uk/~ggrimnes/dev/imdb/IMDB#') + self.graph.bind('rev', 'http://purl.org/stuff/rev#') + + def save(self): + 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.save() + else: + 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'])))) + 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))) + print comment + if comment is not None: + 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 + + def help(): + print __doc__.split('--')[1] + + def main(argv=None): + if not argv: + argv = sys.argv + s = Store() + if argv[1] in ('help', '--help', 'h', '-h'): + help() + 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'): + 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'].encode('utf-8')) + for director in movie['director']: + print 'directed by: %s' % director['name'].encode('utf-8') + for writer in movie['writer']: + print 'writed 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(raw_input('Rating (on five): ')) + except ValueError: + rating = None + date = None + while not date: + try: + i = raw_input('Review date (YYYY-MM-DD): ') + date = datetime.datetime(*time.strptime(i, '%Y-%m-%d')[:6]) + except: + date = None + comment = raw_input('Comment: ') + s.new_review(movie, date, rating, comment) + else: + help() + + if __name__ == '__main__': + main() + diff --git a/docs/_build/html/_sources/gettingstarted.txt b/docs/_build/html/_sources/gettingstarted.txt new file mode 100644 index 00000000..ff89dcc6 --- /dev/null +++ b/docs/_build/html/_sources/gettingstarted.txt @@ -0,0 +1,234 @@ +.. _gettingstarted: + +=========================== +Getting started with rdflib +=========================== + +Introduction to parsing RDF into rdflib graphs +---------------------------------------------- + +Reading an NT file +^^^^^^^^^^^^^^^^^^ + +RDF data has various syntaxes (``xml``, ``n3``, ``ntriples``, ``trix``, etc) that you might want to read. The simplest format is ``ntriples``. Create the file :file:`demo.nt` in the current directory with these two lines: + +.. code-block:: n3 + + <http://bigasterisk.com/foaf.rdf#drewp> \ + <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> \ + <http://xmlns.com/foaf/0.1/Person> . + <http://bigasterisk.com/foaf.rdf#drewp> \ + <http://example.com/says> \ + "Hello world" . + +In an interactive python interpreter, try this: + +.. code-block:: python + + >>> from rdflib.graph import Graph + >>> g = Graph() + >>> g.parse("demo.nt", format="nt") + <Graph identifier=HCbubHJy0 (<class 'rdflib.graph.Graph'>)> + >>> len(g) + 2 + >>> import pprint + >>> for stmt in g: + ... pprint.pprint(stmt) + ... + (rdflib.term.URIRef('http://bigasterisk.com/foaf.rdf#drewp'), + rdflib.term.URIRef('http://example.com/says'), + rdflib.term.Literal(u'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')) + +The final lines show how rdflib represents the two statements in the file. The statements themselves are just length-3 tuples; and the subjects, predicates, and objects are all rdflib types. + +Reading remote graphs +^^^^^^^^^^^^^^^^^^^^^ + +Reading graphs from the net is just as easy: + +.. code-block:: pycon + + >>> g.parse("http://bigasterisk.com/foaf.rdf") + >>> len(g) + 42 + +The format defaults to ``xml``, which is the common format for .rdf files you'll find on the net. + +See also + +.. automethod:: rdflib.graph.Graph.parse + +Other parsers supported by rdflib +--------------------------------- + +.. automodule:: rdflib.syntax.parsers + +.. automodule:: rdflib.syntax.parsers.n3p + +.. automodule:: rdflib.syntax.parsers.N3Parser + +.. autoclass:: rdflib.syntax.parsers.N3Parser.N3Parser + :members: + +.. automodule:: rdflib.syntax.parsers.NTParser + +.. autoclass:: rdflib.syntax.parsers.NTParser.NTParser + :members: + +.. automodule:: rdflib.syntax.parsers.ntriples + +.. autoclass:: rdflib.syntax.parsers.ntriples.NTriplesParser + :members: + +.. automodule:: rdflib.syntax.parsers.RDFXMLParser + +.. autoclass:: rdflib.syntax.parsers.RDFXMLParser.RDFXMLParser + :members: + +.. automodule:: rdflib.syntax.parsers.TriXParser + +.. autoclass:: rdflib.syntax.parsers.TriXParser.TriXParser + :members: + +.. .. automodule:: rdflib.syntax.parsers.RDFaParser +.. :members: +.. +.. .. autoclass:: rdflib.syntax.parsers.RDFaParser.RDFaParser +.. :members: +.. + +Introduction to using SPARQL to query an rdflib graph +----------------------------------------------------- + +Create an Rdflib Graph +^^^^^^^^^^^^^^^^^^^^^^ + +You might parse some files into a new graph (_`Introduction to parsing RDF into rdflib graphs`) or open an on-disk rdflib store. + +.. code-block:: python + + from rdflib.graph import Graph + g = Graph() + g.parse("http://bigasterisk.com/foaf.rdf") + g.parse("http://www.w3.org/People/Berners-Lee/card.rdf") + +LiveJournal produces FOAF data for their users, but they seem to use ``foaf:member_name`` for a person's full name. For this demo, I made ``foaf:name`` act as a synonym for ``foaf:member_name`` (a poor man's one-way ``owl:equivalentProperty``): + +.. code-block:: python + + from rdflib.namespace import Namespace + FOAF = Namespace("http://xmlns.com/foaf/0.1/") + g.parse("http://danbri.livejournal.com/data/foaf") + [g.add((s, FOAF['name'], n)) for s,_,n in g.triples((None, FOAF['member_name'], None))] + +Run a Query +^^^^^^^^^^^ + +.. code-block:: python + + for row in g.query( + """SELECT ?aname ?bname + WHERE { + ?a foaf:knows ?b . + ?a foaf:name ?aname . + ?b foaf:name ?bname . + }""", + initNs=dict(foaf=Namespace("http://xmlns.com/foaf/0.1/"))): + print "%s knows %s" % row + +The results are tuples of values in the same order as your SELECT arguments. + +.. code-block:: text + + Timothy Berners-Lee knows Edd Dumbill + Timothy Berners-Lee knows Jennifer Golbeck + Timothy Berners-Lee knows Nicholas Gibbins + Timothy Berners-Lee knows Nigel Shadbolt + Dan Brickley knows binzac + Timothy Berners-Lee knows Eric Miller + Drew Perttula knows David McClosky + Timothy Berners-Lee knows Dan Connolly + ... + +Namespaces +^^^^^^^^^^ +The :meth:`Graph.parse` :keyword:`initNs` argument is a dictionary of namespaces to be expanded in the query string. In a large program, it's common to use the same dict for every single query. You might even hack your graph instance so that the ``initNs`` arg is already filled in. + +If someone knows how to use the empty prefix (e.g. "?a :knows ?b"), please write about it here and in the :meth:`Graph.query` docs. + +*ewan klein provides the answer, use BASE to set a default namespace ...* + +.. code-block:: sparql + + BASE <http://xmlns.com/foaf/0.1/> + +Bindings +^^^^^^^^ + +Just like with SQL queries, it's common to run the same query many times with only a few terms changing. rdflib calls this ``initBindings``: + +.. code-block:: python + + FOAF = Namespace("http://xmlns.com/foaf/0.1/") + ns = dict(foaf=FOAF) + drew = URIRef('http://bigasterisk.com/foaf.rdf#drewp') + for row in g.query("""SELECT ?name + WHERE { ?p foaf:name ?name }""", + initNs=ns, initBindings={'?p' : drew}): + print row + +Output: + +.. code-block:: python + + (rdflib.Literal('Drew Perttula', language=None, datatype=None),) + +.. automethod:: rdflib.graph.Graph.query + +Store operations +---------------- + +Example code to create a MySQL triple store, add some triples, and serialize the resulting graph. + +.. code-block:: python + + import rdflib + from rdflib.graph import ConjunctiveGraph as Graph + from rdflib import plugin + from rdflib.store import Store, NO_STORE, VALID_STORE + from rdflib.namespace import Namespace + from rdflib.term import Literal + from rdflib.term import URIRef + + default_graph_uri = "http://rdflib.net/rdfstore" + configString = "host=localhost,user=username,password=password,db=rdfstore" + + # Get the mysql plugin. You may have to install the python mysql libraries + store = plugin.get('MySQL', Store)('rdfstore') + + # Open previously created store, or create it if it doesn't exist yet + rt = store.open(configString,create=False) + if rt == NO_STORE: + # There is no underlying MySQL infrastructure, create it + store.open(configString,create=True) + else: + assert rt == VALID_STORE,"There underlying store is corrupted" + + # There is a store, use it + graph = Graph(store, identifier = URIRef(default_graph_uri)) + + 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.add((rdflib['pic:1'], rdflib['name'], Literal('Jane & Bob'))) + graph.add((rdflib['pic:2'], rdflib['name'], Literal('Squirrel in Tree'))) + graph.commit() + + print "Triples in graph after add: ", len(graph) + + # display the graph in RDF/XML + print graph.serialize() diff --git a/docs/_build/html/_sources/graph_merging.txt b/docs/_build/html/_sources/graph_merging.txt new file mode 100644 index 00000000..51c40ff5 --- /dev/null +++ b/docs/_build/html/_sources/graph_merging.txt @@ -0,0 +1,157 @@ +.. _graph_merging: Procedures to merge graphs + +============== +Merging graphs +============== + +Example 1 +--------- + +.. code-block:: python + + import logging + + _logger = logging.getLogger(redfoot_current) + + from rdflib.Graph import Graph + + f = file(args[0], "r") + + pairs = [] + for line in f: + try: + line = line.strip() + source, destination = line.split(" ") + except ValueError, e: + _logger.info("Could not split '%s'" % line) + continue + source, destination = URIRef(source).abstract(), URIRef(destination).abstract() + if destination.startswith(source): + _logger.info("Skipping %s->%s to avoid inf. loop" % (source, destination)) + else: + pairs.append((source, destination)) + + f.close() + + nothing_merged = True + + # merge contexts + for context in list(redfoot.contexts()): + for OLD, NEW in pairs: + if OLD in context.identifier: + if isinstance(context.identifier, URIRef): + identifier = URIRef(context.identifier.replace(OLD, NEW)) + elif isinstance(context.identifier, BNode): + identifier = BNode(context.identifier.replace(OLD, NEW)) + else: + _logger.warning( + "Unexpected identifier type. Skipping context '%s'" \ + % context.identifier) + continue + new_context = Graph(store=redfoot.store, + identifier=identifier, + namespace_manager=redfoot) + nothing_merged = False + else: + new_context = context + + for s, p, o in context: + ss, pp, oo = s, p, o + if isinstance(s, URIRef) and OLD in s: + ss = URIRef(s.replace(OLD, NEW)) + if isinstance(p, URIRef) and OLD in p: + pp = URIRef(p.replace(OLD, NEW)) + if isinstance(o, URIRef) and OLD in o: + oo = URIRef(o.replace(OLD, NEW)) + if (ss, pp, oo)!=(s, p, o) or context!=new_context: + nothing_merged = False + context.remove((s, p, o)) + new_context.add((ss, pp, oo)) + + if new_context!=context: + redfoot.remove_context(context.identifier) + + if nothing_merged: + _logger.warning("nothing merged.") + +Example 2 +--------- + +.. code-block:: python + + ''' + Tutorial 9 - demonstrate graph operations + + (not really quite graph operations since rdflib cannot merge models like + Jena, but this examples shows you can load two different RDF files and + rdflib will merge the two together into one model) + + Copyright (C) 2005 Sylvia Wong <sylvia at whileloop dot org> + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + ''' + + from rdflib.URIRef import URIRef + from rdflib.Literal import Literal + from rdflib.BNode import BNode + from rdflib.Namespace import Namespace + + # Import RDFLib's default TripleStore implementation. + from rdflib.TripleStore import TripleStore + + inputFileName1 = 'vc-db-3.rdf' + inputFileName2 = 'vc-db-4.rdf' + + store = TripleStore() + store.load(inputFileName1) + store.load(inputFileName2) + + print store.serialize() + +vc-db-3.rdf +^^^^^^^^^^^ + +.. code-block:: xml + + <rdf:RDF + xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' + xmlns:vCard='http://www.w3.org/2001/vcard-rdf/3.0#'> + + <rdf:Description rdf:about="http://somewhere/JohnSmith/"> + <vCard:FN>John Smith</vCard:FN> + <vCard:N rdf:parseType="Resource"> + <vCard:Family>Smith</vCard:Family> + <vCard:Given>John</vCard:Given> + </vCard:N> + </rdf:Description> + </rdf:RDF> + +vc-db-4.rdf +^^^^^^^^^^^ + +.. code-block:: xml + + <rdf:RDF + xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' + xmlns:vCard='http://www.w3.org/2001/vcard-rdf/3.0#'> + + <rdf:Description rdf:about="http://somewhere/JohnSmith/"> + <vCard:FN>John Smith</vCard:FN> + <vCard:EMAIL rdf:parseType="Resource"> + <rdf:type rdf:resource="http://www.w3.org/2001/vcard-rdf/3.0#internet"/> + <rdf:value>John@somewhere.com</rdf:value> + </vCard:EMAIL> + </rdf:Description> + </rdf:RDF> diff --git a/docs/_build/html/_sources/graph_utilities.txt b/docs/_build/html/_sources/graph_utilities.txt new file mode 100644 index 00000000..231cad21 --- /dev/null +++ b/docs/_build/html/_sources/graph_utilities.txt @@ -0,0 +1,112 @@ +.. _graph_utilities: + +=============== +Graph utilities +=============== + + +Graphs as Iterators +------------------- + +RDFLib graphs also override :meth:`__iter__` in order to support iteration over the contained triples: + +.. code-block:: python + + for subject,predicate,obj_ in someGraph: + assert (subject,predicate,obj_) in someGraph, "Iterator / Container Protocols are Broken!!" + +Set Operations on RDFLib Graphs +------------------------------- + +:meth:`__iadd__` and :meth:`__isub__` are overridden to support adding and subtracting Graphs to/from each other (in place): + +* G1 += G1 +* G2 -= G2 + +Basic Triple Matching +--------------------- + +RDFLib graphs support basic triple pattern matching with a :meth:`triples` function. + +.. automethod:: rdflib.graph.Graph.triples + +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. + +Managing Triples +---------------- + +Adding Triples +^^^^^^^^^^^^^^ +Triples can be added in two ways: + +* They may be added with with the :meth:`parse` function. + + .. automethod:: rdflib.graph.Graph.parse + + The first argument can be a *source* of many kinds, but the most common is the serialization (in various formats: RDF/XML, Notation 3, NTriples of an RDF graph as a string. The :keyword:`format` parameter is one of ``n3``, ``xml``, or ``ntriples``. :keyword:`publicID` is the name of the graph into which the RDF serialization will be parsed. +* Triples can also be added with the :meth:`add` function: + + .. automethod:: rdflib.graph.Graph.add + +Removing Triples +^^^^^^^^^^^^^^^^ + +Similarly, triples can be removed by a call to :meth:`remove`: + +.. automethod:: rdflib.graph.Graph.remove + + +RDF Literal Support +------------------- + +RDFLib Literals essentially behave like unicode characters with an XML Schema datatype or language attribute. The class provides a mechanism to both convert Python literals (and their built-ins such as time/date/datetime) into equivalent RDF Literals and (conversely) convert Literals to their Python equivalent. There is some support of considering datatypes in comparing Literal instances, implemented as an override to :meth:`__eq__`. This mapping to and from Python literals is achieved with the following dictionaries: + +.. code-block:: python + + PythonToXSD = { + basestring : (None,None), + float : (None,XSD_NS+u'float'), + int : (None,XSD_NS+u'int'), + long : (None,XSD_NS+u'long'), + bool : (None,XSD_NS+u'boolean'), + date : (lambda i:i.isoformat(),XSD_NS+u'date'), + time : (lambda i:i.isoformat(),XSD_NS+u'time'), + datetime : (lambda i:i.isoformat(),XSD_NS+u'dateTime'), + } + +Maps Python instances to WXS datatyped Literals + +.. code-block:: python + + XSDToPython = { + XSD_NS+u'time' : (None,_strToTime), + XSD_NS+u'date' : (None,_strToDate), + XSD_NS+u'dateTime' : (None,_strToDateTime), + XSD_NS+u'string' : (None,None), + XSD_NS+u'normalizedString' : (None,None), + XSD_NS+u'token' : (None,None), + XSD_NS+u'language' : (None,None), + XSD_NS+u'boolean' : (None, lambda i:i.lower() in ['1','true']), + XSD_NS+u'decimal' : (float,None), + XSD_NS+u'integer' : (long ,None), + XSD_NS+u'nonPositiveInteger' : (int,None), + XSD_NS+u'long' : (long,None), + XSD_NS+u'nonNegativeInteger' : (int, None), + XSD_NS+u'negativeInteger' : (int, None), + XSD_NS+u'int' : (int, None), + XSD_NS+u'unsignedLong' : (long, None), + XSD_NS+u'positiveInteger' : (int, None), + XSD_NS+u'short' : (int, None), + XSD_NS+u'unsignedInt' : (long, None), + XSD_NS+u'byte' : (int, None), + XSD_NS+u'unsignedShort' : (int, None), + XSD_NS+u'unsignedByte' : (int, None), + XSD_NS+u'float' : (float, None), + XSD_NS+u'double' : (float, None), + XSD_NS+u'base64Binary' : (base64.decodestring, None), + XSD_NS+u'anyURI' : (None,None), + } + +Maps WXS datatyped Literals to Python. This mapping is used by the :meth:`toPython` method defined on all Literal instances. + + diff --git a/docs/_build/html/_sources/graphs_bnodes.txt b/docs/_build/html/_sources/graphs_bnodes.txt new file mode 100644 index 00000000..aa057336 --- /dev/null +++ b/docs/_build/html/_sources/graphs_bnodes.txt @@ -0,0 +1,475 @@ +.. _graphs_bnodes: + +==================================== +Graphs, Named Graphs and Blank Nodes +==================================== + +Vin's question +============== + +Clarifying the query more precisely: + +.. code-block:: pycon + + >>> from rdflib.Graph import Graph, ConjunctiveGraph + >>> from rdflib import URIRef + +[1] + +.. code-block:: pycon + + >>> graph = Graph('MySQL', identifier = URIRef('http://www.example.com')) + >>> graph.identifier + rdflib.URIRef('http://www.example.com') + +[2] + +.. code-block:: pycon + + >>> graph1 = ConjunctiveGraph('MySQL', identifier = URIRef('http://www.example.com')) + >>> graph1.identifier + rdflib.BNode('VLjQILCh3') + +[3] + +.. code-block:: pycon + + >>> graph1 = ConjunctiveGraph('MySQL', identifier = URIRef('http://www.example.com')) + >>> graph1.identifier + rdflib.BNode('VLjQILCh4') + +In [1] when I mention the Graph identifier the return is a persistent +URIRef (i.e. it can be used out of the current model as well) which +gives me a unique name for the graph and now I am free to use it in +other model as well - may be it can be used for merging graphs. Where +as in [2] and [3] when I mention Graph identifier the return is a +BNode which changes values every time we invoke it (and hence BNodes +have local scope and are not good for using outside the model). My +query was simply to know why the Model "identifier" is giving BNode in +[2] comparing to a persistent URI in case [1]? In ConjunctiveGraph, +identifier is inherited from the Graph class. + +The discourse +============= + +This sparql-dev discussion airs some of the issues ... + +0016: Nuutti Kotivuori +---------------------- +http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0016.html + +This isn't exactly a SPARQL question, but it is very closely +related. I will first outline the question context. + +Assume an RDF statement store, which has a mechanism for tracking +statement origin (scope, context, graph, source whatever). Many of the +statements have a distinct origin, or source graph, they were imported +from. But there are also those which either seemingly have no origin, +or the origin is not known. The origin of these statements have to be +handled somehow. We'll come to the specific choices later on. + +This statement store offers a SPARQL query interface into it. The +facilities for querying named graphs in SPARQL would obviously be used +to query the different origins in the store. But there are two things +to decide. First, how should statements without an origin be accessed +in SPARQL? There are several choices on this, which I will outline +below. And related to the first one, second, what should the default +graph be for the queries if none is given explicitly. + +I will list a few possibilities and mention the problems and benefits +that seem to result from them as a basis for discussion. + + 1. Unknown origin is a distinct node, but separate from all uris, + blank nodes or literals. The default graph for the query is the + graph of the unknown origin nodes. + + - Separation of identifier spaces, no fear of any overlap. The + graph of statements with unknown origin is separate from any + named graph. + + - Since there is no way to represent the unknown origin in SPARQL + syntax, the default graph is the only way to access the nodes in + that graph. + + - The nodes in the unknown origin graph are not matched by any + graph query, since the name of the graph could not be returned + reasonably. That is: + + .. code-block:: sparql + + SELECT ?g ?s ?o ?p + WHERE { GRAPH ?g { ?s ?p ?o } } + + cannot return ?g for the unknown origin graph. + + 2. Unknown origin is a distinct node, as above. The default graph is + the RDF merge of all graphs in the store, including the statements + with an unknown origin. + + - The problems above. + + - In addition, there is no way to select nodes that explicitly + have an unknown origin. (Or is there? Could one match all the + statements for which there is no graph with the same statement? + In any case, this would be quite contorted.) + + 3. Unknown origin is represented by a distinct blank node; that is, + every statement has it's own blank node as the graph name, which + is not shared with any of the other statements. The default graph + is the RDF merge of all graphs in the store, including the + statements with an unknown origin. + + - This is probably closest to accurate modelling of the + situation. We know every statement has an origin, we just don't + know what it is - a situation commonly modelled with a blank + node. Also, we don't know which statements might share an + origin, so until we know better, we make them all distinct. + + - The origin of the statements is nicely queryable with SPARQL + queries and every statement has an origin, even if unknown. + + - Queries which specify several statements from a single graph + will not match the statements with unknown origins as it cannot + be confirmed that they would be from the same graph. + + - There is no way to match the origin of a single statement as + there is no way to match a certain blank node explicitly. The + current SPARQL treats it as an open variable(?). + + - There is no way to explicitly match statements that have an + unknown origin, since the origins are just distinct blank nodes. + + - Possibly hard to implement, because of the number of distinct + blank nodes. + + 4. Unknown origin is represented by a singleton blank node; that is, + every statement with an unknown origin shares one single blank + node as the graph name. The default graph is the RDF merge of all + graphs in the store. + + - Lumps all statements with an unknown origin under a single named + graph. Queries which match several statements from a single + graph will match statement sets from unknown origin as well. + + - The origin of the statements is nicely queryable with SPARQL + queries and every statement has an origin, even if unknown. + + - There is no way to explicitly match statements that have an + unknown origin, since the origin is a single blank node. If the + application provided a magic type for this blank node (_:x a + rdfx:UnknownOrigin), this could be matched with: + + .. code-block:: sparql + + SELECT ?s ?o ?p + WHERE { ?g a rdfx:UnknownOrigin . + GRAPH ?g { ?s ?o ?p } } + + But this again is quite contorted. (The same could be applied to + the third case as well, but the implementation of that would be + really tricky to be effecient.) + + 5. Unknown origin is represented by a singleton blank node as + above. The default graph is the singleton blank node of unknown + origin. + + - Mostly as above, but in the common case, explictly matching + statements that have an unknown origin would be easy in just + matching the statements from the default graph. + + 6. Unknown origin is represented by a well known URI that is shared + universally. The default graph is the RDF merge of all graphs in + the store. + + - Somewhat incorrectly asserts that the statements have a certain + origin, even though we don't know the origin. + + - The origin of the statements is nicely queryable with SPARQL. + + - Statements with an unknown origin can be easily explicitly + matched by comparing them against the well known URI. + + - Assigns a special meaning to an URI. + + - Hard to coordinate with a number of people implementing similar + solutions if not standardized. + +Some other variants of the above were omitted, since their problems +and benefits are easily reasoned. + +On irc, 'chimenzie' outlined the problem as such: + +17:35 chimezie:#swig => Hmm.. well, seems like what is missing is a good + definition of a 'name for nodes that don't have an explicit context' +17:36 chimezie:#swig => or rather 'a name for the context of nodes that aren't + assigned to a context explicitely' + +So, I'm out for some input on what might be the sanest route to +through this. + +TIA, +-- Naked + +0018: Richard Cyganiak +---------------------- + +http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0018.html + +Hi Nuutti, + +Without having thought through all the consequences ... + +Some of your options are not really possible with named graphs +because graphs need to be *named*, that is, the name *must* be a URI +and not a blank node. Blank nodes are always scoped to a single +graph, and using blank nodes as graph labels would make it impossible +to refer to a named graph from the outside world. This excludes #3 +and #4. + +In SPARQL, the default graph is structurally and syntactically +handled so differently from the other graphs that I wouldn't consider +using it for the same kind of data. That is, I tend to reserve the +default graph for metadata or the merge of all named graphs. This +excludes #1 and #5. + +#6 has the problem of re-using a single URI for many different things +-- the statements of unknown origin in Alice's store, *and* the +statements of unknown origin in Bob's store. While workable, this is +not an elegant solution. + +I would suggest that Alice and Bob each mint a new URI for the graph +containing the statements of unknown origin *in their own store*. Or +mint a new URI to hold each individual statement, or anything in +between. Since the owner of a URI gets to say what the meaning of the +URI is, they can declare that this chunk of URI space is reserved for +this purpose (assuming Alice and Bob each own a chunk of URI space). + +I wonder why you discounted this solution? + +I also question the existence of "statements without a known origin". +They surely didn't just pop up magically inside your triple store, +eh? I guess it's more like "statements whose origin I don't want to +model". + + +0020: Chimezie Ogbuji +--------------------- + +http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0020.html + +On Wed, 13 Sep 2006, Richard Cyganiak wrote: + +.. code-block:: text + + > Hi Nuutti, + > + > Without having thought through all the consequences ... + > + > Some of your options are not really possible with named graphs because graphs + > need to be *named*, that is, the name *must* be a URI and not a blank node. + +I don't agree. What's the source of this assertion? I think the core +issue here is that there is *no* concensus formalism for named graphs WRT RDF, yet SPARQL is dependent +on an RDF model that supports named graphs. If there is one, please +point me to it, because I ran across the same problem when constructing +programming APIs for named graphs. The only formalism I know of is Graham Kyle, John McCarthy's work [1]. + +.. code-block:: text + + > Blank nodes are always scoped to a single graph, and using blank nodes as + > graph labels would make it impossible to refer to a named graph from the + > outside world. This excludes #3 and #4. + +Well, Blank nodes used within a graph can't be referred to +directly but they can still be matched by SPARQL - doesn't make them any +less useful. The problem isn't the use of Blank nodes for graph names but +a the lack of a mechanism [2] to match the graph name(s) associated with a +node. Given how closely coupled SPARQL is with (admittedly informal) +named graph semantics, I would expect to be able to answer questions such as: + +"What are the graph names in which all the statements about <someIRI> are +asserted?" + +Assuming I could answer this question, then graph labels that are blank +nodes become as accessible as blank nodes asserted *within* a graph and it +becomes a question of what is the appropriate use for a bnode as a graph +label? + +If BNodes are used for existential assertions about nodes, why wouldn't +they be used as existential assertions about graphs? And if there is +some semantic consequence, it furthers the argument that the formalisms +for named graphs should be well articulated before they are tightly integrated into a query language. + +.. code-block:: text + + > I would suggest that Alice and Bob each mint a new URI for the graph + > containing the statements of unknown origin *in their own store*. Or mint a + > new URI to hold each individual statement, or anything in between. Since the + > owner of a URI gets to say what the meaning of the URI is, they can declare + > that this chunk of URI space is reserved for this purpose (assuming Alice and + > Bob each own a chunk of URI space). + > + > I wonder why you discounted this solution? + +I don't think it's an elegant solution when we already have the means +(within 'vanilla' RDF Model Theory) to express +existential assertions - which is exactly the scenario here. + +If a graph label is nothing but a name associated with a set of graphs, +why should it not behave the same as the name associated with a node +within a graph? + +.. code-block:: text + + > I also question the existence of "statements without a known origin". They + > surely didn't just pop up magically inside your triple store, eh? I guess + > it's more like "statements whose origin I don't want to model". + +How different is this from "nodes whose names I don't care to maintain / +model?" + +[1] http://ninebynine.org/RDFNotes/UsingContextsWithRDF.html#xtocid-6303976 + +[2] http://copia.ogbuji.net/blog/2006-07-14/querying-named-rdf-graph-aggregate + +0023: Nuutti Kotivuori +---------------------- + +http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0023.html + +Chimezie Ogbuji wrote: + +.. code-block:: text + + > I don't agree. What's the source of this assertion? I think the + > core issue here is that there is *no* concensus formalism for named + > graphs WRT RDF, yet SPARQL is dependent on an RDF model that + > supports named graphs. If there is one, please point me to it, + > because I ran across the same problem when constructing programming + > APIs for named graphs. The only formalism I know of is Graham Kyle, + > John McCarthy's work [1]. + +Well, one thing which would help me in this is a survey of the +approaches other people have taken when doing these things. + +I think I know the situation with Redland librdf, when I read the code +last, but I'm not sure if I'm correct. + +I think that in librdf, there are statements explicitly without a +context. In SPARQL queries, the default graph is the merge of all +statements in the store, with or without a context. Queries which +explicitly match the graph in a variable never match statements +without a context. And so there is no easy way to match all the +statements without a context only. + +I'd like to know atleast how rdflib and Jena (with whatever extensions +that this requires) solve this issue. + +-- Naked + +0027: Chimezie Ogbuji +--------------------- + +http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0027.html + +RDFLib has two API's: a Store API and a Graph API. Every Graph (there +are several kinds: QuotedGraphs, ConjunctiveGraphs, Named Graphs, +AggregateGraphs, ..) is associated with a Store instance and an +identifier. The identifiers are either a Blank Node or a URI. + +All the Store API's take a fourth parameter which is the containing Graph +(even the :meth:`__len__` method). So, theoretically the Store can choose to +persist RDF triples in a flat space (i.e., vanilla RDF model) and disregard the fourth parameter or use +the identifier of the containing graph to partition its persistence space +accordingly - it can even choose to partition formulae seperately (to +support N3 persistence) from the kind of Graph passed down to it (it will +receive QuotedGraph instances as the fourth parameter in this case). + +The :meth:`Store.triples` method returns a generator of (s,p,o), graphInst so each +Store implementation is expected to be able to associate each triple with +a containing graph (or None if the Store chooses to persist triples in a +flat space). + +The Graph API's do most of the leg work of named graph aggregation. +:class:`ConjunctiveGraph` is an (unamed) aggregation of all the named graphs within +the Store. It has a 'default' graph, whose name is associated with the +ConjunctiveGraph throughout its life. All methods work against this +default graph. Its constructor can take an identifier to use as the name +of this 'default' graph or it will assign a BNode. In practice (at least +how \*I\* use RDFLib), I instantiate a ConjunctiveGraph if I want to add +triples to the Store but don't care to mint a URI for the graph (the +scenario which triggered this thread). These triples can still be +addressed. + +:class:`ReadOnlyGraphAggregate` is a subset of the :class:`ConjunctiveGraph` where the names +of the graphs it provides an aggregate view for are passed on in the +constructor - this is how a SPARQL query with multiple FROM NAMED is +supported. + +:class:`QuotedGraphs` are meant to implement Notation 3 formulae. They are +associated with a required identifier that the N3 parser must provide in +order to maintain consistent formulae identification for scenarios such as +implication and such. + +The default dataset for SPARQL queries is equivalent to the Graph instance +on which the query is dispatched. If the :meth:`query` method is called on a +:class:`ConjunctiveGraph`, the default dataset is the entire Store, if it's a named +graph it's the named graph. + +This setup supports: + +- Flat space of triples +- Named Graph partitioning +- Notation 3 persistence + +0028: Nuutti Kotivuori +---------------------- + +http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0028.html + +Chimezie Ogbuji wrote: + +.. code-block:: text + + > The Graph API's do most of the leg work of named graph + > aggregation. ConjunctiveGraph is an (unamed) aggregation of all the + > named graphs within the Store. It has a 'default' graph, whose name + > is associated with the ConjunctiveGraph throughout it's life. All + > methods work against this default graph. Its constructor can take an + > identifier to use as the name of this 'default' graph or it will + > assign a BNode. In practice (at least how *I* use RDFLib), I + > instanciate a ConjunctiveGraph if I want to add triples to the Store + > but don't care to mint a URI for the graph (the scenario which + > triggered this thread). These triples can still be addressed. + +Okay, in the context of this discussion, what RDFLib does is that +every time a ConjunctiveGraph is instantiated, it creates a new blank +node and uses that throughout the life of the ConjunctiveGraph +object. And the default graph is the merge of all graphs in the store. + +So triples without an origin will be associated with a blank node, +which is shared between added triples, but distinct between different +ConjunctiveGraph objects. This probably coincides rather nicely with +most usages of the API. Single "sessions" of manipulating nodes will +have the blank node origin shared. + +And the possible problems are mostly what was already mentioned +earlier about an approach like this. The blank node identities might +not coincide with the actual separateness of the sources graphs - +making a query which matches several statements out of a single graph +might not be too meaningful for these blank nodes. It is difficult to +query only nodes which have no specific origin. And since the graph +name is a blank node, there is no way to explicitly specify the graph +name to be specific blank node, as the SPARQL syntax doesn't allow +this. + +-- Naked + +References +---------- + +Two posts by Pat Hayes, recommended by Andy Seaborne. + +http://www.ihmc.us/users/phayes/RDFGraphSyntax.html + +http://lists.w3.org/Archives/Public/public-rdf-dawg/2006JulSep/0153.html diff --git a/docs/_build/html/_sources/graphterms.txt b/docs/_build/html/_sources/graphterms.txt new file mode 100644 index 00000000..dc3b0af8 --- /dev/null +++ b/docs/_build/html/_sources/graphterms.txt @@ -0,0 +1,25 @@ +.. _graphterms: + +=============== +RDF Graph Terms +=============== + +The RDFLib classes listed below model RDF `terms`__ in a graph and inherit from a common `Identifier`_ class, which extends Python unicode. Instances of these are nodes in an RDF graph. + +.. _Seq: +.. autoclass:: rdflib.graph.Seq + :members: + +.. _QuotedGraph: +.. autoclass:: rdflib.graph.QuotedGraph + +.. _ReadOnlyGraphAggregate: +.. autoclass:: rdflib.graph.ReadOnlyGraphAggregate + +.. _Variable: +.. automodule:: rdflib.term +.. autoclass:: rdflib.term.Variable + + +.. __: univrdfstore.html#Terms +.. _Identifier: http://www.w3.org/2002/07/rdf-identifer-terminology/
\ No newline at end of file diff --git a/docs/_build/html/_sources/index.txt b/docs/_build/html/_sources/index.txt new file mode 100644 index 00000000..b8d2a93b --- /dev/null +++ b/docs/_build/html/_sources/index.txt @@ -0,0 +1,52 @@ +.. rdflib documentation documentation master file, created by sphinx-quickstart on Wed May 14 06:45:33 2008. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +========== +rdflib 2.5 +========== + +Introduction +============ +RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information. The library contains an RDF/XML parser/serializer that conforms to the RDF/XML Syntax Specification (Revised) . The library also contains both in-memory and persistent Graph backends. It is being developed by a number of contributors and was created by Daniel Krech who continues to maintain it. + +RDFLib's use of various Python idioms makes them an appropriate way to introduce it to a Python programmer who hasn't used it before. + +RDFLib graphs redefine certain built-in Python methods in order to behave in a predictable way. RDFLib graphs emulate container types and are best thought of as a set of 3-item triples + +.. code-block:: text + + [ + (subject, predicate, object), + (subject1, predicate1, object1), + ... + (subjectN, predicateN, objectN) + ] + +RDFLib graphs are not sorted containers; they have ordinary set operations (e.g. :meth:`~rdflib.Graph.add` to add a triple) plus methods that search triples and return them in arbitrary order. + +Contents +======== +.. toctree:: + :maxdepth: 2 + + gettingstarted + univrdfstore + graphterms + namespace_utilities + graph_utilities + persistence + persisting_n3_terms + graph_merging + graphs_bnodes + assorted_examples + addons + Modules <modules/index> + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/docs/_build/html/_sources/modules/graphs/conjunctive_graph.txt b/docs/_build/html/_sources/modules/graphs/conjunctive_graph.txt new file mode 100644 index 00000000..a0eefdb2 --- /dev/null +++ b/docs/_build/html/_sources/modules/graphs/conjunctive_graph.txt @@ -0,0 +1,15 @@ +:mod:`rdflib.Graph.ConjunctiveGraph` -- ConjunctiveGraph class definition +========================================================================= + +================= +Conjunctive Graph +================= + +.. automodule:: rdflib.graph + + +Module Contents +--------------- + +.. autoclass:: rdflib.graph.ConjunctiveGraph + :members: diff --git a/docs/_build/html/_sources/modules/graphs/graph.txt b/docs/_build/html/_sources/modules/graphs/graph.txt new file mode 100644 index 00000000..962489bd --- /dev/null +++ b/docs/_build/html/_sources/modules/graphs/graph.txt @@ -0,0 +1,12 @@ +:mod:`rdflib.Graph.Graph` -- Graph class definition +=================================================== + +===== +Graph +===== + +Module Contents +--------------- + +.. autoclass:: rdflib.graph.Graph + :members: diff --git a/docs/_build/html/_sources/modules/graphs/index.txt b/docs/_build/html/_sources/modules/graphs/index.txt new file mode 100644 index 00000000..b66a5a8e --- /dev/null +++ b/docs/_build/html/_sources/modules/graphs/index.txt @@ -0,0 +1,22 @@ +.. _graphs: + +======= +Graphs +======= + +RDFLib defines the following kinds of Graphs: + +* 'Graph'(_''store''_,_''identifier''_) +* 'QuotedGraph'(_''store''_,_''identifier''_) +* 'ConjunctiveGraph'(_''store''_,_''default''_''identifier''_= ''None'') + +A Conjunctive Graph is the most relevant collection of graphs that are considered to be the boundary for closed world assumptions. This boundary is equivalent to that of the store instance (which is itself uniquely identified and distinct from other instances of :class:`Store` that signify other Conjunctive Graphs). It is equivalent to all the named graphs within it and associated with a ``_default_`` graph which is automatically assigned a :class:`BNode` for an identifier - if one isn't given. + +.. automodule:: rdflib.graph + +.. toctree:: + :maxdepth: 2 + + graph + conjunctive_graph + ../nodes/quoted_graph
\ No newline at end of file diff --git a/docs/_build/html/_sources/modules/index.txt b/docs/_build/html/_sources/modules/index.txt new file mode 100644 index 00000000..75eaec1c --- /dev/null +++ b/docs/_build/html/_sources/modules/index.txt @@ -0,0 +1,15 @@ +.. _modules: + +======= +Modules +======= + +Contents: +========= + +.. toctree:: + :maxdepth: 3 + + nodes/index + graphs/index + others diff --git a/docs/_build/html/_sources/modules/nodes/bnode.txt b/docs/_build/html/_sources/modules/nodes/bnode.txt new file mode 100644 index 00000000..587f31a6 --- /dev/null +++ b/docs/_build/html/_sources/modules/nodes/bnode.txt @@ -0,0 +1,10 @@ +:mod:`rdflib.term.BNode` -- RDF blank node functions +==================================================== + +.. automodule:: rdflib.term + +Module Contents +--------------- + +.. autoclass:: rdflib.term.BNode + :members: diff --git a/docs/_build/html/_sources/modules/nodes/identifier.txt b/docs/_build/html/_sources/modules/nodes/identifier.txt new file mode 100644 index 00000000..bbd0b108 --- /dev/null +++ b/docs/_build/html/_sources/modules/nodes/identifier.txt @@ -0,0 +1,10 @@ +:mod:`rdflib.term.Identifier` -- Identifier class definition +============================================================ + +.. automodule:: rdflib.term + +Module Contents +--------------- + +.. autoclass:: rdflib.term.Identifier + :members: diff --git a/docs/_build/html/_sources/modules/nodes/index.txt b/docs/_build/html/_sources/modules/nodes/index.txt new file mode 100644 index 00000000..b9fa6a15 --- /dev/null +++ b/docs/_build/html/_sources/modules/nodes/index.txt @@ -0,0 +1,22 @@ +.. _nodes: + +======= +Nodes +======= + +The RDFLib classes listed below model RDF `terms`__ in a graph and inherit from a common `Identifier`_ class, which extends Python unicode. Instances of these are nodes in an RDF graph. + +.. toctree:: + :maxdepth: 2 + + node + identifier + bnode + uriref + literal + variable + quoted_graph + + +.. __: univrdfstore.html#Terms +.. _Identifier: http://www.w3.org/2002/07/rdf-identifer-terminology/ diff --git a/docs/_build/html/_sources/modules/nodes/literal.txt b/docs/_build/html/_sources/modules/nodes/literal.txt new file mode 100644 index 00000000..ad408b9a --- /dev/null +++ b/docs/_build/html/_sources/modules/nodes/literal.txt @@ -0,0 +1,10 @@ +:mod:`rdflib.term.Literal` -- Literal class definition +====================================================== + +.. automodule:: rdflib.term + +Module Contents +--------------- + +.. autoclass:: rdflib.term.Literal + :members: diff --git a/docs/_build/html/_sources/modules/nodes/node.txt b/docs/_build/html/_sources/modules/nodes/node.txt new file mode 100644 index 00000000..90fd2c5d --- /dev/null +++ b/docs/_build/html/_sources/modules/nodes/node.txt @@ -0,0 +1,10 @@ +:mod:`rdflib.term.Node` -- Node class definition +================================================ + +.. automodule:: rdflib.term + +Module Contents +--------------- + +.. autoclass:: rdflib.term.Node + :members: diff --git a/docs/_build/html/_sources/modules/nodes/quoted_graph.txt b/docs/_build/html/_sources/modules/nodes/quoted_graph.txt new file mode 100644 index 00000000..0d202e23 --- /dev/null +++ b/docs/_build/html/_sources/modules/nodes/quoted_graph.txt @@ -0,0 +1,13 @@ +:mod:`rdflib.graph.QuotedGraph` -- Quoted graphs +================================================ + +RDFLib graphs support an additional extension of RDF semantics for formulae. For the academically inclined, Graham Kyles `formal extension`__ is probably a good read. + +.. __: http://ninebynine.org/RDFNotes/UsingContextsWithRDF.html#xtocid-6303976 + +Formulae are represented formally by the :class:`rdflib.Graph.QuotedGraph` class and are disjoint from regular RDF graphs in that their statements are quoted. + +Module Contents +--------------- + +.. autoclass:: rdflib.graph.QuotedGraph diff --git a/docs/_build/html/_sources/modules/nodes/uriref.txt b/docs/_build/html/_sources/modules/nodes/uriref.txt new file mode 100644 index 00000000..672d2b54 --- /dev/null +++ b/docs/_build/html/_sources/modules/nodes/uriref.txt @@ -0,0 +1,12 @@ +:mod:`rdflib.term.URIRef` -- URIRef class definition +==================================================== + +.. automodule:: rdflib.term + + + +Module Contents +--------------- + +.. autoclass:: rdflib.term.URIRef + :members: diff --git a/docs/_build/html/_sources/modules/nodes/variable.txt b/docs/_build/html/_sources/modules/nodes/variable.txt new file mode 100644 index 00000000..651c9a36 --- /dev/null +++ b/docs/_build/html/_sources/modules/nodes/variable.txt @@ -0,0 +1,9 @@ +:mod:`rdflib.term.Variable` -- Variable class definition +======================================================== + +.. automodule:: rdflib.term + +Module Contents +--------------- + +.. autoclass:: rdflib.term.Variable diff --git a/docs/_build/html/_sources/modules/others.txt b/docs/_build/html/_sources/modules/others.txt new file mode 100644 index 00000000..2eb22584 --- /dev/null +++ b/docs/_build/html/_sources/modules/others.txt @@ -0,0 +1,76 @@ +.. _others: Other modules + +============= +Other modules +============= + +Collection +---------- +.. automodule:: rdflib.collection + +.. autoclass:: rdflib.collection.Collection + :members: + +Journal +------- +.. automodule:: rdflib.journal + +.. autoclass:: rdflib.journal.JournalWriter + :members: + +.. autoclass:: rdflib.journal.JournalReader + :members: + +QueryResult +----------- +.. automodule:: rdflib.query.result +.. autoclass:: rdflib.query.result.QueryResult + :members: + +Statement +--------- +.. automodule:: rdflib.term +.. autoclass:: rdflib.term.Statement +.. automethod:: rdflib.term.Statement.__new__ +.. automethod:: rdflib.term.Statement.__reduce__ + +StringInputSource +----------------- +.. automodule:: rdflib.parser +.. autoclass:: rdflib.parser.StringInputSource + :members: + +TextIndex +--------- +.. automodule:: rdflib.textindex +.. autoclass:: rdflib.textindex.TextIndex + :members: + +TripleStore +----------- +.. automodule:: rdflib.TripleStore +.. autoclass:: rdflib.TripleStore.TripleStore + :members: + +URLInputSource +-------------- + +.. autoclass:: rdflib.parser.URLInputSource + :members: + +query +----- +.. automodule:: rdflib.query + +store +----- +.. automodule:: rdflib.store + +sparql +------ +.. automodule:: rdflib.sparql + +syntax +------ +.. automodule:: rdflib.syntax + diff --git a/docs/_build/html/_sources/namespace_utilities.txt b/docs/_build/html/_sources/namespace_utilities.txt new file mode 100644 index 00000000..3a21efcd --- /dev/null +++ b/docs/_build/html/_sources/namespace_utilities.txt @@ -0,0 +1,24 @@ +.. _namespace_utilities: + +=================== +Namespace Utilities +=================== + +RDFLib provides mechanisms for managing Namespaces. In particular, there is a [http://svn.rdflib.net/trunk/rdflib/Namespace.py Namespace] class which takes (as its only argument) the Base URI of the namespace. Fully qualified URIs in the namespace can be constructed by attribute / dictionary access on Namespace instances: + +.. code-block:: pycon + + >>> from rdflib.namespace import Namespace + >>> fuxi = Namespace('http://metacognition.info/ontologies/FuXi.n3#') + >>> fuxi.ruleBase + u'http://metacognition.info/ontologies/FuXi.n3#ruleBase' + >>> fuxi['ruleBase'] + u'http://metacognition.info/ontologies/FuXi.n3#ruleBase' + +.. automodule:: rdflib.namespace + +Contents +-------- + +.. autoclass:: rdflib.namespace.Namespace + :members:
\ No newline at end of file diff --git a/docs/_build/html/_sources/persistence.txt b/docs/_build/html/_sources/persistence.txt new file mode 100644 index 00000000..76a4cb1e --- /dev/null +++ b/docs/_build/html/_sources/persistence.txt @@ -0,0 +1,26 @@ +.. _persistence: + +=========== +Persistence +=========== + + +RDFLib provides an abstracted Store API for persistence of RDF and Notation 3. The :class:`Graph` class works with instances of this API (as the first argument to its constructor) for triple-based management of an RDF store including: garbage collection, transaction management, update, pattern matching, removal, length, and database management (:meth:`open` / :meth:`close` / :meth:`destroy`) . Additional persistence mechanisms can be supported by implementing this API for a different store. + +Currently supported databases: + +* MySQL +* SQLite +* Berkeley DB +* Zope Object Database +* Random access memory +* Redland RDF Application Framework + +Store instances can be created with the :meth:`plugin` function: + +.. code-block:: python + + from rdflib import plugin + from rdflib.store import Store + plugin.get('.. one of the supported Stores ..',Store)(identifier=.. id of conjunctive graph ..) + diff --git a/docs/_build/html/_sources/persisting_n3_terms.txt b/docs/_build/html/_sources/persisting_n3_terms.txt new file mode 100644 index 00000000..32638350 --- /dev/null +++ b/docs/_build/html/_sources/persisting_n3_terms.txt @@ -0,0 +1,92 @@ +.. _persisting_n3_terms: + +=========================== +Persisting Notation 3 Terms +=========================== + +Using N3 Syntax for Persistence +------------------------------- +Blank Nodes, Literals, URI References, and Variables can be distinguished in persistence by relying on Notation 3 syntax convention. + +All URI References can be expanded and persisted as: + +.. code-block:: text + + <..URI..> + +All Literals can be expanded and persisted as: + +.. code-block:: text + + "..value.."@lang or "..value.."^^dtype_uri + +.. note:: ``@lang`` is a language tag and ``^^dtype_uri`` is the URI of a data type associated with the Literal + +Blank Nodes can be expanded and persisted as: + +.. code-block:: text + + _:Id + +.. note:: where Id is an identifier as determined by skolemization. Skolemization is a syntactic transformation routinely used in automatic inference systems in which existential variables are replaced by 'new' functions - function names not used elsewhere - applied to any enclosing universal variables. In RDF, Skolemization amounts to replacing every blank node in a graph by a 'new' name, i.e. a URI reference which is guaranteed to not occur anywhere else. In effect, it gives 'arbitrary' names to the anonymous entities whose existence was asserted by the use of blank nodes: the arbitrariness of the names ensures that nothing can be inferred that would not follow from the bare assertion of existence represented by the blank node. (Using a literal would not do. Literals are never 'new' in the required sense.) + +Variables can be persisted as they appear in their serialization ``(?varName)`` - since they only need be unique within their scope (the context of their associated statements) + +These syntactic conventions can facilitate term round-tripping. + +Variables by Scope +------------------ +Would an interface be needed in order to facilitate a quick way to aggregate all the variables in a scope (given by a formula identifier)? An interface such as: + +.. code-block:: python + + def variables(formula_identifier) + +The Need to Skolemize Formula Identifiers +----------------------------------------- +It would seem reasonable to assume that a formula-aware store would assign Blank Node identifiers as names of formulae that appear in a N3 serialization. So for instance, the following bit of N3: + +.. code-block:: n3 + + {?x a :N3Programmer} => {?x :has :Migrane} + +Could be interpreted as the assertion of the following statement: + +.. code-block:: n3 + + _:a log:implies _:b + +However, how are ``_:a`` and ``_:b`` distinguished from other Blank Nodes? A formula-aware store would be expected to persist the first set of statements as quoted statements in a formula named ``_:a`` and the second set as quoted statements in a formula named ``_:b``, but it would not be cost-effective for a serializer to have to query the store for all statements in a context named ``_:a`` in order to determine if ``_:a`` was associated with a formula (so that it could be serialized properly). + +Relying on ``log:Formula`` Membership +------------------------------------- + +The store could rely on explicit ``log:Formula`` membership (via ``rdf:type`` statements) to model the distinction of Blank Nodes associated with formulae. However, would these statements be expected from an N3 parser or known implicitly by the store? i.e., would all such Blank Nodes match the following pattern: + +.. code-block:: text + + ?formula rdf:type log:Formula + +Relying on an Explicit Interface +-------------------------------- +A formula-aware store could also support the persistence of this distinction by implementing a method that returns an iterator over all the formulae in the store: + +.. code-block:: python + + def formulae(triple=None) + +This function would return all the Blank Node identifiers assigned to formulae or just those that contain statements matching the given triple pattern and would be the way a serializer determines if a term refers to a formula (in order to properly serializer it). + +How much would such an interface reduce the need to model formulae terms as first class objects (perhaps to be returned by the :meth:`~rdflib.Graph.triple` function)? Would it be more useful for the :class:`~rdflib.Graph` (or the store itself) to return a Context object in place of a formula term (using the formulae interface to make this determination)? + +Conversely, would these interfaces (variables and formulae) be considered optimizations only since you have the distinction by the kinds of terms triples returns (which would be expanded to include variables and formulae)? + +Persisting Formula Identifiers +------------------------------ +This is the most straight forward way to maintain this distinction - without relying on extra interfaces. Formula identifiers could be persisted distinctly from other terms by using the following notation: + +.. code-block:: n3 + + {_:bnode} or {<.. URI ..>} + +This would facilitate their persistence round-trip - same as the other terms that rely on N3 syntax to distinguish between each other. diff --git a/docs/_build/html/_sources/univrdfstore.txt b/docs/_build/html/_sources/univrdfstore.txt new file mode 100644 index 00000000..7142ca57 --- /dev/null +++ b/docs/_build/html/_sources/univrdfstore.txt @@ -0,0 +1,363 @@ +.. _univrdfstore: + +=============================== +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. + +.. _RDF Graph: http://www.w3.org/TR/rdf-concepts/#dfn-rdf-graph +.. _Notation 3: http://www.w3.org/2000/10/swap/Primer +.. _First Order Predicate Logic: http://en.wikipedia.org/wiki/First-order_predicate_logic + +Terminology +=========== + +.. topic:: **Context** + + A named, unordered set of statements (that could also be called a sub-graph). The :term:`named graph` `literature`__ and `ontology`__ are relevant to this concept. The term :term:`context` could be thought of as either the sub-graph itself or the relationship between an RDF triple and a sub-graph in which it is found (this latter is how the term context is used in the `Notation 3 Design Issues page`_). + + It is worth noting that the concept of logically grouping `triples`__ within an addressable 'set' or 'subgraph' is just barely beyond the scope of the RDF model. The RDF model defines a graph to be an arbitrary collection of triples and the semantics of these triples --- but doesn't give guidance on how to address such arbitrary collections in a consistent manner. Although a collection of triples can be thought of as a resource itself, the association between a triple and the collection (of which it is a part) is not covered. `Public RDF`_ is an example of an attempt to formally model this relationship - and includes one other unrelated extension: Articulated Text + +.. __: http://www.w3.org/2004/03/trix/ +.. __: http://metacognition.info/Triclops/?xslt=Triclops.xslt&query=type(list(rdfs:Class,owl:Class,rdf:Property))&queryType=Graph&remoteGraph=http://www.w3.org/2004/03/trix/rdfg-1/ +.. __: http://www.w3.org/TR/rdf-concepts/#section-triples +.. _Notation 3 Design Issues page: http://www.w3.org/DesignIssues/Notation3.html +.. _Public RDF: http://laurentszyster.be/blog/public-rdf/ + +.. topic:: **Conjunctive Graph** + + This refers to the 'top-level' Graph. It is the aggregation of all the contexts within it and is also the appropriate, absolute boundary for `closed world assumptions`__ / models. This distinction is the low-hanging fruit of RDF along the path to the semantic web and most of its value is in (corporate/enterprise) real-world problems: + + .. pull-quote:: + + There are at least two situations where the closed world assumption is used. The first is where it is assumed that a knowledge base contains all relevant facts. This is common in corporate databases. That is, the information it contains is assumed to be complete + + From a store perspective, closed world assumptions also provide the benefit of better query response times, due to the explicit closed world boundaries. Closed world boundaries can be made transparent by federated queries that assume each :class:`ConjunctiveGraph` is a section of a larger, unbounded universe. So a closed world assumption does not preclude you from an open world assumption. + + For the sake of persistence, Conjunctive Graphs must be distinguished by identifiers (which may not necessarily be RDF `identifiers`__ or may be an RDF identifier normalized - SHA1/MD5 perhaps - for database naming purposes) that could be referenced to indicate conjunctive queries (queries made across the entire conjunctive graph) or appear as nodes in asserted statements. In this latter case, such statements could be interpreted as being made about the entire 'known' universe. For example: + + .. code-block:: xml + + <urn:uuid:conjunctive-graph-foo> rdf:type :ConjunctiveGraph + <urn:uuid:conjunctive-graph-foo> rdf:type log:Truth + <urn:uuid:conjunctive-graph-foo> :persistedBy :MySQL + +.. __: http://cs.wwc.edu/~aabyan/Logic/CWA.html +.. __: http://www.w3.org/2002/07/rdf-identifer-terminology/ + +.. topic:: **Quoted Statement** + + A statement that isn't asserted but is referred to in some manner. Most often, this happens when we want to make a statement about another statement (or set of statements) without necessarily saying these quoted statements (are true). For example: + + .. code-block:: text + + Chimezie said "higher-order statements are complicated" + + Which can be written (in N3) as: + + .. code-block:: n3 + + :chimezie :said {:higherOrderStatements rdf:type :complicated} + +.. topic:: **Formula** + + A context whose statements are quoted or hypothetical. + + Context quoting can be thought of as very similar to `reification`__. The main difference is that quoted statements are not asserted or considered as statements of truth about the universe and can be referenced as a group: a hypothetical RDF Graph + +.. __: http://www.w3.org/TR/rdf-mt/#Reif + +.. topic:: **Universal Quantifiers / Variables** + + (relevant references): + + * OWL `Definition`__ of `SWRL`__. + * SWRL/RuleML `Variable`__ + +.. __: http://www.w3.org/Submission/SWRL/swrl.owl +.. __: http://www.w3.org/Submission/SWRL/ +.. __: http://www.w3.org/Submission/SWRL/#owls_Variable + +.. topic:: **Terms** + + Terms are the kinds of objects that can appear in a quoted/asserted triple. + + This includes those that are core to RDF: + + * Blank Nodes + * URI References + * Literals (which consist of a literal value, datatype and language tag) + + Those that extend the RDF model into N3: + + * Formulae + * Universal Quantifications (Variables) + + And those that are primarily for matching against 'Nodes' in the underlying Graph: + + * REGEX Expressions + * Date Ranges + * Numerical Ranges + +.. topic:: **Nodes** + + Nodes are a subset of the Terms that the underlying store actually persists. The set of such Terms depends on whether or not the store is formula-aware. Stores that aren't formula-aware would only persist those terms core to the RDF Model, and those that are formula-aware would be able to persist the N3 extensions as well. However, utility terms that only serve the purpose for matching nodes by term-patterns probably will only be terms and not nodes. + + The set of nodes of an RDF graph is the set of subjects and objects of triples in the graph. + +.. topic:: **Context-aware** + + An RDF store capable of storing statements within contexts is considered context-aware. Essentially, such a store is able to partition the RDF model it represents into individual, named, and addressable sub-graphs. + +.. topic:: **Formula-aware** + + An RDF store capable of distinguishing between statements that are asserted and statements that are quoted is considered formula-aware. + + Such a store is responsible for maintaining this separation and ensuring that queries against the entire model (the aggregation of all the contexts - specified by not limiting a 'query' to a specifically name context) do not include quoted statements. Also, it is responsible for distinguishing universal quantifiers (variables). + + .. note:: These 2 additional concepts (formulae and variables) must be thought of as core extensions and distinguishable from the other terms of a triple (for the sake of the persistence rountrip - at the very least). It's worth noting that the 'scope' of universal quantifiers (variables) and existential quantifiers (BNodes) is the formula (or context - to be specific) in which their statements reside. Beyond this, a Formula-aware store behaves the same as a Context-aware store. + +.. topic:: **Conjunctive Query** + + Any query that doesn't limit the store to search within a named context only. Such a query expects a context-aware store to search the entire asserted universe (the conjunctive graph). A formula-aware store is expected not to include quoted statements when matching such a query. + +.. topic:: **N3 Round Trip** + + This refers to the requirements on a formula-aware RDF store's persistence mechanism necessary for it to be properly populated by a N3 parser and rendered as syntax by a N3 serializer. + +.. topic:: **Transactional Store** + + An RDF store capable of providing transactional integrity to the RDF operations performed on it. + +Interpreting Syntax +=================== + +The following Notation 3 `document`__: + +.. code-block:: n3 + + {?x a :N3Programmer} => {?x :has [a :Migrane]} + +Could cause the following statements to be asserted in the store: + +.. code-block:: n3 + + _:a log:implies _:b + +This statement would be asserted in the partition associated with quoted statements (in a formula named ``_:a``) + +.. code-block:: n3 + + ?x rdf:type :N3Programmer + +Finally, these statements would be asserted in the same partition (in a formula named _:b) + +.. code-block:: n3 + + ?x :has _:c + + _:c rdf:type :Migrane + +.. __: http://metacognition.info/Triclops/?xslt=Triclops.xslt&query=log:N3Document&queryType=Triple&remoteGraph=http://www.w3.org/2000/10/swap/log# + +Formulae and Variables as Terms +=============================== +Formulae and variables are distinguishable from URI references, Literals, and BNodes by the following syntax: + +.. code-block:: text + + { .. } - Formula ?x - Variable + +They must also be distinguishable in persistence to ensure they can be round-tripped. + +.. note:: There are a number of other issues regarding the `persisting of N3 terms <persisting_n3_terms.html>`_. + +Database Management +=================== + +An RDF store should provide standard interfaces for the management of database connections. Such interfaces are standard to most database management systems (Oracle, MySQL, Berkeley DB, Postgres, etc..) + +The following methods are defined to provide this capability (see below for description of the :term:`configuration` string): + +.. automethod:: rdflib.store.Store.open + +.. automethod:: rdflib.store.Store.close + +.. automethod:: rdflib.store.Store.destroy + +The *configuration* string is understood by the store implementation and represents all the parameters needed to locate an individual instance of a store. This could be similar to an ODBC string or in fact be an ODBC string, if the connection protocol to the underlying database is ODBC. The :meth:`open` function needs to fail intelligently in order to clearly express that a store (identified by the given configuration string) already exists or that there is no store (at the location specified by the configuration string) depending on the value of :keyword:`create`. + +Triple Interfaces +================= +An RDF store could provide a standard set of interfaces for the manipulation, management, and/or retrieval of its contained triples (asserted or quoted): + +.. automethod:: rdflib.store.Store.add + +.. automethod:: rdflib.store.Store.remove + +.. automethod:: rdflib.store.Store.triples + + .. note:: The :meth:`triples` method can be thought of as the primary mechanism for producing triples with nodes that match the corresponding terms in the *(s, p, o)* term pattern provided. The term pattern ``(None, None, None)`` matches all nodes. + +.. automethod:: rdflib.store.Store.__len__ + + +Formula / Context Interfaces +============================ + +These interfaces work on contexts and formulae (for stores that are formula-aware) interchangeably. + +.. automethod:: rdflib.graph.ConjunctiveGraph.contexts + +.. automethod:: rdflib.graph.ConjunctiveGraph.remove_context + +Interface Test Cases +==================== + +Basic +------------------------- + +Tests parsing, triple patterns, triple pattern removes, size, contextual removes + +Source Graph +^^^^^^^^^^^^^ + +.. code-block:: n3 + + @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + @prefix : <http://test/> . + {:a :b :c; a :foo} => {:a :d :c} . + _:foo a rdfs:Class . + :a :d :c. + +Test code +^^^^^^^^^ + +.. code-block:: python + + implies = URIRef("http://www.w3.org/2000/10/swap/log#implies") + a = URIRef('http://test/a') + b = URIRef('http://test/b') + c = URIRef('http://test/c') + d = URIRef('http://test/d') + for s,p,o in g.triples((None,implies,None)): + formulaA = s + formulaB = o + + #contexts test + assert len(list(g.contexts()))==3 + + #contexts (with triple) test + assert len(list(g.contexts((a,d,c))))==2 + + #triples test cases + assert type(list(g.triples((None,RDF.type,RDFS.Class)))[0][0]) == BNode + assert len(list(g.triples((None,implies,None))))==1 + assert len(list(g.triples((None,RDF.type,None))))==3 + assert len(list(g.triples((None,RDF.type,None),formulaA)))==1 + assert len(list(g.triples((None,None,None),formulaA)))==2 + assert len(list(g.triples((None,None,None),formulaB)))==1 + assert len(list(g.triples((None,None,None))))==5 + assert len(list(g.triples((None,URIRef('http://test/d'),None),formulaB)))==1 + assert len(list(g.triples((None,URIRef('http://test/d'),None))))==1 + + #Remove test cases + g.remove((None,implies,None)) + assert len(list(g.triples((None,implies,None))))==0 + assert len(list(g.triples((None,None,None),formulaA)))==2 + assert len(list(g.triples((None,None,None),formulaB)))==1 + g.remove((None,b,None),formulaA) + assert len(list(g.triples((None,None,None),formulaA)))==1 + g.remove((None,RDF.type,None),formulaA) + assert len(list(g.triples((None,None,None),formulaA)))==0 + g.remove((None,RDF.type,RDFS.Class)) + + #remove_context tests + formulaBContext=Context(g,formulaB) + g.remove_context(formulaB) + assert len(list(g.triples((None,RDF.type,None))))==2 + assert len(g)==3 assert len(formulaBContext)==0 + g.remove((None,None,None)) + assert len(g)==0 + + +Formula and Variables Test +-------------------------- + +Source Graph +^^^^^^^^^^^^ + +.. code-block:: n3 + + @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + @prefix : <http://test/> . + {?x a rdfs:Class} => {?x a :Klass}. + +Test Code +^^^^^^^^^ + +.. code-block:: python + + implies = URIRef("http://www.w3.org/2000/10/swap/log#implies") + klass = URIRef('http://test/Klass') + for s,p,o in g.triples((None,implies,None)): + formulaA = s + formulaB = o + assert type(formulaA) == Formula + assert type(formulaB) == Formula + for s,p,o in g.triples((None,RDF.type,RDFS.Class)),formulaA): + assert type(s) == Variable + for s,p,o in g.triples((None,RDF.type,klass)),formulaB): + assert type(s) == Variable + +Transactional Tests +------------------- + +To be instantiated. + +Additional Terms to Model +========================= +These are a list of additional kinds of RDF terms (all of which are special Literals) + + * RegExLiteral - a REGEX string which can be used in any term slot in order to match by applying the Regular Expression to statements in the underlying graph. + * Date (could provide some utility functions for date manipulation / serialization, etc..) + * DateRange + +Namespace Management Interfaces +=============================== + +The following namespace management interfaces (defined in Graph) could be implemented in the RDF store. Currently, they exist as stub methods of :class:`~rdflib.store.Store` and are defined in the store subclasses (e.g. :class:`~rdflib.store.IOMemory`, :class:`~rdflib.store.AbstractSQLStore`): + +.. automethod:: rdflib.store.Store.bind + +.. automethod:: rdflib.store.Store.prefix + +.. automethod:: rdflib.store.Store.namespace + +.. automethod:: rdflib.store.Store.namespaces + +Open issues +=========== +Does the Store interface need to have an identifier property or can we keep that at the Graph level? + +The Store implementation needs a mechanism to distinguish between triples (quoted or asserted) in ConjunctiveGraphs (which are mutually exclusive universes in systems that make closed world assumptions - and queried separately). This is the separation that the store identifier provides. This is different from the name of a context within a ConjunctiveGraph (or the default context of a conjunctive graph). I tried to diagram the logical separation of ConjunctiveGraphs, SubGraphs and QuotedGraphs in this diagram + +.. image:: _static/ContextHierarchy.png + +An identifier of ``None`` can be used to indicate the store (aka `all contexts`) in methods such as :meth:`triples`, :meth:`__len__`, etc. This works as long as we're only dealing with one Conjunctive Graph at a time -- which may not always be the case. + +Is there any value in persisting terms that lie outside N3 (RegExLiteral,Date,etc..)? + +Potentially, not sure yet. + +Should a conjunctive query always return quads instead of triples? It would seem so, since knowing the context that produced a triple match is an essential aspect of query construction / optimization. Or if having the triples function yield/produce different length tuples is problematic, could an additional - and slightly redundant - interface be introduced?: + +.. automethod:: rdflib.graph.ConjunctiveGraph.quads + +Stores that weren't context-aware could simply return ``None`` as the 4th item in the produced/yielded tuples or simply not support this interface. + diff --git a/docs/_build/html/_static/ContextHierarchy.png b/docs/_build/html/_static/ContextHierarchy.png Binary files differnew file mode 100644 index 00000000..28b4977e --- /dev/null +++ b/docs/_build/html/_static/ContextHierarchy.png diff --git a/docs/_build/html/_static/contents.png b/docs/_build/html/_static/contents.png Binary files differnew file mode 100644 index 00000000..7fb82154 --- /dev/null +++ b/docs/_build/html/_static/contents.png diff --git a/docs/_build/html/_static/default.css b/docs/_build/html/_static/default.css new file mode 100644 index 00000000..3a4ad73a --- /dev/null +++ b/docs/_build/html/_static/default.css @@ -0,0 +1,658 @@ +/** + * Sphinx Doc Design + */ + +body { + font-family: sans-serif; + font-size: 100%; + background-color: #11303d; + color: #000; + margin: 0; + padding: 0; +} + +/* :::: LAYOUT :::: */ + +div.document { + background-color: #1c4e63; +} + +div.documentwrapper { + float: left; + width: 100%; +} + +div.bodywrapper { + margin: 0 0 0 230px; +} + +div.body { + background-color: white; + padding: 0 20px 30px 20px; +} + +div.sphinxsidebarwrapper { + padding: 10px 5px 0 10px; +} + +div.sphinxsidebar { + float: left; + width: 230px; + margin-left: -100%; + font-size: 90%; +} + +div.clearer { + clear: both; +} + +div.footer { + color: #fff; + width: 100%; + padding: 9px 0 9px 0; + text-align: center; + font-size: 75%; +} + +div.footer a { + color: #fff; + text-decoration: underline; +} + +div.related { + background-color: #133f52; + color: #fff; + width: 100%; + line-height: 30px; + font-size: 90%; +} + +div.related h3 { + display: none; +} + +div.related ul { + margin: 0; + padding: 0 0 0 10px; + list-style: none; +} + +div.related li { + display: inline; +} + +div.related li.right { + float: right; + margin-right: 5px; +} + +div.related a { + color: white; +} + +/* ::: TOC :::: */ +div.sphinxsidebar h3 { + font-family: 'Trebuchet MS', sans-serif; + color: white; + font-size: 1.4em; + font-weight: normal; + margin: 0; + padding: 0; +} + +div.sphinxsidebar h3 a { + color: white; +} + +div.sphinxsidebar h4 { + font-family: 'Trebuchet MS', sans-serif; + color: white; + font-size: 1.3em; + font-weight: normal; + margin: 5px 0 0 0; + padding: 0; +} + +div.sphinxsidebar p { + color: white; +} + +div.sphinxsidebar p.topless { + margin: 5px 10px 10px 10px; +} + +div.sphinxsidebar ul { + margin: 10px; + padding: 0; + list-style: none; + color: white; +} + +div.sphinxsidebar ul ul, +div.sphinxsidebar ul.want-points { + margin-left: 20px; + list-style: square; +} + +div.sphinxsidebar ul ul { + margin-top: 0; + margin-bottom: 0; +} + +div.sphinxsidebar a { + color: #98dbcc; +} + +div.sphinxsidebar form { + margin-top: 10px; +} + +div.sphinxsidebar input { + border: 1px solid #98dbcc; + font-family: sans-serif; + font-size: 1em; +} + +/* :::: MODULE CLOUD :::: */ +div.modulecloud { + margin: -5px 10px 5px 10px; + padding: 10px; + line-height: 160%; + border: 1px solid #cbe7e5; + background-color: #f2fbfd; +} + +div.modulecloud a { + padding: 0 5px 0 5px; +} + +/* :::: SEARCH :::: */ +ul.search { + margin: 10px 0 0 20px; + padding: 0; +} + +ul.search li { + padding: 5px 0 5px 20px; + background-image: url(file.png); + background-repeat: no-repeat; + background-position: 0 7px; +} + +ul.search li a { + font-weight: bold; +} + +ul.search li div.context { + color: #888; + margin: 2px 0 0 30px; + text-align: left; +} + +ul.keywordmatches li.goodmatch a { + font-weight: bold; +} + +/* :::: COMMON FORM STYLES :::: */ + +div.actions { + padding: 5px 10px 5px 10px; + border-top: 1px solid #cbe7e5; + border-bottom: 1px solid #cbe7e5; + background-color: #e0f6f4; +} + +form dl { + color: #333; +} + +form dt { + clear: both; + float: left; + min-width: 110px; + margin-right: 10px; + padding-top: 2px; +} + +input#homepage { + display: none; +} + +div.error { + margin: 5px 20px 0 0; + padding: 5px; + border: 1px solid #d00; + font-weight: bold; +} + +/* :::: INDEX PAGE :::: */ + +table.contentstable { + width: 90%; +} + +table.contentstable p.biglink { + line-height: 150%; +} + +a.biglink { + font-size: 1.3em; +} + +span.linkdescr { + font-style: italic; + padding-top: 5px; + font-size: 90%; +} + +/* :::: INDEX STYLES :::: */ + +table.indextable td { + text-align: left; + vertical-align: top; +} + +table.indextable dl, table.indextable dd { + margin-top: 0; + margin-bottom: 0; +} + +table.indextable tr.pcap { + height: 10px; +} + +table.indextable tr.cap { + margin-top: 10px; + background-color: #f2f2f2; +} + +img.toggler { + margin-right: 3px; + margin-top: 3px; + cursor: pointer; +} + +form.pfform { + margin: 10px 0 20px 0; +} + +/* :::: GLOBAL STYLES :::: */ + +.docwarning { + background-color: #ffe4e4; + padding: 10px; + margin: 0 -20px 0 -20px; + border-bottom: 1px solid #f66; +} + +p.subhead { + font-weight: bold; + margin-top: 20px; +} + +a { + color: #355f7c; + text-decoration: none; +} + +a:hover { + text-decoration: underline; +} + +div.body h1, +div.body h2, +div.body h3, +div.body h4, +div.body h5, +div.body h6 { + font-family: 'Trebuchet MS', sans-serif; + background-color: #f2f2f2; + font-weight: normal; + color: #20435c; + border-bottom: 1px solid #ccc; + margin: 20px -20px 10px -20px; + padding: 3px 0 3px 10px; +} + +div.body h1 { margin-top: 0; font-size: 200%; } +div.body h2 { font-size: 160%; } +div.body h3 { font-size: 140%; } +div.body h4 { font-size: 120%; } +div.body h5 { font-size: 110%; } +div.body h6 { font-size: 100%; } + +a.headerlink { + color: #c60f0f; + font-size: 0.8em; + padding: 0 4px 0 4px; + text-decoration: none; + visibility: hidden; +} + +h1:hover > a.headerlink, +h2:hover > a.headerlink, +h3:hover > a.headerlink, +h4:hover > a.headerlink, +h5:hover > a.headerlink, +h6:hover > a.headerlink, +dt:hover > a.headerlink { + visibility: visible; +} + +a.headerlink:hover { + background-color: #c60f0f; + color: white; +} + +div.body p, div.body dd, div.body li { + text-align: justify; + line-height: 130%; +} + +div.body p.caption { + text-align: inherit; +} + +div.body td { + text-align: left; +} + +ul.fakelist { + list-style: none; + margin: 10px 0 10px 20px; + padding: 0; +} + +.field-list ul { + padding-left: 1em; +} + +.first { + margin-top: 0 !important; +} + +/* "Footnotes" heading */ +p.rubric { + margin-top: 30px; + font-weight: bold; +} + +/* Sidebars */ + +div.sidebar { + margin: 0 0 0.5em 1em; + border: 1px solid #ddb; + padding: 7px 7px 0 7px; + background-color: #ffe; + width: 40%; + float: right; +} + +p.sidebar-title { + font-weight: bold; +} + +/* "Topics" */ + +div.topic { + background-color: #eee; + border: 1px solid #ccc; + padding: 7px 7px 0 7px; + margin: 10px 0 10px 0; +} + +p.topic-title { + font-size: 1.1em; + font-weight: bold; + margin-top: 10px; +} + +/* Admonitions */ + +div.admonition { + margin-top: 10px; + margin-bottom: 10px; + padding: 7px; +} + +div.admonition dt { + font-weight: bold; +} + +div.admonition dl { + margin-bottom: 0; +} + +div.admonition p.admonition-title + p { + display: inline; +} + +div.seealso { + background-color: #ffc; + border: 1px solid #ff6; +} + +div.warning { + background-color: #ffe4e4; + border: 1px solid #f66; +} + +div.note { + background-color: #eee; + border: 1px solid #ccc; +} + +p.admonition-title { + margin: 0px 10px 5px 0px; + font-weight: bold; + display: inline; +} + +p.admonition-title:after { + content: ":"; +} + +div.body p.centered { + text-align: center; + margin-top: 25px; +} + +table.docutils { + border: 0; +} + +table.docutils td, table.docutils th { + padding: 1px 8px 1px 0; + border-top: 0; + border-left: 0; + border-right: 0; + border-bottom: 1px solid #aaa; +} + +table.field-list td, table.field-list th { + border: 0 !important; +} + +table.footnote td, table.footnote th { + border: 0 !important; +} + +.field-list ul { + margin: 0; + padding-left: 1em; +} + +.field-list p { + margin: 0; +} + +dl { + margin-bottom: 15px; + clear: both; +} + +dd p { + margin-top: 0px; +} + +dd ul, dd table { + margin-bottom: 10px; +} + +dd { + margin-top: 3px; + margin-bottom: 10px; + margin-left: 30px; +} + +.refcount { + color: #060; +} + +dt:target, +.highlight { + background-color: #fbe54e; +} + +dl.glossary dt { + font-weight: bold; + font-size: 1.1em; +} + +th { + text-align: left; + padding-right: 5px; +} + +pre { + padding: 5px; + background-color: #efc; + color: #333; + line-height: 120%; + border: 1px solid #ac9; + border-left: none; + border-right: none; + overflow: auto; +} + +td.linenos pre { + padding: 5px 0px; + border: 0; + background-color: transparent; + color: #aaa; +} + +table.highlighttable { + margin-left: 0.5em; +} + +table.highlighttable td { + padding: 0 0.5em 0 0.5em; +} + +tt { + background-color: #ecf0f3; + padding: 0 1px 0 1px; + font-size: 0.95em; +} + +tt.descname { + background-color: transparent; + font-weight: bold; + font-size: 1.2em; +} + +tt.descclassname { + background-color: transparent; +} + +tt.xref, a tt { + background-color: transparent; + font-weight: bold; +} + +.footnote:target { background-color: #ffa } + +h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt { + background-color: transparent; +} + +.optional { + font-size: 1.3em; +} + +.versionmodified { + font-style: italic; +} + +form.comment { + margin: 0; + padding: 10px 30px 10px 30px; + background-color: #eee; +} + +form.comment h3 { + background-color: #326591; + color: white; + margin: -10px -30px 10px -30px; + padding: 5px; + font-size: 1.4em; +} + +form.comment input, +form.comment textarea { + border: 1px solid #ccc; + padding: 2px; + font-family: sans-serif; + font-size: 100%; +} + +form.comment input[type="text"] { + width: 240px; +} + +form.comment textarea { + width: 100%; + height: 200px; + margin-bottom: 10px; +} + +.system-message { + background-color: #fda; + padding: 5px; + border: 3px solid red; +} + +img.math { + vertical-align: middle; +} + +div.math p { + text-align: center; +} + +span.eqno { + float: right; +} + +img.logo { + border: 0; +} + +/* :::: PRINT :::: */ +@media print { + div.document, + div.documentwrapper, + div.bodywrapper { + margin: 0; + width : 100%; + } + + div.sphinxsidebar, + div.related, + div.footer, + div#comments div.new-comment-box, + #top-link { + display: none; + } +} diff --git a/docs/_build/html/_static/doctools.js b/docs/_build/html/_static/doctools.js new file mode 100644 index 00000000..be4bdc88 --- /dev/null +++ b/docs/_build/html/_static/doctools.js @@ -0,0 +1,232 @@ +/// XXX: make it cross browser + +/** + * make the code below compatible with browsers without + * an installed firebug like debugger + */ +if (!window.console || !console.firebug) { + var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", + "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; + window.console = {}; + for (var i = 0; i < names.length; ++i) + window.console[names[i]] = function() {} +} + +/** + * small helper function to urldecode strings + */ +jQuery.urldecode = function(x) { + return decodeURIComponent(x).replace(/\+/g, ' '); +} + +/** + * small helper function to urlencode strings + */ +jQuery.urlencode = encodeURIComponent; + +/** + * This function returns the parsed url parameters of the + * current request. Multiple values per key are supported, + * it will always return arrays of strings for the value parts. + */ +jQuery.getQueryParameters = function(s) { + if (typeof s == 'undefined') + s = document.location.search; + var parts = s.substr(s.indexOf('?') + 1).split('&'); + var result = {}; + for (var i = 0; i < parts.length; i++) { + var tmp = parts[i].split('=', 2); + var key = jQuery.urldecode(tmp[0]); + var value = jQuery.urldecode(tmp[1]); + if (key in result) + result[key].push(value); + else + result[key] = [value]; + } + return result; +} + +/** + * small function to check if an array contains + * a given item. + */ +jQuery.contains = function(arr, item) { + for (var i = 0; i < arr.length; i++) { + if (arr[i] == item) + return true; + } + return false; +} + +/** + * highlight a given string on a jquery object by wrapping it in + * span elements with the given class name. + */ +jQuery.fn.highlightText = function(text, className) { + function highlight(node) { + if (node.nodeType == 3) { + var val = node.nodeValue; + var pos = val.toLowerCase().indexOf(text); + if (pos >= 0 && !jQuery.className.has(node.parentNode, className)) { + var span = document.createElement("span"); + span.className = className; + span.appendChild(document.createTextNode(val.substr(pos, text.length))); + node.parentNode.insertBefore(span, node.parentNode.insertBefore( + document.createTextNode(val.substr(pos + text.length)), + node.nextSibling)); + node.nodeValue = val.substr(0, pos); + } + } + else if (!jQuery(node).is("button, select, textarea")) { + jQuery.each(node.childNodes, function() { + highlight(this) + }); + } + } + return this.each(function() { + highlight(this); + }); +} + +/** + * Small JavaScript module for the documentation. + */ +var Documentation = { + + init : function() { + this.fixFirefoxAnchorBug(); + this.highlightSearchWords(); + this.initModIndex(); + }, + + /** + * i18n support + */ + TRANSLATIONS : {}, + PLURAL_EXPR : function(n) { return n == 1 ? 0 : 1; }, + LOCALE : 'unknown', + + // gettext and ngettext don't access this so that the functions + // can savely bound to a different name (_ = Documentation.gettext) + gettext : function(string) { + var translated = Documentation.TRANSLATIONS[string]; + if (typeof translated == 'undefined') + return string; + return (typeof translated == 'string') ? translated : translated[0]; + }, + + ngettext : function(singular, plural, n) { + var translated = Documentation.TRANSLATIONS[singular]; + if (typeof translated == 'undefined') + return (n == 1) ? singular : plural; + return translated[Documentation.PLURALEXPR(n)]; + }, + + addTranslations : function(catalog) { + for (var key in catalog.messages) + this.TRANSLATIONS[key] = catalog.messages[key]; + this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')'); + this.LOCALE = catalog.locale; + }, + + /** + * add context elements like header anchor links + */ + addContextElements : function() { + $('div[@id] > :header:first').each(function() { + $('<a class="headerlink">\u00B6</a>'). + attr('href', '#' + this.id). + attr('title', _('Permalink to this headline')). + appendTo(this); + }); + $('dt[@id]').each(function() { + $('<a class="headerlink">\u00B6</a>'). + attr('href', '#' + this.id). + attr('title', _('Permalink to this definition')). + appendTo(this); + }); + }, + + /** + * workaround a firefox stupidity + */ + fixFirefoxAnchorBug : function() { + if (document.location.hash && $.browser.mozilla) + window.setTimeout(function() { + document.location.href += ''; + }, 10); + }, + + /** + * highlight the search words provided in the url in the text + */ + highlightSearchWords : function() { + var params = $.getQueryParameters(); + var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : []; + if (terms.length) { + var body = $('div.body'); + window.setTimeout(function() { + $.each(terms, function() { + body.highlightText(this.toLowerCase(), 'highlight'); + }); + }, 10); + $('<li class="highlight-link"><a href="javascript:Documentation.' + + 'hideSearchWords()">' + _('Hide Search Matches') + '</a></li>') + .appendTo($('.sidebar .this-page-menu')); + } + }, + + /** + * init the modindex toggle buttons + */ + initModIndex : function() { + var togglers = $('img.toggler').click(function() { + var src = $(this).attr('src'); + var idnum = $(this).attr('id').substr(7); + console.log($('tr.cg-' + idnum).toggle()); + if (src.substr(-9) == 'minus.png') + $(this).attr('src', src.substr(0, src.length-9) + 'plus.png'); + else + $(this).attr('src', src.substr(0, src.length-8) + 'minus.png'); + }).css('display', ''); + if (DOCUMENTATION_OPTIONS.COLLAPSE_MODINDEX) { + togglers.click(); + } + }, + + /** + * helper function to hide the search marks again + */ + hideSearchWords : function() { + $('.sidebar .this-page-menu li.highlight-link').fadeOut(300); + $('span.highlight').removeClass('highlight'); + }, + + /** + * make the url absolute + */ + makeURL : function(relativeURL) { + return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL; + }, + + /** + * get the current relative url + */ + getCurrentURL : function() { + var path = document.location.pathname; + var parts = path.split(/\//); + $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() { + if (this == '..') + parts.pop(); + }); + var url = parts.join('/'); + return path.substring(url.lastIndexOf('/') + 1, path.length - 1); + } +}; + +// quick alias for translations +_ = Documentation.gettext; + +$(document).ready(function() { + Documentation.init(); +}); diff --git a/docs/_build/html/_static/file.png b/docs/_build/html/_static/file.png Binary files differnew file mode 100644 index 00000000..d18082e3 --- /dev/null +++ b/docs/_build/html/_static/file.png diff --git a/docs/_build/html/_static/jquery.js b/docs/_build/html/_static/jquery.js new file mode 100644 index 00000000..82b98e1d --- /dev/null +++ b/docs/_build/html/_static/jquery.js @@ -0,0 +1,32 @@ +/* + * jQuery 1.2.6 - New Wave Javascript + * + * Copyright (c) 2008 John Resig (jquery.com) + * Dual licensed under the MIT (MIT-LICENSE.txt) + * and GPL (GPL-LICENSE.txt) licenses. + * + * $Date: 2008-05-24 14:22:17 -0400 (Sat, 24 May 2008) $ + * $Rev: 5685 $ + */ +(function(){var _jQuery=window.jQuery,_$=window.$;var jQuery=window.jQuery=window.$=function(selector,context){return new jQuery.fn.init(selector,context);};var quickExpr=/^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/,isSimple=/^.[^:#\[\.]*$/,undefined;jQuery.fn=jQuery.prototype={init:function(selector,context){selector=selector||document;if(selector.nodeType){this[0]=selector;this.length=1;return this;}if(typeof selector=="string"){var match=quickExpr.exec(selector);if(match&&(match[1]||!context)){if(match[1])selector=jQuery.clean([match[1]],context);else{var elem=document.getElementById(match[3]);if(elem){if(elem.id!=match[3])return jQuery().find(selector);return jQuery(elem);}selector=[];}}else +return jQuery(context).find(selector);}else if(jQuery.isFunction(selector))return jQuery(document)[jQuery.fn.ready?"ready":"load"](selector);return this.setArray(jQuery.makeArray(selector));},jquery:"1.2.6",size:function(){return this.length;},length:0,get:function(num){return num==undefined?jQuery.makeArray(this):this[num];},pushStack:function(elems){var ret=jQuery(elems);ret.prevObject=this;return ret;},setArray:function(elems){this.length=0;Array.prototype.push.apply(this,elems);return this;},each:function(callback,args){return jQuery.each(this,callback,args);},index:function(elem){var ret=-1;return jQuery.inArray(elem&&elem.jquery?elem[0]:elem,this);},attr:function(name,value,type){var options=name;if(name.constructor==String)if(value===undefined)return this[0]&&jQuery[type||"attr"](this[0],name);else{options={};options[name]=value;}return this.each(function(i){for(name in options)jQuery.attr(type?this.style:this,name,jQuery.prop(this,options[name],type,i,name));});},css:function(key,value){if((key=='width'||key=='height')&&parseFloat(value)<0)value=undefined;return this.attr(key,value,"curCSS");},text:function(text){if(typeof text!="object"&&text!=null)return this.empty().append((this[0]&&this[0].ownerDocument||document).createTextNode(text));var ret="";jQuery.each(text||this,function(){jQuery.each(this.childNodes,function(){if(this.nodeType!=8)ret+=this.nodeType!=1?this.nodeValue:jQuery.fn.text([this]);});});return ret;},wrapAll:function(html){if(this[0])jQuery(html,this[0].ownerDocument).clone().insertBefore(this[0]).map(function(){var elem=this;while(elem.firstChild)elem=elem.firstChild;return elem;}).append(this);return this;},wrapInner:function(html){return this.each(function(){jQuery(this).contents().wrapAll(html);});},wrap:function(html){return this.each(function(){jQuery(this).wrapAll(html);});},append:function(){return this.domManip(arguments,true,false,function(elem){if(this.nodeType==1)this.appendChild(elem);});},prepend:function(){return this.domManip(arguments,true,true,function(elem){if(this.nodeType==1)this.insertBefore(elem,this.firstChild);});},before:function(){return this.domManip(arguments,false,false,function(elem){this.parentNode.insertBefore(elem,this);});},after:function(){return this.domManip(arguments,false,true,function(elem){this.parentNode.insertBefore(elem,this.nextSibling);});},end:function(){return this.prevObject||jQuery([]);},find:function(selector){var elems=jQuery.map(this,function(elem){return jQuery.find(selector,elem);});return this.pushStack(/[^+>] [^+>]/.test(selector)||selector.indexOf("..")>-1?jQuery.unique(elems):elems);},clone:function(events){var ret=this.map(function(){if(jQuery.browser.msie&&!jQuery.isXMLDoc(this)){var clone=this.cloneNode(true),container=document.createElement("div");container.appendChild(clone);return jQuery.clean([container.innerHTML])[0];}else +return this.cloneNode(true);});var clone=ret.find("*").andSelf().each(function(){if(this[expando]!=undefined)this[expando]=null;});if(events===true)this.find("*").andSelf().each(function(i){if(this.nodeType==3)return;var events=jQuery.data(this,"events");for(var type in events)for(var handler in events[type])jQuery.event.add(clone[i],type,events[type][handler],events[type][handler].data);});return ret;},filter:function(selector){return this.pushStack(jQuery.isFunction(selector)&&jQuery.grep(this,function(elem,i){return selector.call(elem,i);})||jQuery.multiFilter(selector,this));},not:function(selector){if(selector.constructor==String)if(isSimple.test(selector))return this.pushStack(jQuery.multiFilter(selector,this,true));else +selector=jQuery.multiFilter(selector,this);var isArrayLike=selector.length&&selector[selector.length-1]!==undefined&&!selector.nodeType;return this.filter(function(){return isArrayLike?jQuery.inArray(this,selector)<0:this!=selector;});},add:function(selector){return this.pushStack(jQuery.unique(jQuery.merge(this.get(),typeof selector=='string'?jQuery(selector):jQuery.makeArray(selector))));},is:function(selector){return!!selector&&jQuery.multiFilter(selector,this).length>0;},hasClass:function(selector){return this.is("."+selector);},val:function(value){if(value==undefined){if(this.length){var elem=this[0];if(jQuery.nodeName(elem,"select")){var index=elem.selectedIndex,values=[],options=elem.options,one=elem.type=="select-one";if(index<0)return null;for(var i=one?index:0,max=one?index+1:options.length;i<max;i++){var option=options[i];if(option.selected){value=jQuery.browser.msie&&!option.attributes.value.specified?option.text:option.value;if(one)return value;values.push(value);}}return values;}else +return(this[0].value||"").replace(/\r/g,"");}return undefined;}if(value.constructor==Number)value+='';return this.each(function(){if(this.nodeType!=1)return;if(value.constructor==Array&&/radio|checkbox/.test(this.type))this.checked=(jQuery.inArray(this.value,value)>=0||jQuery.inArray(this.name,value)>=0);else if(jQuery.nodeName(this,"select")){var values=jQuery.makeArray(value);jQuery("option",this).each(function(){this.selected=(jQuery.inArray(this.value,values)>=0||jQuery.inArray(this.text,values)>=0);});if(!values.length)this.selectedIndex=-1;}else +this.value=value;});},html:function(value){return value==undefined?(this[0]?this[0].innerHTML:null):this.empty().append(value);},replaceWith:function(value){return this.after(value).remove();},eq:function(i){return this.slice(i,i+1);},slice:function(){return this.pushStack(Array.prototype.slice.apply(this,arguments));},map:function(callback){return this.pushStack(jQuery.map(this,function(elem,i){return callback.call(elem,i,elem);}));},andSelf:function(){return this.add(this.prevObject);},data:function(key,value){var parts=key.split(".");parts[1]=parts[1]?"."+parts[1]:"";if(value===undefined){var data=this.triggerHandler("getData"+parts[1]+"!",[parts[0]]);if(data===undefined&&this.length)data=jQuery.data(this[0],key);return data===undefined&&parts[1]?this.data(parts[0]):data;}else +return this.trigger("setData"+parts[1]+"!",[parts[0],value]).each(function(){jQuery.data(this,key,value);});},removeData:function(key){return this.each(function(){jQuery.removeData(this,key);});},domManip:function(args,table,reverse,callback){var clone=this.length>1,elems;return this.each(function(){if(!elems){elems=jQuery.clean(args,this.ownerDocument);if(reverse)elems.reverse();}var obj=this;if(table&&jQuery.nodeName(this,"table")&&jQuery.nodeName(elems[0],"tr"))obj=this.getElementsByTagName("tbody")[0]||this.appendChild(this.ownerDocument.createElement("tbody"));var scripts=jQuery([]);jQuery.each(elems,function(){var elem=clone?jQuery(this).clone(true)[0]:this;if(jQuery.nodeName(elem,"script"))scripts=scripts.add(elem);else{if(elem.nodeType==1)scripts=scripts.add(jQuery("script",elem).remove());callback.call(obj,elem);}});scripts.each(evalScript);});}};jQuery.fn.init.prototype=jQuery.fn;function evalScript(i,elem){if(elem.src)jQuery.ajax({url:elem.src,async:false,dataType:"script"});else +jQuery.globalEval(elem.text||elem.textContent||elem.innerHTML||"");if(elem.parentNode)elem.parentNode.removeChild(elem);}function now(){return+new Date;}jQuery.extend=jQuery.fn.extend=function(){var target=arguments[0]||{},i=1,length=arguments.length,deep=false,options;if(target.constructor==Boolean){deep=target;target=arguments[1]||{};i=2;}if(typeof target!="object"&&typeof target!="function")target={};if(length==i){target=this;--i;}for(;i<length;i++)if((options=arguments[i])!=null)for(var name in options){var src=target[name],copy=options[name];if(target===copy)continue;if(deep&©&&typeof copy=="object"&&!copy.nodeType)target[name]=jQuery.extend(deep,src||(copy.length!=null?[]:{}),copy);else if(copy!==undefined)target[name]=copy;}return target;};var expando="jQuery"+now(),uuid=0,windowData={},exclude=/z-?index|font-?weight|opacity|zoom|line-?height/i,defaultView=document.defaultView||{};jQuery.extend({noConflict:function(deep){window.$=_$;if(deep)window.jQuery=_jQuery;return jQuery;},isFunction:function(fn){return!!fn&&typeof fn!="string"&&!fn.nodeName&&fn.constructor!=Array&&/^[\s[]?function/.test(fn+"");},isXMLDoc:function(elem){return elem.documentElement&&!elem.body||elem.tagName&&elem.ownerDocument&&!elem.ownerDocument.body;},globalEval:function(data){data=jQuery.trim(data);if(data){var head=document.getElementsByTagName("head")[0]||document.documentElement,script=document.createElement("script");script.type="text/javascript";if(jQuery.browser.msie)script.text=data;else +script.appendChild(document.createTextNode(data));head.insertBefore(script,head.firstChild);head.removeChild(script);}},nodeName:function(elem,name){return elem.nodeName&&elem.nodeName.toUpperCase()==name.toUpperCase();},cache:{},data:function(elem,name,data){elem=elem==window?windowData:elem;var id=elem[expando];if(!id)id=elem[expando]=++uuid;if(name&&!jQuery.cache[id])jQuery.cache[id]={};if(data!==undefined)jQuery.cache[id][name]=data;return name?jQuery.cache[id][name]:id;},removeData:function(elem,name){elem=elem==window?windowData:elem;var id=elem[expando];if(name){if(jQuery.cache[id]){delete jQuery.cache[id][name];name="";for(name in jQuery.cache[id])break;if(!name)jQuery.removeData(elem);}}else{try{delete elem[expando];}catch(e){if(elem.removeAttribute)elem.removeAttribute(expando);}delete jQuery.cache[id];}},each:function(object,callback,args){var name,i=0,length=object.length;if(args){if(length==undefined){for(name in object)if(callback.apply(object[name],args)===false)break;}else +for(;i<length;)if(callback.apply(object[i++],args)===false)break;}else{if(length==undefined){for(name in object)if(callback.call(object[name],name,object[name])===false)break;}else +for(var value=object[0];i<length&&callback.call(value,i,value)!==false;value=object[++i]){}}return object;},prop:function(elem,value,type,i,name){if(jQuery.isFunction(value))value=value.call(elem,i);return value&&value.constructor==Number&&type=="curCSS"&&!exclude.test(name)?value+"px":value;},className:{add:function(elem,classNames){jQuery.each((classNames||"").split(/\s+/),function(i,className){if(elem.nodeType==1&&!jQuery.className.has(elem.className,className))elem.className+=(elem.className?" ":"")+className;});},remove:function(elem,classNames){if(elem.nodeType==1)elem.className=classNames!=undefined?jQuery.grep(elem.className.split(/\s+/),function(className){return!jQuery.className.has(classNames,className);}).join(" "):"";},has:function(elem,className){return jQuery.inArray(className,(elem.className||elem).toString().split(/\s+/))>-1;}},swap:function(elem,options,callback){var old={};for(var name in options){old[name]=elem.style[name];elem.style[name]=options[name];}callback.call(elem);for(var name in options)elem.style[name]=old[name];},css:function(elem,name,force){if(name=="width"||name=="height"){var val,props={position:"absolute",visibility:"hidden",display:"block"},which=name=="width"?["Left","Right"]:["Top","Bottom"];function getWH(){val=name=="width"?elem.offsetWidth:elem.offsetHeight;var padding=0,border=0;jQuery.each(which,function(){padding+=parseFloat(jQuery.curCSS(elem,"padding"+this,true))||0;border+=parseFloat(jQuery.curCSS(elem,"border"+this+"Width",true))||0;});val-=Math.round(padding+border);}if(jQuery(elem).is(":visible"))getWH();else +jQuery.swap(elem,props,getWH);return Math.max(0,val);}return jQuery.curCSS(elem,name,force);},curCSS:function(elem,name,force){var ret,style=elem.style;function color(elem){if(!jQuery.browser.safari)return false;var ret=defaultView.getComputedStyle(elem,null);return!ret||ret.getPropertyValue("color")=="";}if(name=="opacity"&&jQuery.browser.msie){ret=jQuery.attr(style,"opacity");return ret==""?"1":ret;}if(jQuery.browser.opera&&name=="display"){var save=style.outline;style.outline="0 solid black";style.outline=save;}if(name.match(/float/i))name=styleFloat;if(!force&&style&&style[name])ret=style[name];else if(defaultView.getComputedStyle){if(name.match(/float/i))name="float";name=name.replace(/([A-Z])/g,"-$1").toLowerCase();var computedStyle=defaultView.getComputedStyle(elem,null);if(computedStyle&&!color(elem))ret=computedStyle.getPropertyValue(name);else{var swap=[],stack=[],a=elem,i=0;for(;a&&color(a);a=a.parentNode)stack.unshift(a);for(;i<stack.length;i++)if(color(stack[i])){swap[i]=stack[i].style.display;stack[i].style.display="block";}ret=name=="display"&&swap[stack.length-1]!=null?"none":(computedStyle&&computedStyle.getPropertyValue(name))||"";for(i=0;i<swap.length;i++)if(swap[i]!=null)stack[i].style.display=swap[i];}if(name=="opacity"&&ret=="")ret="1";}else if(elem.currentStyle){var camelCase=name.replace(/\-(\w)/g,function(all,letter){return letter.toUpperCase();});ret=elem.currentStyle[name]||elem.currentStyle[camelCase];if(!/^\d+(px)?$/i.test(ret)&&/^\d/.test(ret)){var left=style.left,rsLeft=elem.runtimeStyle.left;elem.runtimeStyle.left=elem.currentStyle.left;style.left=ret||0;ret=style.pixelLeft+"px";style.left=left;elem.runtimeStyle.left=rsLeft;}}return ret;},clean:function(elems,context){var ret=[];context=context||document;if(typeof context.createElement=='undefined')context=context.ownerDocument||context[0]&&context[0].ownerDocument||document;jQuery.each(elems,function(i,elem){if(!elem)return;if(elem.constructor==Number)elem+='';if(typeof elem=="string"){elem=elem.replace(/(<(\w+)[^>]*?)\/>/g,function(all,front,tag){return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i)?all:front+"></"+tag+">";});var tags=jQuery.trim(elem).toLowerCase(),div=context.createElement("div");var wrap=!tags.indexOf("<opt")&&[1,"<select multiple='multiple'>","</select>"]||!tags.indexOf("<leg")&&[1,"<fieldset>","</fieldset>"]||tags.match(/^<(thead|tbody|tfoot|colg|cap)/)&&[1,"<table>","</table>"]||!tags.indexOf("<tr")&&[2,"<table><tbody>","</tbody></table>"]||(!tags.indexOf("<td")||!tags.indexOf("<th"))&&[3,"<table><tbody><tr>","</tr></tbody></table>"]||!tags.indexOf("<col")&&[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"]||jQuery.browser.msie&&[1,"div<div>","</div>"]||[0,"",""];div.innerHTML=wrap[1]+elem+wrap[2];while(wrap[0]--)div=div.lastChild;if(jQuery.browser.msie){var tbody=!tags.indexOf("<table")&&tags.indexOf("<tbody")<0?div.firstChild&&div.firstChild.childNodes:wrap[1]=="<table>"&&tags.indexOf("<tbody")<0?div.childNodes:[];for(var j=tbody.length-1;j>=0;--j)if(jQuery.nodeName(tbody[j],"tbody")&&!tbody[j].childNodes.length)tbody[j].parentNode.removeChild(tbody[j]);if(/^\s/.test(elem))div.insertBefore(context.createTextNode(elem.match(/^\s*/)[0]),div.firstChild);}elem=jQuery.makeArray(div.childNodes);}if(elem.length===0&&(!jQuery.nodeName(elem,"form")&&!jQuery.nodeName(elem,"select")))return;if(elem[0]==undefined||jQuery.nodeName(elem,"form")||elem.options)ret.push(elem);else +ret=jQuery.merge(ret,elem);});return ret;},attr:function(elem,name,value){if(!elem||elem.nodeType==3||elem.nodeType==8)return undefined;var notxml=!jQuery.isXMLDoc(elem),set=value!==undefined,msie=jQuery.browser.msie;name=notxml&&jQuery.props[name]||name;if(elem.tagName){var special=/href|src|style/.test(name);if(name=="selected"&&jQuery.browser.safari)elem.parentNode.selectedIndex;if(name in elem&¬xml&&!special){if(set){if(name=="type"&&jQuery.nodeName(elem,"input")&&elem.parentNode)throw"type property can't be changed";elem[name]=value;}if(jQuery.nodeName(elem,"form")&&elem.getAttributeNode(name))return elem.getAttributeNode(name).nodeValue;return elem[name];}if(msie&¬xml&&name=="style")return jQuery.attr(elem.style,"cssText",value);if(set)elem.setAttribute(name,""+value);var attr=msie&¬xml&&special?elem.getAttribute(name,2):elem.getAttribute(name);return attr===null?undefined:attr;}if(msie&&name=="opacity"){if(set){elem.zoom=1;elem.filter=(elem.filter||"").replace(/alpha\([^)]*\)/,"")+(parseInt(value)+''=="NaN"?"":"alpha(opacity="+value*100+")");}return elem.filter&&elem.filter.indexOf("opacity=")>=0?(parseFloat(elem.filter.match(/opacity=([^)]*)/)[1])/100)+'':"";}name=name.replace(/-([a-z])/ig,function(all,letter){return letter.toUpperCase();});if(set)elem[name]=value;return elem[name];},trim:function(text){return(text||"").replace(/^\s+|\s+$/g,"");},makeArray:function(array){var ret=[];if(array!=null){var i=array.length;if(i==null||array.split||array.setInterval||array.call)ret[0]=array;else +while(i)ret[--i]=array[i];}return ret;},inArray:function(elem,array){for(var i=0,length=array.length;i<length;i++)if(array[i]===elem)return i;return-1;},merge:function(first,second){var i=0,elem,pos=first.length;if(jQuery.browser.msie){while(elem=second[i++])if(elem.nodeType!=8)first[pos++]=elem;}else +while(elem=second[i++])first[pos++]=elem;return first;},unique:function(array){var ret=[],done={};try{for(var i=0,length=array.length;i<length;i++){var id=jQuery.data(array[i]);if(!done[id]){done[id]=true;ret.push(array[i]);}}}catch(e){ret=array;}return ret;},grep:function(elems,callback,inv){var ret=[];for(var i=0,length=elems.length;i<length;i++)if(!inv!=!callback(elems[i],i))ret.push(elems[i]);return ret;},map:function(elems,callback){var ret=[];for(var i=0,length=elems.length;i<length;i++){var value=callback(elems[i],i);if(value!=null)ret[ret.length]=value;}return ret.concat.apply([],ret);}});var userAgent=navigator.userAgent.toLowerCase();jQuery.browser={version:(userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1],safari:/webkit/.test(userAgent),opera:/opera/.test(userAgent),msie:/msie/.test(userAgent)&&!/opera/.test(userAgent),mozilla:/mozilla/.test(userAgent)&&!/(compatible|webkit)/.test(userAgent)};var styleFloat=jQuery.browser.msie?"styleFloat":"cssFloat";jQuery.extend({boxModel:!jQuery.browser.msie||document.compatMode=="CSS1Compat",props:{"for":"htmlFor","class":"className","float":styleFloat,cssFloat:styleFloat,styleFloat:styleFloat,readonly:"readOnly",maxlength:"maxLength",cellspacing:"cellSpacing"}});jQuery.each({parent:function(elem){return elem.parentNode;},parents:function(elem){return jQuery.dir(elem,"parentNode");},next:function(elem){return jQuery.nth(elem,2,"nextSibling");},prev:function(elem){return jQuery.nth(elem,2,"previousSibling");},nextAll:function(elem){return jQuery.dir(elem,"nextSibling");},prevAll:function(elem){return jQuery.dir(elem,"previousSibling");},siblings:function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},children:function(elem){return jQuery.sibling(elem.firstChild);},contents:function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}},function(name,fn){jQuery.fn[name]=function(selector){var ret=jQuery.map(this,fn);if(selector&&typeof selector=="string")ret=jQuery.multiFilter(selector,ret);return this.pushStack(jQuery.unique(ret));};});jQuery.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(name,original){jQuery.fn[name]=function(){var args=arguments;return this.each(function(){for(var i=0,length=args.length;i<length;i++)jQuery(args[i])[original](this);});};});jQuery.each({removeAttr:function(name){jQuery.attr(this,name,"");if(this.nodeType==1)this.removeAttribute(name);},addClass:function(classNames){jQuery.className.add(this,classNames);},removeClass:function(classNames){jQuery.className.remove(this,classNames);},toggleClass:function(classNames){jQuery.className[jQuery.className.has(this,classNames)?"remove":"add"](this,classNames);},remove:function(selector){if(!selector||jQuery.filter(selector,[this]).r.length){jQuery("*",this).add(this).each(function(){jQuery.event.remove(this);jQuery.removeData(this);});if(this.parentNode)this.parentNode.removeChild(this);}},empty:function(){jQuery(">*",this).remove();while(this.firstChild)this.removeChild(this.firstChild);}},function(name,fn){jQuery.fn[name]=function(){return this.each(fn,arguments);};});jQuery.each(["Height","Width"],function(i,name){var type=name.toLowerCase();jQuery.fn[type]=function(size){return this[0]==window?jQuery.browser.opera&&document.body["client"+name]||jQuery.browser.safari&&window["inner"+name]||document.compatMode=="CSS1Compat"&&document.documentElement["client"+name]||document.body["client"+name]:this[0]==document?Math.max(Math.max(document.body["scroll"+name],document.documentElement["scroll"+name]),Math.max(document.body["offset"+name],document.documentElement["offset"+name])):size==undefined?(this.length?jQuery.css(this[0],type):null):this.css(type,size.constructor==String?size:size+"px");};});function num(elem,prop){return elem[0]&&parseInt(jQuery.curCSS(elem[0],prop,true),10)||0;}var chars=jQuery.browser.safari&&parseInt(jQuery.browser.version)<417?"(?:[\\w*_-]|\\\\.)":"(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",quickChild=new RegExp("^>\\s*("+chars+"+)"),quickID=new RegExp("^("+chars+"+)(#)("+chars+"+)"),quickClass=new RegExp("^([#.]?)("+chars+"*)");jQuery.extend({expr:{"":function(a,i,m){return m[2]=="*"||jQuery.nodeName(a,m[2]);},"#":function(a,i,m){return a.getAttribute("id")==m[2];},":":{lt:function(a,i,m){return i<m[3]-0;},gt:function(a,i,m){return i>m[3]-0;},nth:function(a,i,m){return m[3]-0==i;},eq:function(a,i,m){return m[3]-0==i;},first:function(a,i){return i==0;},last:function(a,i,m,r){return i==r.length-1;},even:function(a,i){return i%2==0;},odd:function(a,i){return i%2;},"first-child":function(a){return a.parentNode.getElementsByTagName("*")[0]==a;},"last-child":function(a){return jQuery.nth(a.parentNode.lastChild,1,"previousSibling")==a;},"only-child":function(a){return!jQuery.nth(a.parentNode.lastChild,2,"previousSibling");},parent:function(a){return a.firstChild;},empty:function(a){return!a.firstChild;},contains:function(a,i,m){return(a.textContent||a.innerText||jQuery(a).text()||"").indexOf(m[3])>=0;},visible:function(a){return"hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden";},hidden:function(a){return"hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden";},enabled:function(a){return!a.disabled;},disabled:function(a){return a.disabled;},checked:function(a){return a.checked;},selected:function(a){return a.selected||jQuery.attr(a,"selected");},text:function(a){return"text"==a.type;},radio:function(a){return"radio"==a.type;},checkbox:function(a){return"checkbox"==a.type;},file:function(a){return"file"==a.type;},password:function(a){return"password"==a.type;},submit:function(a){return"submit"==a.type;},image:function(a){return"image"==a.type;},reset:function(a){return"reset"==a.type;},button:function(a){return"button"==a.type||jQuery.nodeName(a,"button");},input:function(a){return/input|select|textarea|button/i.test(a.nodeName);},has:function(a,i,m){return jQuery.find(m[3],a).length;},header:function(a){return/h\d/i.test(a.nodeName);},animated:function(a){return jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length;}}},parse:[/^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,/^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,new RegExp("^([:.#]*)("+chars+"+)")],multiFilter:function(expr,elems,not){var old,cur=[];while(expr&&expr!=old){old=expr;var f=jQuery.filter(expr,elems,not);expr=f.t.replace(/^\s*,\s*/,"");cur=not?elems=f.r:jQuery.merge(cur,f.r);}return cur;},find:function(t,context){if(typeof t!="string")return[t];if(context&&context.nodeType!=1&&context.nodeType!=9)return[];context=context||document;var ret=[context],done=[],last,nodeName;while(t&&last!=t){var r=[];last=t;t=jQuery.trim(t);var foundToken=false,re=quickChild,m=re.exec(t);if(m){nodeName=m[1].toUpperCase();for(var i=0;ret[i];i++)for(var c=ret[i].firstChild;c;c=c.nextSibling)if(c.nodeType==1&&(nodeName=="*"||c.nodeName.toUpperCase()==nodeName))r.push(c);ret=r;t=t.replace(re,"");if(t.indexOf(" ")==0)continue;foundToken=true;}else{re=/^([>+~])\s*(\w*)/i;if((m=re.exec(t))!=null){r=[];var merge={};nodeName=m[2].toUpperCase();m=m[1];for(var j=0,rl=ret.length;j<rl;j++){var n=m=="~"||m=="+"?ret[j].nextSibling:ret[j].firstChild;for(;n;n=n.nextSibling)if(n.nodeType==1){var id=jQuery.data(n);if(m=="~"&&merge[id])break;if(!nodeName||n.nodeName.toUpperCase()==nodeName){if(m=="~")merge[id]=true;r.push(n);}if(m=="+")break;}}ret=r;t=jQuery.trim(t.replace(re,""));foundToken=true;}}if(t&&!foundToken){if(!t.indexOf(",")){if(context==ret[0])ret.shift();done=jQuery.merge(done,ret);r=ret=[context];t=" "+t.substr(1,t.length);}else{var re2=quickID;var m=re2.exec(t);if(m){m=[0,m[2],m[3],m[1]];}else{re2=quickClass;m=re2.exec(t);}m[2]=m[2].replace(/\\/g,"");var elem=ret[ret.length-1];if(m[1]=="#"&&elem&&elem.getElementById&&!jQuery.isXMLDoc(elem)){var oid=elem.getElementById(m[2]);if((jQuery.browser.msie||jQuery.browser.opera)&&oid&&typeof oid.id=="string"&&oid.id!=m[2])oid=jQuery('[@id="'+m[2]+'"]',elem)[0];ret=r=oid&&(!m[3]||jQuery.nodeName(oid,m[3]))?[oid]:[];}else{for(var i=0;ret[i];i++){var tag=m[1]=="#"&&m[3]?m[3]:m[1]!=""||m[0]==""?"*":m[2];if(tag=="*"&&ret[i].nodeName.toLowerCase()=="object")tag="param";r=jQuery.merge(r,ret[i].getElementsByTagName(tag));}if(m[1]==".")r=jQuery.classFilter(r,m[2]);if(m[1]=="#"){var tmp=[];for(var i=0;r[i];i++)if(r[i].getAttribute("id")==m[2]){tmp=[r[i]];break;}r=tmp;}ret=r;}t=t.replace(re2,"");}}if(t){var val=jQuery.filter(t,r);ret=r=val.r;t=jQuery.trim(val.t);}}if(t)ret=[];if(ret&&context==ret[0])ret.shift();done=jQuery.merge(done,ret);return done;},classFilter:function(r,m,not){m=" "+m+" ";var tmp=[];for(var i=0;r[i];i++){var pass=(" "+r[i].className+" ").indexOf(m)>=0;if(!not&&pass||not&&!pass)tmp.push(r[i]);}return tmp;},filter:function(t,r,not){var last;while(t&&t!=last){last=t;var p=jQuery.parse,m;for(var i=0;p[i];i++){m=p[i].exec(t);if(m){t=t.substring(m[0].length);m[2]=m[2].replace(/\\/g,"");break;}}if(!m)break;if(m[1]==":"&&m[2]=="not")r=isSimple.test(m[3])?jQuery.filter(m[3],r,true).r:jQuery(r).not(m[3]);else if(m[1]==".")r=jQuery.classFilter(r,m[2],not);else if(m[1]=="["){var tmp=[],type=m[3];for(var i=0,rl=r.length;i<rl;i++){var a=r[i],z=a[jQuery.props[m[2]]||m[2]];if(z==null||/href|src|selected/.test(m[2]))z=jQuery.attr(a,m[2])||'';if((type==""&&!!z||type=="="&&z==m[5]||type=="!="&&z!=m[5]||type=="^="&&z&&!z.indexOf(m[5])||type=="$="&&z.substr(z.length-m[5].length)==m[5]||(type=="*="||type=="~=")&&z.indexOf(m[5])>=0)^not)tmp.push(a);}r=tmp;}else if(m[1]==":"&&m[2]=="nth-child"){var merge={},tmp=[],test=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(m[3]=="even"&&"2n"||m[3]=="odd"&&"2n+1"||!/\D/.test(m[3])&&"0n+"+m[3]||m[3]),first=(test[1]+(test[2]||1))-0,last=test[3]-0;for(var i=0,rl=r.length;i<rl;i++){var node=r[i],parentNode=node.parentNode,id=jQuery.data(parentNode);if(!merge[id]){var c=1;for(var n=parentNode.firstChild;n;n=n.nextSibling)if(n.nodeType==1)n.nodeIndex=c++;merge[id]=true;}var add=false;if(first==0){if(node.nodeIndex==last)add=true;}else if((node.nodeIndex-last)%first==0&&(node.nodeIndex-last)/first>=0)add=true;if(add^not)tmp.push(node);}r=tmp;}else{var fn=jQuery.expr[m[1]];if(typeof fn=="object")fn=fn[m[2]];if(typeof fn=="string")fn=eval("false||function(a,i){return "+fn+";}");r=jQuery.grep(r,function(elem,i){return fn(elem,i,m,r);},not);}}return{r:r,t:t};},dir:function(elem,dir){var matched=[],cur=elem[dir];while(cur&&cur!=document){if(cur.nodeType==1)matched.push(cur);cur=cur[dir];}return matched;},nth:function(cur,result,dir,elem){result=result||1;var num=0;for(;cur;cur=cur[dir])if(cur.nodeType==1&&++num==result)break;return cur;},sibling:function(n,elem){var r=[];for(;n;n=n.nextSibling){if(n.nodeType==1&&n!=elem)r.push(n);}return r;}});jQuery.event={add:function(elem,types,handler,data){if(elem.nodeType==3||elem.nodeType==8)return;if(jQuery.browser.msie&&elem.setInterval)elem=window;if(!handler.guid)handler.guid=this.guid++;if(data!=undefined){var fn=handler;handler=this.proxy(fn,function(){return fn.apply(this,arguments);});handler.data=data;}var events=jQuery.data(elem,"events")||jQuery.data(elem,"events",{}),handle=jQuery.data(elem,"handle")||jQuery.data(elem,"handle",function(){if(typeof jQuery!="undefined"&&!jQuery.event.triggered)return jQuery.event.handle.apply(arguments.callee.elem,arguments);});handle.elem=elem;jQuery.each(types.split(/\s+/),function(index,type){var parts=type.split(".");type=parts[0];handler.type=parts[1];var handlers=events[type];if(!handlers){handlers=events[type]={};if(!jQuery.event.special[type]||jQuery.event.special[type].setup.call(elem)===false){if(elem.addEventListener)elem.addEventListener(type,handle,false);else if(elem.attachEvent)elem.attachEvent("on"+type,handle);}}handlers[handler.guid]=handler;jQuery.event.global[type]=true;});elem=null;},guid:1,global:{},remove:function(elem,types,handler){if(elem.nodeType==3||elem.nodeType==8)return;var events=jQuery.data(elem,"events"),ret,index;if(events){if(types==undefined||(typeof types=="string"&&types.charAt(0)=="."))for(var type in events)this.remove(elem,type+(types||""));else{if(types.type){handler=types.handler;types=types.type;}jQuery.each(types.split(/\s+/),function(index,type){var parts=type.split(".");type=parts[0];if(events[type]){if(handler)delete events[type][handler.guid];else +for(handler in events[type])if(!parts[1]||events[type][handler].type==parts[1])delete events[type][handler];for(ret in events[type])break;if(!ret){if(!jQuery.event.special[type]||jQuery.event.special[type].teardown.call(elem)===false){if(elem.removeEventListener)elem.removeEventListener(type,jQuery.data(elem,"handle"),false);else if(elem.detachEvent)elem.detachEvent("on"+type,jQuery.data(elem,"handle"));}ret=null;delete events[type];}}});}for(ret in events)break;if(!ret){var handle=jQuery.data(elem,"handle");if(handle)handle.elem=null;jQuery.removeData(elem,"events");jQuery.removeData(elem,"handle");}}},trigger:function(type,data,elem,donative,extra){data=jQuery.makeArray(data);if(type.indexOf("!")>=0){type=type.slice(0,-1);var exclusive=true;}if(!elem){if(this.global[type])jQuery("*").add([window,document]).trigger(type,data);}else{if(elem.nodeType==3||elem.nodeType==8)return undefined;var val,ret,fn=jQuery.isFunction(elem[type]||null),event=!data[0]||!data[0].preventDefault;if(event){data.unshift({type:type,target:elem,preventDefault:function(){},stopPropagation:function(){},timeStamp:now()});data[0][expando]=true;}data[0].type=type;if(exclusive)data[0].exclusive=true;var handle=jQuery.data(elem,"handle");if(handle)val=handle.apply(elem,data);if((!fn||(jQuery.nodeName(elem,'a')&&type=="click"))&&elem["on"+type]&&elem["on"+type].apply(elem,data)===false)val=false;if(event)data.shift();if(extra&&jQuery.isFunction(extra)){ret=extra.apply(elem,val==null?data:data.concat(val));if(ret!==undefined)val=ret;}if(fn&&donative!==false&&val!==false&&!(jQuery.nodeName(elem,'a')&&type=="click")){this.triggered=true;try{elem[type]();}catch(e){}}this.triggered=false;}return val;},handle:function(event){var val,ret,namespace,all,handlers;event=arguments[0]=jQuery.event.fix(event||window.event);namespace=event.type.split(".");event.type=namespace[0];namespace=namespace[1];all=!namespace&&!event.exclusive;handlers=(jQuery.data(this,"events")||{})[event.type];for(var j in handlers){var handler=handlers[j];if(all||handler.type==namespace){event.handler=handler;event.data=handler.data;ret=handler.apply(this,arguments);if(val!==false)val=ret;if(ret===false){event.preventDefault();event.stopPropagation();}}}return val;},fix:function(event){if(event[expando]==true)return event;var originalEvent=event;event={originalEvent:originalEvent};var props="altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target timeStamp toElement type view wheelDelta which".split(" ");for(var i=props.length;i;i--)event[props[i]]=originalEvent[props[i]];event[expando]=true;event.preventDefault=function(){if(originalEvent.preventDefault)originalEvent.preventDefault();originalEvent.returnValue=false;};event.stopPropagation=function(){if(originalEvent.stopPropagation)originalEvent.stopPropagation();originalEvent.cancelBubble=true;};event.timeStamp=event.timeStamp||now();if(!event.target)event.target=event.srcElement||document;if(event.target.nodeType==3)event.target=event.target.parentNode;if(!event.relatedTarget&&event.fromElement)event.relatedTarget=event.fromElement==event.target?event.toElement:event.fromElement;if(event.pageX==null&&event.clientX!=null){var doc=document.documentElement,body=document.body;event.pageX=event.clientX+(doc&&doc.scrollLeft||body&&body.scrollLeft||0)-(doc.clientLeft||0);event.pageY=event.clientY+(doc&&doc.scrollTop||body&&body.scrollTop||0)-(doc.clientTop||0);}if(!event.which&&((event.charCode||event.charCode===0)?event.charCode:event.keyCode))event.which=event.charCode||event.keyCode;if(!event.metaKey&&event.ctrlKey)event.metaKey=event.ctrlKey;if(!event.which&&event.button)event.which=(event.button&1?1:(event.button&2?3:(event.button&4?2:0)));return event;},proxy:function(fn,proxy){proxy.guid=fn.guid=fn.guid||proxy.guid||this.guid++;return proxy;},special:{ready:{setup:function(){bindReady();return;},teardown:function(){return;}},mouseenter:{setup:function(){if(jQuery.browser.msie)return false;jQuery(this).bind("mouseover",jQuery.event.special.mouseenter.handler);return true;},teardown:function(){if(jQuery.browser.msie)return false;jQuery(this).unbind("mouseover",jQuery.event.special.mouseenter.handler);return true;},handler:function(event){if(withinElement(event,this))return true;event.type="mouseenter";return jQuery.event.handle.apply(this,arguments);}},mouseleave:{setup:function(){if(jQuery.browser.msie)return false;jQuery(this).bind("mouseout",jQuery.event.special.mouseleave.handler);return true;},teardown:function(){if(jQuery.browser.msie)return false;jQuery(this).unbind("mouseout",jQuery.event.special.mouseleave.handler);return true;},handler:function(event){if(withinElement(event,this))return true;event.type="mouseleave";return jQuery.event.handle.apply(this,arguments);}}}};jQuery.fn.extend({bind:function(type,data,fn){return type=="unload"?this.one(type,data,fn):this.each(function(){jQuery.event.add(this,type,fn||data,fn&&data);});},one:function(type,data,fn){var one=jQuery.event.proxy(fn||data,function(event){jQuery(this).unbind(event,one);return(fn||data).apply(this,arguments);});return this.each(function(){jQuery.event.add(this,type,one,fn&&data);});},unbind:function(type,fn){return this.each(function(){jQuery.event.remove(this,type,fn);});},trigger:function(type,data,fn){return this.each(function(){jQuery.event.trigger(type,data,this,true,fn);});},triggerHandler:function(type,data,fn){return this[0]&&jQuery.event.trigger(type,data,this[0],false,fn);},toggle:function(fn){var args=arguments,i=1;while(i<args.length)jQuery.event.proxy(fn,args[i++]);return this.click(jQuery.event.proxy(fn,function(event){this.lastToggle=(this.lastToggle||0)%i;event.preventDefault();return args[this.lastToggle++].apply(this,arguments)||false;}));},hover:function(fnOver,fnOut){return this.bind('mouseenter',fnOver).bind('mouseleave',fnOut);},ready:function(fn){bindReady();if(jQuery.isReady)fn.call(document,jQuery);else +jQuery.readyList.push(function(){return fn.call(this,jQuery);});return this;}});jQuery.extend({isReady:false,readyList:[],ready:function(){if(!jQuery.isReady){jQuery.isReady=true;if(jQuery.readyList){jQuery.each(jQuery.readyList,function(){this.call(document);});jQuery.readyList=null;}jQuery(document).triggerHandler("ready");}}});var readyBound=false;function bindReady(){if(readyBound)return;readyBound=true;if(document.addEventListener&&!jQuery.browser.opera)document.addEventListener("DOMContentLoaded",jQuery.ready,false);if(jQuery.browser.msie&&window==top)(function(){if(jQuery.isReady)return;try{document.documentElement.doScroll("left");}catch(error){setTimeout(arguments.callee,0);return;}jQuery.ready();})();if(jQuery.browser.opera)document.addEventListener("DOMContentLoaded",function(){if(jQuery.isReady)return;for(var i=0;i<document.styleSheets.length;i++)if(document.styleSheets[i].disabled){setTimeout(arguments.callee,0);return;}jQuery.ready();},false);if(jQuery.browser.safari){var numStyles;(function(){if(jQuery.isReady)return;if(document.readyState!="loaded"&&document.readyState!="complete"){setTimeout(arguments.callee,0);return;}if(numStyles===undefined)numStyles=jQuery("style, link[rel=stylesheet]").length;if(document.styleSheets.length!=numStyles){setTimeout(arguments.callee,0);return;}jQuery.ready();})();}jQuery.event.add(window,"load",jQuery.ready);}jQuery.each(("blur,focus,load,resize,scroll,unload,click,dblclick,"+"mousedown,mouseup,mousemove,mouseover,mouseout,change,select,"+"submit,keydown,keypress,keyup,error").split(","),function(i,name){jQuery.fn[name]=function(fn){return fn?this.bind(name,fn):this.trigger(name);};});var withinElement=function(event,elem){var parent=event.relatedTarget;while(parent&&parent!=elem)try{parent=parent.parentNode;}catch(error){parent=elem;}return parent==elem;};jQuery(window).bind("unload",function(){jQuery("*").add(document).unbind();});jQuery.fn.extend({_load:jQuery.fn.load,load:function(url,params,callback){if(typeof url!='string')return this._load(url);var off=url.indexOf(" ");if(off>=0){var selector=url.slice(off,url.length);url=url.slice(0,off);}callback=callback||function(){};var type="GET";if(params)if(jQuery.isFunction(params)){callback=params;params=null;}else{params=jQuery.param(params);type="POST";}var self=this;jQuery.ajax({url:url,type:type,dataType:"html",data:params,complete:function(res,status){if(status=="success"||status=="notmodified")self.html(selector?jQuery("<div/>").append(res.responseText.replace(/<script(.|\s)*?\/script>/g,"")).find(selector):res.responseText);self.each(callback,[res.responseText,status,res]);}});return this;},serialize:function(){return jQuery.param(this.serializeArray());},serializeArray:function(){return this.map(function(){return jQuery.nodeName(this,"form")?jQuery.makeArray(this.elements):this;}).filter(function(){return this.name&&!this.disabled&&(this.checked||/select|textarea/i.test(this.nodeName)||/text|hidden|password/i.test(this.type));}).map(function(i,elem){var val=jQuery(this).val();return val==null?null:val.constructor==Array?jQuery.map(val,function(val,i){return{name:elem.name,value:val};}):{name:elem.name,value:val};}).get();}});jQuery.each("ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","),function(i,o){jQuery.fn[o]=function(f){return this.bind(o,f);};});var jsc=now();jQuery.extend({get:function(url,data,callback,type){if(jQuery.isFunction(data)){callback=data;data=null;}return jQuery.ajax({type:"GET",url:url,data:data,success:callback,dataType:type});},getScript:function(url,callback){return jQuery.get(url,null,callback,"script");},getJSON:function(url,data,callback){return jQuery.get(url,data,callback,"json");},post:function(url,data,callback,type){if(jQuery.isFunction(data)){callback=data;data={};}return jQuery.ajax({type:"POST",url:url,data:data,success:callback,dataType:type});},ajaxSetup:function(settings){jQuery.extend(jQuery.ajaxSettings,settings);},ajaxSettings:{url:location.href,global:true,type:"GET",timeout:0,contentType:"application/x-www-form-urlencoded",processData:true,async:true,data:null,username:null,password:null,accepts:{xml:"application/xml, text/xml",html:"text/html",script:"text/javascript, application/javascript",json:"application/json, text/javascript",text:"text/plain",_default:"*/*"}},lastModified:{},ajax:function(s){s=jQuery.extend(true,s,jQuery.extend(true,{},jQuery.ajaxSettings,s));var jsonp,jsre=/=\?(&|$)/g,status,data,type=s.type.toUpperCase();if(s.data&&s.processData&&typeof s.data!="string")s.data=jQuery.param(s.data);if(s.dataType=="jsonp"){if(type=="GET"){if(!s.url.match(jsre))s.url+=(s.url.match(/\?/)?"&":"?")+(s.jsonp||"callback")+"=?";}else if(!s.data||!s.data.match(jsre))s.data=(s.data?s.data+"&":"")+(s.jsonp||"callback")+"=?";s.dataType="json";}if(s.dataType=="json"&&(s.data&&s.data.match(jsre)||s.url.match(jsre))){jsonp="jsonp"+jsc++;if(s.data)s.data=(s.data+"").replace(jsre,"="+jsonp+"$1");s.url=s.url.replace(jsre,"="+jsonp+"$1");s.dataType="script";window[jsonp]=function(tmp){data=tmp;success();complete();window[jsonp]=undefined;try{delete window[jsonp];}catch(e){}if(head)head.removeChild(script);};}if(s.dataType=="script"&&s.cache==null)s.cache=false;if(s.cache===false&&type=="GET"){var ts=now();var ret=s.url.replace(/(\?|&)_=.*?(&|$)/,"$1_="+ts+"$2");s.url=ret+((ret==s.url)?(s.url.match(/\?/)?"&":"?")+"_="+ts:"");}if(s.data&&type=="GET"){s.url+=(s.url.match(/\?/)?"&":"?")+s.data;s.data=null;}if(s.global&&!jQuery.active++)jQuery.event.trigger("ajaxStart");var remote=/^(?:\w+:)?\/\/([^\/?#]+)/;if(s.dataType=="script"&&type=="GET"&&remote.test(s.url)&&remote.exec(s.url)[1]!=location.host){var head=document.getElementsByTagName("head")[0];var script=document.createElement("script");script.src=s.url;if(s.scriptCharset)script.charset=s.scriptCharset;if(!jsonp){var done=false;script.onload=script.onreadystatechange=function(){if(!done&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){done=true;success();complete();head.removeChild(script);}};}head.appendChild(script);return undefined;}var requestDone=false;var xhr=window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();if(s.username)xhr.open(type,s.url,s.async,s.username,s.password);else +xhr.open(type,s.url,s.async);try{if(s.data)xhr.setRequestHeader("Content-Type",s.contentType);if(s.ifModified)xhr.setRequestHeader("If-Modified-Since",jQuery.lastModified[s.url]||"Thu, 01 Jan 1970 00:00:00 GMT");xhr.setRequestHeader("X-Requested-With","XMLHttpRequest");xhr.setRequestHeader("Accept",s.dataType&&s.accepts[s.dataType]?s.accepts[s.dataType]+", */*":s.accepts._default);}catch(e){}if(s.beforeSend&&s.beforeSend(xhr,s)===false){s.global&&jQuery.active--;xhr.abort();return false;}if(s.global)jQuery.event.trigger("ajaxSend",[xhr,s]);var onreadystatechange=function(isTimeout){if(!requestDone&&xhr&&(xhr.readyState==4||isTimeout=="timeout")){requestDone=true;if(ival){clearInterval(ival);ival=null;}status=isTimeout=="timeout"&&"timeout"||!jQuery.httpSuccess(xhr)&&"error"||s.ifModified&&jQuery.httpNotModified(xhr,s.url)&&"notmodified"||"success";if(status=="success"){try{data=jQuery.httpData(xhr,s.dataType,s.dataFilter);}catch(e){status="parsererror";}}if(status=="success"){var modRes;try{modRes=xhr.getResponseHeader("Last-Modified");}catch(e){}if(s.ifModified&&modRes)jQuery.lastModified[s.url]=modRes;if(!jsonp)success();}else +jQuery.handleError(s,xhr,status);complete();if(s.async)xhr=null;}};if(s.async){var ival=setInterval(onreadystatechange,13);if(s.timeout>0)setTimeout(function(){if(xhr){xhr.abort();if(!requestDone)onreadystatechange("timeout");}},s.timeout);}try{xhr.send(s.data);}catch(e){jQuery.handleError(s,xhr,null,e);}if(!s.async)onreadystatechange();function success(){if(s.success)s.success(data,status);if(s.global)jQuery.event.trigger("ajaxSuccess",[xhr,s]);}function complete(){if(s.complete)s.complete(xhr,status);if(s.global)jQuery.event.trigger("ajaxComplete",[xhr,s]);if(s.global&&!--jQuery.active)jQuery.event.trigger("ajaxStop");}return xhr;},handleError:function(s,xhr,status,e){if(s.error)s.error(xhr,status,e);if(s.global)jQuery.event.trigger("ajaxError",[xhr,s,e]);},active:0,httpSuccess:function(xhr){try{return!xhr.status&&location.protocol=="file:"||(xhr.status>=200&&xhr.status<300)||xhr.status==304||xhr.status==1223||jQuery.browser.safari&&xhr.status==undefined;}catch(e){}return false;},httpNotModified:function(xhr,url){try{var xhrRes=xhr.getResponseHeader("Last-Modified");return xhr.status==304||xhrRes==jQuery.lastModified[url]||jQuery.browser.safari&&xhr.status==undefined;}catch(e){}return false;},httpData:function(xhr,type,filter){var ct=xhr.getResponseHeader("content-type"),xml=type=="xml"||!type&&ct&&ct.indexOf("xml")>=0,data=xml?xhr.responseXML:xhr.responseText;if(xml&&data.documentElement.tagName=="parsererror")throw"parsererror";if(filter)data=filter(data,type);if(type=="script")jQuery.globalEval(data);if(type=="json")data=eval("("+data+")");return data;},param:function(a){var s=[];if(a.constructor==Array||a.jquery)jQuery.each(a,function(){s.push(encodeURIComponent(this.name)+"="+encodeURIComponent(this.value));});else +for(var j in a)if(a[j]&&a[j].constructor==Array)jQuery.each(a[j],function(){s.push(encodeURIComponent(j)+"="+encodeURIComponent(this));});else +s.push(encodeURIComponent(j)+"="+encodeURIComponent(jQuery.isFunction(a[j])?a[j]():a[j]));return s.join("&").replace(/%20/g,"+");}});jQuery.fn.extend({show:function(speed,callback){return speed?this.animate({height:"show",width:"show",opacity:"show"},speed,callback):this.filter(":hidden").each(function(){this.style.display=this.oldblock||"";if(jQuery.css(this,"display")=="none"){var elem=jQuery("<"+this.tagName+" />").appendTo("body");this.style.display=elem.css("display");if(this.style.display=="none")this.style.display="block";elem.remove();}}).end();},hide:function(speed,callback){return speed?this.animate({height:"hide",width:"hide",opacity:"hide"},speed,callback):this.filter(":visible").each(function(){this.oldblock=this.oldblock||jQuery.css(this,"display");this.style.display="none";}).end();},_toggle:jQuery.fn.toggle,toggle:function(fn,fn2){return jQuery.isFunction(fn)&&jQuery.isFunction(fn2)?this._toggle.apply(this,arguments):fn?this.animate({height:"toggle",width:"toggle",opacity:"toggle"},fn,fn2):this.each(function(){jQuery(this)[jQuery(this).is(":hidden")?"show":"hide"]();});},slideDown:function(speed,callback){return this.animate({height:"show"},speed,callback);},slideUp:function(speed,callback){return this.animate({height:"hide"},speed,callback);},slideToggle:function(speed,callback){return this.animate({height:"toggle"},speed,callback);},fadeIn:function(speed,callback){return this.animate({opacity:"show"},speed,callback);},fadeOut:function(speed,callback){return this.animate({opacity:"hide"},speed,callback);},fadeTo:function(speed,to,callback){return this.animate({opacity:to},speed,callback);},animate:function(prop,speed,easing,callback){var optall=jQuery.speed(speed,easing,callback);return this[optall.queue===false?"each":"queue"](function(){if(this.nodeType!=1)return false;var opt=jQuery.extend({},optall),p,hidden=jQuery(this).is(":hidden"),self=this;for(p in prop){if(prop[p]=="hide"&&hidden||prop[p]=="show"&&!hidden)return opt.complete.call(this);if(p=="height"||p=="width"){opt.display=jQuery.css(this,"display");opt.overflow=this.style.overflow;}}if(opt.overflow!=null)this.style.overflow="hidden";opt.curAnim=jQuery.extend({},prop);jQuery.each(prop,function(name,val){var e=new jQuery.fx(self,opt,name);if(/toggle|show|hide/.test(val))e[val=="toggle"?hidden?"show":"hide":val](prop);else{var parts=val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),start=e.cur(true)||0;if(parts){var end=parseFloat(parts[2]),unit=parts[3]||"px";if(unit!="px"){self.style[name]=(end||1)+unit;start=((end||1)/e.cur(true))*start;self.style[name]=start+unit;}if(parts[1])end=((parts[1]=="-="?-1:1)*end)+start;e.custom(start,end,unit);}else +e.custom(start,val,"");}});return true;});},queue:function(type,fn){if(jQuery.isFunction(type)||(type&&type.constructor==Array)){fn=type;type="fx";}if(!type||(typeof type=="string"&&!fn))return queue(this[0],type);return this.each(function(){if(fn.constructor==Array)queue(this,type,fn);else{queue(this,type).push(fn);if(queue(this,type).length==1)fn.call(this);}});},stop:function(clearQueue,gotoEnd){var timers=jQuery.timers;if(clearQueue)this.queue([]);this.each(function(){for(var i=timers.length-1;i>=0;i--)if(timers[i].elem==this){if(gotoEnd)timers[i](true);timers.splice(i,1);}});if(!gotoEnd)this.dequeue();return this;}});var queue=function(elem,type,array){if(elem){type=type||"fx";var q=jQuery.data(elem,type+"queue");if(!q||array)q=jQuery.data(elem,type+"queue",jQuery.makeArray(array));}return q;};jQuery.fn.dequeue=function(type){type=type||"fx";return this.each(function(){var q=queue(this,type);q.shift();if(q.length)q[0].call(this);});};jQuery.extend({speed:function(speed,easing,fn){var opt=speed&&speed.constructor==Object?speed:{complete:fn||!fn&&easing||jQuery.isFunction(speed)&&speed,duration:speed,easing:fn&&easing||easing&&easing.constructor!=Function&&easing};opt.duration=(opt.duration&&opt.duration.constructor==Number?opt.duration:jQuery.fx.speeds[opt.duration])||jQuery.fx.speeds.def;opt.old=opt.complete;opt.complete=function(){if(opt.queue!==false)jQuery(this).dequeue();if(jQuery.isFunction(opt.old))opt.old.call(this);};return opt;},easing:{linear:function(p,n,firstNum,diff){return firstNum+diff*p;},swing:function(p,n,firstNum,diff){return((-Math.cos(p*Math.PI)/2)+0.5)*diff+firstNum;}},timers:[],timerId:null,fx:function(elem,options,prop){this.options=options;this.elem=elem;this.prop=prop;if(!options.orig)options.orig={};}});jQuery.fx.prototype={update:function(){if(this.options.step)this.options.step.call(this.elem,this.now,this);(jQuery.fx.step[this.prop]||jQuery.fx.step._default)(this);if(this.prop=="height"||this.prop=="width")this.elem.style.display="block";},cur:function(force){if(this.elem[this.prop]!=null&&this.elem.style[this.prop]==null)return this.elem[this.prop];var r=parseFloat(jQuery.css(this.elem,this.prop,force));return r&&r>-10000?r:parseFloat(jQuery.curCSS(this.elem,this.prop))||0;},custom:function(from,to,unit){this.startTime=now();this.start=from;this.end=to;this.unit=unit||this.unit||"px";this.now=this.start;this.pos=this.state=0;this.update();var self=this;function t(gotoEnd){return self.step(gotoEnd);}t.elem=this.elem;jQuery.timers.push(t);if(jQuery.timerId==null){jQuery.timerId=setInterval(function(){var timers=jQuery.timers;for(var i=0;i<timers.length;i++)if(!timers[i]())timers.splice(i--,1);if(!timers.length){clearInterval(jQuery.timerId);jQuery.timerId=null;}},13);}},show:function(){this.options.orig[this.prop]=jQuery.attr(this.elem.style,this.prop);this.options.show=true;this.custom(0,this.cur());if(this.prop=="width"||this.prop=="height")this.elem.style[this.prop]="1px";jQuery(this.elem).show();},hide:function(){this.options.orig[this.prop]=jQuery.attr(this.elem.style,this.prop);this.options.hide=true;this.custom(this.cur(),0);},step:function(gotoEnd){var t=now();if(gotoEnd||t>this.options.duration+this.startTime){this.now=this.end;this.pos=this.state=1;this.update();this.options.curAnim[this.prop]=true;var done=true;for(var i in this.options.curAnim)if(this.options.curAnim[i]!==true)done=false;if(done){if(this.options.display!=null){this.elem.style.overflow=this.options.overflow;this.elem.style.display=this.options.display;if(jQuery.css(this.elem,"display")=="none")this.elem.style.display="block";}if(this.options.hide)this.elem.style.display="none";if(this.options.hide||this.options.show)for(var p in this.options.curAnim)jQuery.attr(this.elem.style,p,this.options.orig[p]);}if(done)this.options.complete.call(this.elem);return false;}else{var n=t-this.startTime;this.state=n/this.options.duration;this.pos=jQuery.easing[this.options.easing||(jQuery.easing.swing?"swing":"linear")](this.state,n,0,1,this.options.duration);this.now=this.start+((this.end-this.start)*this.pos);this.update();}return true;}};jQuery.extend(jQuery.fx,{speeds:{slow:600,fast:200,def:400},step:{scrollLeft:function(fx){fx.elem.scrollLeft=fx.now;},scrollTop:function(fx){fx.elem.scrollTop=fx.now;},opacity:function(fx){jQuery.attr(fx.elem.style,"opacity",fx.now);},_default:function(fx){fx.elem.style[fx.prop]=fx.now+fx.unit;}}});jQuery.fn.offset=function(){var left=0,top=0,elem=this[0],results;if(elem)with(jQuery.browser){var parent=elem.parentNode,offsetChild=elem,offsetParent=elem.offsetParent,doc=elem.ownerDocument,safari2=safari&&parseInt(version)<522&&!/adobeair/i.test(userAgent),css=jQuery.curCSS,fixed=css(elem,"position")=="fixed";if(elem.getBoundingClientRect){var box=elem.getBoundingClientRect();add(box.left+Math.max(doc.documentElement.scrollLeft,doc.body.scrollLeft),box.top+Math.max(doc.documentElement.scrollTop,doc.body.scrollTop));add(-doc.documentElement.clientLeft,-doc.documentElement.clientTop);}else{add(elem.offsetLeft,elem.offsetTop);while(offsetParent){add(offsetParent.offsetLeft,offsetParent.offsetTop);if(mozilla&&!/^t(able|d|h)$/i.test(offsetParent.tagName)||safari&&!safari2)border(offsetParent);if(!fixed&&css(offsetParent,"position")=="fixed")fixed=true;offsetChild=/^body$/i.test(offsetParent.tagName)?offsetChild:offsetParent;offsetParent=offsetParent.offsetParent;}while(parent&&parent.tagName&&!/^body|html$/i.test(parent.tagName)){if(!/^inline|table.*$/i.test(css(parent,"display")))add(-parent.scrollLeft,-parent.scrollTop);if(mozilla&&css(parent,"overflow")!="visible")border(parent);parent=parent.parentNode;}if((safari2&&(fixed||css(offsetChild,"position")=="absolute"))||(mozilla&&css(offsetChild,"position")!="absolute"))add(-doc.body.offsetLeft,-doc.body.offsetTop);if(fixed)add(Math.max(doc.documentElement.scrollLeft,doc.body.scrollLeft),Math.max(doc.documentElement.scrollTop,doc.body.scrollTop));}results={top:top,left:left};}function border(elem){add(jQuery.curCSS(elem,"borderLeftWidth",true),jQuery.curCSS(elem,"borderTopWidth",true));}function add(l,t){left+=parseInt(l,10)||0;top+=parseInt(t,10)||0;}return results;};jQuery.fn.extend({position:function(){var left=0,top=0,results;if(this[0]){var offsetParent=this.offsetParent(),offset=this.offset(),parentOffset=/^body|html$/i.test(offsetParent[0].tagName)?{top:0,left:0}:offsetParent.offset();offset.top-=num(this,'marginTop');offset.left-=num(this,'marginLeft');parentOffset.top+=num(offsetParent,'borderTopWidth');parentOffset.left+=num(offsetParent,'borderLeftWidth');results={top:offset.top-parentOffset.top,left:offset.left-parentOffset.left};}return results;},offsetParent:function(){var offsetParent=this[0].offsetParent;while(offsetParent&&(!/^body|html$/i.test(offsetParent.tagName)&&jQuery.css(offsetParent,'position')=='static'))offsetParent=offsetParent.offsetParent;return jQuery(offsetParent);}});jQuery.each(['Left','Top'],function(i,name){var method='scroll'+name;jQuery.fn[method]=function(val){if(!this[0])return;return val!=undefined?this.each(function(){this==window||this==document?window.scrollTo(!i?val:jQuery(window).scrollLeft(),i?val:jQuery(window).scrollTop()):this[method]=val;}):this[0]==window||this[0]==document?self[i?'pageYOffset':'pageXOffset']||jQuery.boxModel&&document.documentElement[method]||document.body[method]:this[0][method];};});jQuery.each(["Height","Width"],function(i,name){var tl=i?"Left":"Top",br=i?"Right":"Bottom";jQuery.fn["inner"+name]=function(){return this[name.toLowerCase()]()+num(this,"padding"+tl)+num(this,"padding"+br);};jQuery.fn["outer"+name]=function(margin){return this["inner"+name]()+num(this,"border"+tl+"Width")+num(this,"border"+br+"Width")+(margin?num(this,"margin"+tl)+num(this,"margin"+br):0);};});})();
\ No newline at end of file diff --git a/docs/_build/html/_static/minus.png b/docs/_build/html/_static/minus.png Binary files differnew file mode 100644 index 00000000..da1c5620 --- /dev/null +++ b/docs/_build/html/_static/minus.png diff --git a/docs/_build/html/_static/navigation.png b/docs/_build/html/_static/navigation.png Binary files differnew file mode 100644 index 00000000..1081dc14 --- /dev/null +++ b/docs/_build/html/_static/navigation.png diff --git a/docs/_build/html/_static/plus.png b/docs/_build/html/_static/plus.png Binary files differnew file mode 100644 index 00000000..b3cb3742 --- /dev/null +++ b/docs/_build/html/_static/plus.png diff --git a/docs/_build/html/_static/pygments.css b/docs/_build/html/_static/pygments.css new file mode 100644 index 00000000..1f2d2b61 --- /dev/null +++ b/docs/_build/html/_static/pygments.css @@ -0,0 +1,61 @@ +.hll { background-color: #ffffcc } +.c { color: #408090; font-style: italic } /* Comment */ +.err { border: 1px solid #FF0000 } /* Error */ +.k { color: #007020; font-weight: bold } /* Keyword */ +.o { color: #666666 } /* Operator */ +.cm { color: #408090; font-style: italic } /* Comment.Multiline */ +.cp { color: #007020 } /* Comment.Preproc */ +.c1 { color: #408090; font-style: italic } /* Comment.Single */ +.cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */ +.gd { color: #A00000 } /* Generic.Deleted */ +.ge { font-style: italic } /* Generic.Emph */ +.gr { color: #FF0000 } /* Generic.Error */ +.gh { color: #000080; font-weight: bold } /* Generic.Heading */ +.gi { color: #00A000 } /* Generic.Inserted */ +.go { color: #303030 } /* Generic.Output */ +.gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ +.gs { font-weight: bold } /* Generic.Strong */ +.gu { color: #800080; font-weight: bold } /* Generic.Subheading */ +.gt { color: #0040D0 } /* Generic.Traceback */ +.kc { color: #007020; font-weight: bold } /* Keyword.Constant */ +.kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ +.kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ +.kp { color: #007020 } /* Keyword.Pseudo */ +.kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ +.kt { color: #902000 } /* Keyword.Type */ +.m { color: #208050 } /* Literal.Number */ +.s { color: #4070a0 } /* Literal.String */ +.na { color: #4070a0 } /* Name.Attribute */ +.nb { color: #007020 } /* Name.Builtin */ +.nc { color: #0e84b5; font-weight: bold } /* Name.Class */ +.no { color: #60add5 } /* Name.Constant */ +.nd { color: #555555; font-weight: bold } /* Name.Decorator */ +.ni { color: #d55537; font-weight: bold } /* Name.Entity */ +.ne { color: #007020 } /* Name.Exception */ +.nf { color: #06287e } /* Name.Function */ +.nl { color: #002070; font-weight: bold } /* Name.Label */ +.nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ +.nt { color: #062873; font-weight: bold } /* Name.Tag */ +.nv { color: #bb60d5 } /* Name.Variable */ +.ow { color: #007020; font-weight: bold } /* Operator.Word */ +.w { color: #bbbbbb } /* Text.Whitespace */ +.mf { color: #208050 } /* Literal.Number.Float */ +.mh { color: #208050 } /* Literal.Number.Hex */ +.mi { color: #208050 } /* Literal.Number.Integer */ +.mo { color: #208050 } /* Literal.Number.Oct */ +.sb { color: #4070a0 } /* Literal.String.Backtick */ +.sc { color: #4070a0 } /* Literal.String.Char */ +.sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ +.s2 { color: #4070a0 } /* Literal.String.Double */ +.se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ +.sh { color: #4070a0 } /* Literal.String.Heredoc */ +.si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ +.sx { color: #c65d09 } /* Literal.String.Other */ +.sr { color: #235388 } /* Literal.String.Regex */ +.s1 { color: #4070a0 } /* Literal.String.Single */ +.ss { color: #517918 } /* Literal.String.Symbol */ +.bp { color: #007020 } /* Name.Builtin.Pseudo */ +.vc { color: #bb60d5 } /* Name.Variable.Class */ +.vg { color: #bb60d5 } /* Name.Variable.Global */ +.vi { color: #bb60d5 } /* Name.Variable.Instance */ +.il { color: #208050 } /* Literal.Number.Integer.Long */
\ No newline at end of file diff --git a/docs/_build/html/_static/rightsidebar.css b/docs/_build/html/_static/rightsidebar.css new file mode 100644 index 00000000..bc604a89 --- /dev/null +++ b/docs/_build/html/_static/rightsidebar.css @@ -0,0 +1,16 @@ +/** + * Sphinx Doc Design -- Right Side Bar Overrides + */ + + +div.sphinxsidebar { + float: right; +} + +div.bodywrapper { + margin: 0 230px 0 0; +} + +div.inlinecomments { + right: 250px; +} diff --git a/docs/_build/html/_static/searchtools.js b/docs/_build/html/_static/searchtools.js new file mode 100644 index 00000000..f9d9b6c3 --- /dev/null +++ b/docs/_build/html/_static/searchtools.js @@ -0,0 +1,467 @@ +/** + * helper function to return a node containing the + * search summary for a given text. keywords is a list + * of stemmed words, hlwords is the list of normal, unstemmed + * words. the first one is used to find the occurance, the + * latter for highlighting it. + */ + +jQuery.makeSearchSummary = function(text, keywords, hlwords) { + var textLower = text.toLowerCase(); + var start = 0; + $.each(keywords, function() { + var i = textLower.indexOf(this.toLowerCase()); + if (i > -1) + start = i; + }); + start = Math.max(start - 120, 0); + var excerpt = ((start > 0) ? '...' : '') + + $.trim(text.substr(start, 240)) + + ((start + 240 - text.length) ? '...' : ''); + var rv = $('<div class="context"></div>').text(excerpt); + $.each(hlwords, function() { + rv = rv.highlightText(this, 'highlight'); + }); + return rv; +} + +/** + * Porter Stemmer + */ +var PorterStemmer = function() { + + var step2list = { + ational: 'ate', + tional: 'tion', + enci: 'ence', + anci: 'ance', + izer: 'ize', + bli: 'ble', + alli: 'al', + entli: 'ent', + eli: 'e', + ousli: 'ous', + ization: 'ize', + ation: 'ate', + ator: 'ate', + alism: 'al', + iveness: 'ive', + fulness: 'ful', + ousness: 'ous', + aliti: 'al', + iviti: 'ive', + biliti: 'ble', + logi: 'log' + }; + + var step3list = { + icate: 'ic', + ative: '', + alize: 'al', + iciti: 'ic', + ical: 'ic', + ful: '', + ness: '' + }; + + var c = "[^aeiou]"; // consonant + var v = "[aeiouy]"; // vowel + var C = c + "[^aeiouy]*"; // consonant sequence + var V = v + "[aeiou]*"; // vowel sequence + + var mgr0 = "^(" + C + ")?" + V + C; // [C]VC... is m>0 + var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$"; // [C]VC[V] is m=1 + var mgr1 = "^(" + C + ")?" + V + C + V + C; // [C]VCVC... is m>1 + var s_v = "^(" + C + ")?" + v; // vowel in stem + + this.stemWord = function (w) { + var stem; + var suffix; + var firstch; + var origword = w; + + if (w.length < 3) + return w; + + var re; + var re2; + var re3; + var re4; + + firstch = w.substr(0,1); + if (firstch == "y") + w = firstch.toUpperCase() + w.substr(1); + + // Step 1a + re = /^(.+?)(ss|i)es$/; + re2 = /^(.+?)([^s])s$/; + + if (re.test(w)) + w = w.replace(re,"$1$2"); + else if (re2.test(w)) + w = w.replace(re2,"$1$2"); + + // Step 1b + re = /^(.+?)eed$/; + re2 = /^(.+?)(ed|ing)$/; + if (re.test(w)) { + var fp = re.exec(w); + re = new RegExp(mgr0); + if (re.test(fp[1])) { + re = /.$/; + w = w.replace(re,""); + } + } + else if (re2.test(w)) { + var fp = re2.exec(w); + stem = fp[1]; + re2 = new RegExp(s_v); + if (re2.test(stem)) { + w = stem; + re2 = /(at|bl|iz)$/; + re3 = new RegExp("([^aeiouylsz])\\1$"); + re4 = new RegExp("^" + C + v + "[^aeiouwxy]$"); + if (re2.test(w)) + w = w + "e"; + else if (re3.test(w)) { + re = /.$/; + w = w.replace(re,""); + } + else if (re4.test(w)) + w = w + "e"; + } + } + + // Step 1c + re = /^(.+?)y$/; + if (re.test(w)) { + var fp = re.exec(w); + stem = fp[1]; + re = new RegExp(s_v); + if (re.test(stem)) + w = stem + "i"; + } + + // Step 2 + re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/; + if (re.test(w)) { + var fp = re.exec(w); + stem = fp[1]; + suffix = fp[2]; + re = new RegExp(mgr0); + if (re.test(stem)) + w = stem + step2list[suffix]; + } + + // Step 3 + re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/; + if (re.test(w)) { + var fp = re.exec(w); + stem = fp[1]; + suffix = fp[2]; + re = new RegExp(mgr0); + if (re.test(stem)) + w = stem + step3list[suffix]; + } + + // Step 4 + re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/; + re2 = /^(.+?)(s|t)(ion)$/; + if (re.test(w)) { + var fp = re.exec(w); + stem = fp[1]; + re = new RegExp(mgr1); + if (re.test(stem)) + w = stem; + } + else if (re2.test(w)) { + var fp = re2.exec(w); + stem = fp[1] + fp[2]; + re2 = new RegExp(mgr1); + if (re2.test(stem)) + w = stem; + } + + // Step 5 + re = /^(.+?)e$/; + if (re.test(w)) { + var fp = re.exec(w); + stem = fp[1]; + re = new RegExp(mgr1); + re2 = new RegExp(meq1); + re3 = new RegExp("^" + C + v + "[^aeiouwxy]$"); + if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) + w = stem; + } + re = /ll$/; + re2 = new RegExp(mgr1); + if (re.test(w) && re2.test(w)) { + re = /.$/; + w = w.replace(re,""); + } + + // and turn initial Y back to y + if (firstch == "y") + w = firstch.toLowerCase() + w.substr(1); + return w; + } +} + + +/** + * Search Module + */ +var Search = { + + _index : null, + _queued_query : null, + _pulse_status : -1, + + init : function() { + var params = $.getQueryParameters(); + if (params.q) { + var query = params.q[0]; + $('input[@name="q"]')[0].value = query; + this.performSearch(query); + } + }, + + /** + * Sets the index + */ + setIndex : function(index) { + var q; + this._index = index; + if ((q = this._queued_query) !== null) { + this._queued_query = null; + Search.query(q); + } + }, + + hasIndex : function() { + return this._index !== null; + }, + + deferQuery : function(query) { + this._queued_query = query; + }, + + stopPulse : function() { + this._pulse_status = 0; + }, + + startPulse : function() { + if (this._pulse_status >= 0) + return; + function pulse() { + Search._pulse_status = (Search._pulse_status + 1) % 4; + var dotString = ''; + for (var i = 0; i < Search._pulse_status; i++) + dotString += '.'; + Search.dots.text(dotString); + if (Search._pulse_status > -1) + window.setTimeout(pulse, 500); + }; + pulse(); + }, + + /** + * perform a search for something + */ + performSearch : function(query) { + // create the required interface elements + this.out = $('#search-results'); + this.title = $('<h2>' + _('Searching') + '</h2>').appendTo(this.out); + this.dots = $('<span></span>').appendTo(this.title); + this.status = $('<p style="display: none"></p>').appendTo(this.out); + this.output = $('<ul class="search"/>').appendTo(this.out); + + $('#search-progress').text(_('Preparing search...')); + this.startPulse(); + + // index already loaded, the browser was quick! + if (this.hasIndex()) + this.query(query); + else + this.setQuery(query); + }, + + query : function(query) { + // stem the searchterms and add them to the + // correct list + var stemmer = new PorterStemmer(); + var searchterms = []; + var excluded = []; + var hlterms = []; + var tmp = query.split(/\s+/); + var object = (tmp.length == 1) ? tmp[0].toLowerCase() : null; + for (var i = 0; i < tmp.length; i++) { + // stem the word + var word = stemmer.stemWord(tmp[i]).toLowerCase(); + // select the correct list + if (word[0] == '-') { + var toAppend = excluded; + word = word.substr(1); + } + else { + var toAppend = searchterms; + hlterms.push(tmp[i].toLowerCase()); + } + // only add if not already in the list + if (!$.contains(toAppend, word)) + toAppend.push(word); + }; + var highlightstring = '?highlight=' + $.urlencode(hlterms.join(" ")); + + console.debug('SEARCH: searching for:'); + console.info('required: ', searchterms); + console.info('excluded: ', excluded); + + // prepare search + var filenames = this._index.filenames; + var titles = this._index.titles; + var terms = this._index.terms; + var descrefs = this._index.descrefs; + var modules = this._index.modules; + var desctypes = this._index.desctypes; + var fileMap = {}; + var files = null; + var objectResults = []; + var regularResults = []; + $('#search-progress').empty(); + + // lookup as object + if (object != null) { + for (var module in modules) { + if (module.indexOf(object) > -1) { + fn = modules[module]; + descr = _('module, in ') + titles[fn]; + objectResults.push([filenames[fn], module, '#module-'+module, descr]); + } + } + for (var prefix in descrefs) { + for (var name in descrefs[prefix]) { + if (name.toLowerCase().indexOf(object) > -1) { + match = descrefs[prefix][name]; + fullname = (prefix ? prefix + '.' : '') + name; + descr = desctypes[match[1]] + _(', in ') + titles[match[0]]; + objectResults.push([filenames[match[0]], fullname, '#'+fullname, descr]); + } + } + } + } + + // sort results descending + objectResults.sort(function(a, b) { + return (a[1] > b[1]) ? -1 : ((a[1] < b[1]) ? 1 : 0); + }); + + + // perform the search on the required terms + for (var i = 0; i < searchterms.length; i++) { + var word = searchterms[i]; + // no match but word was a required one + if ((files = terms[word]) == null) + break; + if (files.length == undefined) { + files = [files]; + } + // create the mapping + for (var j = 0; j < files.length; j++) { + var file = files[j]; + if (file in fileMap) + fileMap[file].push(word); + else + fileMap[file] = [word]; + } + } + + // now check if the files don't contain excluded terms + for (var file in fileMap) { + var valid = true; + + // check if all requirements are matched + if (fileMap[file].length != searchterms.length) + continue; + + // ensure that none of the excluded terms is in the + // search result. + for (var i = 0; i < excluded.length; i++) { + if (terms[excluded[i]] == file || + $.contains(terms[excluded[i]] || [], file)) { + valid = false; + break; + } + } + + // if we have still a valid result we can add it + // to the result list + if (valid) + regularResults.push([filenames[file], titles[file], '', null]); + } + + // delete unused variables in order to not waste + // memory until list is retrieved completely + delete filenames, titles, terms; + + // now sort the regular results descending by title + regularResults.sort(function(a, b) { + var left = a[1].toLowerCase(); + var right = b[1].toLowerCase(); + return (left > right) ? -1 : ((left < right) ? 1 : 0); + }); + + // combine both + var results = regularResults.concat(objectResults); + + // print the results + var resultCount = results.length; + function displayNextItem() { + // results left, load the summary and display it + if (results.length) { + var item = results.pop(); + var listItem = $('<li style="display:none"></li>'); + listItem.append($('<a/>').attr( + 'href', + item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX + + highlightstring + item[2]).html(item[1])); + if (item[3]) { + listItem.append($('<span> (' + item[3] + ')</span>')); + Search.output.append(listItem); + listItem.slideDown(5, function() { + displayNextItem(); + }); + } else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) { + $.get('_sources/' + item[0] + '.txt', function(data) { + listItem.append($.makeSearchSummary(data, searchterms, hlterms)); + Search.output.append(listItem); + listItem.slideDown(5, function() { + displayNextItem(); + }); + }); + } else { + // no source available, just display title + Search.output.append(listItem); + listItem.slideDown(5, function() { + displayNextItem(); + }); + } + } + // search finished, update title and status message + else { + Search.stopPulse(); + Search.title.text(_('Search Results')); + if (!resultCount) + Search.status.text(_('Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.')); + else + Search.status.text(_('Search finished, found %s page(s) matching the search query.').replace('%s', resultCount)); + Search.status.fadeIn(500); + } + } + displayNextItem(); + } +} + +$(document).ready(function() { + Search.init(); +}); diff --git a/docs/_build/html/_static/sphinxdoc.css b/docs/_build/html/_static/sphinxdoc.css new file mode 100644 index 00000000..999bf48c --- /dev/null +++ b/docs/_build/html/_static/sphinxdoc.css @@ -0,0 +1,557 @@ +/** + * Alternate Sphinx design + * Originally created by Armin Ronacher for Werkzeug, adapted by Georg Brandl. + */ + +body { + font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'Geneva', 'Verdana', sans-serif; + font-size: 14px; + letter-spacing: -0.01em; + line-height: 150%; + text-align: center; + /*background-color: #AFC1C4; */ + background-color: #BFD1D4; + color: black; + padding: 0; + border: 1px solid #aaa; + + margin: 0px 80px 0px 80px; + min-width: 740px; +} + +a { + color: #CA7900; + text-decoration: none; +} + +a:hover { + color: #2491CF; +} + +pre { + font-family: 'Consolas', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; + font-size: 0.95em; + letter-spacing: 0.015em; + padding: 0.5em; + border: 1px solid #ccc; + background-color: #f8f8f8; +} + +td.linenos pre { + padding: 0.5em 0; + border: 0; + background-color: transparent; + color: #aaa; +} + +table.highlighttable { + margin-left: 0.5em; +} + +table.highlighttable td { + padding: 0 0.5em 0 0.5em; +} + +cite, code, tt { + font-family: 'Consolas', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; + font-size: 0.95em; + letter-spacing: 0.01em; +} + +hr { + border: 1px solid #abc; + margin: 2em; +} + +tt { + background-color: #f2f2f2; + border-bottom: 1px solid #ddd; + color: #333; +} + +tt.descname { + background-color: transparent; + font-weight: bold; + font-size: 1.2em; + border: 0; +} + +tt.descclassname { + background-color: transparent; + border: 0; +} + +tt.xref { + background-color: transparent; + font-weight: bold; + border: 0; +} + +a tt { + background-color: transparent; + font-weight: bold; + border: 0; + color: #CA7900; +} + +a tt:hover { + color: #2491CF; +} + +.field-list ul { + margin: 0; + padding-left: 1em; +} + +.field-list p { + margin: 0; +} + +dl { + margin-bottom: 15px; +} + +dd p { + margin-top: 0px; +} + +dd ul, dd table { + margin-bottom: 10px; +} + +dd { + margin-top: 3px; + margin-bottom: 10px; + margin-left: 30px; +} + +.refcount { + color: #060; +} + +dt:target, +.highlight { + background-color: #fbe54e; +} + +dl.glossary dt { + font-weight: bold; + font-size: 1.1em; +} + +pre { + line-height: 120%; +} + +pre a { + color: inherit; + text-decoration: underline; +} + +.first { + margin-top: 0 !important; +} + +div.document { + background-color: white; + text-align: left; + background-image: url(contents.png); + background-repeat: repeat-x; +} + +/* +div.documentwrapper { + width: 100%; +} +*/ + +div.clearer { + clear: both; +} + +div.related h3 { + display: none; +} + +div.related ul { + background-image: url(navigation.png); + height: 2em; + list-style: none; + border-top: 1px solid #ddd; + border-bottom: 1px solid #ddd; + margin: 0; + padding-left: 10px; +} + +div.related ul li { + margin: 0; + padding: 0; + height: 2em; + float: left; +} + +div.related ul li.right { + float: right; + margin-right: 5px; +} + +div.related ul li a { + margin: 0; + padding: 0 5px 0 5px; + line-height: 1.75em; + color: #EE9816; +} + +div.related ul li a:hover { + color: #3CA8E7; +} + +div.body { + margin: 0; + padding: 0.5em 20px 20px 20px; +} + +div.bodywrapper { + margin: 0 240px 0 0; + border-right: 1px solid #ccc; +} + +div.body a { + text-decoration: underline; +} + +div.sphinxsidebar { + margin: 0; + padding: 0.5em 15px 15px 0; + width: 210px; + float: right; + text-align: left; +/* margin-left: -100%; */ +} + +div.sphinxsidebar h4, div.sphinxsidebar h3 { + margin: 1em 0 0.5em 0; + font-size: 0.9em; + padding: 0.1em 0 0.1em 0.5em; + color: white; + border: 1px solid #86989B; + background-color: #AFC1C4; +} + +div.sphinxsidebar h3 a { + color: white; +} + +div.sphinxsidebar ul { + padding-left: 1.5em; + margin-top: 7px; + list-style: none; + padding: 0; + line-height: 130%; +} + +div.sphinxsidebar ul ul { + list-style: square; + margin-left: 20px; +} + +p { + margin: 0.8em 0 0.5em 0; +} + +p.rubric { + font-weight: bold; +} + +div.sidebar { + margin: 0 0 0.5em 1em; + border: 1px solid #ddb; + padding: 7px 7px 0 7px; + background-color: #ffe; + width: 40%; + float: right; +} + +div.quotebar { + background-color: #f8f8f8; + max-width: 250px; + float: right; + padding: 2px 7px; + border: 1px solid #ccc; +} + +p.sidebar-title { + font-weight: bold; +} + +div.topic { + background-color: #f8f8f8; + border: 1px solid #ccc; + padding: 7px 7px 0 7px; + margin: 10px 0 10px 0; +} + +p.topic-title { + font-size: 1.1em; + font-weight: bold; +} + +h1 { + margin: 0; + padding: 0.7em 0 0.3em 0; + font-size: 1.5em; + color: #11557C; +} + +h2 { + margin: 1.3em 0 0.2em 0; + font-size: 1.35em; + padding: 0; +} + +h3 { + margin: 1em 0 -0.3em 0; + font-size: 1.2em; +} + +div.body h1 a, div.body h2 a, div.body h3 a, div.body h4 a, div.body h5 a, div.body h6 a { + color: black!important; +} + +h1 a.anchor, h2 a.anchor, h3 a.anchor, h4 a.anchor, h5 a.anchor, h6 a.anchor { + display: none; + margin: 0 0 0 0.3em; + padding: 0 0.2em 0 0.2em; + color: #aaa!important; +} + +h1:hover a.anchor, h2:hover a.anchor, h3:hover a.anchor, h4:hover a.anchor, +h5:hover a.anchor, h6:hover a.anchor { + display: inline; +} + +h1 a.anchor:hover, h2 a.anchor:hover, h3 a.anchor:hover, h4 a.anchor:hover, +h5 a.anchor:hover, h6 a.anchor:hover { + color: #777; + background-color: #eee; +} + +table { + border-collapse: collapse; + margin: 0 -0.5em 0 -0.5em; +} + +table td, table th { + padding: 0.2em 0.5em 0.2em 0.5em; +} + +div.footer { + background-color: #E3EFF1; + color: #86989B; + padding: 3px 8px 3px 0; + clear: both; + font-size: 0.8em; + text-align: right; +} + +div.footer a { + color: #86989B; + text-decoration: underline; +} + +div.pagination { + margin-top: 2em; + padding-top: 0.5em; + border-top: 1px solid black; + text-align: center; +} + +div.sphinxsidebar ul.toc { + margin: 1em 0 1em 0; + padding: 0 0 0 0.5em; + list-style: none; +} + +div.sphinxsidebar ul.toc li { + margin: 0.5em 0 0.5em 0; + font-size: 0.9em; + line-height: 130%; +} + +div.sphinxsidebar ul.toc li p { + margin: 0; + padding: 0; +} + +div.sphinxsidebar ul.toc ul { + margin: 0.2em 0 0.2em 0; + padding: 0 0 0 1.8em; +} + +div.sphinxsidebar ul.toc ul li { + padding: 0; +} + +div.admonition, div.warning { + font-size: 0.9em; + margin: 1em 0 0 0; + border: 1px solid #86989B; + background-color: #f7f7f7; +} + +div.admonition p, div.warning p { + margin: 0.5em 1em 0.5em 1em; + padding: 0; +} + +div.admonition pre, div.warning pre { + margin: 0.4em 1em 0.4em 1em; +} + +div.admonition p.admonition-title, +div.warning p.admonition-title { + margin: 0; + padding: 0.1em 0 0.1em 0.5em; + color: white; + border-bottom: 1px solid #86989B; + font-weight: bold; + background-color: #AFC1C4; +} + +div.warning { + border: 1px solid #940000; +} + +div.warning p.admonition-title { + background-color: #CF0000; + border-bottom-color: #940000; +} + +div.admonition ul, div.admonition ol, +div.warning ul, div.warning ol { + margin: 0.1em 0.5em 0.5em 3em; + padding: 0; +} + +div.versioninfo { + margin: 1em 0 0 0; + border: 1px solid #ccc; + background-color: #DDEAF0; + padding: 8px; + line-height: 1.3em; + font-size: 0.9em; +} + + +a.headerlink { + color: #c60f0f!important; + font-size: 1em; + margin-left: 6px; + padding: 0 4px 0 4px; + text-decoration: none!important; + visibility: hidden; +} + +h1:hover > a.headerlink, +h2:hover > a.headerlink, +h3:hover > a.headerlink, +h4:hover > a.headerlink, +h5:hover > a.headerlink, +h6:hover > a.headerlink, +dt:hover > a.headerlink { + visibility: visible; +} + +a.headerlink:hover { + background-color: #ccc; + color: white!important; +} + +table.indextable td { + text-align: left; + vertical-align: top; +} + +table.indextable dl, table.indextable dd { + margin-top: 0; + margin-bottom: 0; +} + +table.indextable tr.pcap { + height: 10px; +} + +table.indextable tr.cap { + margin-top: 10px; + background-color: #f2f2f2; +} + +img.toggler { + margin-right: 3px; + margin-top: 3px; + cursor: pointer; +} + +form.pfform { + margin: 10px 0 20px 0; +} + +table.contentstable { + width: 90%; +} + +table.contentstable p.biglink { + line-height: 150%; +} + +a.biglink { + font-size: 1.3em; +} + +span.linkdescr { + font-style: italic; + padding-top: 5px; + font-size: 90%; +} + +ul.search { + margin: 10px 0 0 20px; + padding: 0; +} + +ul.search li { + padding: 5px 0 5px 20px; + background-image: url(file.png); + background-repeat: no-repeat; + background-position: 0 7px; +} + +ul.search li a { + font-weight: bold; +} + +ul.search li div.context { + color: #888; + margin: 2px 0 0 30px; + text-align: left; +} + +ul.keywordmatches li.goodmatch a { + font-weight: bold; +} + +img.math { + vertical-align: center; +} + +div.math { + text-align: center; +} + +span.eqno { + float: right; +} + +img.logo { + border: 0; +} diff --git a/docs/_build/html/_static/stickysidebar.css b/docs/_build/html/_static/stickysidebar.css new file mode 100644 index 00000000..dfc99c77 --- /dev/null +++ b/docs/_build/html/_static/stickysidebar.css @@ -0,0 +1,19 @@ +/** + * Sphinx Doc Design -- Sticky sidebar Overrides + */ + +div.sphinxsidebar { + top: 30px; + left: 0px; + position: fixed; + margin: 0; + float: none; +} + +div.related { + position: fixed; +} + +div.documentwrapper { + margin-top: 30px; +} diff --git a/docs/_build/html/_static/traditional.css b/docs/_build/html/_static/traditional.css new file mode 100644 index 00000000..8c224c07 --- /dev/null +++ b/docs/_build/html/_static/traditional.css @@ -0,0 +1,700 @@ +/** + * Sphinx Doc Design -- traditional python.org style + */ + +body { + color: #000; + margin: 0; + padding: 0; +} + +/* :::: LAYOUT :::: */ + +div.documentwrapper { + float: left; + width: 100%; +} + +div.bodywrapper { + margin: 0 230px 0 0; +} + +div.body { + background-color: white; + padding: 0 20px 30px 20px; +} + +div.sphinxsidebarwrapper { + border: 1px solid #99ccff; + padding: 10px; + margin: 10px 15px 10px 0; +} + +div.sphinxsidebar { + float: right; + margin-left: -100%; + width: 230px; +} + +div.clearer { + clear: both; +} + +div.footer { + clear: both; + width: 100%; + background-color: #99ccff; + padding: 9px 0 9px 0; + text-align: center; +} + +div.related { + background-color: #99ccff; + color: #333; + width: 100%; + height: 30px; + line-height: 30px; + border-bottom: 5px solid white; +} + +div.related h3 { + display: none; +} + +div.related ul { + margin: 0; + padding: 0 0 0 10px; + list-style: none; +} + +div.related li { + display: inline; + font-weight: bold; +} + +div.related li.right { + float: right; + margin-right: 5px; +} + +/* ::: SIDEBAR :::: */ +div.sphinxsidebar h3 { + margin: 0; +} + +div.sphinxsidebar h4 { + margin: 5px 0 0 0; +} + +div.sphinxsidebar p.topless { + margin: 5px 10px 10px 10px; +} + +div.sphinxsidebar ul { + margin: 10px; + margin-left: 15px; + padding: 0; +} + +div.sphinxsidebar ul ul { + margin-top: 0; + margin-bottom: 0; +} + +div.sphinxsidebar form { + margin-top: 10px; +} + + +/* :::: SEARCH :::: */ +ul.search { + margin: 10px 0 0 20px; + padding: 0; +} + +ul.search li { + padding: 5px 0 5px 20px; + background-image: url(file.png); + background-repeat: no-repeat; + background-position: 0 7px; +} + +ul.search li a { + font-weight: bold; +} + +ul.search li div.context { + color: #888; + margin: 2px 0 0 30px; + text-align: left; +} + +ul.keywordmatches li.goodmatch a { + font-weight: bold; +} + +/* :::: COMMON FORM STYLES :::: */ + +div.actions { + border-top: 1px solid #aaa; + background-color: #ddd; + margin: 10px 0 0 -20px; + padding: 5px 0 5px 20px; +} + +form dl { + color: #333; +} + +form dt { + clear: both; + float: left; + min-width: 110px; + margin-right: 10px; + padding-top: 2px; +} + +input#homepage { + display: none; +} + +div.error { + margin: 5px 20px 0 0; + padding: 5px; + border: 1px solid #d00; + /*border: 2px solid #05171e; + background-color: #092835; + color: white;*/ + font-weight: bold; +} + +/* :::: INLINE COMMENTS :::: */ + +div.inlinecommentswrapper { + float: right; + max-width: 40%; +} + +div.commentmarker { + float: right; + background-image: url(style/comment.png); + background-repeat: no-repeat; + width: 25px; + height: 25px; + text-align: center; + padding-top: 3px; +} + +div.nocommentmarker { + float: right; + background-image: url(style/nocomment.png); + background-repeat: no-repeat; + width: 25px; + height: 25px; +} + +div.inlinecomments { + margin-left: 10px; + margin-bottom: 5px; + background-color: #eee; + border: 1px solid #ccc; + padding: 5px; +} + +div.inlinecomment { + border-top: 1px solid #ccc; + padding-top: 5px; + margin-top: 5px; +} + +.inlinecomments p { + margin: 5px 0 5px 0; +} + +.inlinecomments .head { + font-weight: bold; +} + +.inlinecomments .meta { + font-style: italic; +} + + +/* :::: COMMENTS :::: */ + +div#comments h3 { + border-top: 1px solid #aaa; + padding: 5px 20px 5px 20px; + margin: 20px -20px 20px -20px; + background-color: #ddd; +} + +/* +div#comments { + background-color: #ccc; + margin: 40px -20px -30px -20px; + padding: 0 0 1px 0; +} + +div#comments h4 { + margin: 30px 0 20px 0; + background-color: #aaa; + border-bottom: 1px solid #09232e; + color: #333; +} + +div#comments form { + display: block; + margin: 0 0 0 20px; +} + +div#comments textarea { + width: 98%; + height: 160px; +} + +div#comments div.help { + margin: 20px 20px 10px 0; + background-color: #ccc; + color: #333; +} + +div#comments div.help p { + margin: 0; + padding: 0 0 10px 0; +} + +div#comments input, div#comments textarea { + font-family: 'Bitstream Vera Sans', 'Arial', sans-serif; + font-size: 13px; + color: black; + background-color: #aaa; + border: 1px solid #092835; +} + +div#comments input[type="reset"], +div#comments input[type="submit"] { + cursor: pointer; + font-weight: bold; + padding: 2px; + margin: 5px 5px 5px 0; + background-color: #666; + color: white; +} + +div#comments div.comment { + margin: 10px 10px 10px 20px; + padding: 10px; + border: 1px solid #0f3646; + background-color: #aaa; + color: #333; +} + +div#comments div.comment p { + margin: 5px 0 5px 0; +} + +div#comments div.comment p.meta { + font-style: italic; + color: #444; + text-align: right; + margin: -5px 0 -5px 0; +} + +div#comments div.comment h4 { + margin: -10px -10px 5px -10px; + padding: 3px; + font-size: 15px; + background-color: #888; + color: white; + border: 0; +} + +div#comments div.comment pre, +div#comments div.comment tt { + background-color: #ddd; + color: #111; + border: none; +} + +div#comments div.comment a { + color: #fff; + text-decoration: underline; +} + +div#comments div.comment blockquote { + margin: 10px; + padding: 10px; + border-left: 1px solid #0f3646; + /*border: 1px solid #0f3646; + background-color: #071c25;*/ +} + +div#comments em.important { + color: #d00; + font-weight: bold; + font-style: normal; +}*/ + +/* :::: SUGGEST CHANGES :::: */ +div#suggest-changes-box input, div#suggest-changes-box textarea { + border: 1px solid #ccc; + background-color: white; + color: black; +} + +div#suggest-changes-box textarea { + width: 99%; + height: 400px; +} + + +/* :::: PREVIEW :::: */ +div.preview { + background-image: url(style/preview.png); + padding: 0 20px 20px 20px; + margin-bottom: 30px; +} + + +/* :::: INDEX PAGE :::: */ + +table.contentstable { + width: 90%; +} + +table.contentstable p.biglink { + line-height: 150%; +} + +a.biglink { + font-size: 1.5em; +} + +span.linkdescr { + font-style: italic; + padding-top: 5px; +} + +/* :::: GENINDEX STYLES :::: */ + +table.indextable td { + text-align: left; + vertical-align: top; +} + +table.indextable dl, table.indextable dd { + margin-top: 0; + margin-bottom: 0; +} + +table.indextable tr.pcap { + height: 10px; +} + +table.indextable tr.cap { + margin-top: 10px; + background-color: #f2f2f2; +} + +img.toggler { + margin-right: 3px; + margin-top: 3px; + cursor: pointer; +} + +/* :::: GLOBAL STYLES :::: */ + +p.subhead { + font-weight: bold; + margin-top: 20px; +} + +a:link:active { color: #ff0000; } +a:link:hover { background-color: #bbeeff; } +a:visited:hover { background-color: #bbeeff; } +a:visited { color: #551a8b; } +a:link { color: #0000bb; } + +div.body h1, +div.body h2, +div.body h3, +div.body h4, +div.body h5, +div.body h6 { + font-family: avantgarde, sans-serif; + font-weight: bold; +} + +div.body h1 { font-size: 180%; } +div.body h2 { font-size: 150%; } +div.body h3 { font-size: 120%; } +div.body h4 { font-size: 120%; } + +a.headerlink, +a.headerlink, +a.headerlink, +a.headerlink, +a.headerlink, +a.headerlink { + color: #c60f0f; + font-size: 0.8em; + padding: 0 4px 0 4px; + text-decoration: none; + visibility: hidden; +} + +*:hover > a.headerlink, +*:hover > a.headerlink, +*:hover > a.headerlink, +*:hover > a.headerlink, +*:hover > a.headerlink, +*:hover > a.headerlink { + visibility: visible; +} + +a.headerlink:hover, +a.headerlink:hover, +a.headerlink:hover, +a.headerlink:hover, +a.headerlink:hover, +a.headerlink:hover { + background-color: #c60f0f; + color: white; +} + +div.body p, div.body dd, div.body li { + text-align: justify; +} + +div.body td { + text-align: left; +} + +ul.fakelist { + list-style: none; + margin: 10px 0 10px 20px; + padding: 0; +} + +/* "Footnotes" heading */ +p.rubric { + margin-top: 30px; + font-weight: bold; +} + +/* "Topics" */ + +div.topic { + background-color: #eee; + border: 1px solid #ccc; + padding: 0 7px 0 7px; + margin: 10px 0 10px 0; +} + +p.topic-title { + font-size: 1.1em; + font-weight: bold; + margin-top: 10px; +} + +/* Admonitions */ + +div.admonition { + margin-top: 10px; + margin-bottom: 10px; + padding: 7px; +} + +div.admonition dt { + font-weight: bold; +} + +div.admonition dd { + margin-bottom: 10px; +} + +div.admonition dl { + margin-bottom: 0; +} + +div.admonition p { + display: inline; +} + +div.seealso { + background-color: #ffc; + border: 1px solid #ff6; +} + +div.warning { + background-color: #ffe4e4; + border: 1px solid #f66; +} + +div.note { + background-color: #eee; + border: 1px solid #ccc; +} + +p.admonition-title { + margin: 0px 10px 5px 0px; + font-weight: bold; + display: inline; +} + +p.admonition-title:after { + content: ":"; +} + +div.body p.centered { + text-align: center; + margin-top: 25px; +} + +table.docutils { + border: 0; +} + +table.docutils td, table.docutils th { + padding: 0 8px 2px 0; + border-top: 0; + border-left: 0; + border-right: 0; + border-bottom: 1px solid #aaa; +} + +table.field-list td, table.field-list th { + border: 0 !important; +} + +table.footnote td, table.footnote th { + border: 0 !important; +} + +dl { + margin-bottom: 15px; + clear: both; +} + +dd p { + margin-top: 0px; +} + +dd ul, dd table { + margin-bottom: 10px; +} + +dd { + margin-top: 3px; + margin-bottom: 10px; + margin-left: 30px; +} + +dl.glossary dt { + font-weight: bold; + font-size: 1.1em; +} + +.refcount { + color: #060; +} + +th { + text-align: left; + padding-right: 5px; +} + +pre { + font-family: monospace; + padding: 5px; + color: #00008b; + border-left: none; + border-right: none; +} + +tt { + font-family: monospace; + background-color: #ecf0f3; + padding: 0 1px 0 1px; +} + +tt.descname { + background-color: transparent; + font-weight: bold; + font-size: 1.2em; +} + +tt.descclassname { + background-color: transparent; +} + +tt.xref, a tt { + background-color: transparent; + font-weight: bold; +} + +.footnote:target { background-color: #ffa } + +h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt { + background-color: transparent; +} + +.optional { + font-size: 1.3em; +} + +.versionmodified { + font-style: italic; +} + +form.comment { + margin: 0; + padding: 10px 30px 10px 30px; + background-color: #eee; +} + +form.comment h3 { + background-color: #326591; + color: white; + margin: -10px -30px 10px -30px; + padding: 5px; + font-size: 1.4em; +} + +form.comment input, +form.comment textarea { + border: 1px solid #ccc; + padding: 2px; + font-family: sans-serif; + font-size: 13px; +} + +form.comment input[type="text"] { + width: 240px; +} + +form.comment textarea { + width: 100%; + height: 200px; + margin-bottom: 10px; +} + +/* :::: PRINT :::: */ +@media print { + div.documentwrapper { + width: 100%; + } + + div.body { + margin: 0; + } + + div.sphinxsidebar, + div.related, + div.footer, + div#comments div.new-comment-box, + #top-link { + display: none; + } +} diff --git a/docs/_build/html/addons.html b/docs/_build/html/addons.html new file mode 100644 index 00000000..e16855c2 --- /dev/null +++ b/docs/_build/html/addons.html @@ -0,0 +1,474 @@ +<!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>Additions — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="_static/default.css" type="text/css" /> + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="_static/jquery.js"></script> + <script type="text/javascript" src="_static/doctools.js"></script> + <link rel="index" title="Index" href="genindex.html" /> + <link rel="search" title="Search" href="search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="index.html" /> + <link rel="next" title="Modules" href="modules/index.html" /> + <link rel="prev" title="Assorted examples" href="assorted_examples.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="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="modules/index.html" title="Modules" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="assorted_examples.html" title="Assorted examples" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="additions"> +<h1>Additions<a class="headerlink" href="#additions" title="Permalink to this headline">¶</a></h1> +<div class="section" id="trixserializer"> +<h2>TriXSerializer<a class="headerlink" href="#trixserializer" title="Permalink to this headline">¶</a></h2> +<p>John L. Clark jlc6 at po.cwru.edu</p> +<p>Tue Aug 7 01:55:07 EDT 2007</p> +<div class="admonition note"> +<p class="first admonition-title">Note</p> +<p>Devs,</p> +<p>I’ve taken a first pass at implementing a simple TriX serializer. I +should have attached the new file (which goes in +<cite>.../rdflib/syntax/serializers/TriXSerializer.py</cite>) to this email, +along with a crazy little test script. The test script exercises +round tripping, but it turned out parsing was broken, so I fixed it; +the patch for that (and adding the new serializer to the plugin list) +should be attached as well. Finally, does anyone mind if I clean up +the TriX parser a bit?</p> +<p>Take care,</p> +<blockquote class="last"> +John L. Clark</blockquote> +</div> +<div class="section" id="trixserializer-py"> +<h3>TriXSerializer.py<a class="headerlink" href="#trixserializer-py" title="Permalink to this headline">¶</a></h3> +<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">rdflib.syntax.serializers</span> <span class="kn">import</span> <span class="n">Serializer</span> + +<span class="kn">from</span> <span class="nn">rdflib.URIRef</span> <span class="kn">import</span> <span class="n">URIRef</span> +<span class="kn">from</span> <span class="nn">rdflib.Literal</span> <span class="kn">import</span> <span class="n">Literal</span> +<span class="kn">from</span> <span class="nn">rdflib.BNode</span> <span class="kn">import</span> <span class="n">BNode</span> + +<span class="kn">from</span> <span class="nn">rdflib.Graph</span> <span class="kn">import</span> <span class="n">Graph</span><span class="p">,</span> <span class="n">ConjunctiveGraph</span> + +<span class="kn">from</span> <span class="nn">Ft.Xml</span> <span class="kn">import</span> <span class="n">MarkupWriter</span><span class="p">,</span> <span class="n">XML_NAMESPACE</span> + +<span class="n">TRIX_NS</span> <span class="o">=</span> <span class="s">u"http://www.w3.org/2004/03/trix/trix-1/"</span> + +<span class="k">class</span> <span class="nc">TriXSerializer</span><span class="p">(</span><span class="n">Serializer</span><span class="p">):</span> + <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">store</span><span class="p">):</span> + <span class="nb">super</span><span class="p">(</span><span class="n">TriXSerializer</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">store</span><span class="p">)</span> + + <span class="k">def</span> <span class="nf">serialize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">stream</span><span class="p">,</span> <span class="n">base</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">args</span><span class="p">):</span> + <span class="bp">self</span><span class="o">.</span><span class="n">writer</span> <span class="o">=</span> <span class="n">MarkupWriter</span><span class="p">(</span><span class="n">stream</span><span class="o">=</span><span class="n">stream</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="n">encoding</span><span class="p">,</span> + <span class="n">indent</span><span class="o">=</span><span class="s">"yes"</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">startDocument</span><span class="p">()</span> + <span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">startElement</span><span class="p">(</span><span class="s">u"TriX"</span><span class="p">,</span> <span class="n">TRIX_NS</span><span class="p">)</span> + + <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="p">,</span> <span class="n">ConjunctiveGraph</span><span class="p">):</span> + <span class="k">for</span> <span class="n">subgraph</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">contexts</span><span class="p">():</span> + <span class="bp">self</span><span class="o">.</span><span class="n">_writeGraph</span><span class="p">(</span><span class="n">subgraph</span><span class="p">)</span> + <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="p">,</span> <span class="n">Graph</span><span class="p">):</span> + <span class="bp">self</span><span class="o">.</span><span class="n">_writeGraph</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">store</span><span class="p">)</span> + <span class="k">else</span><span class="p">:</span> + <span class="k">pass</span> + + <span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">endElement</span><span class="p">(</span><span class="s">u"TriX"</span><span class="p">,</span> <span class="n">TRIX_NS</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">endDocument</span><span class="p">()</span> + + <span class="k">def</span> <span class="nf">_writeGraph</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">graph</span><span class="p">):</span> + <span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">startElement</span><span class="p">(</span><span class="s">u"graph"</span><span class="p">,</span> <span class="n">TRIX_NS</span><span class="p">)</span> + <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">graph</span><span class="o">.</span><span class="n">identifier</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">):</span> + <span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">simpleElement</span><span class="p">(</span><span class="s">u"uri"</span><span class="p">,</span> <span class="n">TRIX_NS</span><span class="p">,</span> + <span class="n">content</span><span class="o">=</span><span class="nb">unicode</span><span class="p">(</span><span class="n">graph</span><span class="o">.</span><span class="n">identifier</span><span class="p">))</span> + + <span class="k">for</span> <span class="n">triple</span> <span class="ow">in</span> <span class="n">graph</span><span class="o">.</span><span class="n">triples</span><span class="p">((</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">)):</span> + <span class="bp">self</span><span class="o">.</span><span class="n">_writeTriple</span><span class="p">(</span><span class="n">triple</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">endElement</span><span class="p">(</span><span class="s">u"graph"</span><span class="p">,</span> <span class="n">TRIX_NS</span><span class="p">)</span> + + <span class="k">def</span> <span class="nf">_writeTriple</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">triple</span><span class="p">):</span> + <span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">startElement</span><span class="p">(</span><span class="s">u"triple"</span><span class="p">,</span> <span class="n">TRIX_NS</span><span class="p">)</span> + <span class="k">for</span> <span class="n">component</span> <span class="ow">in</span> <span class="n">triple</span><span class="p">:</span> + <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">component</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">):</span> + <span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">simpleElement</span><span class="p">(</span><span class="s">u"uri"</span><span class="p">,</span> <span class="n">TRIX_NS</span><span class="p">,</span> + <span class="n">content</span><span class="o">=</span><span class="nb">unicode</span><span class="p">(</span><span class="n">component</span><span class="p">))</span> + <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">component</span><span class="p">,</span> <span class="n">BNode</span><span class="p">):</span> + <span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">simpleElement</span><span class="p">(</span><span class="s">u"id"</span><span class="p">,</span> <span class="n">TRIX_NS</span><span class="p">,</span> + <span class="n">content</span><span class="o">=</span><span class="nb">unicode</span><span class="p">(</span><span class="n">component</span><span class="p">))</span> + <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">component</span><span class="p">,</span> <span class="n">Literal</span><span class="p">):</span> + <span class="k">if</span> <span class="n">component</span><span class="o">.</span><span class="n">datatype</span><span class="p">:</span> + <span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">simpleElement</span><span class="p">(</span><span class="s">u"typedLiteral"</span><span class="p">,</span> <span class="n">TRIX_NS</span><span class="p">,</span> + <span class="n">content</span><span class="o">=</span><span class="nb">unicode</span><span class="p">(</span><span class="n">component</span><span class="p">),</span> + <span class="n">attributes</span><span class="o">=</span><span class="p">{</span><span class="s">u"datatype"</span><span class="p">:</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">component</span><span class="o">.</span><span class="n">datatype</span><span class="p">)})</span> + <span class="k">elif</span> <span class="n">component</span><span class="o">.</span><span class="n">language</span><span class="p">:</span> + <span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">simpleElement</span><span class="p">(</span><span class="s">u"plainLiteral"</span><span class="p">,</span> <span class="n">TRIX_NS</span><span class="p">,</span> + <span class="n">content</span><span class="o">=</span><span class="nb">unicode</span><span class="p">(</span><span class="n">component</span><span class="p">),</span> + <span class="n">attributes</span><span class="o">=</span><span class="p">{</span> + <span class="p">(</span><span class="s">u"xml:lang"</span><span class="p">,</span> <span class="n">XML_NAMESPACE</span><span class="p">):</span> <span class="nb">unicode</span><span class="p">(</span><span class="n">component</span><span class="o">.</span><span class="n">language</span><span class="p">)})</span> + <span class="k">else</span><span class="p">:</span> + <span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">simpleElement</span><span class="p">(</span><span class="s">u"plainLiteral"</span><span class="p">,</span> <span class="n">TRIX_NS</span><span class="p">,</span> + <span class="n">content</span><span class="o">=</span><span class="nb">unicode</span><span class="p">(</span><span class="n">component</span><span class="p">))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">writer</span><span class="o">.</span><span class="n">endElement</span><span class="p">(</span><span class="s">u"triple"</span><span class="p">,</span> <span class="n">TRIX_NS</span><span class="p">)</span> +</pre></div> +</div> +</div> +<div class="section" id="trixserializer-diff"> +<h3>trixserializer.diff<a class="headerlink" href="#trixserializer-diff" title="Permalink to this headline">¶</a></h3> +<div class="highlight-text"><div class="highlight"><pre>Index: rdflib/plugin.py +=================================================================== +--- rdflib/plugin.py (revision 1239) ++++ rdflib/plugin.py (working copy) +@@ -49,6 +49,9 @@ + register('pretty-xml', serializers.Serializer, + 'rdflib.syntax.serializers.PrettyXMLSerializer', 'PrettyXMLSerializer') + ++register('TriX', serializers.Serializer, ++ 'rdflib.syntax.serializers.TriXSerializer', 'TriXSerializer') ++ + register('nt', serializers.Serializer, + 'rdflib.syntax.serializers.NTSerializer', 'NTSerializer') + +Index: rdflib/syntax/parsers/TriXHandler.py +=================================================================== +--- rdflib/syntax/parsers/TriXHandler.py (revision 1239) ++++ rdflib/syntax/parsers/TriXHandler.py (working copy) +@@ -33,6 +33,7 @@ + """ + from rdflib import RDF, RDFS, Namespace + from rdflib import URIRef, BNode, Literal ++from rdflib.Namespace import Namespace + from rdflib.Graph import Graph + from rdflib.exceptions import ParserError, Error + from rdflib.syntax.xml_names import is_ncname +@@ -42,7 +43,7 @@ + + RDFNS = RDF.RDFNS + +-TRIXNS=Namespace.Namespace("http://www.w3.org/2004/03/trix/trix-1/") ++TRIXNS=u"http://www.w3.org/2004/03/trix/trix-1/" + + + class TriXHandler(handler.ContentHandler): +@@ -200,6 +201,7 @@ + self.error("This should never happen if the SAX parser ensures XML syntax correctness") + + if name[1]=="graph": ++ self.graph = Graph(store = self.store.store) + self.state=1 + + if name[1]=="TriX": +</pre></div> +</div> +</div> +<div class="section" id="test-trixserializer-py"> +<h3>test_trixserializer.py<a class="headerlink" href="#test-trixserializer-py" title="Permalink to this headline">¶</a></h3> +<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">rdflib.Graph</span> <span class="kn">import</span> <span class="n">ConjunctiveGraph</span> +<span class="kn">from</span> <span class="nn">rdflib</span> <span class="kn">import</span> <span class="n">URIRef</span><span class="p">,</span> <span class="n">Literal</span> +<span class="kn">from</span> <span class="nn">rdflib.Graph</span> <span class="kn">import</span> <span class="n">Graph</span> + +<span class="n">s1</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'store:1'</span><span class="p">)</span> +<span class="n">r1</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'resource:1'</span><span class="p">)</span> +<span class="n">r2</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'resource:2'</span><span class="p">)</span> + +<span class="n">label</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'predicate:label'</span><span class="p">)</span> + +<span class="n">g1</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">identifier</span> <span class="o">=</span> <span class="n">s1</span><span class="p">)</span> +<span class="n">g1</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">r1</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">Literal</span><span class="p">(</span><span class="s">"label 1"</span><span class="p">,</span> <span class="n">lang</span><span class="o">=</span><span class="s">"en"</span><span class="p">)))</span> +<span class="n">g1</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">r1</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">Literal</span><span class="p">(</span><span class="s">"label 2"</span><span class="p">)))</span> + +<span class="n">s2</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'store:2'</span><span class="p">)</span> +<span class="n">g2</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">identifier</span> <span class="o">=</span> <span class="n">s2</span><span class="p">)</span> +<span class="n">g2</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">r2</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">Literal</span><span class="p">(</span><span class="s">"label 3"</span><span class="p">)))</span> + +<span class="n">g</span> <span class="o">=</span> <span class="n">ConjunctiveGraph</span><span class="p">()</span> + +<span class="k">for</span> <span class="n">s</span><span class="p">,</span><span class="n">p</span><span class="p">,</span><span class="n">o</span> <span class="ow">in</span> <span class="n">g1</span><span class="o">.</span><span class="n">triples</span><span class="p">((</span><span class="bp">None</span><span class="p">,</span> <span class="bp">None</span><span class="p">,</span> <span class="bp">None</span><span class="p">)):</span> + <span class="n">g</span><span class="o">.</span><span class="n">addN</span><span class="p">([(</span><span class="n">s</span><span class="p">,</span><span class="n">p</span><span class="p">,</span><span class="n">o</span><span class="p">,</span><span class="n">g1</span><span class="p">)])</span> + +<span class="k">for</span> <span class="n">s</span><span class="p">,</span><span class="n">p</span><span class="p">,</span><span class="n">o</span> <span class="ow">in</span> <span class="n">g2</span><span class="o">.</span><span class="n">triples</span><span class="p">((</span><span class="bp">None</span><span class="p">,</span> <span class="bp">None</span><span class="p">,</span> <span class="bp">None</span><span class="p">)):</span> + <span class="n">g</span><span class="o">.</span><span class="n">addN</span><span class="p">([(</span><span class="n">s</span><span class="p">,</span><span class="n">p</span><span class="p">,</span><span class="n">o</span><span class="p">,</span><span class="n">g2</span><span class="p">)])</span> + +<span class="n">r3</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'resource:3'</span><span class="p">)</span> + +<span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">r3</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">Literal</span><span class="p">(</span><span class="mf">4</span><span class="p">)))</span> +<span class="c">#g.addN([(r1, label, Literal("label 1"), s1),</span> +<span class="c"># (r1, label, Literal("label 2"), s1),</span> +<span class="c"># (r2, label, Literal("label 3"), s2)])</span> + +<span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">contexts</span><span class="p">():</span> + <span class="k">pass</span> + <span class="c">#s = Graph(g.store, identifier=c)</span> + <span class="c">#print c, c.identifier.__class__, c.identifier, len(c)</span> + +<span class="n">r</span> <span class="o">=</span> <span class="n">g</span><span class="o">.</span><span class="n">serialize</span><span class="p">(</span><span class="n">format</span><span class="o">=</span><span class="s">'TriX'</span><span class="p">)</span> +<span class="k">print</span> <span class="n">r</span> + +<span class="n">g3</span> <span class="o">=</span> <span class="n">ConjunctiveGraph</span><span class="p">()</span> +<span class="kn">from</span> <span class="nn">rdflib.StringInputSource</span> <span class="kn">import</span> <span class="n">StringInputSource</span> +<span class="n">g3</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">StringInputSource</span><span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="bp">None</span><span class="p">),</span> <span class="n">format</span><span class="o">=</span><span class="s">'trix'</span><span class="p">)</span> +<span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">g3</span><span class="o">.</span><span class="n">contexts</span><span class="p">():</span> + <span class="k">print</span> <span class="n">c</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">identifier</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">identifier</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> +</pre></div> +</div> +</div> +<div class="section" id="test-output"> +<h3>test output<a class="headerlink" href="#test-output" title="Permalink to this headline">¶</a></h3> +<div class="highlight-xml"><div class="highlight"><pre><span class="cp"><?xml version="1.0" encoding="UTF-8"?></span> +<span class="nt"><TriX</span> <span class="na">xmlns=</span><span class="s">"http://www.w3.org/2004/03/trix/trix-1/"</span><span class="nt">></span> + <span class="nt"><graph></span> + <span class="nt"><uri></span>store:2<span class="nt"></uri></span> + <span class="nt"><triple></span> + <span class="nt"><uri></span>resource:2<span class="nt"></uri></span> + <span class="nt"><uri></span>predicate:label<span class="nt"></uri></span> + <span class="nt"><plainLiteral></span>label 3<span class="nt"></plainLiteral></span> + <span class="nt"></triple></span> + <span class="nt"></graph></span> + <span class="nt"><graph></span> + <span class="nt"><uri></span>store:1<span class="nt"></uri></span> + <span class="nt"><triple></span> + <span class="nt"><uri></span>resource:1<span class="nt"></uri></span> + <span class="nt"><uri></span>predicate:label<span class="nt"></uri></span> + <span class="nt"><plainLiteral></span>label 2<span class="nt"></plainLiteral></span> + <span class="nt"></triple></span> + <span class="nt"><triple></span> + <span class="nt"><uri></span>resource:1<span class="nt"></uri></span> + <span class="nt"><uri></span>predicate:label<span class="nt"></uri></span> + <span class="nt"><plainLiteral</span> <span class="na">xml:lang=</span><span class="s">"en"</span><span class="nt">></span>label 1<span class="nt"></plainLiteral></span> + <span class="nt"></triple></span> + <span class="nt"></graph></span> + <span class="nt"><graph></span> + <span class="nt"><triple></span> + <span class="nt"><uri></span>resource:3<span class="nt"></uri></span> + <span class="nt"><uri></span>predicate:label<span class="nt"></uri></span> + <span class="nt"><typedLiteral</span> <span class="na">datatype=</span><span class="s">"http://www.w3.org/2001/XMLSchema#integer"</span><span class="nt">></span>4<span class="nt"></typedLiteral></span> + <span class="nt"></triple></span> + <span class="nt"></graph></span> +<span class="nt"></TriX></span> +</pre></div> +</div> +<div class="highlight-n3"><pre>[a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']]. +<class 'rdflib.BNode.BNode'> QeDIviuA11 1 +<store:2> a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']. +<class 'rdflib.URIRef.URIRef'> store:2 1 +<store:1> a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']. +<class 'rdflib.URIRef.URIRef'> store:1 2</pre> +</div> +</div> +</div> +<div class="section" id="sparql-xml-serializer"> +<h2>SPARQL-XML Serializer<a class="headerlink" href="#sparql-xml-serializer" title="Permalink to this headline">¶</a></h2> +<div class="highlight-python"><div class="highlight"><pre><span class="c"># -*- coding: iso-8859-15 -*-</span> +<span class="c"># (c) Mikael Högqvist, ZIB, AstroGrid-D</span> +<span class="c"># This software is licensed under the software license specified at</span> +<span class="c"># http://www.gac-grid.org/</span> + +<span class="c"># this is a work-around of the SPARQL XML-serialization in rdflib which does</span> +<span class="c"># not work on all installation due to a bug in the python sax-parser</span> +<span class="c"># We rely on ElementTree which is only available in Python 2.5</span> + +<span class="kn">from</span> <span class="nn">cStringIO</span> <span class="kn">import</span> <span class="n">StringIO</span> + +<span class="k">try</span><span class="p">:</span> + <span class="kn">from</span> <span class="nn">xml.etree.cElementTree</span> <span class="kn">import</span> <span class="n">Element</span><span class="p">,</span> <span class="n">SubElement</span><span class="p">,</span> <span class="n">ElementTree</span><span class="p">,</span> <span class="n">ProcessingInstruction</span> + <span class="kn">import</span> <span class="nn">xml.etree.cElementTree</span> <span class="kn">as</span> <span class="nn">ET</span> +<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span> + <span class="kn">from</span> <span class="nn">cElementTree</span> <span class="kn">import</span> <span class="n">Element</span><span class="p">,</span> <span class="n">SubElement</span><span class="p">,</span> <span class="n">ElementTree</span> + <span class="kn">import</span> <span class="nn">cElementTree</span> <span class="kn">as</span> <span class="nn">ET</span> + +<span class="kn">from</span> <span class="nn">rdflib</span> <span class="kn">import</span> <span class="n">URIRef</span><span class="p">,</span> <span class="n">BNode</span><span class="p">,</span> <span class="n">Literal</span> + +<span class="n">SPARQL_XML_NAMESPACE</span> <span class="o">=</span> <span class="s">u'http://www.w3.org/2005/sparql-results#'</span> +<span class="n">XML_NAMESPACE</span> <span class="o">=</span> <span class="s">"http://www.w3.org/2001/XMLSchema#"</span> + +<span class="n">name</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">elem</span><span class="p">:</span> <span class="s">u'{</span><span class="si">%s</span><span class="s">}</span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">SPARQL_XML_NAMESPACE</span><span class="p">,</span> <span class="n">elem</span><span class="p">)</span> +<span class="n">xml_name</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">elem</span><span class="p">:</span> <span class="s">u'{</span><span class="si">%s</span><span class="s">}</span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">XML_NAMESPACE</span><span class="p">,</span> <span class="n">elem</span><span class="p">)</span> + +<span class="k">def</span> <span class="nf">variables</span><span class="p">(</span><span class="n">results</span><span class="p">):</span> + <span class="c"># don't include any variables which are not part of the</span> + <span class="c"># result set</span> + <span class="c">#res_vars = set(results.selectionF).intersection(set(results.allVariables))</span> + + + <span class="c"># this means select *, use all variables from the result-set</span> + <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">results</span><span class="o">.</span><span class="n">selectionF</span><span class="p">)</span> <span class="o">==</span> <span class="mf">0</span><span class="p">:</span> + <span class="n">res_vars</span> <span class="o">=</span> <span class="n">results</span><span class="o">.</span><span class="n">allVariables</span> + <span class="k">else</span><span class="p">:</span> + <span class="n">res_vars</span> <span class="o">=</span> <span class="p">[</span><span class="n">v</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">results</span><span class="o">.</span><span class="n">selectionF</span> <span class="k">if</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">results</span><span class="o">.</span><span class="n">allVariables</span><span class="p">]</span> + + <span class="k">return</span> <span class="n">res_vars</span> + +<span class="k">def</span> <span class="nf">header</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">root</span><span class="p">):</span> + <span class="n">head</span> <span class="o">=</span> <span class="n">SubElement</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">(</span><span class="s">u'head'</span><span class="p">))</span> + + <span class="n">res_vars</span> <span class="o">=</span> <span class="n">variables</span><span class="p">(</span><span class="n">results</span><span class="p">)</span> + <span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="n">res_vars</span><span class="p">:</span> + <span class="n">v</span> <span class="o">=</span> <span class="n">SubElement</span><span class="p">(</span><span class="n">head</span><span class="p">,</span> <span class="n">name</span><span class="p">(</span><span class="s">u'variable'</span><span class="p">))</span> + <span class="c"># remove the ?</span> + <span class="n">v</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s">u'name'</span><span class="p">]</span> <span class="o">=</span> <span class="n">var</span><span class="p">[</span><span class="mf">1</span><span class="p">:]</span> + + +<span class="k">def</span> <span class="nf">binding</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="n">var</span><span class="p">,</span> <span class="n">elem</span><span class="p">):</span> + <span class="n">bindingElem</span> <span class="o">=</span> <span class="n">SubElement</span><span class="p">(</span><span class="n">elem</span><span class="p">,</span> <span class="n">name</span><span class="p">(</span><span class="s">u'binding'</span><span class="p">))</span> + <span class="n">bindingElem</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="s">u'name'</span><span class="p">]</span> <span class="o">=</span> <span class="n">var</span> + + <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span><span class="n">URIRef</span><span class="p">):</span> + <span class="n">varElem</span> <span class="o">=</span> <span class="n">SubElement</span><span class="p">(</span><span class="n">bindingElem</span><span class="p">,</span> <span class="n">name</span><span class="p">(</span><span class="s">u'uri'</span><span class="p">))</span> + <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span><span class="n">BNode</span><span class="p">)</span> <span class="p">:</span> + <span class="n">varElem</span> <span class="o">=</span> <span class="n">SubElement</span><span class="p">(</span><span class="n">bindingElem</span><span class="p">,</span> <span class="n">name</span><span class="p">(</span><span class="s">u'bnode'</span><span class="p">))</span> + <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">val</span><span class="p">,</span><span class="n">Literal</span><span class="p">):</span> + <span class="n">varElem</span> <span class="o">=</span> <span class="n">SubElement</span><span class="p">(</span><span class="n">bindingElem</span><span class="p">,</span> <span class="n">name</span><span class="p">(</span><span class="s">u'literal'</span><span class="p">))</span> + + <span class="k">if</span> <span class="n">val</span><span class="o">.</span><span class="n">language</span> <span class="o">!=</span> <span class="s">""</span> <span class="ow">and</span> <span class="n">val</span><span class="o">.</span><span class="n">language</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span> + <span class="n">varElem</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="n">xml_name</span><span class="p">(</span><span class="s">u'lang'</span><span class="p">)]</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">val</span><span class="o">.</span><span class="n">language</span><span class="p">)</span> + <span class="k">elif</span> <span class="n">val</span><span class="o">.</span><span class="n">datatype</span> <span class="o">!=</span> <span class="s">""</span> <span class="ow">and</span> <span class="n">val</span><span class="o">.</span><span class="n">datatype</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span> + <span class="n">varElem</span><span class="o">.</span><span class="n">attrib</span><span class="p">[</span><span class="n">name</span><span class="p">(</span><span class="s">u'datatype'</span><span class="p">)]</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">val</span><span class="o">.</span><span class="n">datatype</span><span class="p">)</span> + + <span class="n">varElem</span><span class="o">.</span><span class="n">text</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">val</span><span class="p">)</span> + +<span class="k">def</span> <span class="nf">res_iter</span><span class="p">(</span><span class="n">results</span><span class="p">):</span> + <span class="n">res_vars</span> <span class="o">=</span> <span class="n">variables</span><span class="p">(</span><span class="n">results</span><span class="p">)</span> + + <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">results</span><span class="o">.</span><span class="n">selected</span><span class="p">:</span> + <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">res_vars</span><span class="p">)</span> <span class="o">==</span> <span class="mf">1</span><span class="p">:</span> + <span class="n">row</span> <span class="o">=</span> <span class="p">(</span><span class="n">row</span><span class="p">,</span> <span class="p">)</span> + + <span class="k">yield</span> <span class="nb">zip</span><span class="p">(</span><span class="n">row</span><span class="p">,</span> <span class="n">res_vars</span><span class="p">)</span> + +<span class="k">def</span> <span class="nf">result_list</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">root</span><span class="p">):</span> + <span class="n">resultsElem</span> <span class="o">=</span> <span class="n">SubElement</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">(</span><span class="s">u'results'</span><span class="p">))</span> + + <span class="n">ordered</span> <span class="o">=</span> <span class="n">results</span><span class="o">.</span><span class="n">orderBy</span> + + <span class="k">if</span> <span class="n">ordered</span> <span class="o">==</span> <span class="bp">None</span><span class="p">:</span> + <span class="n">ordered</span> <span class="o">=</span> <span class="bp">False</span> + + <span class="c"># removed according to the new working draft (2007-06-14)</span> + <span class="c"># resultsElem.attrib[u'ordered'] = str(ordered)</span> + <span class="c"># resultsElem.attrib[u'distinct'] = str(results.distinct)</span> + + <span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">res_iter</span><span class="p">(</span><span class="n">results</span><span class="p">):</span> + <span class="n">resultElem</span> <span class="o">=</span> <span class="n">SubElement</span><span class="p">(</span><span class="n">resultsElem</span><span class="p">,</span> <span class="n">name</span><span class="p">(</span><span class="s">u'result'</span><span class="p">))</span> + <span class="c"># remove the ? from the variable name</span> + <span class="p">[</span><span class="n">binding</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="n">var</span><span class="p">[</span><span class="mf">1</span><span class="p">:],</span> <span class="n">resultElem</span><span class="p">)</span> <span class="k">for</span> <span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="n">var</span><span class="p">)</span> <span class="ow">in</span> <span class="n">row</span><span class="p">]</span> + +<span class="k">def</span> <span class="nf">serializeXML</span><span class="p">(</span><span class="n">results</span><span class="p">):</span> + <span class="n">root</span> <span class="o">=</span> <span class="n">Element</span><span class="p">(</span><span class="n">name</span><span class="p">(</span><span class="s">u'sparql'</span><span class="p">))</span> + + <span class="n">header</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">root</span><span class="p">)</span> + <span class="n">result_list</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">root</span><span class="p">)</span> + + <span class="n">out</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">()</span> + <span class="n">tree</span> <span class="o">=</span> <span class="n">ElementTree</span><span class="p">(</span><span class="n">root</span><span class="p">)</span> + + <span class="c"># xml declaration must be written by hand</span> + <span class="c"># http://www.nabble.com/Writing-XML-files-with-ElementTree-t3433325.html</span> + <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">'<?xml version="1.0" encoding="utf-8"?>'</span><span class="p">)</span> + <span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">'<?xml-stylesheet type="text/xsl" href="/static/sparql-xml-to-html.xsl"?>'</span><span class="p">)</span> + <span class="n">tree</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">out</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s">'utf-8'</span><span class="p">)</span> + + <span class="k">return</span> <span class="n">out</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span> +</pre></div> +</div> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href="">Additions</a><ul> +<li><a class="reference external" href="#trixserializer">TriXSerializer</a><ul> +<li><a class="reference external" href="#trixserializer-py">TriXSerializer.py</a></li> +<li><a class="reference external" href="#trixserializer-diff">trixserializer.diff</a></li> +<li><a class="reference external" href="#test-trixserializer-py">test_trixserializer.py</a></li> +<li><a class="reference external" href="#test-output">test output</a></li> +</ul> +</li> +<li><a class="reference external" href="#sparql-xml-serializer">SPARQL-XML Serializer</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="assorted_examples.html" + title="previous chapter">Assorted examples</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="modules/index.html" + title="next chapter">Modules</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="_sources/addons.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="modules/index.html" title="Modules" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="assorted_examples.html" title="Assorted examples" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/assorted_examples.html b/docs/_build/html/assorted_examples.html new file mode 100644 index 00000000..3af0a50f --- /dev/null +++ b/docs/_build/html/assorted_examples.html @@ -0,0 +1,736 @@ +<!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>Assorted examples — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="_static/default.css" type="text/css" /> + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="_static/jquery.js"></script> + <script type="text/javascript" src="_static/doctools.js"></script> + <link rel="index" title="Index" href="genindex.html" /> + <link rel="search" title="Search" href="search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="index.html" /> + <link rel="next" title="Additions" href="addons.html" /> + <link rel="prev" title="Graphs, Named Graphs and Blank Nodes" href="graphs_bnodes.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="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="addons.html" title="Additions" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="graphs_bnodes.html" title="Graphs, Named Graphs and Blank Nodes" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="id1"> +<span id="assorted-examples"></span><h1>Assorted examples<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h1> +<div class="section" id="conjunctive-graphs"> +<h2>Conjunctive Graphs<a class="headerlink" href="#conjunctive-graphs" title="Permalink to this headline">¶</a></h2> +<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="p">,</span> <span class="n">BNode</span><span class="p">,</span> <span class="n">Literal</span><span class="p">,</span> <span class="n">URIRef</span> +<span class="kn">from</span> <span class="nn">rdflib.Graph</span> <span class="kn">import</span> <span class="n">Graph</span><span class="p">,</span> <span class="n">ConjunctiveGraph</span> +<span class="kn">from</span> <span class="nn">rdflib.store.IOMemory</span> <span class="kn">import</span> <span class="n">IOMemory</span> + +<span class="n">ns</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">(</span><span class="s">"http://love.com#"</span><span class="p">)</span> + +<span class="n">mary</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">"http://love.com/lovers/mary#"</span><span class="p">)</span> +<span class="n">john</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">"http://love.com/lovers/john#"</span><span class="p">)</span> + +<span class="n">cmary</span><span class="o">=</span><span class="n">URIRef</span><span class="p">(</span><span class="s">"http://love.com/lovers/mary#"</span><span class="p">)</span> +<span class="n">cjohn</span><span class="o">=</span><span class="n">URIRef</span><span class="p">(</span><span class="s">"http://love.com/lovers/john#"</span><span class="p">)</span> + +<span class="n">store</span> <span class="o">=</span> <span class="n">IOMemory</span><span class="p">()</span> + +<span class="n">g</span> <span class="o">=</span> <span class="n">ConjunctiveGraph</span><span class="p">(</span><span class="n">store</span><span class="o">=</span><span class="n">store</span><span class="p">)</span> +<span class="n">g</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">"love"</span><span class="p">,</span><span class="n">ns</span><span class="p">)</span> + +<span class="n">gmary</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">store</span><span class="o">=</span><span class="n">store</span><span class="p">,</span> <span class="n">identifier</span><span class="o">=</span><span class="n">cmary</span><span class="p">)</span> + +<span class="n">gmary</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">mary</span><span class="p">,</span> <span class="n">ns</span><span class="p">[</span><span class="s">'hasName'</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="s">"Mary"</span><span class="p">)))</span> +<span class="n">gmary</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">mary</span><span class="p">,</span> <span class="n">ns</span><span class="p">[</span><span class="s">'loves'</span><span class="p">],</span> <span class="n">john</span><span class="p">))</span> + +<span class="n">gjohn</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">store</span><span class="o">=</span><span class="n">store</span><span class="p">,</span> <span class="n">identifier</span><span class="o">=</span><span class="n">cjohn</span><span class="p">)</span> +<span class="n">gjohn</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">john</span><span class="p">,</span> <span class="n">ns</span><span class="p">[</span><span class="s">'hasName'</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="s">"John"</span><span class="p">)))</span> + +<span class="c">#enumerate contexts</span> +<span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">contexts</span><span class="p">():</span> + <span class="k">print</span> <span class="s">"-- </span><span class="si">%s</span><span class="s"> "</span> <span class="o">%</span> <span class="n">c</span> + +<span class="c">#separate graphs</span> +<span class="k">print</span> <span class="n">gjohn</span><span class="o">.</span><span class="n">serialize</span><span class="p">(</span><span class="n">format</span><span class="o">=</span><span class="s">'n3'</span><span class="p">)</span> +<span class="k">print</span> <span class="s">"==================="</span> +<span class="k">print</span> <span class="n">gmary</span><span class="o">.</span><span class="n">serialize</span><span class="p">(</span><span class="n">format</span><span class="o">=</span><span class="s">'n3'</span><span class="p">)</span> +<span class="k">print</span> <span class="s">"==================="</span> + +<span class="c">#full graph</span> +<span class="k">print</span> <span class="n">g</span><span class="o">.</span><span class="n">serialize</span><span class="p">(</span><span class="n">format</span><span class="o">=</span><span class="s">'n3'</span><span class="p">)</span> +</pre></div> +</div> +</div> +<div class="section" id="two-finger-exercises"> +<h2>Two-finger exercises<a class="headerlink" href="#two-finger-exercises" title="Permalink to this headline">¶</a></h2> +<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">logging</span> + +<span class="c"># Configure how we want rdflib logger to log messages</span> +<span class="n">_logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s">"rdflib"</span><span class="p">)</span> +<span class="n">_logger</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">)</span> +<span class="n">_hdlr</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">StreamHandler</span><span class="p">()</span> +<span class="n">_hdlr</span><span class="o">.</span><span class="n">setFormatter</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">Formatter</span><span class="p">(</span><span class="s">'</span><span class="si">%(name)s</span><span class="s"> </span><span class="si">%(levelname)s</span><span class="s">: </span><span class="si">%(message)s</span><span class="s">'</span><span class="p">))</span> +<span class="n">_logger</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">_hdlr</span><span class="p">)</span> + +<span class="kn">from</span> <span class="nn">rdflib.Graph</span> <span class="kn">import</span> <span class="n">Graph</span> +<span class="kn">from</span> <span class="nn">rdflib</span> <span class="kn">import</span> <span class="n">URIRef</span><span class="p">,</span> <span class="n">Literal</span><span class="p">,</span> <span class="n">BNode</span><span class="p">,</span> <span class="n">Namespace</span> +<span class="kn">from</span> <span class="nn">rdflib</span> <span class="kn">import</span> <span class="n">RDF</span> + +<span class="n">store</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> + +<span class="c"># Bind a few prefix, namespace pairs.</span> +<span class="n">store</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">"dc"</span><span class="p">,</span> <span class="s">"http://http://purl.org/dc/elements/1.1/"</span><span class="p">)</span> +<span class="n">store</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">"foaf"</span><span class="p">,</span> <span class="s">"http://xmlns.com/foaf/0.1/"</span><span class="p">)</span> + +<span class="c"># Create a namespace object for the Friend of a friend namespace.</span> +<span class="n">FOAF</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">(</span><span class="s">"http://xmlns.com/foaf/0.1/"</span><span class="p">)</span> + +<span class="c"># Create an identifier to use as the subject for Donna.</span> +<span class="n">donna</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> + +<span class="c"># Add triples using store's add method.</span> +<span class="n">store</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">donna</span><span class="p">,</span> <span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="n">FOAF</span><span class="p">[</span><span class="s">"Person"</span><span class="p">]))</span> +<span class="n">store</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">donna</span><span class="p">,</span> <span class="n">FOAF</span><span class="p">[</span><span class="s">"nick"</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="s">"donna"</span><span class="p">,</span> <span class="n">lang</span><span class="o">=</span><span class="s">"foo"</span><span class="p">)))</span> +<span class="n">store</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">donna</span><span class="p">,</span> <span class="n">FOAF</span><span class="p">[</span><span class="s">"name"</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="s">"Donna Fales"</span><span class="p">)))</span> + +<span class="c"># Iterate over triples in store and print them out.</span> +<span class="k">print</span> <span class="s">"--- printing raw triples ---"</span> +<span class="k">for</span> <span class="n">s</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">store</span><span class="p">:</span> + <span class="k">print</span> <span class="n">s</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">o</span> + +<span class="c"># For each foaf:Person in the store print out its mbox property.</span> +<span class="k">print</span> <span class="s">"--- printing mboxes ---"</span> +<span class="k">for</span> <span class="n">person</span> <span class="ow">in</span> <span class="n">store</span><span class="o">.</span><span class="n">subjects</span><span class="p">(</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="n">FOAF</span><span class="p">[</span><span class="s">"Person"</span><span class="p">]):</span> + <span class="k">for</span> <span class="n">mbox</span> <span class="ow">in</span> <span class="n">store</span><span class="o">.</span><span class="n">objects</span><span class="p">(</span><span class="n">person</span><span class="p">,</span> <span class="n">FOAF</span><span class="p">[</span><span class="s">"mbox"</span><span class="p">]):</span> + <span class="k">print</span> <span class="n">mbox</span> + +<span class="c"># Serialize the store as RDF/XML to the file foaf.rdf.</span> +<span class="n">store</span><span class="o">.</span><span class="n">serialize</span><span class="p">(</span><span class="s">"foaf.rdf"</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s">"pretty-xml"</span><span class="p">,</span> <span class="n">max_depth</span><span class="o">=</span><span class="mf">3</span><span class="p">)</span> + +<span class="c"># Let's show off the serializers</span> + +<span class="k">print</span> <span class="s">"RDF Serializations:"</span> + +<span class="c"># Serialize as XML</span> +<span class="k">print</span> <span class="s">"--- start: rdf-xml ---"</span> +<span class="k">print</span> <span class="n">store</span><span class="o">.</span><span class="n">serialize</span><span class="p">(</span><span class="n">format</span><span class="o">=</span><span class="s">"pretty-xml"</span><span class="p">)</span> +<span class="k">print</span> <span class="s">"--- end: rdf-xml ---</span><span class="se">\n</span><span class="s">"</span> + +<span class="c"># Serialize as NTriples</span> +<span class="k">print</span> <span class="s">"--- start: ntriples ---"</span> +<span class="k">print</span> <span class="n">store</span><span class="o">.</span><span class="n">serialize</span><span class="p">(</span><span class="n">format</span><span class="o">=</span><span class="s">"nt"</span><span class="p">)</span> +<span class="k">print</span> <span class="s">"--- end: ntriples ---</span><span class="se">\n</span><span class="s">"</span> +</pre></div> +</div> +</div> +<div class="section" id="update-namespace"> +<h2>Update namespace<a class="headerlink" href="#update-namespace" title="Permalink to this headline">¶</a></h2> +<div class="highlight-python"><div class="highlight"><pre><span class="c">#OLD = "http://www.mindswap.org/2004/terrorOnt.owl#"</span> +<span class="c">#OLD = "http://wang-desktop/TerrorOrgInstances#"</span> +<span class="n">OLD</span> <span class="o">=</span> <span class="s">"http://localhost/"</span> +<span class="n">NEW</span> <span class="o">=</span> <span class="s">"http://profilesinterror.mindswap.org/"</span> + +<span class="n">redfoot</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">"terror"</span><span class="p">,</span> <span class="s">"http://counterterror.mindswap.org/2005/terrorism.owl#"</span><span class="p">)</span> +<span class="n">redfoot</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">"terror_old"</span><span class="p">,</span> <span class="s">"http://www.mindswap.org/2004/terrorOnt.owl#"</span><span class="p">)</span> +<span class="n">redfoot</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">"tech"</span><span class="p">,</span> <span class="s">"http://www.mindswap.org/~glapizco/technical.owl#"</span><span class="p">)</span> +<span class="n">redfoot</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">"wang-desk"</span><span class="p">,</span> <span class="s">"http://wang-desktop/TerrorOrgInstances#"</span><span class="p">)</span> +<span class="n">redfoot</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">"foaf"</span><span class="p">,</span> <span class="s">'http://xmlns.com/foaf/0.1/'</span><span class="p">)</span> +<span class="n">redfoot</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">"dc"</span><span class="p">,</span> <span class="s">'http://purl.org/dc/elements/1.1/'</span><span class="p">)</span> + + +<span class="n">REDFOOT</span> <span class="o">=</span> <span class="n">redfoot</span><span class="o">.</span><span class="n">namespace</span><span class="p">(</span><span class="s">"http://redfoot.net/2005/redfoot#"</span><span class="p">)</span> + +<span class="k">for</span> <span class="n">cid</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">source</span> <span class="ow">in</span> <span class="n">redfoot</span><span class="o">.</span><span class="n">triples</span><span class="p">((</span><span class="bp">None</span><span class="p">,</span> <span class="n">REDFOOT</span><span class="o">.</span><span class="n">source</span><span class="p">,</span> <span class="bp">None</span><span class="p">)):</span> + <span class="k">if</span> <span class="n">source</span><span class="p">:</span> + <span class="k">print</span> <span class="s">"updating </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="n">source</span> + <span class="k">try</span><span class="p">:</span> + <span class="n">context</span> <span class="o">=</span> <span class="n">redfoot</span><span class="o">.</span><span class="n">get_context</span><span class="p">(</span><span class="n">cid</span><span class="p">)</span> + + <span class="k">for</span> <span class="n">s</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">context</span><span class="p">:</span> + <span class="n">context</span><span class="o">.</span><span class="n">remove</span><span class="p">((</span><span class="n">s</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">o</span><span class="p">))</span> + <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">)</span> <span class="ow">and</span> <span class="n">OLD</span> <span class="ow">in</span> <span class="n">s</span><span class="p">:</span> + <span class="n">s</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">OLD</span><span class="p">,</span> <span class="n">NEW</span><span class="p">))</span> + <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">)</span> <span class="ow">and</span> <span class="n">OLD</span> <span class="ow">in</span> <span class="n">p</span><span class="p">:</span> + <span class="n">p</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">OLD</span><span class="p">,</span> <span class="n">NEW</span><span class="p">))</span> + <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">)</span> <span class="ow">and</span> <span class="n">OLD</span> <span class="ow">in</span> <span class="n">o</span><span class="p">:</span> + <span class="n">o</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="n">o</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">OLD</span><span class="p">,</span> <span class="n">NEW</span><span class="p">))</span> + <span class="n">context</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">s</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">o</span><span class="p">))</span> + + <span class="n">context</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s">"pretty-xml"</span><span class="p">)</span> + <span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> + <span class="k">print</span> <span class="n">e</span> +</pre></div> +</div> +</div> +<div class="section" id="sparql-query"> +<h2>SPARQL query<a class="headerlink" href="#sparql-query" title="Permalink to this headline">¶</a></h2> +<div class="highlight-python"><pre>from rdflib import Literal, ConjunctiveGraph, Namespace, BNode, URIRef + +DC = Namespace(u"http://purl.org/dc/elements/1.1/";) +FOAF = Namespace(u"http://xmlns.com/foaf/0.1/";) + +graph = ConjunctiveGraph() +s = BNode() +graph.add((s, FOAF['givenName'], Literal('Alice'))) +b = BNode() +graph.add((b, FOAF['givenName'], Literal('Bob'))) +graph.add((b, DC['date'], Literal("2005-04-04T04:04:04Z"))) + +print graph.query("""PREFIX foaf: <http://xmlns.com/foaf/0.1/> + PREFIX dc: <http://purl.org/dc/elements/1.1/> + PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> + SELECT ?name + WHERE { ?x foaf:givenName ?name . + OPTIONAL { ?x dc:date ?date } . + FILTER ( bound(?date) ) }""").serialize('python')</pre> +</div> +</div> +<div class="section" id="data-reading-exercise"> +<h2>Data reading exercise<a class="headerlink" href="#data-reading-exercise" title="Permalink to this headline">¶</a></h2> +<div class="highlight-python"><div class="highlight"><pre><span class="c">#!/usr/bin/env python</span> +<span class="c"># -*- coding: utf-8 -*-</span> + +<span class="sd">"""Demo script to show the different ways to read information</span> +<span class="sd">from an RDF file using rdflib, as found at http://rdflib.net/.</span> + +<span class="sd">The tree main methods are:</span> +<span class="sd">1. Simple lookup in a list of triplets (SimpleLookup),</span> +<span class="sd">2. SPARQL query, created with rdflib.sparql.* objects (CustomSparql),</span> +<span class="sd">3. SPARQL query, created with bison (BisonSparql).</span> + +<span class="sd">The main function reads a file, xfn-example.rdf, and displays all resource</span> +<span class="sd">pairs with a symmetrical "xfn:met" relation (e.g. A met B and B met A)</span> +<span class="sd">Uses the rdfs:label of the resources to display the name.</span> + +<span class="sd">This demo file has been tested with the following versions of RDFlib:</span> +<span class="sd"> rdflib 2.0.6 -- unsupported (since it has no "Graph" modules)</span> +<span class="sd"> rdflib 2.1.3 -- methods 1, and 2 work fine</span> +<span class="sd"> rdflib 2.1.4 -- methods 1, and 2 work fine</span> +<span class="sd"> rdflib 2.2.3 -- methods 1, and 2 work fine</span> +<span class="sd"> rdflib 2.3.0 -- methods 1, and 2 work fine</span> +<span class="sd"> rdflib 2.3.1 -- methods 1, and 2 work fine</span> +<span class="sd"> rdflib 2.3.2 -- methods 1, and 2 work fine</span> +<span class="sd"> rdflib 2.3.3 -- methods 1, 2, and 3 work fine</span> +<span class="sd"> rdflib 2.4.0 -- methods 1, 2, and 3 work fine (but function call for method 2 was changed)</span> +<span class="sd">"""</span> + +<span class="n">__copyright__</span> <span class="o">=</span> <span class="s">"rdflibdemo written by Freek Dijkstra, Universiteit van Amsterdam, april 2007, contributed to the public domain (feel free to attribute me, but it's not needed)."</span> + +<span class="kn">import</span> <span class="nn">os</span> +<span class="kn">import</span> <span class="nn">sys</span> +<span class="kn">import</span> <span class="nn">distutils.version</span> +<span class="c"># semi-standard modules</span> +<span class="k">try</span><span class="p">:</span> + <span class="kn">import</span> <span class="nn">rdflib</span> +<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span> + <span class="k">raise</span> <span class="ne">ImportError</span><span class="p">(</span><span class="s">"Module rdflib is not available. It can be downloaded from http://rdflib.net/</span><span class="se">\n</span><span class="s">"</span><span class="p">)</span> +<span class="k">if</span> <span class="n">distutils</span><span class="o">.</span><span class="n">version</span><span class="o">.</span><span class="n">StrictVersion</span><span class="p">(</span><span class="n">rdflib</span><span class="o">.</span><span class="n">__version__</span><span class="p">)</span> <span class="o"><</span> <span class="s">"2.0.9"</span><span class="p">:</span> + <span class="k">raise</span> <span class="ne">ImportError</span><span class="p">(</span><span class="s">"The installed version of rdflib, </span><span class="si">%s</span><span class="s">, is too old. 2.1 or higher is required"</span> <span class="o">%</span> <span class="n">rdflib</span><span class="o">.</span><span class="n">__version__</span><span class="p">)</span> +<span class="kn">from</span> <span class="nn">rdflib.Graph</span> <span class="kn">import</span> <span class="n">Graph</span> +<span class="kn">from</span> <span class="nn">rdflib.sparql.sparqlGraph</span> <span class="kn">import</span> <span class="n">SPARQLGraph</span> +<span class="kn">from</span> <span class="nn">rdflib.sparql.graphPattern</span> <span class="kn">import</span> <span class="n">GraphPattern</span> +<span class="k">if</span> <span class="n">distutils</span><span class="o">.</span><span class="n">version</span><span class="o">.</span><span class="n">StrictVersion</span><span class="p">(</span><span class="n">rdflib</span><span class="o">.</span><span class="n">__version__</span><span class="p">)</span> <span class="o">></span> <span class="s">"2.3.2"</span><span class="p">:</span> + <span class="kn">from</span> <span class="nn">rdflib.sparql.bison</span> <span class="kn">import</span> <span class="n">Parse</span> <span class="c"># available in 2.3.3 and up</span> +<span class="k">if</span> <span class="n">distutils</span><span class="o">.</span><span class="n">version</span><span class="o">.</span><span class="n">StrictVersion</span><span class="p">(</span><span class="n">rdflib</span><span class="o">.</span><span class="n">__version__</span><span class="p">)</span> <span class="o">></span> <span class="s">"2.3.9"</span><span class="p">:</span> + <span class="kn">from</span> <span class="nn">rdflib.sparql</span> <span class="kn">import</span> <span class="n">Query</span> <span class="c"># available in 2.4.0 and up</span> + + + + +<span class="k">def</span> <span class="nf">SimpleLookup</span><span class="p">(</span><span class="n">graph</span><span class="p">):</span> + <span class="sd">"""</span> +<span class="sd"> Extracts information form a rdflib Graph object</span> +<span class="sd"> using a simple list lookup. E.g.:</span> +<span class="sd"> result = list(graph.subject_objects(self.xfn["met"])):</span> +<span class="sd"> """</span> + <span class="k">assert</span><span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">graph</span><span class="p">,</span> <span class="n">Graph</span><span class="p">))</span> + <span class="n">xfn</span> <span class="o">=</span> <span class="n">rdflib</span><span class="o">.</span><span class="n">Namespace</span><span class="p">(</span><span class="s">"http://gmpg.org/xfn/1#"</span><span class="p">)</span> + <span class="n">rdf</span> <span class="o">=</span> <span class="n">rdflib</span><span class="o">.</span><span class="n">Namespace</span><span class="p">(</span><span class="s">"http://www.w3.org/1999/02/22-rdf-syntax-ns#"</span><span class="p">)</span> + <span class="n">rdfs</span> <span class="o">=</span> <span class="n">rdflib</span><span class="o">.</span><span class="n">Namespace</span><span class="p">(</span><span class="s">"http://www.w3.org/2000/01/rdf-schema#"</span><span class="p">)</span> + <span class="n">meetings</span> <span class="o">=</span> <span class="p">[]</span> + <span class="c"># Get a list of (subject, object) tuples in the graph with the xfn:met predicate</span> + <span class="n">relations</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">graph</span><span class="o">.</span><span class="n">subject_objects</span><span class="p">(</span><span class="n">xfn</span><span class="p">[</span><span class="s">"met"</span><span class="p">]))</span> + <span class="k">for</span> <span class="p">(</span><span class="n">person</span><span class="p">,</span> <span class="n">peer</span><span class="p">)</span> <span class="ow">in</span> <span class="n">relations</span><span class="p">:</span> + <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">peer</span><span class="p">,</span> <span class="n">person</span><span class="p">)</span> <span class="ow">in</span> <span class="n">relations</span><span class="p">:</span> + <span class="c"># person says he/she has met peer, but peer doesn't say he/she has met person. Skip.</span> + <span class="k">continue</span> + <span class="c"># since we're processing (person, peer), we can skip (peer, person) later</span> + <span class="n">relations</span><span class="o">.</span><span class="n">remove</span><span class="p">((</span><span class="n">peer</span><span class="p">,</span> <span class="n">person</span><span class="p">))</span> + <span class="n">personname</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">graph</span><span class="o">.</span><span class="n">objects</span><span class="p">(</span><span class="n">person</span><span class="p">,</span> <span class="n">rdfs</span><span class="p">[</span><span class="s">"label"</span><span class="p">]))</span> + <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">personname</span><span class="p">)</span> <span class="o">==</span> <span class="mf">0</span><span class="p">:</span> + <span class="k">continue</span> <span class="c"># skip persons with no name</span> + <span class="n">peername</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">graph</span><span class="o">.</span><span class="n">objects</span><span class="p">(</span><span class="n">peer</span><span class="p">,</span> <span class="n">rdfs</span><span class="p">[</span><span class="s">"label"</span><span class="p">]))</span> + <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">peername</span><span class="p">)</span> <span class="o">==</span> <span class="mf">0</span><span class="p">:</span> + <span class="k">continue</span> <span class="c"># skip peers with no name</span> + <span class="n">personname</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">graph</span><span class="o">.</span><span class="n">objects</span><span class="p">(</span><span class="n">person</span><span class="p">,</span> <span class="n">rdfs</span><span class="p">[</span><span class="s">"label"</span><span class="p">]))</span> + <span class="c"># Add the name of the person and peer to list of people who've met.</span> + <span class="n">meetings</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">personname</span><span class="p">[</span><span class="mf">0</span><span class="p">],</span> <span class="n">peername</span><span class="p">[</span><span class="mf">0</span><span class="p">]))</span> + + <span class="c"># Print the results</span> + <span class="k">print</span> <span class="s">"Simple Lookup (</span><span class="si">%d</span><span class="s"> meetings found)"</span> <span class="o">%</span> <span class="nb">len</span><span class="p">(</span><span class="n">meetings</span><span class="p">)</span> + <span class="k">print</span> <span class="mf">40</span><span class="o">*</span><span class="s">"-"</span> + <span class="k">for</span> <span class="p">(</span><span class="n">person</span><span class="p">,</span> <span class="n">peer</span><span class="p">)</span> <span class="ow">in</span> <span class="n">meetings</span><span class="p">:</span> + <span class="k">print</span> <span class="s">"</span><span class="si">%s</span><span class="s"> and </span><span class="si">%s</span><span class="s"> have met"</span> <span class="o">%</span> <span class="p">(</span><span class="n">person</span><span class="p">,</span> <span class="n">peer</span><span class="p">)</span> + <span class="k">print</span> + + +<span class="k">def</span> <span class="nf">CustomSparql</span><span class="p">(</span><span class="n">graph</span><span class="p">):</span> + <span class="sd">"""</span> +<span class="sd"> Extracts information form a rdflib Graph object</span> +<span class="sd"> using a SPARQL query, put together using GraphPattern objects. E.g.:</span> +<span class="sd"> select = ("?ifA","?ifB")</span> +<span class="sd"> where = GraphPattern([("?ifA", xfn["met"], "?ifB")])</span> +<span class="sd"> result = graph.query(select,where)</span> +<span class="sd"> See http://dev.w3.org/cvsweb/~checkout~/2004/PythonLib-IH/Doc/sparqlDesc.html for more information.</span> +<span class="sd"> """</span> + <span class="k">assert</span><span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">graph</span><span class="p">,</span> <span class="n">Graph</span><span class="p">))</span> + <span class="n">xfn</span> <span class="o">=</span> <span class="n">rdflib</span><span class="o">.</span><span class="n">Namespace</span><span class="p">(</span><span class="s">"http://gmpg.org/xfn/1#"</span><span class="p">)</span> + <span class="n">rdf</span> <span class="o">=</span> <span class="n">rdflib</span><span class="o">.</span><span class="n">Namespace</span><span class="p">(</span><span class="s">"http://www.w3.org/1999/02/22-rdf-syntax-ns#"</span><span class="p">)</span> + <span class="n">rdfs</span> <span class="o">=</span> <span class="n">rdflib</span><span class="o">.</span><span class="n">Namespace</span><span class="p">(</span><span class="s">"http://www.w3.org/2000/01/rdf-schema#"</span><span class="p">)</span> + <span class="n">select</span> <span class="o">=</span> <span class="p">(</span><span class="s">"?personname"</span><span class="p">,</span><span class="s">"?peername"</span><span class="p">)</span> + <span class="n">where</span> <span class="o">=</span> <span class="n">GraphPattern</span><span class="p">([</span> + <span class="p">(</span><span class="s">"?person"</span><span class="p">,</span> <span class="n">xfn</span><span class="p">[</span><span class="s">"met"</span><span class="p">],</span> <span class="s">"?peer"</span><span class="p">),</span> + <span class="p">(</span><span class="s">"?peer"</span><span class="p">,</span> <span class="n">xfn</span><span class="p">[</span><span class="s">"met"</span><span class="p">],</span> <span class="s">"?person"</span><span class="p">),</span> + <span class="p">(</span><span class="s">"?person"</span><span class="p">,</span> <span class="n">rdfs</span><span class="p">[</span><span class="s">"label"</span><span class="p">],</span> <span class="s">"?personname"</span><span class="p">),</span> + <span class="p">(</span><span class="s">"?peer"</span><span class="p">,</span> <span class="n">rdfs</span><span class="p">[</span><span class="s">"label"</span><span class="p">],</span> <span class="s">"?peername"</span><span class="p">),</span> + <span class="p">])</span> + <span class="c"># Create a SPARQLGraph wrapper object out of the normal Graph</span> + <span class="n">sparqlGrph</span> <span class="o">=</span> <span class="n">SPARQLGraph</span><span class="p">(</span><span class="n">graph</span><span class="p">)</span> + <span class="c"># Make the query</span> + <span class="k">if</span> <span class="n">distutils</span><span class="o">.</span><span class="n">version</span><span class="o">.</span><span class="n">StrictVersion</span><span class="p">(</span><span class="n">rdflib</span><span class="o">.</span><span class="n">__version__</span><span class="p">)</span> <span class="o"><=</span> <span class="s">"2.3.9"</span><span class="p">:</span> + <span class="n">relations</span> <span class="o">=</span> <span class="n">sparqlGrph</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">select</span><span class="p">,</span> <span class="n">where</span><span class="p">)</span> + <span class="k">else</span><span class="p">:</span> + <span class="c"># graph.query() function was changed in RDFlib 2.4.0</span> + <span class="n">bindings</span> <span class="o">=</span> <span class="p">{</span> <span class="s">u"xfn"</span><span class="p">:</span> <span class="n">xfn</span><span class="p">,</span> <span class="s">u"rdf"</span><span class="p">:</span> <span class="n">rdf</span><span class="p">,</span> <span class="s">u"rdfs"</span><span class="p">:</span> <span class="n">rdfs</span> <span class="p">}</span> + <span class="n">relations</span> <span class="o">=</span> <span class="n">Query</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">sparqlGrph</span><span class="p">,</span> <span class="n">select</span><span class="p">,</span> <span class="n">where</span><span class="p">,</span> <span class="n">initialBindings</span><span class="o">=</span><span class="n">bindings</span><span class="p">)</span> + + <span class="k">for</span> <span class="p">(</span><span class="n">person</span><span class="p">,</span> <span class="n">peer</span><span class="p">)</span> <span class="ow">in</span> <span class="n">relations</span><span class="p">:</span> + <span class="c"># since we're processing (person, peer), we can skip (peer, person) later</span> + <span class="n">relations</span><span class="o">.</span><span class="n">remove</span><span class="p">((</span><span class="n">peer</span><span class="p">,</span> <span class="n">person</span><span class="p">))</span> + + <span class="c"># Print the results</span> + <span class="k">print</span> <span class="s">"Manual formatted SPARQL query (</span><span class="si">%d</span><span class="s"> meetings found)"</span> <span class="o">%</span> <span class="nb">len</span><span class="p">(</span><span class="n">relations</span><span class="p">)</span> + <span class="k">print</span> <span class="mf">40</span><span class="o">*</span><span class="s">"-"</span> + <span class="k">for</span> <span class="p">(</span><span class="n">person</span><span class="p">,</span> <span class="n">peer</span><span class="p">)</span> <span class="ow">in</span> <span class="n">relations</span><span class="p">:</span> + <span class="k">print</span> <span class="s">"</span><span class="si">%s</span><span class="s"> and </span><span class="si">%s</span><span class="s"> have met"</span> <span class="o">%</span> <span class="p">(</span><span class="n">person</span><span class="p">,</span> <span class="n">peer</span><span class="p">)</span> + <span class="k">print</span> + + +<span class="k">def</span> <span class="nf">BisonSparql</span><span class="p">(</span><span class="n">graph</span><span class="p">):</span> + <span class="sd">"""</span> +<span class="sd"> Extracts information form a rdflib Graph object</span> +<span class="sd"> using a SPARQL query, parsed by the bison parser in RDFlib.</span> +<span class="sd"> graphpattern = Parse('SELECT ?ifA ?ifB WHERE { ?ifA xfn:met ?ifB . ?ifB xfn:met ?ifA }')</span> +<span class="sd"> result = graph.query(graphpattern, initNs=bindings)</span> +<span class="sd"> """</span> + <span class="k">assert</span><span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">graph</span><span class="p">,</span> <span class="n">Graph</span><span class="p">))</span> + <span class="k">if</span> <span class="n">distutils</span><span class="o">.</span><span class="n">version</span><span class="o">.</span><span class="n">StrictVersion</span><span class="p">(</span><span class="n">rdflib</span><span class="o">.</span><span class="n">__version__</span><span class="p">)</span> <span class="o"><=</span> <span class="s">"2.3.2"</span><span class="p">:</span> + <span class="k">print</span> <span class="s">"Skipping Bison SPARQL query (requires RDFlib 2.3.3 or higher; version </span><span class="si">%s</span><span class="s"> detected)"</span> <span class="o">%</span> <span class="p">(</span><span class="n">rdflib</span><span class="o">.</span><span class="n">__version__</span><span class="p">)</span> + <span class="k">print</span> + <span class="k">return</span> + <span class="n">xfn</span> <span class="o">=</span> <span class="n">rdflib</span><span class="o">.</span><span class="n">Namespace</span><span class="p">(</span><span class="s">"http://gmpg.org/xfn/1#"</span><span class="p">)</span> + <span class="n">rdf</span> <span class="o">=</span> <span class="n">rdflib</span><span class="o">.</span><span class="n">Namespace</span><span class="p">(</span><span class="s">"http://www.w3.org/1999/02/22-rdf-syntax-ns#"</span><span class="p">)</span> + <span class="n">rdfs</span> <span class="o">=</span> <span class="n">rdflib</span><span class="o">.</span><span class="n">Namespace</span><span class="p">(</span><span class="s">"http://www.w3.org/2000/01/rdf-schema#"</span><span class="p">)</span> + <span class="n">bindings</span> <span class="o">=</span> <span class="p">{</span> <span class="s">u"xfn"</span><span class="p">:</span> <span class="n">xfn</span><span class="p">,</span> <span class="s">u"rdf"</span><span class="p">:</span> <span class="n">rdf</span><span class="p">,</span> <span class="s">u"rdfs"</span><span class="p">:</span> <span class="n">rdfs</span> <span class="p">}</span> + <span class="n">query</span> <span class="o">=</span> <span class="n">Parse</span><span class="p">(</span><span class="s">'SELECT ?personname ?peername WHERE </span><span class="se">\</span> +<span class="s"> { ?person xfn:met ?peer . ?peer xfn:met ?person . </span><span class="se">\</span> +<span class="s"> ?person rdfs:label ?personname . ?peer rdfs:label ?peername }'</span><span class="p">)</span> + <span class="c"># Make the query, and serialize the result as python objects (as opposed to for example XML)</span> + <span class="n">relations</span> <span class="o">=</span> <span class="n">graph</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">query</span><span class="p">,</span> <span class="n">initNs</span><span class="o">=</span><span class="n">bindings</span><span class="p">)</span><span class="o">.</span><span class="n">serialize</span><span class="p">(</span><span class="s">'python'</span><span class="p">)</span> + <span class="k">for</span> <span class="p">(</span><span class="n">person</span><span class="p">,</span> <span class="n">peer</span><span class="p">)</span> <span class="ow">in</span> <span class="n">relations</span><span class="p">:</span> + <span class="c"># since we're processing (person, peer), we can skip (peer, person) later</span> + <span class="n">relations</span><span class="o">.</span><span class="n">remove</span><span class="p">((</span><span class="n">peer</span><span class="p">,</span> <span class="n">person</span><span class="p">))</span> + + <span class="c"># Print the results</span> + <span class="k">print</span> <span class="s">"Bison SPARQL query (</span><span class="si">%d</span><span class="s"> meetings found)"</span> <span class="o">%</span> <span class="nb">len</span><span class="p">(</span><span class="n">relations</span><span class="p">)</span> + <span class="k">print</span> <span class="mf">40</span><span class="o">*</span><span class="s">"-"</span> + <span class="k">for</span> <span class="p">(</span><span class="n">person</span><span class="p">,</span> <span class="n">peer</span><span class="p">)</span> <span class="ow">in</span> <span class="n">relations</span><span class="p">:</span> + <span class="k">print</span> <span class="s">"</span><span class="si">%s</span><span class="s"> and </span><span class="si">%s</span><span class="s"> have met"</span> <span class="o">%</span> <span class="p">(</span><span class="n">person</span><span class="p">,</span> <span class="n">peer</span><span class="p">)</span> + <span class="k">print</span> + +<span class="k">def</span> <span class="nf">ReadFile</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="s">"xfn-example.rdf"</span><span class="p">):</span> + <span class="sd">"""Read a RDF and returns the objects in a rdflib Graph object"""</span> + <span class="n">graph</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> + <span class="k">print</span> <span class="s">"Read RDF data from </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="n">filename</span> + <span class="k">print</span> + <span class="n">graph</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span> + <span class="k">return</span> <span class="n">graph</span> + +<span class="k">if</span> <span class="n">__name__</span><span class="o">==</span><span class="s">"__main__"</span><span class="p">:</span> + <span class="k">print</span> <span class="s">"RDFlib version </span><span class="si">%s</span><span class="s"> detected"</span> <span class="o">%</span> <span class="n">rdflib</span><span class="o">.</span><span class="n">__version__</span> + <span class="k">print</span> + <span class="n">graph</span> <span class="o">=</span> <span class="n">ReadFile</span><span class="p">()</span> + <span class="n">SimpleLookup</span><span class="p">(</span><span class="n">graph</span><span class="p">)</span> + <span class="n">CustomSparql</span><span class="p">(</span><span class="n">graph</span><span class="p">)</span> + <span class="n">BisonSparql</span><span class="p">(</span><span class="n">graph</span><span class="p">)</span> +</pre></div> +</div> +</div> +<div class="section" id="example-foaf-smushing"> +<h2>Example Foaf Smushing<a class="headerlink" href="#example-foaf-smushing" title="Permalink to this headline">¶</a></h2> +<p>Filter a graph by normalizing all foaf persons into URIs based on their mbox_sha1sum.</p> +<p>Suppose I got two FOAF documents each talking about the same person (according to mbox_sha1sum) but they each used a BNode for the subject. For this demo I’ve combined those two documents into one file:</p> +<div class="section" id="demo-n3"> +<h3>demo.n3<a class="headerlink" href="#demo-n3" title="Permalink to this headline">¶</a></h3> +<div class="highlight-n3"><pre>@prefix foaf: <http://xmlns.com/foaf/0.1/> . + +# from one document +:p0 a foaf:Person; + foaf:mbox_sha1sum "65b983bb397fb71849da910996741752ace8369b"; + foaf:nick "mortenf"; + foaf:weblog <http://www.wasab.dk/morten/blog/archives/author/mortenf/> . + +# from another document +:p1 a foaf:Person; + foaf:mbox_sha1sum "65b983bb397fb71849da910996741752ace8369b"; + foaf:nick "mortenf"; + foaf:homepage <http://www.wasab.dk/morten/>; + foaf:interest <http://en.wikipedia.org/wiki/Atom_(standard)>,</pre> +</div> +<p>Now I’ll use rdflib to transform all the incoming FOAF data to new data that lies about the subjects. It might be easier to do some queries on this resulting graph, although you wouldn’t want to actually publish the result anywhere since it loses some information about FOAF people who really had a meaningful URI.</p> +</div> +<div class="section" id="fold-sha1-py"> +<h3>fold_sha1.py<a class="headerlink" href="#fold-sha1-py" title="Permalink to this headline">¶</a></h3> +<div class="highlight-python"><div class="highlight"><pre><span class="sd">"""filter a graph by changing every subject with a foaf:mbox_sha1sum</span> +<span class="sd">into a new subject whose URI is based on the sha1sum. This new graph</span> +<span class="sd">might be easier to do some operations on.</span> +<span class="sd">"""</span> + +<span class="kn">from</span> <span class="nn">rdflib.Graph</span> <span class="kn">import</span> <span class="n">Graph</span> +<span class="kn">from</span> <span class="nn">rdflib</span> <span class="kn">import</span> <span class="n">Namespace</span> + +<span class="n">FOAF</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">(</span><span class="s">"http://xmlns.com/foaf/0.1/"</span><span class="p">)</span> +<span class="n">STABLE</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">(</span><span class="s">"http://example.com/person/mbox_sha1sum/"</span><span class="p">)</span> + +<span class="n">g</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> +<span class="n">g</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s">"demo.n3"</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s">"n3"</span><span class="p">)</span> + +<span class="n">newURI</span> <span class="o">=</span> <span class="p">{}</span> <span class="c"># old subject : stable uri</span> +<span class="k">for</span> <span class="n">s</span><span class="p">,</span><span class="n">p</span><span class="p">,</span><span class="n">o</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">triples</span><span class="p">((</span><span class="bp">None</span><span class="p">,</span> <span class="n">FOAF</span><span class="p">[</span><span class="s">'mbox_sha1sum'</span><span class="p">],</span> <span class="bp">None</span><span class="p">)):</span> + <span class="n">newURI</span><span class="p">[</span><span class="n">s</span><span class="p">]</span> <span class="o">=</span> <span class="n">STABLE</span><span class="p">[</span><span class="n">o</span><span class="p">]</span> + + +<span class="n">out</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> +<span class="n">out</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">'foaf'</span><span class="p">,</span> <span class="n">FOAF</span><span class="p">)</span> + +<span class="k">for</span> <span class="n">s</span><span class="p">,</span><span class="n">p</span><span class="p">,</span><span class="n">o</span> <span class="ow">in</span> <span class="n">g</span><span class="p">:</span> + <span class="n">s</span> <span class="o">=</span> <span class="n">newURI</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span> + <span class="n">o</span> <span class="o">=</span> <span class="n">newURI</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">o</span><span class="p">)</span> <span class="c"># might be linked to another person</span> + <span class="n">out</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">s</span><span class="p">,</span><span class="n">p</span><span class="p">,</span><span class="n">o</span><span class="p">))</span> + +<span class="k">print</span> <span class="n">out</span><span class="o">.</span><span class="n">serialize</span><span class="p">(</span><span class="n">format</span><span class="o">=</span><span class="s">"n3"</span><span class="p">)</span> +</pre></div> +</div> +</div> +<div class="section" id="output"> +<h3>Output<a class="headerlink" href="#output" title="Permalink to this headline">¶</a></h3> +<p>note how all of the data has come together under one subject:</p> +<div class="highlight-n3"><div class="highlight"><pre><span class="k">@prefix </span><span class="nv">_5: </span><span class="nn"><http://example.com/person/mbox_sha1sum/65>.</span> +<span class="k">@prefix </span><span class="nv">foaf: </span><span class="nn"><http://xmlns.com/foaf/0.1/>.</span> +<span class="k">@prefix </span><span class="nv">rdf: </span><span class="nn"><http://www.w3.org/1999/02/22-rdf-syntax-ns#>.</span> + +<span class="nn"> </span><span class="nc">_5:b983bb397fb71849da910996741752ace8369b </span><span class="o">a </span><span class="na">foaf:Person</span>; + <span class="o">foaf:homepage </span><span class="na"><http://www.wasab.dk/morten/></span>; + <span class="o">foaf:interest </span><span class="na"><http://en.wikipedia.org/wiki/Atom_(standard)></span>; + <span class="o">foaf:mbox_sha1sum </span><span class="s">"65b983bb397fb71849da910996741752ace8369b"</span>; + <span class="o">foaf:nick </span><span class="s">"mortenf"</span>; + <span class="o">foaf:weblog </span><span class="na"><http://www.wasab.dk/morten/blog/archives/author/mortenf/></span>. +</pre></div> +</div> +<p>An advantage of this approach over other methods for collapsing BNodes is that I can incrementally process new FOAF documents as they come in 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.</p> +</div> +</div> +<div class="section" id="transitive-traversal"> +<h2>Transitive traversal<a class="headerlink" href="#transitive-traversal" title="Permalink to this headline">¶</a></h2> +<p>How to use the <cite>transitive_objects</cite> and <cite>transitive_subjects</cite> graph methods</p> +<div class="section" id="formal-definition"> +<h3>Formal definition<a class="headerlink" href="#formal-definition" title="Permalink to this headline">¶</a></h3> +<p>The <tt class="xref docutils literal"><span class="pre">transitive_objects()</span></tt> method finds all nodes such that there is a path from subject to one of those nodes using only the predicate property in the triples. The <tt class="xref docutils literal"><span class="pre">transitive_subjects()</span></tt> method is similar; it finds all nodes such that there is a path from the node to the object using only the predicate property.</p> +</div> +<div class="section" id="informal-description-with-an-example"> +<h3>Informal description, with an example<a class="headerlink" href="#informal-description-with-an-example" title="Permalink to this headline">¶</a></h3> +<p>In brief, <tt class="xref docutils literal"><span class="pre">transitive_objects()</span></tt> walks forward in a graph using a particular property, and <tt class="xref docutils literal"><span class="pre">transitive_subjects()</span></tt> walks backward. A good example uses a property <tt class="docutils literal"><span class="pre">ex:parent</span></tt>, the semantics of which are biological parentage. The <tt class="xref docutils literal"><span class="pre">transitive_objects()</span></tt> method would get all the ancestors of a particular person (all nodes such that there is a parent path between the person and the object). The <tt class="xref docutils literal"><span class="pre">transitive_subjects()</span></tt> method would get all the descendants of a particular person (all nodes such that there is a parent path between the node and the person). So, say that your URI is <tt class="docutils literal"><span class="pre">ex:person</span></tt>.</p> +<p>The following code would get all of your (known) ancestors, and then get all the (known) descendants of your maternal grandmother:</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">ConjunctiveGraph</span><span class="p">,</span> <span class="n">URIRef</span> + +<span class="n">person</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'ex:person'</span><span class="p">)</span> +<span class="n">dad</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'ex:d'</span><span class="p">)</span> +<span class="n">mom</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'ex:m'</span><span class="p">)</span> +<span class="n">momOfDad</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'ex:gm0'</span><span class="p">)</span> +<span class="n">momOfMom</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'ex:gm1'</span><span class="p">)</span> +<span class="n">dadOfDad</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'ex:gf0'</span><span class="p">)</span> +<span class="n">dadOfMom</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'ex:gf1'</span><span class="p">)</span> + +<span class="n">parent</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'ex:parent'</span><span class="p">)</span> + +<span class="n">g</span> <span class="o">=</span> <span class="n">ConjunctiveGraph</span><span class="p">()</span> +<span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">person</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">dad</span><span class="p">))</span> +<span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">person</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">mom</span><span class="p">))</span> +<span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">dad</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">momOfDad</span><span class="p">))</span> +<span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">dad</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">dadOfDad</span><span class="p">))</span> +<span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">mom</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">momOfMom</span><span class="p">))</span> +<span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">mom</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">dadOfMom</span><span class="p">))</span> + +<span class="k">print</span> <span class="s">"Parents, forward from `ex:person`:"</span> +<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">transitive_objects</span><span class="p">(</span><span class="n">person</span><span class="p">,</span> <span class="n">parent</span><span class="p">):</span> + <span class="k">print</span> <span class="n">i</span> + +<span class="k">print</span> <span class="s">"Parents, *backward* from `ex:gm1`:"</span> +<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">transitive_subjects</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">momOfMom</span><span class="p">):</span> + <span class="k">print</span> <span class="n">i</span> +</pre></div> +</div> +<div class="admonition warning"> +<p class="first admonition-title">Warning</p> +<p class="last">The <tt class="xref docutils literal"><span class="pre">transitive_objects()</span></tt> method has the start node as the <em>first</em> argument, but the <tt class="xref docutils literal"><span class="pre">transitive_subjects()</span></tt> method has the start node as the <em>second</em> argument.</p> +</div> +</div> +</div> +<div class="section" id="film-py"> +<h2>film.py<a class="headerlink" href="#film-py" title="Permalink to this headline">¶</a></h2> +<div class="highlight-python"><div class="highlight"><pre><span class="c">#!/usr/bin/env python</span> +<span class="sd">""" film.py: a simple tool to manage your movies review</span> +<span class="sd">Simon Rozet, http://atonie.org/</span> + +<span class="sd">@@ :</span> +<span class="sd">- manage directors and writers</span> +<span class="sd">- manage actors</span> +<span class="sd">- handle non IMDB uri</span> +<span class="sd">- markdown support in comment</span> + +<span class="sd">--</span> +<span class="sd">Usage:</span> +<span class="sd"> film.py whoami "John Doe <john@doe.org>"</span> +<span class="sd"> Initialize the store and set your name and email.</span> +<span class="sd"> film.py whoami</span> +<span class="sd"> Tell you who you are</span> +<span class="sd"> film.py http://www.imdb.com/title/tt0105236/</span> +<span class="sd"> Review the movie "Reservoir Dogs"</span> +<span class="sd">"""</span> +<span class="kn">import</span> <span class="nn">datetime</span><span class="o">,</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">re</span><span class="o">,</span> <span class="nn">time</span><span class="o">,</span> <span class="nn">imdb</span> +<span class="kn">from</span> <span class="nn">rdflib</span> <span class="kn">import</span> <span class="n">BNode</span><span class="p">,</span> <span class="n">ConjunctiveGraph</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">,</span> <span class="n">Literal</span><span class="p">,</span> <span class="n">Namespace</span><span class="p">,</span> <span class="n">RDF</span> + +<span class="c">#storefn = os.path.expanduser('~/movies.n3')</span> +<span class="n">storefn</span> <span class="o">=</span> <span class="s">'/home/simon/codes/film.dev/movies.n3'</span> +<span class="n">storeuri</span> <span class="o">=</span> <span class="s">'file://'</span><span class="o">+</span><span class="n">storefn</span> +<span class="n">title</span> <span class="o">=</span> <span class="s">'Movies viewed by </span><span class="si">%s</span><span class="s">'</span> + +<span class="n">r_who</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s">'^(.*?) <([a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9_-]+(\.[a-z0-9_-]+)+)>$'</span><span class="p">)</span> + +<span class="n">DC</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">(</span><span class="s">'http://purl.org/dc/elements/1.1/'</span><span class="p">)</span> +<span class="n">FOAF</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">(</span><span class="s">'http://xmlns.com/foaf/0.1/'</span><span class="p">)</span> +<span class="n">IMDB</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">(</span><span class="s">'http://www.csd.abdn.ac.uk/~ggrimnes/dev/imdb/IMDB#'</span><span class="p">)</span> +<span class="n">REV</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">(</span><span class="s">'http://purl.org/stuff/rev#'</span><span class="p">)</span> + +<span class="k">class</span> <span class="nc">Store</span><span class="p">:</span> + <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span> <span class="o">=</span> <span class="n">ConjunctiveGraph</span><span class="p">()</span> + <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">storefn</span><span class="p">):</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">storeuri</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s">'n3'</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">'dc'</span><span class="p">,</span> <span class="s">'http://purl.org/dc/elements/1.1/'</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">'foaf'</span><span class="p">,</span> <span class="s">'http://xmlns.com/foaf/0.1/'</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">'imdb'</span><span class="p">,</span> <span class="s">'http://www.csd.abdn.ac.uk/~ggrimnes/dev/imdb/IMDB#'</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">'rev'</span><span class="p">,</span> <span class="s">'http://purl.org/stuff/rev#'</span><span class="p">)</span> + + <span class="k">def</span> <span class="nf">save</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">serialize</span><span class="p">(</span><span class="n">storeuri</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s">'n3'</span><span class="p">)</span> + + <span class="k">def</span> <span class="nf">who</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">who</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span> + <span class="k">if</span> <span class="n">who</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> + <span class="n">name</span><span class="p">,</span> <span class="n">email</span> <span class="o">=</span> <span class="p">(</span><span class="n">r_who</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">who</span><span class="p">)</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mf">1</span><span class="p">),</span> <span class="n">r_who</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">who</span><span class="p">)</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mf">2</span><span class="p">))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">URIRef</span><span class="p">(</span><span class="n">storeuri</span><span class="p">),</span> <span class="n">DC</span><span class="p">[</span><span class="s">'title'</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="n">title</span> <span class="o">%</span> <span class="n">name</span><span class="p">)))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">URIRef</span><span class="p">(</span><span class="n">storeuri</span><span class="o">+</span><span class="s">'#author'</span><span class="p">),</span> <span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="n">FOAF</span><span class="p">[</span><span class="s">'Person'</span><span class="p">]))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">URIRef</span><span class="p">(</span><span class="n">storeuri</span><span class="o">+</span><span class="s">'#author'</span><span class="p">),</span> <span class="n">FOAF</span><span class="p">[</span><span class="s">'name'</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="n">name</span><span class="p">)))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">URIRef</span><span class="p">(</span><span class="n">storeuri</span><span class="o">+</span><span class="s">'#author'</span><span class="p">),</span> <span class="n">FOAF</span><span class="p">[</span><span class="s">'mbox'</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="n">email</span><span class="p">)))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">save</span><span class="p">()</span> + <span class="k">else</span><span class="p">:</span> + <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">objects</span><span class="p">(</span><span class="n">URIRef</span><span class="p">(</span><span class="n">storeuri</span><span class="o">+</span><span class="s">'#author'</span><span class="p">),</span> <span class="n">FOAF</span><span class="p">[</span><span class="s">'name'</span><span class="p">])</span> + + <span class="k">def</span> <span class="nf">new_movie</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">movie</span><span class="p">):</span> + <span class="n">movieuri</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'http://www.imdb.com/title/tt</span><span class="si">%s</span><span class="s">/'</span> <span class="o">%</span> <span class="n">movie</span><span class="o">.</span><span class="n">movieID</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">movieuri</span><span class="p">,</span> <span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="n">IMDB</span><span class="p">[</span><span class="s">'Movie'</span><span class="p">]))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">movieuri</span><span class="p">,</span> <span class="n">DC</span><span class="p">[</span><span class="s">'title'</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="n">movie</span><span class="p">[</span><span class="s">'title'</span><span class="p">])))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">movieuri</span><span class="p">,</span> <span class="n">IMDB</span><span class="p">[</span><span class="s">'year'</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">movie</span><span class="p">[</span><span class="s">'year'</span><span class="p">]))))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">save</span><span class="p">()</span> + + <span class="k">def</span> <span class="nf">new_review</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">movie</span><span class="p">,</span> <span class="n">date</span><span class="p">,</span> <span class="n">rating</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span> + <span class="n">review</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> <span class="c"># @@ humanize the identifier (something like #rev-$date)</span> + <span class="n">movieuri</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'http://www.imdb.com/title/tt</span><span class="si">%s</span><span class="s">/'</span> <span class="o">%</span> <span class="n">movie</span><span class="o">.</span><span class="n">movieID</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">movieuri</span><span class="p">,</span> <span class="n">REV</span><span class="p">[</span><span class="s">'hasReview'</span><span class="p">],</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'</span><span class="si">%s</span><span class="s">#</span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">storeuri</span><span class="p">,</span> <span class="n">review</span><span class="p">))))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">review</span><span class="p">,</span> <span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="n">REV</span><span class="p">[</span><span class="s">'Review'</span><span class="p">]))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">review</span><span class="p">,</span> <span class="n">DC</span><span class="p">[</span><span class="s">'date'</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="n">date</span><span class="p">)))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">review</span><span class="p">,</span> <span class="n">REV</span><span class="p">[</span><span class="s">'maxRating'</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="mf">5</span><span class="p">)))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">review</span><span class="p">,</span> <span class="n">REV</span><span class="p">[</span><span class="s">'minRating'</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="mf">0</span><span class="p">)))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">review</span><span class="p">,</span> <span class="n">REV</span><span class="p">[</span><span class="s">'reviewer'</span><span class="p">],</span> <span class="n">URIRef</span><span class="p">(</span><span class="n">storeuri</span><span class="o">+</span><span class="s">'#author'</span><span class="p">)))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">review</span><span class="p">,</span> <span class="n">REV</span><span class="p">[</span><span class="s">'rating'</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="n">rating</span><span class="p">)))</span> + <span class="k">print</span> <span class="n">comment</span> + <span class="k">if</span> <span class="n">comment</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> + <span class="bp">self</span><span class="o">.</span><span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">review</span><span class="p">,</span> <span class="n">REV</span><span class="p">[</span><span class="s">'text'</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="n">comment</span><span class="p">)))</span> + <span class="bp">self</span><span class="o">.</span><span class="n">save</span><span class="p">()</span> + + <span class="k">def</span> <span class="nf">movie_is_in</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">uri</span><span class="p">):</span> + <span class="k">return</span> <span class="p">(</span><span class="n">URIRef</span><span class="p">(</span><span class="n">uri</span><span class="p">),</span> <span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="n">IMDB</span><span class="p">[</span><span class="s">'Movie'</span><span class="p">])</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">graph</span> + +<span class="k">def</span> <span class="nf">help</span><span class="p">():</span> + <span class="k">print</span> <span class="n">__doc__</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">'--'</span><span class="p">)[</span><span class="mf">1</span><span class="p">]</span> + +<span class="k">def</span> <span class="nf">main</span><span class="p">(</span><span class="n">argv</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span> + <span class="k">if</span> <span class="ow">not</span> <span class="n">argv</span><span class="p">:</span> + <span class="n">argv</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span> + <span class="n">s</span> <span class="o">=</span> <span class="n">Store</span><span class="p">()</span> + <span class="k">if</span> <span class="n">argv</span><span class="p">[</span><span class="mf">1</span><span class="p">]</span> <span class="ow">in</span> <span class="p">(</span><span class="s">'help'</span><span class="p">,</span> <span class="s">'--help'</span><span class="p">,</span> <span class="s">'h'</span><span class="p">,</span> <span class="s">'-h'</span><span class="p">):</span> + <span class="n">help</span><span class="p">()</span> + <span class="k">elif</span> <span class="n">argv</span><span class="p">[</span><span class="mf">1</span><span class="p">]</span> <span class="o">==</span> <span class="s">'whoami'</span><span class="p">:</span> + <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">storefn</span><span class="p">):</span> + <span class="k">print</span> <span class="nb">list</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">who</span><span class="p">())[</span><span class="mf">0</span><span class="p">]</span> + <span class="k">else</span><span class="p">:</span> + <span class="n">s</span><span class="o">.</span><span class="n">who</span><span class="p">(</span><span class="n">argv</span><span class="p">[</span><span class="mf">2</span><span class="p">])</span> + <span class="k">elif</span> <span class="n">argv</span><span class="p">[</span><span class="mf">1</span><span class="p">]</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">'http://www.imdb.com/title/tt'</span><span class="p">):</span> + <span class="k">if</span> <span class="n">s</span><span class="o">.</span><span class="n">movie_is_in</span><span class="p">(</span><span class="n">argv</span><span class="p">[</span><span class="mf">1</span><span class="p">]):</span> + <span class="k">raise</span> + <span class="k">else</span><span class="p">:</span> + <span class="n">i</span> <span class="o">=</span> <span class="n">imdb</span><span class="o">.</span><span class="n">IMDb</span><span class="p">()</span> + <span class="n">movie</span> <span class="o">=</span> <span class="n">i</span><span class="o">.</span><span class="n">get_movie</span><span class="p">(</span><span class="n">argv</span><span class="p">[</span><span class="mf">1</span><span class="p">][</span><span class="nb">len</span><span class="p">(</span><span class="s">'http://www.imdb.com/title/tt'</span><span class="p">):</span><span class="o">-</span><span class="mf">1</span><span class="p">])</span> + <span class="k">print</span> <span class="s">'</span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">)'</span> <span class="o">%</span> <span class="p">(</span><span class="n">movie</span><span class="p">[</span><span class="s">'title'</span><span class="p">]</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s">'utf-8'</span><span class="p">),</span> <span class="n">movie</span><span class="p">[</span><span class="s">'year'</span><span class="p">]</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s">'utf-8'</span><span class="p">))</span> + <span class="k">for</span> <span class="n">director</span> <span class="ow">in</span> <span class="n">movie</span><span class="p">[</span><span class="s">'director'</span><span class="p">]:</span> + <span class="k">print</span> <span class="s">'directed by: </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">director</span><span class="p">[</span><span class="s">'name'</span><span class="p">]</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s">'utf-8'</span><span class="p">)</span> + <span class="k">for</span> <span class="n">writer</span> <span class="ow">in</span> <span class="n">movie</span><span class="p">[</span><span class="s">'writer'</span><span class="p">]:</span> + <span class="k">print</span> <span class="s">'writed by: </span><span class="si">%s</span><span class="s">'</span> <span class="o">%</span> <span class="n">writer</span><span class="p">[</span><span class="s">'name'</span><span class="p">]</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s">'utf-8'</span><span class="p">)</span> + <span class="n">s</span><span class="o">.</span><span class="n">new_movie</span><span class="p">(</span><span class="n">movie</span><span class="p">)</span> + <span class="n">rating</span> <span class="o">=</span> <span class="bp">None</span> + <span class="k">while</span> <span class="ow">not</span> <span class="n">rating</span> <span class="ow">or</span> <span class="p">(</span><span class="n">rating</span> <span class="o">></span> <span class="mf">5</span> <span class="ow">or</span> <span class="n">rating</span> <span class="o"><=</span> <span class="mf">0</span><span class="p">):</span> + <span class="k">try</span><span class="p">:</span> + <span class="n">rating</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">raw_input</span><span class="p">(</span><span class="s">'Rating (on five): '</span><span class="p">))</span> + <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> + <span class="n">rating</span> <span class="o">=</span> <span class="bp">None</span> + <span class="n">date</span> <span class="o">=</span> <span class="bp">None</span> + <span class="k">while</span> <span class="ow">not</span> <span class="n">date</span><span class="p">:</span> + <span class="k">try</span><span class="p">:</span> + <span class="n">i</span> <span class="o">=</span> <span class="nb">raw_input</span><span class="p">(</span><span class="s">'Review date (YYYY-MM-DD): '</span><span class="p">)</span> + <span class="n">date</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="p">(</span><span class="o">*</span><span class="n">time</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="s">'%Y-%m-</span><span class="si">%d</span><span class="s">'</span><span class="p">)[:</span><span class="mf">6</span><span class="p">])</span> + <span class="k">except</span><span class="p">:</span> + <span class="n">date</span> <span class="o">=</span> <span class="bp">None</span> + <span class="n">comment</span> <span class="o">=</span> <span class="nb">raw_input</span><span class="p">(</span><span class="s">'Comment: '</span><span class="p">)</span> + <span class="n">s</span><span class="o">.</span><span class="n">new_review</span><span class="p">(</span><span class="n">movie</span><span class="p">,</span> <span class="n">date</span><span class="p">,</span> <span class="n">rating</span><span class="p">,</span> <span class="n">comment</span><span class="p">)</span> + <span class="k">else</span><span class="p">:</span> + <span class="n">help</span><span class="p">()</span> + +<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">'__main__'</span><span class="p">:</span> + <span class="n">main</span><span class="p">()</span> +</pre></div> +</div> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href="">Assorted examples</a><ul> +<li><a class="reference external" href="#conjunctive-graphs">Conjunctive Graphs</a></li> +<li><a class="reference external" href="#two-finger-exercises">Two-finger exercises</a></li> +<li><a class="reference external" href="#update-namespace">Update namespace</a></li> +<li><a class="reference external" href="#sparql-query">SPARQL query</a></li> +<li><a class="reference external" href="#data-reading-exercise">Data reading exercise</a></li> +<li><a class="reference external" href="#example-foaf-smushing">Example Foaf Smushing</a><ul> +<li><a class="reference external" href="#demo-n3">demo.n3</a></li> +<li><a class="reference external" href="#fold-sha1-py">fold_sha1.py</a></li> +<li><a class="reference external" href="#output">Output</a></li> +</ul> +</li> +<li><a class="reference external" href="#transitive-traversal">Transitive traversal</a><ul> +<li><a class="reference external" href="#formal-definition">Formal definition</a></li> +<li><a class="reference external" href="#informal-description-with-an-example">Informal description, with an example</a></li> +</ul> +</li> +<li><a class="reference external" href="#film-py">film.py</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="graphs_bnodes.html" + title="previous chapter">Graphs, Named Graphs and Blank Nodes</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="addons.html" + title="next chapter">Additions</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="_sources/assorted_examples.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="addons.html" title="Additions" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="graphs_bnodes.html" title="Graphs, Named Graphs and Blank Nodes" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/genindex.html b/docs/_build/html/genindex.html new file mode 100644 index 00000000..661b2cd3 --- /dev/null +++ b/docs/_build/html/genindex.html @@ -0,0 +1,337 @@ +<!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>Index — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="_static/default.css" type="text/css" /> + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="_static/jquery.js"></script> + <script type="text/javascript" src="_static/doctools.js"></script> + <link rel="index" title="Index" href="" /> + <link rel="search" title="Search" href="search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="index.html" /> + </head> + <body> + <div class="related"> + <h3>Navigation</h3> + <ul> + <li class="right" style="margin-right: 10px"> + <a href="" title="General Index" + accesskey="I">index</a></li> + <li class="right" > + <a href="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + + <h1 id="index">Index</h1> + + <a href="#_"><strong>_</strong></a> | <a href="#A"><strong>A</strong></a> | <a href="#B"><strong>B</strong></a> | <a href="#C"><strong>C</strong></a> | <a href="#D"><strong>D</strong></a> | <a href="#G"><strong>G</strong></a> | <a href="#I"><strong>I</strong></a> | <a href="#J"><strong>J</strong></a> | <a href="#L"><strong>L</strong></a> | <a href="#N"><strong>N</strong></a> | <a href="#O"><strong>O</strong></a> | <a href="#P"><strong>P</strong></a> | <a href="#Q"><strong>Q</strong></a> | <a href="#R"><strong>R</strong></a> | <a href="#S"><strong>S</strong></a> | <a href="#T"><strong>T</strong></a> | <a href="#U"><strong>U</strong></a> | <a href="#V"><strong>V</strong></a> + + <hr /> + + +<h2 id="_">_</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="univrdfstore.html#rdflib.store.Store.__len__">__len__() (rdflib.store.Store method)</a></dt> +<dt><a href="modules/others.html#rdflib.term.Statement.__new__">__new__() (rdflib.term.Statement static method)</a></dt></dl></td><td width="33%" valign="top"><dl> +<dt><a href="modules/others.html#rdflib.term.Statement.__reduce__">__reduce__() (rdflib.term.Statement method)</a></dt> +</dl></td></tr></table> + +<h2 id="A">A</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.absolutize">absolutize() (rdflib.graph.Graph method)</a></dt> +<dt><a href="modules/graphs/conjunctive_graph.html#rdflib.graph.ConjunctiveGraph.add">add() (rdflib.graph.ConjunctiveGraph method)</a></dt> + <dd><dl> + <dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.add">(rdflib.graph.Graph method)</a>, <a href="graph_utilities.html#rdflib.graph.Graph.add">[1]</a></dt> + <dt><a href="univrdfstore.html#rdflib.store.Store.add">(rdflib.store.Store method)</a></dt> + </dl></dd></dl></td><td width="33%" valign="top"><dl> +<dt><a href="modules/graphs/conjunctive_graph.html#rdflib.graph.ConjunctiveGraph.addN">addN() (rdflib.graph.ConjunctiveGraph method)</a></dt> + <dd><dl> + <dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.addN">(rdflib.graph.Graph method)</a></dt> + </dl></dd> +<dt><a href="modules/others.html#rdflib.collection.Collection.append">append() (rdflib.collection.Collection method)</a></dt> +</dl></td></tr></table> + +<h2 id="B">B</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.bind">bind() (rdflib.graph.Graph method)</a></dt> + <dd><dl> + <dt><a href="univrdfstore.html#rdflib.store.Store.bind">(rdflib.store.Store method)</a></dt> + </dl></dd></dl></td><td width="33%" valign="top"><dl> +<dt><a href="modules/nodes/bnode.html#rdflib.term.BNode">BNode (class in rdflib.term)</a></dt> +</dl></td></tr></table> + +<h2 id="C">C</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.close">close() (rdflib.graph.Graph method)</a></dt> + <dd><dl> + <dt><a href="univrdfstore.html#rdflib.store.Store.close">(rdflib.store.Store method)</a></dt> + </dl></dd> +<dt><a href="modules/others.html#rdflib.collection.Collection">Collection (class in rdflib.collection)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.comment">comment() (rdflib.graph.Graph method)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.commit">commit() (rdflib.graph.Graph method)</a></dt></dl></td><td width="33%" valign="top"><dl> +<dt><a href="modules/graphs/conjunctive_graph.html#rdflib.graph.ConjunctiveGraph">ConjunctiveGraph (class in rdflib.graph)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.connected">connected() (rdflib.graph.Graph method)</a></dt> +<dt><a href="modules/graphs/conjunctive_graph.html#rdflib.graph.ConjunctiveGraph.context_id">context_id() (rdflib.graph.ConjunctiveGraph method)</a></dt> +<dt><a href="modules/graphs/conjunctive_graph.html#rdflib.graph.ConjunctiveGraph.contexts">contexts() (rdflib.graph.ConjunctiveGraph method)</a>, <a href="univrdfstore.html#rdflib.graph.ConjunctiveGraph.contexts">[1]</a></dt> +</dl></td></tr></table> + +<h2 id="D">D</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.destroy">destroy() (rdflib.graph.Graph method)</a></dt> + <dd><dl> + <dt><a href="univrdfstore.html#rdflib.store.Store.destroy">(rdflib.store.Store method)</a></dt> + </dl></dd></dl></td><td width="33%" valign="top"><dl> +</dl></td></tr></table> + +<h2 id="G">G</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/graphs/conjunctive_graph.html#rdflib.graph.ConjunctiveGraph.get_context">get_context() (rdflib.graph.ConjunctiveGraph method)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph">Graph (class in rdflib.graph)</a></dt></dl></td><td width="33%" valign="top"><dl> +</dl></td></tr></table> + +<h2 id="I">I</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/nodes/identifier.html#rdflib.term.Identifier">Identifier (class in rdflib.term)</a></dt> +<dt><a href="modules/others.html#rdflib.collection.Collection.index">index() (rdflib.collection.Collection method)</a></dt> +<dt><a href="modules/others.html#rdflib.textindex.TextIndex.index_graph">index_graph() (rdflib.textindex.TextIndex method)</a></dt></dl></td><td width="33%" valign="top"><dl> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.items">items() (rdflib.graph.Graph method)</a></dt> +</dl></td></tr></table> + +<h2 id="J">J</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/others.html#rdflib.journal.JournalReader">JournalReader (class in rdflib.journal)</a></dt> +<dt><a href="modules/others.html#rdflib.journal.JournalWriter">JournalWriter (class in rdflib.journal)</a></dt></dl></td><td width="33%" valign="top"><dl> +</dl></td></tr></table> + +<h2 id="L">L</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.label">label() (rdflib.graph.Graph method)</a></dt> +<dt><a href="modules/others.html#rdflib.textindex.TextIndex.link_to">link_to() (rdflib.textindex.TextIndex method)</a></dt></dl></td><td width="33%" valign="top"><dl> +<dt><a href="modules/nodes/literal.html#rdflib.term.Literal">Literal (class in rdflib.term)</a></dt> +</dl></td></tr></table> + +<h2 id="N">N</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/others.html#rdflib.collection.Collection.n3">n3() (rdflib.collection.Collection method)</a></dt> + <dd><dl> + <dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.n3">(rdflib.graph.Graph method)</a></dt> + </dl></dd> +<dt><a href="gettingstarted.html#rdflib.syntax.parsers.N3Parser.N3Parser">N3Parser (class in rdflib.syntax.parsers.N3Parser)</a></dt> +<dt><a href="namespace_utilities.html#rdflib.namespace.Namespace">Namespace (class in rdflib.namespace)</a></dt> +<dt><a href="univrdfstore.html#rdflib.store.Store.namespace">namespace() (rdflib.store.Store method)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.namespaces">namespaces() (rdflib.graph.Graph method)</a></dt> + <dd><dl> + <dt><a href="univrdfstore.html#rdflib.store.Store.namespaces">(rdflib.store.Store method)</a></dt> + </dl></dd></dl></td><td width="33%" valign="top"><dl> +<dt><a href="modules/nodes/node.html#rdflib.term.Node">Node (class in rdflib.term)</a></dt> +<dt><a href="gettingstarted.html#rdflib.syntax.parsers.NTParser.NTParser">NTParser (class in rdflib.syntax.parsers.NTParser)</a></dt> +<dt><a href="gettingstarted.html#rdflib.syntax.parsers.ntriples.NTriplesParser">NTriplesParser (class in rdflib.syntax.parsers.ntriples)</a></dt> +</dl></td></tr></table> + +<h2 id="O">O</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.objects">objects() (rdflib.graph.Graph method)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.open">open() (rdflib.graph.Graph method)</a></dt> + <dd><dl> + <dt><a href="univrdfstore.html#rdflib.store.Store.open">(rdflib.store.Store method)</a></dt> + </dl></dd></dl></td><td width="33%" valign="top"><dl> +</dl></td></tr></table> + +<h2 id="P">P</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/graphs/conjunctive_graph.html#rdflib.graph.ConjunctiveGraph.parse">parse() (rdflib.graph.ConjunctiveGraph method)</a></dt> + <dd><dl> + <dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.parse">(rdflib.graph.Graph method)</a>, <a href="gettingstarted.html#rdflib.graph.Graph.parse">[1]</a>, <a href="graph_utilities.html#rdflib.graph.Graph.parse">[2]</a></dt> + <dt><a href="gettingstarted.html#rdflib.syntax.parsers.ntriples.NTriplesParser.parse">(rdflib.syntax.parsers.ntriples.NTriplesParser method)</a></dt> + </dl></dd> +<dt><a href="gettingstarted.html#rdflib.syntax.parsers.ntriples.NTriplesParser.parsestring">parsestring() (rdflib.syntax.parsers.ntriples.NTriplesParser method)</a></dt></dl></td><td width="33%" valign="top"><dl> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.predicate_objects">predicate_objects() (rdflib.graph.Graph method)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.predicates">predicates() (rdflib.graph.Graph method)</a></dt> +<dt><a href="univrdfstore.html#rdflib.store.Store.prefix">prefix() (rdflib.store.Store method)</a></dt> +</dl></td></tr></table> + +<h2 id="Q">Q</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/graphs/conjunctive_graph.html#rdflib.graph.ConjunctiveGraph.quads">quads() (rdflib.graph.ConjunctiveGraph method)</a>, <a href="univrdfstore.html#rdflib.graph.ConjunctiveGraph.quads">[1]</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.query">query() (rdflib.graph.Graph method)</a>, <a href="gettingstarted.html#rdflib.graph.Graph.query">[1]</a></dt> +<dt><a href="modules/others.html#rdflib.query.result.QueryResult">QueryResult (class in rdflib.query.result)</a></dt></dl></td><td width="33%" valign="top"><dl> +<dt><a href="graphterms.html#rdflib.graph.QuotedGraph">QuotedGraph (class in rdflib.graph)</a>, <a href="modules/nodes/quoted_graph.html#rdflib.graph.QuotedGraph">[1]</a></dt> +</dl></td></tr></table> + +<h2 id="R">R</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/others.html#module-rdflib.collection">rdflib.collection (module)</a></dt> +<dt><a href="modules/graphs/index.html#module-rdflib.graph">rdflib.graph (module)</a>, <a href="modules/graphs/conjunctive_graph.html#module-rdflib.graph">[1]</a></dt> +<dt><a href="modules/others.html#module-rdflib.journal">rdflib.journal (module)</a></dt> +<dt><a href="namespace_utilities.html#module-rdflib.namespace">rdflib.namespace (module)</a></dt> +<dt><a href="modules/others.html#module-rdflib.parser">rdflib.parser (module)</a></dt> +<dt><a href="modules/others.html#module-rdflib.query">rdflib.query (module)</a></dt> +<dt><a href="modules/others.html#module-rdflib.query.result">rdflib.query.result (module)</a></dt> +<dt><a href="modules/others.html#module-rdflib.sparql">rdflib.sparql (module)</a></dt> +<dt><a href="modules/others.html#module-rdflib.store">rdflib.store (module)</a></dt> +<dt><a href="modules/others.html#module-rdflib.syntax">rdflib.syntax (module)</a></dt> +<dt><a href="gettingstarted.html#module-rdflib.syntax.parsers">rdflib.syntax.parsers (module)</a></dt> +<dt><a href="gettingstarted.html#module-rdflib.syntax.parsers.n3p">rdflib.syntax.parsers.n3p (module)</a></dt> +<dt><a href="gettingstarted.html#module-rdflib.syntax.parsers.N3Parser">rdflib.syntax.parsers.N3Parser (module)</a></dt> +<dt><a href="gettingstarted.html#module-rdflib.syntax.parsers.NTParser">rdflib.syntax.parsers.NTParser (module)</a></dt></dl></td><td width="33%" valign="top"><dl> +<dt><a href="gettingstarted.html#module-rdflib.syntax.parsers.ntriples">rdflib.syntax.parsers.ntriples (module)</a></dt> +<dt><a href="gettingstarted.html#module-rdflib.syntax.parsers.RDFXMLParser">rdflib.syntax.parsers.RDFXMLParser (module)</a></dt> +<dt><a href="gettingstarted.html#module-rdflib.syntax.parsers.TriXParser">rdflib.syntax.parsers.TriXParser (module)</a></dt> +<dt><a href="graphterms.html#module-rdflib.term">rdflib.term (module)</a>, <a href="modules/nodes/identifier.html#module-rdflib.term">[1]</a>, <a href="modules/nodes/uriref.html#module-rdflib.term">[2]</a>, <a href="modules/others.html#module-rdflib.term">[3]</a>, <a href="modules/nodes/bnode.html#module-rdflib.term">[4]</a>, <a href="modules/nodes/node.html#module-rdflib.term">[5]</a>, <a href="modules/nodes/literal.html#module-rdflib.term">[6]</a>, <a href="modules/nodes/variable.html#module-rdflib.term">[7]</a></dt> +<dt><a href="modules/others.html#module-rdflib.textindex">rdflib.textindex (module)</a></dt> +<dt><a href="gettingstarted.html#rdflib.syntax.parsers.RDFXMLParser.RDFXMLParser">RDFXMLParser (class in rdflib.syntax.parsers.RDFXMLParser)</a></dt> +<dt><a href="gettingstarted.html#rdflib.syntax.parsers.ntriples.NTriplesParser.readline">readline() (rdflib.syntax.parsers.ntriples.NTriplesParser method)</a></dt> +<dt><a href="graphterms.html#rdflib.graph.ReadOnlyGraphAggregate">ReadOnlyGraphAggregate (class in rdflib.graph)</a></dt> +<dt><a href="modules/graphs/conjunctive_graph.html#rdflib.graph.ConjunctiveGraph.remove">remove() (rdflib.graph.ConjunctiveGraph method)</a></dt> + <dd><dl> + <dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.remove">(rdflib.graph.Graph method)</a>, <a href="graph_utilities.html#rdflib.graph.Graph.remove">[1]</a></dt> + <dt><a href="univrdfstore.html#rdflib.store.Store.remove">(rdflib.store.Store method)</a></dt> + </dl></dd> +<dt><a href="modules/graphs/conjunctive_graph.html#rdflib.graph.ConjunctiveGraph.remove_context">remove_context() (rdflib.graph.ConjunctiveGraph method)</a>, <a href="univrdfstore.html#rdflib.graph.ConjunctiveGraph.remove_context">[1]</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.rollback">rollback() (rdflib.graph.Graph method)</a></dt> +</dl></td></tr></table> + +<h2 id="S">S</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/others.html#rdflib.textindex.TextIndex.search">search() (rdflib.textindex.TextIndex method)</a></dt> +<dt><a href="graphterms.html#rdflib.graph.Seq">Seq (class in rdflib.graph)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.seq">seq() (rdflib.graph.Graph method)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.serialize">serialize() (rdflib.graph.Graph method)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.set">set() (rdflib.graph.Graph method)</a></dt> +<dt><a href="modules/others.html#rdflib.term.Statement">Statement (class in rdflib.term)</a></dt></dl></td><td width="33%" valign="top"><dl> +<dt><a href="modules/others.html#rdflib.parser.StringInputSource">StringInputSource (class in rdflib.parser)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.subject_objects">subject_objects() (rdflib.graph.Graph method)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.subject_predicates">subject_predicates() (rdflib.graph.Graph method)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.subjects">subjects() (rdflib.graph.Graph method)</a></dt> +<dt><a href="modules/others.html#rdflib.textindex.TextIndex.subscribe_to">subscribe_to() (rdflib.textindex.TextIndex method)</a></dt> +</dl></td></tr></table> + +<h2 id="T">T</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/others.html#rdflib.textindex.TextIndex.term_strings">term_strings() (rdflib.textindex.TextIndex method)</a></dt> +<dt><a href="modules/others.html#rdflib.textindex.TextIndex.terms">terms() (rdflib.textindex.TextIndex method)</a></dt> +<dt><a href="modules/others.html#rdflib.textindex.TextIndex">TextIndex (class in rdflib.textindex)</a></dt> +<dt><a href="modules/nodes/literal.html#rdflib.term.Literal.toPython">toPython() (rdflib.term.Literal method)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.transitive_objects">transitive_objects() (rdflib.graph.Graph method)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.transitive_subjects">transitive_subjects() (rdflib.graph.Graph method)</a></dt> +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.transitiveClosure">transitiveClosure() (rdflib.graph.Graph method)</a></dt></dl></td><td width="33%" valign="top"><dl> +<dt><a href="modules/graphs/conjunctive_graph.html#rdflib.graph.ConjunctiveGraph.triples">triples() (rdflib.graph.ConjunctiveGraph method)</a></dt> + <dd><dl> + <dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.triples">(rdflib.graph.Graph method)</a>, <a href="graph_utilities.html#rdflib.graph.Graph.triples">[1]</a></dt> + <dt><a href="univrdfstore.html#rdflib.store.Store.triples">(rdflib.store.Store method)</a></dt> + </dl></dd> +<dt><a href="modules/graphs/conjunctive_graph.html#rdflib.graph.ConjunctiveGraph.triples_choices">triples_choices() (rdflib.graph.ConjunctiveGraph method)</a></dt> +<dt><a href="gettingstarted.html#rdflib.syntax.parsers.TriXParser.TriXParser">TriXParser (class in rdflib.syntax.parsers.TriXParser)</a></dt> +</dl></td></tr></table> + +<h2 id="U">U</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/nodes/uriref.html#rdflib.term.URIRef">URIRef (class in rdflib.term)</a></dt> +<dt><a href="modules/others.html#rdflib.parser.URLInputSource">URLInputSource (class in rdflib.parser)</a></dt></dl></td><td width="33%" valign="top"><dl> +</dl></td></tr></table> + +<h2 id="V">V</h2> +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> +<dl> + +<dt><a href="modules/graphs/graph.html#rdflib.graph.Graph.value">value() (rdflib.graph.Graph method)</a></dt> +<dt><a href="graphterms.html#rdflib.term.Variable">Variable (class in rdflib.term)</a>, <a href="modules/nodes/variable.html#rdflib.term.Variable">[1]</a></dt></dl></td><td width="33%" valign="top"><dl> +</dl></td></tr></table> + + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + + + + <div id="searchbox" style="display: none"> + <h3>Quick search</h3> + <form class="search" action="search.html" method="get"> + <input type="text" name="q" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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="" title="General Index" + accesskey="I">index</a></li> + <li class="right" > + <a href="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/gettingstarted.html b/docs/_build/html/gettingstarted.html new file mode 100644 index 00000000..9e6bd4e5 --- /dev/null +++ b/docs/_build/html/gettingstarted.html @@ -0,0 +1,461 @@ +<!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>Getting started with rdflib — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="_static/default.css" type="text/css" /> + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="_static/jquery.js"></script> + <script type="text/javascript" src="_static/doctools.js"></script> + <link rel="index" title="Index" href="genindex.html" /> + <link rel="search" title="Search" href="search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="index.html" /> + <link rel="next" title="A Universal RDF Store Interface" href="univrdfstore.html" /> + <link rel="prev" title="rdflib 2.5" href="index.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="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="univrdfstore.html" title="A Universal RDF Store Interface" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="index.html" title="rdflib 2.5" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="getting-started-with-rdflib"> +<span id="gettingstarted"></span><h1>Getting started with rdflib<a class="headerlink" href="#getting-started-with-rdflib" title="Permalink to this headline">¶</a></h1> +<div class="section" id="introduction-to-parsing-rdf-into-rdflib-graphs"> +<h2>Introduction to parsing RDF into rdflib graphs<a class="headerlink" href="#introduction-to-parsing-rdf-into-rdflib-graphs" title="Permalink to this headline">¶</a></h2> +<div class="section" id="reading-an-nt-file"> +<h3>Reading an NT file<a class="headerlink" href="#reading-an-nt-file" title="Permalink to this headline">¶</a></h3> +<p>RDF data has various syntaxes (<tt class="docutils literal"><span class="pre">xml</span></tt>, <tt class="docutils literal"><span class="pre">n3</span></tt>, <tt class="docutils literal"><span class="pre">ntriples</span></tt>, <tt class="docutils literal"><span class="pre">trix</span></tt>, etc) that you might want to read. The simplest format is <tt class="docutils literal"><span class="pre">ntriples</span></tt>. Create the file <tt class="docutils literal"><span class="pre">demo.nt</span></tt> in the current directory with these two lines:</p> +<div class="highlight-n3"><pre><http://bigasterisk.com/foaf.rdf#drewp> \ +<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> \ +<http://xmlns.com/foaf/0.1/Person> . +<http://bigasterisk.com/foaf.rdf#drewp> \ +<http://example.com/says> \ +"Hello world" .</pre> +</div> +<p>In an interactive python interpreter, try this:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">rdflib.graph</span> <span class="kn">import</span> <span class="n">Graph</span> +<span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s">"demo.nt"</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s">"nt"</span><span class="p">)</span> +<span class="go"><Graph identifier=HCbubHJy0 (<class 'rdflib.graph.Graph'>)></span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">2</span> +<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">pprint</span> +<span class="gp">>>> </span><span class="k">for</span> <span class="n">stmt</span> <span class="ow">in</span> <span class="n">g</span><span class="p">:</span> +<span class="gp">... </span> <span class="n">pprint</span><span class="o">.</span><span class="n">pprint</span><span class="p">(</span><span class="n">stmt</span><span class="p">)</span> +<span class="gp">...</span> +<span class="go">(rdflib.term.URIRef('http://bigasterisk.com/foaf.rdf#drewp'),</span> +<span class="go"> rdflib.term.URIRef('http://example.com/says'),</span> +<span class="go"> rdflib.term.Literal(u'Hello world'))</span> +<span class="go">(rdflib.term.URIRef('http://bigasterisk.com/foaf.rdf#drewp'),</span> +<span class="go"> rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),</span> +<span class="go"> rdflib.term.URIRef('http://xmlns.com/foaf/0.1/Person'))</span> +</pre></div> +</div> +<p>The final lines show how rdflib represents the two statements in the file. The statements themselves are just length-3 tuples; and the subjects, predicates, and objects are all rdflib types.</p> +</div> +<div class="section" id="reading-remote-graphs"> +<h3>Reading remote graphs<a class="headerlink" href="#reading-remote-graphs" title="Permalink to this headline">¶</a></h3> +<p>Reading graphs from the net is just as easy:</p> +<div class="highlight-pycon"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s">"http://bigasterisk.com/foaf.rdf"</span><span class="p">)</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">42</span> +</pre></div> +</div> +<p>The format defaults to <tt class="docutils literal"><span class="pre">xml</span></tt>, which is the common format for .rdf files you’ll find on the net.</p> +<p>See also</p> +<dl class="method"> +<dt id="rdflib.graph.Graph.parse"> +<!--[rdflib.graph.Graph.parse]--><tt class="descclassname">Graph.</tt><tt class="descname">parse</tt><big>(</big><em>source=None</em>, <em>publicID=None</em>, <em>format=None</em>, <em>location=None</em>, <em>file=None</em>, <em>data=None</em>, <em>**args</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.parse" title="Permalink to this definition">¶</a></dt> +<dd><p>Parse source adding the resulting triples to the Graph.</p> +<p>The source is specified using one of source, location, file or +data.</p> +<table class="docutils field-list" frame="void" rules="none"> +<col class="field-name" /> +<col class="field-body" /> +<tbody valign="top"> +<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> +<li><cite>source</cite>: An InputSource, file-like object, or string. In the case of a string the string is the location of the source.</li> +<li><cite>location</cite>: A string indicating the relative or absolute URL of the source. Graph’s absolutize method is used if a relative location is specified.</li> +<li><cite>file</cite>: A file-like object.</li> +<li><cite>data</cite>: A string containing the data to be parsed.</li> +<li><cite>format</cite>: Used if format can not be determined from source. Defaults to rdf/xml.</li> +<li><cite>publicID</cite>: 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).</li> +</ul> +</td> +</tr> +<tr class="field"><th class="field-name">Returns:</th><td class="field-body"></td> +</tr> +</tbody> +</table> +<p>self, the graph instance.</p> +<p>Examples:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">my_data</span> <span class="o">=</span> <span class="s">'''</span> +<span class="gp">... </span><span class="s"><rdf:RDF</span> +<span class="gp">... </span><span class="s"> xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'</span> +<span class="gp">... </span><span class="s"> xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'</span> +<span class="gp">... </span><span class="s">></span> +<span class="gp">... </span><span class="s"> <rdf:Description></span> +<span class="gp">... </span><span class="s"> <rdfs:label>Example</rdfs:label></span> +<span class="gp">... </span><span class="s"> <rdfs:comment>This is really just an example.</rdfs:comment></span> +<span class="gp">... </span><span class="s"> </rdf:Description></span> +<span class="gp">... </span><span class="s"></rdf:RDF></span> +<span class="gp">... </span><span class="s">'''</span> +<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">tempfile</span> +<span class="gp">>>> </span><span class="n">file_name</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mktemp</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="nb">file</span><span class="p">(</span><span class="n">file_name</span><span class="p">,</span> <span class="s">"w"</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">my_data</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> +</pre></div> +</div> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">g</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">my_data</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s">"application/rdf+xml"</span><span class="p">)</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">2</span> +</pre></div> +</div> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">g</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">location</span><span class="o">=</span><span class="n">file_name</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s">"application/rdf+xml"</span><span class="p">)</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">2</span> +</pre></div> +</div> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">g</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="nb">file</span><span class="o">=</span><span class="nb">file</span><span class="p">(</span><span class="n">file_name</span><span class="p">,</span> <span class="s">"r"</span><span class="p">),</span> <span class="n">format</span><span class="o">=</span><span class="s">"application/rdf+xml"</span><span class="p">)</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">2</span> +</pre></div> +</div> +</dd></dl> + +</div> +</div> +<div class="section" id="module-rdflib.syntax.parsers.TriXParser"> +<h2>Other parsers supported by rdflib<a class="headerlink" href="#module-rdflib.syntax.parsers.TriXParser" title="Permalink to this headline">¶</a></h2> +<dl class="class"> +<dt id="rdflib.syntax.parsers.N3Parser.N3Parser"> +<!--[rdflib.syntax.parsers.N3Parser.N3Parser]-->class <tt class="descclassname">rdflib.syntax.parsers.N3Parser.</tt><tt class="descname">N3Parser</tt><a class="headerlink" href="#rdflib.syntax.parsers.N3Parser.N3Parser" title="Permalink to this definition">¶</a></dt> +<dd></dd></dl> + +<dl class="class"> +<dt id="rdflib.syntax.parsers.NTParser.NTParser"> +<!--[rdflib.syntax.parsers.NTParser.NTParser]-->class <tt class="descclassname">rdflib.syntax.parsers.NTParser.</tt><tt class="descname">NTParser</tt><a class="headerlink" href="#rdflib.syntax.parsers.NTParser.NTParser" title="Permalink to this definition">¶</a></dt> +<dd></dd></dl> + +<p>N-Triples Parser +License: GPL 2, W3C, BSD, or MIT +Author: Sean B. Palmer, inamidst.com +Documentation: <a class="reference external" href="http://inamidst.com/proj/rdf/ntriples-doc">http://inamidst.com/proj/rdf/ntriples-doc</a></p> +<p>Command line usage:</p> +<div class="highlight-python"><pre>./ntriples.py <URI> - parses URI as N-Triples +./ntriples.py --help - prints out this help message</pre> +</div> +<p># @@ fully empty document?</p> +<dl class="class"> +<dt id="rdflib.syntax.parsers.ntriples.NTriplesParser"> +<!--[rdflib.syntax.parsers.ntriples.NTriplesParser]-->class <tt class="descclassname">rdflib.syntax.parsers.ntriples.</tt><tt class="descname">NTriplesParser</tt><big>(</big><em>sink=None</em><big>)</big><a class="headerlink" href="#rdflib.syntax.parsers.ntriples.NTriplesParser" title="Permalink to this definition">¶</a></dt> +<dd><p>An N-Triples Parser.</p> +<p>Usage:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="n">p</span> <span class="o">=</span> <span class="n">NTriplesParser</span><span class="p">(</span><span class="n">sink</span><span class="o">=</span><span class="n">MySink</span><span class="p">())</span> +<span class="n">sink</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="c"># file; use parsestring for a string</span> +</pre></div> +</div> +<dl class="method"> +<dt id="rdflib.syntax.parsers.ntriples.NTriplesParser.parse"> +<!--[rdflib.syntax.parsers.ntriples.NTriplesParser.parse]--><tt class="descname">parse</tt><big>(</big><em>f</em><big>)</big><a class="headerlink" href="#rdflib.syntax.parsers.ntriples.NTriplesParser.parse" title="Permalink to this definition">¶</a></dt> +<dd>Parse f as an N-Triples file.</dd></dl> + +<dl class="method"> +<dt id="rdflib.syntax.parsers.ntriples.NTriplesParser.parsestring"> +<!--[rdflib.syntax.parsers.ntriples.NTriplesParser.parsestring]--><tt class="descname">parsestring</tt><big>(</big><em>s</em><big>)</big><a class="headerlink" href="#rdflib.syntax.parsers.ntriples.NTriplesParser.parsestring" title="Permalink to this definition">¶</a></dt> +<dd>Parse s as an N-Triples string.</dd></dl> + +<dl class="method"> +<dt id="rdflib.syntax.parsers.ntriples.NTriplesParser.readline"> +<!--[rdflib.syntax.parsers.ntriples.NTriplesParser.readline]--><tt class="descname">readline</tt><big>(</big><big>)</big><a class="headerlink" href="#rdflib.syntax.parsers.ntriples.NTriplesParser.readline" title="Permalink to this definition">¶</a></dt> +<dd>Read an N-Triples line from buffered input.</dd></dl> + +</dd></dl> + +<dl class="class"> +<dt id="rdflib.syntax.parsers.RDFXMLParser.RDFXMLParser"> +<!--[rdflib.syntax.parsers.RDFXMLParser.RDFXMLParser]-->class <tt class="descclassname">rdflib.syntax.parsers.RDFXMLParser.</tt><tt class="descname">RDFXMLParser</tt><a class="headerlink" href="#rdflib.syntax.parsers.RDFXMLParser.RDFXMLParser" title="Permalink to this definition">¶</a></dt> +<dd></dd></dl> + +<dl class="class"> +<dt id="rdflib.syntax.parsers.TriXParser.TriXParser"> +<!--[rdflib.syntax.parsers.TriXParser.TriXParser]-->class <tt class="descclassname">rdflib.syntax.parsers.TriXParser.</tt><tt class="descname">TriXParser</tt><a class="headerlink" href="#rdflib.syntax.parsers.TriXParser.TriXParser" title="Permalink to this definition">¶</a></dt> +<dd>A parser for TriX. See <a class="reference external" href="http://swdev.nokia.com/trix/TriX.html">http://swdev.nokia.com/trix/TriX.html</a></dd></dl> + +</div> +<div class="section" id="introduction-to-using-sparql-to-query-an-rdflib-graph"> +<h2>Introduction to using SPARQL to query an rdflib graph<a class="headerlink" href="#introduction-to-using-sparql-to-query-an-rdflib-graph" title="Permalink to this headline">¶</a></h2> +<div class="section" id="create-an-rdflib-graph"> +<h3>Create an Rdflib Graph<a class="headerlink" href="#create-an-rdflib-graph" title="Permalink to this headline">¶</a></h3> +<p>You might parse some files into a new graph (<span class="target" id="id1">Introduction to parsing RDF into rdflib graphs</span>) or open an on-disk rdflib store.</p> +<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">rdflib.graph</span> <span class="kn">import</span> <span class="n">Graph</span> +<span class="n">g</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> +<span class="n">g</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s">"http://bigasterisk.com/foaf.rdf"</span><span class="p">)</span> +<span class="n">g</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s">"http://www.w3.org/People/Berners-Lee/card.rdf"</span><span class="p">)</span> +</pre></div> +</div> +<p>LiveJournal produces FOAF data for their users, but they seem to use <tt class="docutils literal"><span class="pre">foaf:member_name</span></tt> for a person’s full name. For this demo, I made <tt class="docutils literal"><span class="pre">foaf:name</span></tt> act as a synonym for <tt class="docutils literal"><span class="pre">foaf:member_name</span></tt> (a poor man’s one-way <tt class="docutils literal"><span class="pre">owl:equivalentProperty</span></tt>):</p> +<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">rdflib.namespace</span> <span class="kn">import</span> <span class="n">Namespace</span> +<span class="n">FOAF</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">(</span><span class="s">"http://xmlns.com/foaf/0.1/"</span><span class="p">)</span> +<span class="n">g</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s">"http://danbri.livejournal.com/data/foaf"</span><span class="p">)</span> +<span class="p">[</span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">s</span><span class="p">,</span> <span class="n">FOAF</span><span class="p">[</span><span class="s">'name'</span><span class="p">],</span> <span class="n">n</span><span class="p">))</span> <span class="k">for</span> <span class="n">s</span><span class="p">,</span><span class="n">_</span><span class="p">,</span><span class="n">n</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">triples</span><span class="p">((</span><span class="bp">None</span><span class="p">,</span> <span class="n">FOAF</span><span class="p">[</span><span class="s">'member_name'</span><span class="p">],</span> <span class="bp">None</span><span class="p">))]</span> +</pre></div> +</div> +</div> +<div class="section" id="run-a-query"> +<h3>Run a Query<a class="headerlink" href="#run-a-query" title="Permalink to this headline">¶</a></h3> +<div class="highlight-python"><div class="highlight"><pre><span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">query</span><span class="p">(</span> + <span class="sd">"""SELECT ?aname ?bname</span> +<span class="sd"> WHERE {</span> +<span class="sd"> ?a foaf:knows ?b .</span> +<span class="sd"> ?a foaf:name ?aname .</span> +<span class="sd"> ?b foaf:name ?bname .</span> +<span class="sd"> }"""</span><span class="p">,</span> + <span class="n">initNs</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span><span class="n">foaf</span><span class="o">=</span><span class="n">Namespace</span><span class="p">(</span><span class="s">"http://xmlns.com/foaf/0.1/"</span><span class="p">))):</span> + <span class="k">print</span> <span class="s">"</span><span class="si">%s</span><span class="s"> knows </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="n">row</span> +</pre></div> +</div> +<p>The results are tuples of values in the same order as your SELECT arguments.</p> +<div class="highlight-text"><div class="highlight"><pre>Timothy Berners-Lee knows Edd Dumbill +Timothy Berners-Lee knows Jennifer Golbeck +Timothy Berners-Lee knows Nicholas Gibbins +Timothy Berners-Lee knows Nigel Shadbolt +Dan Brickley knows binzac +Timothy Berners-Lee knows Eric Miller +Drew Perttula knows David McClosky +Timothy Berners-Lee knows Dan Connolly +... +</pre></div> +</div> +</div> +<div class="section" id="namespaces"> +<h3>Namespaces<a class="headerlink" href="#namespaces" title="Permalink to this headline">¶</a></h3> +<p>The <tt class="xref docutils literal"><span class="pre">Graph.parse()</span></tt> <tt class="xref docutils literal"><span class="pre">initNs</span></tt> argument is a dictionary of namespaces to be expanded in the query string. In a large program, it’s common to use the same dict for every single query. You might even hack your graph instance so that the <tt class="docutils literal"><span class="pre">initNs</span></tt> arg is already filled in.</p> +<p>If someone knows how to use the empty prefix (e.g. “?a :knows ?b”), please write about it here and in the <tt class="xref docutils literal"><span class="pre">Graph.query()</span></tt> docs.</p> +<p><em>ewan klein provides the answer, use BASE to set a default namespace ...</em></p> +<div class="highlight-sparql"><div class="highlight"><pre><span class="k">BASE </span><span class="nn"><http://xmlns.com/foaf/0.1/></span> +</pre></div> +</div> +</div> +<div class="section" id="bindings"> +<h3>Bindings<a class="headerlink" href="#bindings" title="Permalink to this headline">¶</a></h3> +<p>Just like with SQL queries, it’s common to run the same query many times with only a few terms changing. rdflib calls this <tt class="docutils literal"><span class="pre">initBindings</span></tt>:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="n">FOAF</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">(</span><span class="s">"http://xmlns.com/foaf/0.1/"</span><span class="p">)</span> +<span class="n">ns</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">foaf</span><span class="o">=</span><span class="n">FOAF</span><span class="p">)</span> +<span class="n">drew</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'http://bigasterisk.com/foaf.rdf#drewp'</span><span class="p">)</span> +<span class="k">for</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="s">"""SELECT ?name</span> +<span class="s"> WHERE { ?p foaf:name ?name }"""</span><span class="p">,</span> + <span class="n">initNs</span><span class="o">=</span><span class="n">ns</span><span class="p">,</span> <span class="n">initBindings</span><span class="o">=</span><span class="p">{</span><span class="s">'?p'</span> <span class="p">:</span> <span class="n">drew</span><span class="p">}):</span> + <span class="k">print</span> <span class="n">row</span> +</pre></div> +</div> +<p>Output:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="p">(</span><span class="n">rdflib</span><span class="o">.</span><span class="n">Literal</span><span class="p">(</span><span class="s">'Drew Perttula'</span><span class="p">,</span> <span class="n">language</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">datatype</span><span class="o">=</span><span class="bp">None</span><span class="p">),)</span> +</pre></div> +</div> +<dl class="method"> +<dt id="rdflib.graph.Graph.query"> +<!--[rdflib.graph.Graph.query]--><tt class="descclassname">Graph.</tt><tt class="descname">query</tt><big>(</big><em>strOrQuery</em>, <em>initBindings={}</em>, <em>initNs={}</em>, <em>DEBUG=False</em>, <em>PARSE_DEBUG=False</em>, <em>dataSetBase=None</em>, <em>processor='sparql'</em>, <em>extensionFunctions={rdflib.term.URIRef('http://www.w3.org/TR/rdf-sparql-query/#describe'): <function describe at 0x15ab130>}</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.query" title="Permalink to this definition">¶</a></dt> +<dd><p>Executes a SPARQL query (eventually will support Versa queries with +same method) against this Graph.</p> +<blockquote> +<ul> +<li><dl class="first docutils"> +<dt><cite>strOrQuery</cite>: Either a string consisting of the SPARQL query or</dt> +<dd><p class="first last">an instance of rdflib.sparql.bison.Query.Query</p> +</dd> +</dl> +</li> +<li><dl class="first docutils"> +<dt><cite>initBindings</cite>: A mapping from a Variable to an RDFLib term (used</dt> +<dd><p class="first last">as initial bindings for SPARQL query)</p> +</dd> +</dl> +</li> +<li><dl class="first docutils"> +<dt><cite>initNS</cite>: A mapping from a namespace prefix to an instance of</dt> +<dd><p class="first last">rdflib.Namespace (used for SPARQL query)</p> +</dd> +</dl> +</li> +<li><dl class="first docutils"> +<dt><cite>DEBUG</cite>: A boolean flag passed on to the SPARQL parser and</dt> +<dd><p class="first last">evaluation engine</p> +</dd> +</dl> +</li> +<li><dl class="first docutils"> +<dt><cite>processor</cite>: The kind of RDF query (must be ‘sparql’ until Versa</dt> +<dd><p class="first last">is ported)</p> +</dd> +</dl> +</li> +<li><dl class="first docutils"> +<dt><cite>USE_PYPARSING</cite>: A flag indicating whether to use the</dt> +<dd><p class="first last">experimental pyparsing parser for SPARQL</p> +</dd> +</dl> +</li> +</ul> +</blockquote> +</dd></dl> + +</div> +</div> +<div class="section" id="store-operations"> +<h2>Store operations<a class="headerlink" href="#store-operations" title="Permalink to this headline">¶</a></h2> +<p>Example code to create a MySQL triple store, add some triples, and serialize the resulting graph.</p> +<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">rdflib</span> +<span class="kn">from</span> <span class="nn">rdflib.graph</span> <span class="kn">import</span> <span class="n">ConjunctiveGraph</span> <span class="k">as</span> <span class="n">Graph</span> +<span class="kn">from</span> <span class="nn">rdflib</span> <span class="kn">import</span> <span class="n">plugin</span> +<span class="kn">from</span> <span class="nn">rdflib.store</span> <span class="kn">import</span> <span class="n">Store</span><span class="p">,</span> <span class="n">NO_STORE</span><span class="p">,</span> <span class="n">VALID_STORE</span> +<span class="kn">from</span> <span class="nn">rdflib.namespace</span> <span class="kn">import</span> <span class="n">Namespace</span> +<span class="kn">from</span> <span class="nn">rdflib.term</span> <span class="kn">import</span> <span class="n">Literal</span> +<span class="kn">from</span> <span class="nn">rdflib.term</span> <span class="kn">import</span> <span class="n">URIRef</span> + +<span class="n">default_graph_uri</span> <span class="o">=</span> <span class="s">"http://rdflib.net/rdfstore"</span> +<span class="n">configString</span> <span class="o">=</span> <span class="s">"host=localhost,user=username,password=password,db=rdfstore"</span> + +<span class="c"># Get the mysql plugin. You may have to install the python mysql libraries</span> +<span class="n">store</span> <span class="o">=</span> <span class="n">plugin</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'MySQL'</span><span class="p">,</span> <span class="n">Store</span><span class="p">)(</span><span class="s">'rdfstore'</span><span class="p">)</span> + +<span class="c"># Open previously created store, or create it if it doesn't exist yet</span> +<span class="n">rt</span> <span class="o">=</span> <span class="n">store</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">configString</span><span class="p">,</span><span class="n">create</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span> +<span class="k">if</span> <span class="n">rt</span> <span class="o">==</span> <span class="n">NO_STORE</span><span class="p">:</span> + <span class="c"># There is no underlying MySQL infrastructure, create it</span> + <span class="n">store</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">configString</span><span class="p">,</span><span class="n">create</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> +<span class="k">else</span><span class="p">:</span> + <span class="k">assert</span> <span class="n">rt</span> <span class="o">==</span> <span class="n">VALID_STORE</span><span class="p">,</span><span class="s">"There underlying store is corrupted"</span> + +<span class="c"># There is a store, use it</span> +<span class="n">graph</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">store</span><span class="p">,</span> <span class="n">identifier</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="n">default_graph_uri</span><span class="p">))</span> + +<span class="k">print</span> <span class="s">"Triples in graph before add: "</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">graph</span><span class="p">)</span> + +<span class="c"># Now we'll add some triples to the graph & commit the changes</span> +<span class="n">rdflib</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">(</span><span class="s">'http://rdflib.net/test/'</span><span class="p">)</span> +<span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">rdflib</span><span class="p">[</span><span class="s">'pic:1'</span><span class="p">],</span> <span class="n">rdflib</span><span class="p">[</span><span class="s">'name'</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'Jane & Bob'</span><span class="p">)))</span> +<span class="n">graph</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">rdflib</span><span class="p">[</span><span class="s">'pic:2'</span><span class="p">],</span> <span class="n">rdflib</span><span class="p">[</span><span class="s">'name'</span><span class="p">],</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'Squirrel in Tree'</span><span class="p">)))</span> +<span class="n">graph</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span> + +<span class="k">print</span> <span class="s">"Triples in graph after add: "</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">graph</span><span class="p">)</span> + +<span class="c"># display the graph in RDF/XML</span> +<span class="k">print</span> <span class="n">graph</span><span class="o">.</span><span class="n">serialize</span><span class="p">()</span> +</pre></div> +</div> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href="">Getting started with rdflib</a><ul> +<li><a class="reference external" href="#introduction-to-parsing-rdf-into-rdflib-graphs">Introduction to parsing RDF into rdflib graphs</a><ul> +<li><a class="reference external" href="#reading-an-nt-file">Reading an NT file</a></li> +<li><a class="reference external" href="#reading-remote-graphs">Reading remote graphs</a></li> +</ul> +</li> +<li><a class="reference external" href="#module-rdflib.syntax.parsers.TriXParser">Other parsers supported by rdflib</a></li> +<li><a class="reference external" href="#introduction-to-using-sparql-to-query-an-rdflib-graph">Introduction to using SPARQL to query an rdflib graph</a><ul> +<li><a class="reference external" href="#create-an-rdflib-graph">Create an Rdflib Graph</a></li> +<li><a class="reference external" href="#run-a-query">Run a Query</a></li> +<li><a class="reference external" href="#namespaces">Namespaces</a></li> +<li><a class="reference external" href="#bindings">Bindings</a></li> +</ul> +</li> +<li><a class="reference external" href="#store-operations">Store operations</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="index.html" + title="previous chapter">rdflib 2.5</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="univrdfstore.html" + title="next chapter">A Universal RDF Store Interface</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="_sources/gettingstarted.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="univrdfstore.html" title="A Universal RDF Store Interface" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="index.html" title="rdflib 2.5" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/graph_merging.html b/docs/_build/html/graph_merging.html new file mode 100644 index 00000000..00765f6d --- /dev/null +++ b/docs/_build/html/graph_merging.html @@ -0,0 +1,272 @@ +<!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>Merging graphs — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="_static/default.css" type="text/css" /> + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="_static/jquery.js"></script> + <script type="text/javascript" src="_static/doctools.js"></script> + <link rel="index" title="Index" href="genindex.html" /> + <link rel="search" title="Search" href="search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="index.html" /> + <link rel="next" title="Graphs, Named Graphs and Blank Nodes" href="graphs_bnodes.html" /> + <link rel="prev" title="Persisting Notation 3 Terms" href="persisting_n3_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="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="graphs_bnodes.html" title="Graphs, Named Graphs and Blank Nodes" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="persisting_n3_terms.html" title="Persisting Notation 3 Terms" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="merging-graphs"> +<h1>Merging graphs<a class="headerlink" href="#merging-graphs" title="Permalink to this headline">¶</a></h1> +<div class="section" id="example-1"> +<h2>Example 1<a class="headerlink" href="#example-1" title="Permalink to this headline">¶</a></h2> +<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">logging</span> + +<span class="n">_logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="n">redfoot_current</span><span class="p">)</span> + +<span class="kn">from</span> <span class="nn">rdflib.Graph</span> <span class="kn">import</span> <span class="n">Graph</span> + +<span class="n">f</span> <span class="o">=</span> <span class="nb">file</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">],</span> <span class="s">"r"</span><span class="p">)</span> + +<span class="n">pairs</span> <span class="o">=</span> <span class="p">[]</span> +<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span> + <span class="k">try</span><span class="p">:</span> + <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> + <span class="n">source</span><span class="p">,</span> <span class="n">destination</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">" "</span><span class="p">)</span> + <span class="k">except</span> <span class="ne">ValueError</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> + <span class="n">_logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">"Could not split '</span><span class="si">%s</span><span class="s">'"</span> <span class="o">%</span> <span class="n">line</span><span class="p">)</span> + <span class="k">continue</span> + <span class="n">source</span><span class="p">,</span> <span class="n">destination</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="n">source</span><span class="p">)</span><span class="o">.</span><span class="n">abstract</span><span class="p">(),</span> <span class="n">URIRef</span><span class="p">(</span><span class="n">destination</span><span class="p">)</span><span class="o">.</span><span class="n">abstract</span><span class="p">()</span> + <span class="k">if</span> <span class="n">destination</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="n">source</span><span class="p">):</span> + <span class="n">_logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">"Skipping </span><span class="si">%s</span><span class="s">-></span><span class="si">%s</span><span class="s"> to avoid inf. loop"</span> <span class="o">%</span> <span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">destination</span><span class="p">))</span> + <span class="k">else</span><span class="p">:</span> + <span class="n">pairs</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">source</span><span class="p">,</span> <span class="n">destination</span><span class="p">))</span> + +<span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> + +<span class="n">nothing_merged</span> <span class="o">=</span> <span class="bp">True</span> + +<span class="c"># merge contexts</span> +<span class="k">for</span> <span class="n">context</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">redfoot</span><span class="o">.</span><span class="n">contexts</span><span class="p">()):</span> + <span class="k">for</span> <span class="n">OLD</span><span class="p">,</span> <span class="n">NEW</span> <span class="ow">in</span> <span class="n">pairs</span><span class="p">:</span> + <span class="k">if</span> <span class="n">OLD</span> <span class="ow">in</span> <span class="n">context</span><span class="o">.</span><span class="n">identifier</span><span class="p">:</span> + <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">context</span><span class="o">.</span><span class="n">identifier</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">):</span> + <span class="n">identifier</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="n">context</span><span class="o">.</span><span class="n">identifier</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">OLD</span><span class="p">,</span> <span class="n">NEW</span><span class="p">))</span> + <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">context</span><span class="o">.</span><span class="n">identifier</span><span class="p">,</span> <span class="n">BNode</span><span class="p">):</span> + <span class="n">identifier</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">(</span><span class="n">context</span><span class="o">.</span><span class="n">identifier</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">OLD</span><span class="p">,</span> <span class="n">NEW</span><span class="p">))</span> + <span class="k">else</span><span class="p">:</span> + <span class="n">_logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span> + <span class="s">"Unexpected identifier type. Skipping context '</span><span class="si">%s</span><span class="s">'"</span> \ + <span class="o">%</span> <span class="n">context</span><span class="o">.</span><span class="n">identifier</span><span class="p">)</span> + <span class="k">continue</span> + <span class="n">new_context</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">store</span><span class="o">=</span><span class="n">redfoot</span><span class="o">.</span><span class="n">store</span><span class="p">,</span> + <span class="n">identifier</span><span class="o">=</span><span class="n">identifier</span><span class="p">,</span> + <span class="n">namespace_manager</span><span class="o">=</span><span class="n">redfoot</span><span class="p">)</span> + <span class="n">nothing_merged</span> <span class="o">=</span> <span class="bp">False</span> + <span class="k">else</span><span class="p">:</span> + <span class="n">new_context</span> <span class="o">=</span> <span class="n">context</span> + + <span class="k">for</span> <span class="n">s</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">context</span><span class="p">:</span> + <span class="n">ss</span><span class="p">,</span> <span class="n">pp</span><span class="p">,</span> <span class="n">oo</span> <span class="o">=</span> <span class="n">s</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">o</span> + <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">)</span> <span class="ow">and</span> <span class="n">OLD</span> <span class="ow">in</span> <span class="n">s</span><span class="p">:</span> + <span class="n">ss</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">OLD</span><span class="p">,</span> <span class="n">NEW</span><span class="p">))</span> + <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">)</span> <span class="ow">and</span> <span class="n">OLD</span> <span class="ow">in</span> <span class="n">p</span><span class="p">:</span> + <span class="n">pp</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">OLD</span><span class="p">,</span> <span class="n">NEW</span><span class="p">))</span> + <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">)</span> <span class="ow">and</span> <span class="n">OLD</span> <span class="ow">in</span> <span class="n">o</span><span class="p">:</span> + <span class="n">oo</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="n">o</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">OLD</span><span class="p">,</span> <span class="n">NEW</span><span class="p">))</span> + <span class="k">if</span> <span class="p">(</span><span class="n">ss</span><span class="p">,</span> <span class="n">pp</span><span class="p">,</span> <span class="n">oo</span><span class="p">)</span><span class="o">!=</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">o</span><span class="p">)</span> <span class="ow">or</span> <span class="n">context</span><span class="o">!=</span><span class="n">new_context</span><span class="p">:</span> + <span class="n">nothing_merged</span> <span class="o">=</span> <span class="bp">False</span> + <span class="n">context</span><span class="o">.</span><span class="n">remove</span><span class="p">((</span><span class="n">s</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">o</span><span class="p">))</span> + <span class="n">new_context</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">ss</span><span class="p">,</span> <span class="n">pp</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span> + + <span class="k">if</span> <span class="n">new_context</span><span class="o">!=</span><span class="n">context</span><span class="p">:</span> + <span class="n">redfoot</span><span class="o">.</span><span class="n">remove_context</span><span class="p">(</span><span class="n">context</span><span class="o">.</span><span class="n">identifier</span><span class="p">)</span> + +<span class="k">if</span> <span class="n">nothing_merged</span><span class="p">:</span> + <span class="n">_logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s">"nothing merged."</span><span class="p">)</span> +</pre></div> +</div> +</div> +<div class="section" id="example-2"> +<h2>Example 2<a class="headerlink" href="#example-2" title="Permalink to this headline">¶</a></h2> +<div class="highlight-python"><div class="highlight"><pre><span class="sd">'''</span> +<span class="sd">Tutorial 9 - demonstrate graph operations</span> + +<span class="sd">(not really quite graph operations since rdflib cannot merge models like</span> +<span class="sd">Jena, but this examples shows you can load two different RDF files and</span> +<span class="sd">rdflib will merge the two together into one model)</span> + +<span class="sd">Copyright (C) 2005 Sylvia Wong <sylvia at whileloop dot org></span> + +<span class="sd">This program is free software; you can redistribute it and/or modify it</span> +<span class="sd">under the terms of the GNU General Public License as published by the</span> +<span class="sd">Free Software Foundation; either version 2 of the License, or (at your</span> +<span class="sd">option) any later version.</span> + +<span class="sd">This program is distributed in the hope that it will be useful, but</span> +<span class="sd">WITHOUT ANY WARRANTY; without even the implied warranty of</span> +<span class="sd">MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> +<span class="sd">General Public License for more details.</span> + +<span class="sd">You should have received a copy of the GNU General Public License along</span> +<span class="sd">with this program; if not, write to the Free Software</span> +<span class="sd">Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span> +<span class="sd">'''</span> + +<span class="kn">from</span> <span class="nn">rdflib.URIRef</span> <span class="kn">import</span> <span class="n">URIRef</span> +<span class="kn">from</span> <span class="nn">rdflib.Literal</span> <span class="kn">import</span> <span class="n">Literal</span> +<span class="kn">from</span> <span class="nn">rdflib.BNode</span> <span class="kn">import</span> <span class="n">BNode</span> +<span class="kn">from</span> <span class="nn">rdflib.Namespace</span> <span class="kn">import</span> <span class="n">Namespace</span> + +<span class="c"># Import RDFLib's default TripleStore implementation.</span> +<span class="kn">from</span> <span class="nn">rdflib.TripleStore</span> <span class="kn">import</span> <span class="n">TripleStore</span> + +<span class="n">inputFileName1</span> <span class="o">=</span> <span class="s">'vc-db-3.rdf'</span> +<span class="n">inputFileName2</span> <span class="o">=</span> <span class="s">'vc-db-4.rdf'</span> + +<span class="n">store</span> <span class="o">=</span> <span class="n">TripleStore</span><span class="p">()</span> +<span class="n">store</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">inputFileName1</span><span class="p">)</span> +<span class="n">store</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">inputFileName2</span><span class="p">)</span> + +<span class="k">print</span> <span class="n">store</span><span class="o">.</span><span class="n">serialize</span><span class="p">()</span> +</pre></div> +</div> +<div class="section" id="vc-db-3-rdf"> +<h3>vc-db-3.rdf<a class="headerlink" href="#vc-db-3-rdf" title="Permalink to this headline">¶</a></h3> +<div class="highlight-xml"><div class="highlight"><pre><span class="nt"><rdf:RDF</span> + <span class="na">xmlns:rdf=</span><span class="s">'http://www.w3.org/1999/02/22-rdf-syntax-ns#'</span> + <span class="na">xmlns:vCard=</span><span class="s">'http://www.w3.org/2001/vcard-rdf/3.0#'</span><span class="nt">></span> + + <span class="nt"><rdf:Description</span> <span class="na">rdf:about=</span><span class="s">"http://somewhere/JohnSmith/"</span><span class="nt">></span> + <span class="nt"><vCard:FN></span>John Smith<span class="nt"></vCard:FN></span> + <span class="nt"><vCard:N</span> <span class="na">rdf:parseType=</span><span class="s">"Resource"</span><span class="nt">></span> + <span class="nt"><vCard:Family></span>Smith<span class="nt"></vCard:Family></span> + <span class="nt"><vCard:Given></span>John<span class="nt"></vCard:Given></span> + <span class="nt"></vCard:N></span> + <span class="nt"></rdf:Description></span> +<span class="nt"></rdf:RDF></span> +</pre></div> +</div> +</div> +<div class="section" id="vc-db-4-rdf"> +<h3>vc-db-4.rdf<a class="headerlink" href="#vc-db-4-rdf" title="Permalink to this headline">¶</a></h3> +<div class="highlight-xml"><div class="highlight"><pre><span class="nt"><rdf:RDF</span> + <span class="na">xmlns:rdf=</span><span class="s">'http://www.w3.org/1999/02/22-rdf-syntax-ns#'</span> + <span class="na">xmlns:vCard=</span><span class="s">'http://www.w3.org/2001/vcard-rdf/3.0#'</span><span class="nt">></span> + + <span class="nt"><rdf:Description</span> <span class="na">rdf:about=</span><span class="s">"http://somewhere/JohnSmith/"</span><span class="nt">></span> + <span class="nt"><vCard:FN></span>John Smith<span class="nt"></vCard:FN></span> + <span class="nt"><vCard:EMAIL</span> <span class="na">rdf:parseType=</span><span class="s">"Resource"</span><span class="nt">></span> + <span class="nt"><rdf:type</span> <span class="na">rdf:resource=</span><span class="s">"http://www.w3.org/2001/vcard-rdf/3.0#internet"</span><span class="nt">/></span> + <span class="nt"><rdf:value></span>John@somewhere.com<span class="nt"></rdf:value></span> + <span class="nt"></vCard:EMAIL></span> + <span class="nt"></rdf:Description></span> +<span class="nt"></rdf:RDF></span> +</pre></div> +</div> +</div> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href="">Merging graphs</a><ul> +<li><a class="reference external" href="#example-1">Example 1</a></li> +<li><a class="reference external" href="#example-2">Example 2</a><ul> +<li><a class="reference external" href="#vc-db-3-rdf">vc-db-3.rdf</a></li> +<li><a class="reference external" href="#vc-db-4-rdf">vc-db-4.rdf</a></li> +</ul> +</li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="persisting_n3_terms.html" + title="previous chapter">Persisting Notation 3 Terms</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="graphs_bnodes.html" + title="next chapter">Graphs, Named Graphs and Blank Nodes</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="_sources/graph_merging.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="graphs_bnodes.html" title="Graphs, Named Graphs and Blank Nodes" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="persisting_n3_terms.html" title="Persisting Notation 3 Terms" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/graph_utilities.html b/docs/_build/html/graph_utilities.html new file mode 100644 index 00000000..0775fb22 --- /dev/null +++ b/docs/_build/html/graph_utilities.html @@ -0,0 +1,304 @@ +<!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>Graph utilities — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="_static/default.css" type="text/css" /> + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="_static/jquery.js"></script> + <script type="text/javascript" src="_static/doctools.js"></script> + <link rel="index" title="Index" href="genindex.html" /> + <link rel="search" title="Search" href="search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="index.html" /> + <link rel="next" title="Persistence" href="persistence.html" /> + <link rel="prev" title="Namespace Utilities" href="namespace_utilities.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="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="persistence.html" title="Persistence" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="namespace_utilities.html" title="Namespace Utilities" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="id1"> +<span id="graph-utilities"></span><h1>Graph utilities<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h1> +<div class="section" id="graphs-as-iterators"> +<h2>Graphs as Iterators<a class="headerlink" href="#graphs-as-iterators" title="Permalink to this headline">¶</a></h2> +<p>RDFLib graphs also override <tt class="xref docutils literal"><span class="pre">__iter__()</span></tt> in order to support iteration over the contained triples:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="k">for</span> <span class="n">subject</span><span class="p">,</span><span class="n">predicate</span><span class="p">,</span><span class="n">obj_</span> <span class="ow">in</span> <span class="n">someGraph</span><span class="p">:</span> + <span class="k">assert</span> <span class="p">(</span><span class="n">subject</span><span class="p">,</span><span class="n">predicate</span><span class="p">,</span><span class="n">obj_</span><span class="p">)</span> <span class="ow">in</span> <span class="n">someGraph</span><span class="p">,</span> <span class="s">"Iterator / Container Protocols are Broken!!"</span> +</pre></div> +</div> +</div> +<div class="section" id="set-operations-on-rdflib-graphs"> +<h2>Set Operations on RDFLib Graphs<a class="headerlink" href="#set-operations-on-rdflib-graphs" title="Permalink to this headline">¶</a></h2> +<p><tt class="xref docutils literal"><span class="pre">__iadd__()</span></tt> and <tt class="xref docutils literal"><span class="pre">__isub__()</span></tt> are overridden to support adding and subtracting Graphs to/from each other (in place):</p> +<ul class="simple"> +<li>G1 += G1</li> +<li>G2 -= G2</li> +</ul> +</div> +<div class="section" id="basic-triple-matching"> +<h2>Basic Triple Matching<a class="headerlink" href="#basic-triple-matching" title="Permalink to this headline">¶</a></h2> +<p>RDFLib graphs support basic triple pattern matching with a <tt class="xref docutils literal"><span class="pre">triples()</span></tt> function.</p> +<dl class="method"> +<dt id="rdflib.graph.Graph.triples"> +<!--[rdflib.graph.Graph.triples]--><tt class="descclassname">Graph.</tt><tt class="descname">triples</tt><big>(</big><em>(s</em>, <em>p</em>, <em>o)</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.triples" title="Permalink to this definition">¶</a></dt> +<dd><p>Generator over the triple store</p> +<p>Returns triples that match the given triple pattern. If triple pattern +does not provide a context, all contexts will be searched.</p> +</dd></dl> + +<p>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 <tt class="xref xref docutils literal"><span class="pre">None</span></tt> are treated as a wildcard.</p> +</div> +<div class="section" id="managing-triples"> +<h2>Managing Triples<a class="headerlink" href="#managing-triples" title="Permalink to this headline">¶</a></h2> +<div class="section" id="adding-triples"> +<h3>Adding Triples<a class="headerlink" href="#adding-triples" title="Permalink to this headline">¶</a></h3> +<p>Triples can be added in two ways:</p> +<ul> +<li><p class="first">They may be added with with the <tt class="xref docutils literal"><span class="pre">parse()</span></tt> function.</p> +<blockquote> +<dl class="method"> +<dt id="rdflib.graph.Graph.parse"> +<!--[rdflib.graph.Graph.parse]--><tt class="descclassname">Graph.</tt><tt class="descname">parse</tt><big>(</big><em>source=None</em>, <em>publicID=None</em>, <em>format=None</em>, <em>location=None</em>, <em>file=None</em>, <em>data=None</em>, <em>**args</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.parse" title="Permalink to this definition">¶</a></dt> +<dd><p>Parse source adding the resulting triples to the Graph.</p> +<p>The source is specified using one of source, location, file or +data.</p> +<table class="docutils field-list" frame="void" rules="none"> +<col class="field-name" /> +<col class="field-body" /> +<tbody valign="top"> +<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> +<li><cite>source</cite>: An InputSource, file-like object, or string. In the case of a string the string is the location of the source.</li> +<li><cite>location</cite>: A string indicating the relative or absolute URL of the source. Graph’s absolutize method is used if a relative location is specified.</li> +<li><cite>file</cite>: A file-like object.</li> +<li><cite>data</cite>: A string containing the data to be parsed.</li> +<li><cite>format</cite>: Used if format can not be determined from source. Defaults to rdf/xml.</li> +<li><cite>publicID</cite>: 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).</li> +</ul> +</td> +</tr> +<tr class="field"><th class="field-name">Returns:</th><td class="field-body"></td> +</tr> +</tbody> +</table> +<p>self, the graph instance.</p> +<p>Examples:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">my_data</span> <span class="o">=</span> <span class="s">'''</span> +<span class="gp">... </span><span class="s"><rdf:RDF</span> +<span class="gp">... </span><span class="s"> xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'</span> +<span class="gp">... </span><span class="s"> xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'</span> +<span class="gp">... </span><span class="s">></span> +<span class="gp">... </span><span class="s"> <rdf:Description></span> +<span class="gp">... </span><span class="s"> <rdfs:label>Example</rdfs:label></span> +<span class="gp">... </span><span class="s"> <rdfs:comment>This is really just an example.</rdfs:comment></span> +<span class="gp">... </span><span class="s"> </rdf:Description></span> +<span class="gp">... </span><span class="s"></rdf:RDF></span> +<span class="gp">... </span><span class="s">'''</span> +<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">tempfile</span> +<span class="gp">>>> </span><span class="n">file_name</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mktemp</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="nb">file</span><span class="p">(</span><span class="n">file_name</span><span class="p">,</span> <span class="s">"w"</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">my_data</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> +</pre></div> +</div> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">g</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">my_data</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s">"application/rdf+xml"</span><span class="p">)</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">2</span> +</pre></div> +</div> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">g</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">location</span><span class="o">=</span><span class="n">file_name</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s">"application/rdf+xml"</span><span class="p">)</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">2</span> +</pre></div> +</div> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">g</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="nb">file</span><span class="o">=</span><span class="nb">file</span><span class="p">(</span><span class="n">file_name</span><span class="p">,</span> <span class="s">"r"</span><span class="p">),</span> <span class="n">format</span><span class="o">=</span><span class="s">"application/rdf+xml"</span><span class="p">)</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">2</span> +</pre></div> +</div> +</dd></dl> + +<p>The first argument can be a <em>source</em> of many kinds, but the most common is the serialization (in various formats: RDF/XML, Notation 3, NTriples of an RDF graph as a string. The <tt class="xref docutils literal"><span class="pre">format</span></tt> parameter is one of <tt class="docutils literal"><span class="pre">n3</span></tt>, <tt class="docutils literal"><span class="pre">xml</span></tt>, or <tt class="docutils literal"><span class="pre">ntriples</span></tt>. <tt class="xref docutils literal"><span class="pre">publicID</span></tt> is the name of the graph into which the RDF serialization will be parsed.</p> +</blockquote> +</li> +<li><p class="first">Triples can also be added with the <tt class="xref docutils literal"><span class="pre">add()</span></tt> function:</p> +<blockquote> +<dl class="method"> +<dt id="rdflib.graph.Graph.add"> +<!--[rdflib.graph.Graph.add]--><tt class="descclassname">Graph.</tt><tt class="descname">add</tt><big>(</big><em>(s</em>, <em>p</em>, <em>o)</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.add" title="Permalink to this definition">¶</a></dt> +<dd><p>Add a triple with self as context</p> +</dd></dl> + +</blockquote> +</li> +</ul> +</div> +<div class="section" id="removing-triples"> +<h3>Removing Triples<a class="headerlink" href="#removing-triples" title="Permalink to this headline">¶</a></h3> +<p>Similarly, triples can be removed by a call to <tt class="xref docutils literal"><span class="pre">remove()</span></tt>:</p> +<dl class="method"> +<dt id="rdflib.graph.Graph.remove"> +<!--[rdflib.graph.Graph.remove]--><tt class="descclassname">Graph.</tt><tt class="descname">remove</tt><big>(</big><em>(s</em>, <em>p</em>, <em>o)</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.remove" title="Permalink to this definition">¶</a></dt> +<dd><p>Remove a triple from the graph</p> +<p>If the triple does not provide a context attribute, removes the triple +from all contexts.</p> +</dd></dl> + +</div> +</div> +<div class="section" id="rdf-literal-support"> +<h2>RDF Literal Support<a class="headerlink" href="#rdf-literal-support" title="Permalink to this headline">¶</a></h2> +<p>RDFLib Literals essentially behave like unicode characters with an XML Schema datatype or language attribute. The class provides a mechanism to both convert Python literals (and their built-ins such as time/date/datetime) into equivalent RDF Literals and (conversely) convert Literals to their Python equivalent. There is some support of considering datatypes in comparing Literal instances, implemented as an override to <tt class="xref docutils literal"><span class="pre">__eq__()</span></tt>. This mapping to and from Python literals is achieved with the following dictionaries:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="n">PythonToXSD</span> <span class="o">=</span> <span class="p">{</span> + <span class="nb">basestring</span> <span class="p">:</span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">),</span> + <span class="nb">float</span> <span class="p">:</span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span><span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'float'</span><span class="p">),</span> + <span class="nb">int</span> <span class="p">:</span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span><span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'int'</span><span class="p">),</span> + <span class="nb">long</span> <span class="p">:</span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span><span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'long'</span><span class="p">),</span> + <span class="nb">bool</span> <span class="p">:</span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span><span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'boolean'</span><span class="p">),</span> + <span class="n">date</span> <span class="p">:</span> <span class="p">(</span><span class="k">lambda</span> <span class="n">i</span><span class="p">:</span><span class="n">i</span><span class="o">.</span><span class="n">isoformat</span><span class="p">(),</span><span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'date'</span><span class="p">),</span> + <span class="n">time</span> <span class="p">:</span> <span class="p">(</span><span class="k">lambda</span> <span class="n">i</span><span class="p">:</span><span class="n">i</span><span class="o">.</span><span class="n">isoformat</span><span class="p">(),</span><span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'time'</span><span class="p">),</span> + <span class="n">datetime</span> <span class="p">:</span> <span class="p">(</span><span class="k">lambda</span> <span class="n">i</span><span class="p">:</span><span class="n">i</span><span class="o">.</span><span class="n">isoformat</span><span class="p">(),</span><span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'dateTime'</span><span class="p">),</span> +<span class="p">}</span> +</pre></div> +</div> +<p>Maps Python instances to WXS datatyped Literals</p> +<div class="highlight-python"><div class="highlight"><pre><span class="n">XSDToPython</span> <span class="o">=</span> <span class="p">{</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'time'</span> <span class="p">:</span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span><span class="n">_strToTime</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'date'</span> <span class="p">:</span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span><span class="n">_strToDate</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'dateTime'</span> <span class="p">:</span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span><span class="n">_strToDateTime</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'string'</span> <span class="p">:</span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'normalizedString'</span> <span class="p">:</span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'token'</span> <span class="p">:</span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'language'</span> <span class="p">:</span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'boolean'</span> <span class="p">:</span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">i</span><span class="p">:</span><span class="n">i</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="ow">in</span> <span class="p">[</span><span class="s">'1'</span><span class="p">,</span><span class="s">'true'</span><span class="p">]),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'decimal'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">float</span><span class="p">,</span><span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'integer'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">long</span> <span class="p">,</span><span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'nonPositiveInteger'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span><span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'long'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">long</span><span class="p">,</span><span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'nonNegativeInteger'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'negativeInteger'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'int'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'unsignedLong'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">long</span><span class="p">,</span> <span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'positiveInteger'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'short'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'unsignedInt'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">long</span><span class="p">,</span> <span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'byte'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'unsignedShort'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'unsignedByte'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'float'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'double'</span> <span class="p">:</span> <span class="p">(</span><span class="nb">float</span><span class="p">,</span> <span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'base64Binary'</span> <span class="p">:</span> <span class="p">(</span><span class="n">base64</span><span class="o">.</span><span class="n">decodestring</span><span class="p">,</span> <span class="bp">None</span><span class="p">),</span> + <span class="n">XSD_NS</span><span class="o">+</span><span class="s">u'anyURI'</span> <span class="p">:</span> <span class="p">(</span><span class="bp">None</span><span class="p">,</span><span class="bp">None</span><span class="p">),</span> +<span class="p">}</span> +</pre></div> +</div> +<p>Maps WXS datatyped Literals to Python. This mapping is used by the <tt class="xref docutils literal"><span class="pre">toPython()</span></tt> method defined on all Literal instances.</p> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href="">Graph utilities</a><ul> +<li><a class="reference external" href="#graphs-as-iterators">Graphs as Iterators</a></li> +<li><a class="reference external" href="#set-operations-on-rdflib-graphs">Set Operations on RDFLib Graphs</a></li> +<li><a class="reference external" href="#basic-triple-matching">Basic Triple Matching</a></li> +<li><a class="reference external" href="#managing-triples">Managing Triples</a><ul> +<li><a class="reference external" href="#adding-triples">Adding Triples</a></li> +<li><a class="reference external" href="#removing-triples">Removing Triples</a></li> +</ul> +</li> +<li><a class="reference external" href="#rdf-literal-support">RDF Literal Support</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="namespace_utilities.html" + title="previous chapter">Namespace Utilities</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/graph_utilities.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="persistence.html" title="Persistence" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="namespace_utilities.html" title="Namespace Utilities" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/graphs_bnodes.html b/docs/_build/html/graphs_bnodes.html new file mode 100644 index 00000000..70abcac9 --- /dev/null +++ b/docs/_build/html/graphs_bnodes.html @@ -0,0 +1,526 @@ +<!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>Graphs, Named Graphs and Blank Nodes — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="_static/default.css" type="text/css" /> + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="_static/jquery.js"></script> + <script type="text/javascript" src="_static/doctools.js"></script> + <link rel="index" title="Index" href="genindex.html" /> + <link rel="search" title="Search" href="search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="index.html" /> + <link rel="next" title="Assorted examples" href="assorted_examples.html" /> + <link rel="prev" title="Merging graphs" href="graph_merging.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="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="assorted_examples.html" title="Assorted examples" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="graph_merging.html" title="Merging graphs" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="graphs-named-graphs-and-blank-nodes"> +<span id="graphs-bnodes"></span><h1>Graphs, Named Graphs and Blank Nodes<a class="headerlink" href="#graphs-named-graphs-and-blank-nodes" title="Permalink to this headline">¶</a></h1> +<div class="section" id="vin-s-question"> +<h2>Vin’s question<a class="headerlink" href="#vin-s-question" title="Permalink to this headline">¶</a></h2> +<p>Clarifying the query more precisely:</p> +<div class="highlight-pycon"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">rdflib.Graph</span> <span class="kn">import</span> <span class="n">Graph</span><span class="p">,</span> <span class="n">ConjunctiveGraph</span> +<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">rdflib</span> <span class="kn">import</span> <span class="n">URIRef</span> +</pre></div> +</div> +<p>[1]</p> +<div class="highlight-pycon"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">graph</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="s">'MySQL'</span><span class="p">,</span> <span class="n">identifier</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'http://www.example.com'</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">graph</span><span class="o">.</span><span class="n">identifier</span> +<span class="go">rdflib.URIRef('http://www.example.com')</span> +</pre></div> +</div> +<p>[2]</p> +<div class="highlight-pycon"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">graph1</span> <span class="o">=</span> <span class="n">ConjunctiveGraph</span><span class="p">(</span><span class="s">'MySQL'</span><span class="p">,</span> <span class="n">identifier</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'http://www.example.com'</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">graph1</span><span class="o">.</span><span class="n">identifier</span> +<span class="go">rdflib.BNode('VLjQILCh3')</span> +</pre></div> +</div> +<p>[3]</p> +<div class="highlight-pycon"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">graph1</span> <span class="o">=</span> <span class="n">ConjunctiveGraph</span><span class="p">(</span><span class="s">'MySQL'</span><span class="p">,</span> <span class="n">identifier</span> <span class="o">=</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'http://www.example.com'</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">graph1</span><span class="o">.</span><span class="n">identifier</span> +<span class="go">rdflib.BNode('VLjQILCh4')</span> +</pre></div> +</div> +<p>In [1] when I mention the Graph identifier the return is a persistent +URIRef (i.e. it can be used out of the current model as well) which +gives me a unique name for the graph and now I am free to use it in +other model as well - may be it can be used for merging graphs. Where +as in [2] and [3] when I mention Graph identifier the return is a +BNode which changes values every time we invoke it (and hence BNodes +have local scope and are not good for using outside the model). My +query was simply to know why the Model “identifier” is giving BNode in +[2] comparing to a persistent URI in case [1]? In ConjunctiveGraph, +identifier is inherited from the Graph class.</p> +</div> +<div class="section" id="the-discourse"> +<h2>The discourse<a class="headerlink" href="#the-discourse" title="Permalink to this headline">¶</a></h2> +<p>This sparql-dev discussion airs some of the issues ...</p> +<div class="section" id="nuutti-kotivuori"> +<h3>0016: Nuutti Kotivuori<a class="headerlink" href="#nuutti-kotivuori" title="Permalink to this headline">¶</a></h3> +<p><a class="reference external" href="http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0016.html">http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0016.html</a></p> +<p>This isn’t exactly a SPARQL question, but it is very closely +related. I will first outline the question context.</p> +<p>Assume an RDF statement store, which has a mechanism for tracking +statement origin (scope, context, graph, source whatever). Many of the +statements have a distinct origin, or source graph, they were imported +from. But there are also those which either seemingly have no origin, +or the origin is not known. The origin of these statements have to be +handled somehow. We’ll come to the specific choices later on.</p> +<p>This statement store offers a SPARQL query interface into it. The +facilities for querying named graphs in SPARQL would obviously be used +to query the different origins in the store. But there are two things +to decide. First, how should statements without an origin be accessed +in SPARQL? There are several choices on this, which I will outline +below. And related to the first one, second, what should the default +graph be for the queries if none is given explicitly.</p> +<p>I will list a few possibilities and mention the problems and benefits +that seem to result from them as a basis for discussion.</p> +<blockquote> +<ol class="arabic"> +<li><p class="first">Unknown origin is a distinct node, but separate from all uris, +blank nodes or literals. The default graph for the query is the +graph of the unknown origin nodes.</p> +<ul> +<li><p class="first">Separation of identifier spaces, no fear of any overlap. The +graph of statements with unknown origin is separate from any +named graph.</p> +</li> +<li><p class="first">Since there is no way to represent the unknown origin in SPARQL +syntax, the default graph is the only way to access the nodes in +that graph.</p> +</li> +<li><p class="first">The nodes in the unknown origin graph are not matched by any +graph query, since the name of the graph could not be returned +reasonably. That is:</p> +<div class="highlight-sparql"><pre>SELECT ?g ?s ?o ?p +WHERE { GRAPH ?g { ?s ?p ?o } }</pre> +</div> +<p>cannot return ?g for the unknown origin graph.</p> +</li> +</ul> +</li> +<li><p class="first">Unknown origin is a distinct node, as above. The default graph is +the RDF merge of all graphs in the store, including the statements +with an unknown origin.</p> +<ul class="simple"> +<li>The problems above.</li> +<li>In addition, there is no way to select nodes that explicitly +have an unknown origin. (Or is there? Could one match all the +statements for which there is no graph with the same statement? +In any case, this would be quite contorted.)</li> +</ul> +</li> +<li><p class="first">Unknown origin is represented by a distinct blank node; that is, +every statement has it’s own blank node as the graph name, which +is not shared with any of the other statements. The default graph +is the RDF merge of all graphs in the store, including the +statements with an unknown origin.</p> +<ul class="simple"> +<li>This is probably closest to accurate modelling of the +situation. We know every statement has an origin, we just don’t +know what it is - a situation commonly modelled with a blank +node. Also, we don’t know which statements might share an +origin, so until we know better, we make them all distinct.</li> +<li>The origin of the statements is nicely queryable with SPARQL +queries and every statement has an origin, even if unknown.</li> +<li>Queries which specify several statements from a single graph +will not match the statements with unknown origins as it cannot +be confirmed that they would be from the same graph.</li> +<li>There is no way to match the origin of a single statement as +there is no way to match a certain blank node explicitly. The +current SPARQL treats it as an open variable(?).</li> +<li>There is no way to explicitly match statements that have an +unknown origin, since the origins are just distinct blank nodes.</li> +<li>Possibly hard to implement, because of the number of distinct +blank nodes.</li> +</ul> +</li> +<li><p class="first">Unknown origin is represented by a singleton blank node; that is, +every statement with an unknown origin shares one single blank +node as the graph name. The default graph is the RDF merge of all +graphs in the store.</p> +<ul> +<li><p class="first">Lumps all statements with an unknown origin under a single named +graph. Queries which match several statements from a single +graph will match statement sets from unknown origin as well.</p> +</li> +<li><p class="first">The origin of the statements is nicely queryable with SPARQL +queries and every statement has an origin, even if unknown.</p> +</li> +<li><p class="first">There is no way to explicitly match statements that have an +unknown origin, since the origin is a single blank node. If the +application provided a magic type for this blank node (_:x a +rdfx:UnknownOrigin), this could be matched with:</p> +<div class="highlight-sparql"><pre>SELECT ?s ?o ?p +WHERE { ?g a rdfx:UnknownOrigin . + GRAPH ?g { ?s ?o ?p } }</pre> +</div> +<p>But this again is quite contorted. (The same could be applied to +the third case as well, but the implementation of that would be +really tricky to be effecient.)</p> +</li> +</ul> +</li> +<li><p class="first">Unknown origin is represented by a singleton blank node as +above. The default graph is the singleton blank node of unknown +origin.</p> +<ul class="simple"> +<li>Mostly as above, but in the common case, explictly matching +statements that have an unknown origin would be easy in just +matching the statements from the default graph.</li> +</ul> +</li> +<li><p class="first">Unknown origin is represented by a well known URI that is shared +universally. The default graph is the RDF merge of all graphs in +the store.</p> +<ul class="simple"> +<li>Somewhat incorrectly asserts that the statements have a certain +origin, even though we don’t know the origin.</li> +<li>The origin of the statements is nicely queryable with SPARQL.</li> +<li>Statements with an unknown origin can be easily explicitly +matched by comparing them against the well known URI.</li> +<li>Assigns a special meaning to an URI.</li> +<li>Hard to coordinate with a number of people implementing similar +solutions if not standardized.</li> +</ul> +</li> +</ol> +</blockquote> +<p>Some other variants of the above were omitted, since their problems +and benefits are easily reasoned.</p> +<p>On irc, ‘chimenzie’ outlined the problem as such:</p> +<dl class="docutils"> +<dt>17:35 chimezie:#swig => Hmm.. well, seems like what is missing is a good</dt> +<dd>definition of a ‘name for nodes that don’t have an explicit context’</dd> +<dt>17:36 chimezie:#swig => or rather ‘a name for the context of nodes that aren’t</dt> +<dd>assigned to a context explicitely’</dd> +</dl> +<p>So, I’m out for some input on what might be the sanest route to +through this.</p> +<p>TIA, +– Naked</p> +</div> +<div class="section" id="richard-cyganiak"> +<h3>0018: Richard Cyganiak<a class="headerlink" href="#richard-cyganiak" title="Permalink to this headline">¶</a></h3> +<p><a class="reference external" href="http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0018.html">http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0018.html</a></p> +<p>Hi Nuutti,</p> +<p>Without having thought through all the consequences ...</p> +<p>Some of your options are not really possible with named graphs +because graphs need to be <em>named</em>, that is, the name <em>must</em> be a URI +and not a blank node. Blank nodes are always scoped to a single +graph, and using blank nodes as graph labels would make it impossible +to refer to a named graph from the outside world. This excludes #3 +and #4.</p> +<p>In SPARQL, the default graph is structurally and syntactically +handled so differently from the other graphs that I wouldn’t consider +using it for the same kind of data. That is, I tend to reserve the +default graph for metadata or the merge of all named graphs. This +excludes #1 and #5.</p> +<p>#6 has the problem of re-using a single URI for many different things +– the statements of unknown origin in Alice’s store, <em>and</em> the +statements of unknown origin in Bob’s store. While workable, this is +not an elegant solution.</p> +<p>I would suggest that Alice and Bob each mint a new URI for the graph +containing the statements of unknown origin <em>in their own store</em>. Or +mint a new URI to hold each individual statement, or anything in +between. Since the owner of a URI gets to say what the meaning of the +URI is, they can declare that this chunk of URI space is reserved for +this purpose (assuming Alice and Bob each own a chunk of URI space).</p> +<p>I wonder why you discounted this solution?</p> +<p>I also question the existence of “statements without a known origin”. +They surely didn’t just pop up magically inside your triple store, +eh? I guess it’s more like “statements whose origin I don’t want to +model”.</p> +</div> +<div class="section" id="chimezie-ogbuji"> +<h3>0020: Chimezie Ogbuji<a class="headerlink" href="#chimezie-ogbuji" title="Permalink to this headline">¶</a></h3> +<p><a class="reference external" href="http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0020.html">http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0020.html</a></p> +<p>On Wed, 13 Sep 2006, Richard Cyganiak wrote:</p> +<div class="highlight-text"><div class="highlight"><pre>> Hi Nuutti, +> +> Without having thought through all the consequences ... +> +> Some of your options are not really possible with named graphs because graphs +> need to be *named*, that is, the name *must* be a URI and not a blank node. +</pre></div> +</div> +<p>I don’t agree. What’s the source of this assertion? I think the core +issue here is that there is <em>no</em> concensus formalism for named graphs WRT RDF, yet SPARQL is dependent +on an RDF model that supports named graphs. If there is one, please +point me to it, because I ran across the same problem when constructing +programming APIs for named graphs. The only formalism I know of is Graham Kyle, John McCarthy’s work [1].</p> +<div class="highlight-text"><div class="highlight"><pre>> Blank nodes are always scoped to a single graph, and using blank nodes as +> graph labels would make it impossible to refer to a named graph from the +> outside world. This excludes #3 and #4. +</pre></div> +</div> +<p>Well, Blank nodes used within a graph can’t be referred to +directly but they can still be matched by SPARQL - doesn’t make them any +less useful. The problem isn’t the use of Blank nodes for graph names but +a the lack of a mechanism [2] to match the graph name(s) associated with a +node. Given how closely coupled SPARQL is with (admittedly informal) +named graph semantics, I would expect to be able to answer questions such as:</p> +<p>“What are the graph names in which all the statements about <someIRI> are +asserted?”</p> +<p>Assuming I could answer this question, then graph labels that are blank +nodes become as accessible as blank nodes asserted <em>within</em> a graph and it +becomes a question of what is the appropriate use for a bnode as a graph +label?</p> +<p>If BNodes are used for existential assertions about nodes, why wouldn’t +they be used as existential assertions about graphs? And if there is +some semantic consequence, it furthers the argument that the formalisms +for named graphs should be well articulated before they are tightly integrated into a query language.</p> +<div class="highlight-text"><div class="highlight"><pre>> I would suggest that Alice and Bob each mint a new URI for the graph +> containing the statements of unknown origin *in their own store*. Or mint a +> new URI to hold each individual statement, or anything in between. Since the +> owner of a URI gets to say what the meaning of the URI is, they can declare +> that this chunk of URI space is reserved for this purpose (assuming Alice and +> Bob each own a chunk of URI space). +> +> I wonder why you discounted this solution? +</pre></div> +</div> +<p>I don’t think it’s an elegant solution when we already have the means +(within ‘vanilla’ RDF Model Theory) to express +existential assertions - which is exactly the scenario here.</p> +<p>If a graph label is nothing but a name associated with a set of graphs, +why should it not behave the same as the name associated with a node +within a graph?</p> +<div class="highlight-text"><div class="highlight"><pre>> I also question the existence of "statements without a known origin". They +> surely didn't just pop up magically inside your triple store, eh? I guess +> it's more like "statements whose origin I don't want to model". +</pre></div> +</div> +<p>How different is this from “nodes whose names I don’t care to maintain / +model?”</p> +<p>[1] <a class="reference external" href="http://ninebynine.org/RDFNotes/UsingContextsWithRDF.html#xtocid-6303976">http://ninebynine.org/RDFNotes/UsingContextsWithRDF.html#xtocid-6303976</a></p> +<p>[2] <a class="reference external" href="http://copia.ogbuji.net/blog/2006-07-14/querying-named-rdf-graph-aggregate">http://copia.ogbuji.net/blog/2006-07-14/querying-named-rdf-graph-aggregate</a></p> +</div> +<div class="section" id="id1"> +<h3>0023: Nuutti Kotivuori<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3> +<p><a class="reference external" href="http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0023.html">http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0023.html</a></p> +<p>Chimezie Ogbuji wrote:</p> +<div class="highlight-text"><div class="highlight"><pre>> I don't agree. What's the source of this assertion? I think the +> core issue here is that there is *no* concensus formalism for named +> graphs WRT RDF, yet SPARQL is dependent on an RDF model that +> supports named graphs. If there is one, please point me to it, +> because I ran across the same problem when constructing programming +> APIs for named graphs. The only formalism I know of is Graham Kyle, +> John McCarthy's work [1]. +</pre></div> +</div> +<p>Well, one thing which would help me in this is a survey of the +approaches other people have taken when doing these things.</p> +<p>I think I know the situation with Redland librdf, when I read the code +last, but I’m not sure if I’m correct.</p> +<p>I think that in librdf, there are statements explicitly without a +context. In SPARQL queries, the default graph is the merge of all +statements in the store, with or without a context. Queries which +explicitly match the graph in a variable never match statements +without a context. And so there is no easy way to match all the +statements without a context only.</p> +<p>I’d like to know atleast how rdflib and Jena (with whatever extensions +that this requires) solve this issue.</p> +<p>– Naked</p> +</div> +<div class="section" id="id2"> +<h3>0027: Chimezie Ogbuji<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3> +<p><a class="reference external" href="http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0027.html">http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0027.html</a></p> +<p>RDFLib has two API’s: a Store API and a Graph API. Every Graph (there +are several kinds: QuotedGraphs, ConjunctiveGraphs, Named Graphs, +AggregateGraphs, ..) is associated with a Store instance and an +identifier. The identifiers are either a Blank Node or a URI.</p> +<p>All the Store API’s take a fourth parameter which is the containing Graph +(even the <tt class="xref docutils literal"><span class="pre">__len__()</span></tt> method). So, theoretically the Store can choose to +persist RDF triples in a flat space (i.e., vanilla RDF model) and disregard the fourth parameter or use +the identifier of the containing graph to partition its persistence space +accordingly - it can even choose to partition formulae seperately (to +support N3 persistence) from the kind of Graph passed down to it (it will +receive QuotedGraph instances as the fourth parameter in this case).</p> +<p>The <tt class="xref docutils literal"><span class="pre">Store.triples()</span></tt> method returns a generator of (s,p,o), graphInst so each +Store implementation is expected to be able to associate each triple with +a containing graph (or None if the Store chooses to persist triples in a +flat space).</p> +<p>The Graph API’s do most of the leg work of named graph aggregation. +<tt class="xref docutils literal"><span class="pre">ConjunctiveGraph</span></tt> is an (unamed) aggregation of all the named graphs within +the Store. It has a ‘default’ graph, whose name is associated with the +ConjunctiveGraph throughout its life. All methods work against this +default graph. Its constructor can take an identifier to use as the name +of this ‘default’ graph or it will assign a BNode. In practice (at least +how *I* use RDFLib), I instantiate a ConjunctiveGraph if I want to add +triples to the Store but don’t care to mint a URI for the graph (the +scenario which triggered this thread). These triples can still be +addressed.</p> +<p><tt class="xref docutils literal"><span class="pre">ReadOnlyGraphAggregate</span></tt> is a subset of the <tt class="xref docutils literal"><span class="pre">ConjunctiveGraph</span></tt> where the names +of the graphs it provides an aggregate view for are passed on in the +constructor - this is how a SPARQL query with multiple FROM NAMED is +supported.</p> +<p><tt class="xref docutils literal"><span class="pre">QuotedGraphs</span></tt> are meant to implement Notation 3 formulae. They are +associated with a required identifier that the N3 parser must provide in +order to maintain consistent formulae identification for scenarios such as +implication and such.</p> +<p>The default dataset for SPARQL queries is equivalent to the Graph instance +on which the query is dispatched. If the <tt class="xref docutils literal"><span class="pre">query()</span></tt> method is called on a +<tt class="xref docutils literal"><span class="pre">ConjunctiveGraph</span></tt>, the default dataset is the entire Store, if it’s a named +graph it’s the named graph.</p> +<p>This setup supports:</p> +<ul class="simple"> +<li>Flat space of triples</li> +<li>Named Graph partitioning</li> +<li>Notation 3 persistence</li> +</ul> +</div> +<div class="section" id="id3"> +<h3>0028: Nuutti Kotivuori<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h3> +<p><a class="reference external" href="http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0028.html">http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0028.html</a></p> +<p>Chimezie Ogbuji wrote:</p> +<div class="highlight-text"><div class="highlight"><pre>> The Graph API's do most of the leg work of named graph +> aggregation. ConjunctiveGraph is an (unamed) aggregation of all the +> named graphs within the Store. It has a 'default' graph, whose name +> is associated with the ConjunctiveGraph throughout it's life. All +> methods work against this default graph. Its constructor can take an +> identifier to use as the name of this 'default' graph or it will +> assign a BNode. In practice (at least how *I* use RDFLib), I +> instanciate a ConjunctiveGraph if I want to add triples to the Store +> but don't care to mint a URI for the graph (the scenario which +> triggered this thread). These triples can still be addressed. +</pre></div> +</div> +<p>Okay, in the context of this discussion, what RDFLib does is that +every time a ConjunctiveGraph is instantiated, it creates a new blank +node and uses that throughout the life of the ConjunctiveGraph +object. And the default graph is the merge of all graphs in the store.</p> +<p>So triples without an origin will be associated with a blank node, +which is shared between added triples, but distinct between different +ConjunctiveGraph objects. This probably coincides rather nicely with +most usages of the API. Single “sessions” of manipulating nodes will +have the blank node origin shared.</p> +<p>And the possible problems are mostly what was already mentioned +earlier about an approach like this. The blank node identities might +not coincide with the actual separateness of the sources graphs - +making a query which matches several statements out of a single graph +might not be too meaningful for these blank nodes. It is difficult to +query only nodes which have no specific origin. And since the graph +name is a blank node, there is no way to explicitly specify the graph +name to be specific blank node, as the SPARQL syntax doesn’t allow +this.</p> +<p>– Naked</p> +</div> +<div class="section" id="references"> +<h3>References<a class="headerlink" href="#references" title="Permalink to this headline">¶</a></h3> +<p>Two posts by Pat Hayes, recommended by Andy Seaborne.</p> +<p><a class="reference external" href="http://www.ihmc.us/users/phayes/RDFGraphSyntax.html">http://www.ihmc.us/users/phayes/RDFGraphSyntax.html</a></p> +<p><a class="reference external" href="http://lists.w3.org/Archives/Public/public-rdf-dawg/2006JulSep/0153.html">http://lists.w3.org/Archives/Public/public-rdf-dawg/2006JulSep/0153.html</a></p> +</div> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href="">Graphs, Named Graphs and Blank Nodes</a><ul> +<li><a class="reference external" href="#vin-s-question">Vin’s question</a></li> +<li><a class="reference external" href="#the-discourse">The discourse</a><ul> +<li><a class="reference external" href="#nuutti-kotivuori">0016: Nuutti Kotivuori</a></li> +<li><a class="reference external" href="#richard-cyganiak">0018: Richard Cyganiak</a></li> +<li><a class="reference external" href="#chimezie-ogbuji">0020: Chimezie Ogbuji</a></li> +<li><a class="reference external" href="#id1">0023: Nuutti Kotivuori</a></li> +<li><a class="reference external" href="#id2">0027: Chimezie Ogbuji</a></li> +<li><a class="reference external" href="#id3">0028: Nuutti Kotivuori</a></li> +<li><a class="reference external" href="#references">References</a></li> +</ul> +</li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="graph_merging.html" + title="previous chapter">Merging graphs</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="assorted_examples.html" + title="next chapter">Assorted examples</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="_sources/graphs_bnodes.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="assorted_examples.html" title="Assorted examples" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="graph_merging.html" title="Merging graphs" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/graphterms.html b/docs/_build/html/graphterms.html new file mode 100644 index 00000000..fe33a78e --- /dev/null +++ b/docs/_build/html/graphterms.html @@ -0,0 +1,141 @@ +<!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>RDF Graph Terms — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="_static/default.css" type="text/css" /> + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="_static/jquery.js"></script> + <script type="text/javascript" src="_static/doctools.js"></script> + <link rel="index" title="Index" href="genindex.html" /> + <link rel="search" title="Search" href="search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="index.html" /> + <link rel="next" title="Namespace Utilities" href="namespace_utilities.html" /> + <link rel="prev" title="A Universal RDF Store Interface" href="univrdfstore.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="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="namespace_utilities.html" title="Namespace Utilities" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="univrdfstore.html" title="A Universal RDF Store Interface" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="module-rdflib.term"> +<span id="graphterms"></span><h1>RDF Graph Terms<a class="headerlink" href="#module-rdflib.term" title="Permalink to this headline">¶</a></h1> +<p>The RDFLib classes listed below model RDF <a class="reference external" href="univrdfstore.html#Terms">terms</a> in a graph and inherit from a common <a class="reference external" href="http://www.w3.org/2002/07/rdf-identifer-terminology/">Identifier</a> class, which extends Python unicode. Instances of these are nodes in an RDF graph.</p> +<span class="target" id="seq"></span><dl class="class"> +<dt id="rdflib.graph.Seq"> +<!--[rdflib.graph.Seq]-->class <tt class="descclassname">rdflib.graph.</tt><tt class="descname">Seq</tt><big>(</big><em>graph</em>, <em>subject</em><big>)</big><a class="headerlink" href="#rdflib.graph.Seq" title="Permalink to this definition">¶</a></dt> +<dd><p>Wrapper around an RDF Seq resource</p> +<p>It implements a container type in Python with the order of the items +returned corresponding to the Seq content. It is based on the natural +ordering of the predicate names _1, _2, _3, etc, which is the +‘implementation’ of a sequence in RDF terms.</p> +</dd></dl> + +<span class="target" id="quotedgraph"></span><dl class="class"> +<dt id="rdflib.graph.QuotedGraph"> +<!--[rdflib.graph.QuotedGraph]-->class <tt class="descclassname">rdflib.graph.</tt><tt class="descname">QuotedGraph</tt><big>(</big><em>store</em>, <em>identifier</em><big>)</big><a class="headerlink" href="#rdflib.graph.QuotedGraph" title="Permalink to this definition">¶</a></dt> +<dd></dd></dl> + +<span class="target" id="readonlygraphaggregate"></span><dl class="class"> +<dt id="rdflib.graph.ReadOnlyGraphAggregate"> +<!--[rdflib.graph.ReadOnlyGraphAggregate]-->class <tt class="descclassname">rdflib.graph.</tt><tt class="descname">ReadOnlyGraphAggregate</tt><big>(</big><em>graphs</em>, <em>store='default'</em><big>)</big><a class="headerlink" href="#rdflib.graph.ReadOnlyGraphAggregate" title="Permalink to this definition">¶</a></dt> +<dd><p>Utility class for treating a set of graphs as a single graph</p> +<p>Only read operations are supported (hence the name). Essentially a +ConjunctiveGraph over an explicit subset of the entire store.</p> +</dd></dl> + +<span class="target" id="variable"></span><p>This module defines the different types of terms...</p> +<dl class="class"> +<dt id="rdflib.term.Variable"> +<!--[rdflib.term.Variable]-->class <tt class="descclassname">rdflib.term.</tt><tt class="descname">Variable</tt><a class="headerlink" href="#rdflib.term.Variable" title="Permalink to this definition">¶</a></dt> +<dd></dd></dl> + +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h4>Previous topic</h4> + <p class="topless"><a href="univrdfstore.html" + title="previous chapter">A Universal RDF Store Interface</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="namespace_utilities.html" + title="next chapter">Namespace Utilities</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="_sources/graphterms.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="namespace_utilities.html" title="Namespace Utilities" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="univrdfstore.html" title="A Universal RDF Store Interface" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/index.html b/docs/_build/html/index.html new file mode 100644 index 00000000..5b644440 --- /dev/null +++ b/docs/_build/html/index.html @@ -0,0 +1,214 @@ +<!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>rdflib 2.5 — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="_static/default.css" type="text/css" /> + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="_static/jquery.js"></script> + <script type="text/javascript" src="_static/doctools.js"></script> + <link rel="index" title="Index" href="genindex.html" /> + <link rel="search" title="Search" href="search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="" /> + <link rel="next" title="Getting started with rdflib" href="gettingstarted.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="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="gettingstarted.html" title="Getting started with rdflib" + accesskey="N">next</a> |</li> + <li><a href="">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="rdflib-2-5"> +<h1>rdflib 2.5<a class="headerlink" href="#rdflib-2-5" title="Permalink to this headline">¶</a></h1> +<div class="section" id="introduction"> +<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2> +<p>RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information. The library contains an RDF/XML parser/serializer that conforms to the RDF/XML Syntax Specification (Revised) . The library also contains both in-memory and persistent Graph backends. It is being developed by a number of contributors and was created by Daniel Krech who continues to maintain it.</p> +<p>RDFLib’s use of various Python idioms makes them an appropriate way to introduce it to a Python programmer who hasn’t used it before.</p> +<p>RDFLib graphs redefine certain built-in Python methods in order to behave in a predictable way. RDFLib graphs emulate container types and are best thought of as a set of 3-item triples</p> +<div class="highlight-text"><div class="highlight"><pre>[ + (subject, predicate, object), + (subject1, predicate1, object1), + ... + (subjectN, predicateN, objectN) + ] +</pre></div> +</div> +<p>RDFLib graphs are not sorted containers; they have ordinary set operations (e.g. <tt class="xref docutils literal"><span class="pre">add()</span></tt> to add a triple) plus methods that search triples and return them in arbitrary order.</p> +</div> +<div class="section" id="contents"> +<h2>Contents<a class="headerlink" href="#contents" title="Permalink to this headline">¶</a></h2> +<ul> +<li class="toctree-l1"><a class="reference external" href="gettingstarted.html">Getting started with rdflib</a><ul> +<li class="toctree-l2"><a class="reference external" href="gettingstarted.html#introduction-to-parsing-rdf-into-rdflib-graphs">Introduction to parsing RDF into rdflib graphs</a></li> +<li class="toctree-l2"><a class="reference external" href="gettingstarted.html#module-rdflib.syntax.parsers.TriXParser">Other parsers supported by rdflib</a></li> +<li class="toctree-l2"><a class="reference external" href="gettingstarted.html#introduction-to-using-sparql-to-query-an-rdflib-graph">Introduction to using SPARQL to query an rdflib graph</a></li> +<li class="toctree-l2"><a class="reference external" href="gettingstarted.html#store-operations">Store operations</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="univrdfstore.html">A Universal RDF Store Interface</a><ul> +<li class="toctree-l2"><a class="reference external" href="univrdfstore.html#terminology">Terminology</a></li> +<li class="toctree-l2"><a class="reference external" href="univrdfstore.html#interpreting-syntax">Interpreting Syntax</a></li> +<li class="toctree-l2"><a class="reference external" href="univrdfstore.html#formulae-and-variables-as-terms">Formulae and Variables as Terms</a></li> +<li class="toctree-l2"><a class="reference external" href="univrdfstore.html#database-management">Database Management</a></li> +<li class="toctree-l2"><a class="reference external" href="univrdfstore.html#triple-interfaces">Triple Interfaces</a></li> +<li class="toctree-l2"><a class="reference external" href="univrdfstore.html#formula-context-interfaces">Formula / Context Interfaces</a></li> +<li class="toctree-l2"><a class="reference external" href="univrdfstore.html#interface-test-cases">Interface Test Cases</a></li> +<li class="toctree-l2"><a class="reference external" href="univrdfstore.html#additional-terms-to-model">Additional Terms to Model</a></li> +<li class="toctree-l2"><a class="reference external" href="univrdfstore.html#namespace-management-interfaces">Namespace Management Interfaces</a></li> +<li class="toctree-l2"><a class="reference external" href="univrdfstore.html#open-issues">Open issues</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="graphterms.html">RDF Graph Terms</a></li> +<li class="toctree-l1"><a class="reference external" href="namespace_utilities.html">Namespace Utilities</a><ul> +<li class="toctree-l2"><a class="reference external" href="namespace_utilities.html#contents">Contents</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="graph_utilities.html">Graph utilities</a><ul> +<li class="toctree-l2"><a class="reference external" href="graph_utilities.html#graphs-as-iterators">Graphs as Iterators</a></li> +<li class="toctree-l2"><a class="reference external" href="graph_utilities.html#set-operations-on-rdflib-graphs">Set Operations on RDFLib Graphs</a></li> +<li class="toctree-l2"><a class="reference external" href="graph_utilities.html#basic-triple-matching">Basic Triple Matching</a></li> +<li class="toctree-l2"><a class="reference external" href="graph_utilities.html#managing-triples">Managing Triples</a></li> +<li class="toctree-l2"><a class="reference external" href="graph_utilities.html#rdf-literal-support">RDF Literal Support</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="persistence.html">Persistence</a></li> +<li class="toctree-l1"><a class="reference external" href="persisting_n3_terms.html">Persisting Notation 3 Terms</a><ul> +<li class="toctree-l2"><a class="reference external" href="persisting_n3_terms.html#using-n3-syntax-for-persistence">Using N3 Syntax for Persistence</a></li> +<li class="toctree-l2"><a class="reference external" href="persisting_n3_terms.html#variables-by-scope">Variables by Scope</a></li> +<li class="toctree-l2"><a class="reference external" href="persisting_n3_terms.html#the-need-to-skolemize-formula-identifiers">The Need to Skolemize Formula Identifiers</a></li> +<li class="toctree-l2"><a class="reference external" href="persisting_n3_terms.html#relying-on-log-formula-membership">Relying on <tt class="docutils literal"><span class="pre">log:Formula</span></tt> Membership</a></li> +<li class="toctree-l2"><a class="reference external" href="persisting_n3_terms.html#relying-on-an-explicit-interface">Relying on an Explicit Interface</a></li> +<li class="toctree-l2"><a class="reference external" href="persisting_n3_terms.html#persisting-formula-identifiers">Persisting Formula Identifiers</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="graph_merging.html">Merging graphs</a><ul> +<li class="toctree-l2"><a class="reference external" href="graph_merging.html#example-1">Example 1</a></li> +<li class="toctree-l2"><a class="reference external" href="graph_merging.html#example-2">Example 2</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="graphs_bnodes.html">Graphs, Named Graphs and Blank Nodes</a><ul> +<li class="toctree-l2"><a class="reference external" href="graphs_bnodes.html#vin-s-question">Vin’s question</a></li> +<li class="toctree-l2"><a class="reference external" href="graphs_bnodes.html#the-discourse">The discourse</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="assorted_examples.html">Assorted examples</a><ul> +<li class="toctree-l2"><a class="reference external" href="assorted_examples.html#conjunctive-graphs">Conjunctive Graphs</a></li> +<li class="toctree-l2"><a class="reference external" href="assorted_examples.html#two-finger-exercises">Two-finger exercises</a></li> +<li class="toctree-l2"><a class="reference external" href="assorted_examples.html#update-namespace">Update namespace</a></li> +<li class="toctree-l2"><a class="reference external" href="assorted_examples.html#sparql-query">SPARQL query</a></li> +<li class="toctree-l2"><a class="reference external" href="assorted_examples.html#data-reading-exercise">Data reading exercise</a></li> +<li class="toctree-l2"><a class="reference external" href="assorted_examples.html#example-foaf-smushing">Example Foaf Smushing</a></li> +<li class="toctree-l2"><a class="reference external" href="assorted_examples.html#transitive-traversal">Transitive traversal</a></li> +<li class="toctree-l2"><a class="reference external" href="assorted_examples.html#film-py">film.py</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="addons.html">Additions</a><ul> +<li class="toctree-l2"><a class="reference external" href="addons.html#trixserializer">TriXSerializer</a></li> +<li class="toctree-l2"><a class="reference external" href="addons.html#sparql-xml-serializer">SPARQL-XML Serializer</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="modules/index.html">Modules</a><ul> +<li class="toctree-l2"><a class="reference external" href="modules/index.html#contents">Contents:</a></li> +</ul> +</li> +</ul> +</div> +<div class="section" id="indices-and-tables"> +<h2>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h2> +<ul class="simple"> +<li><a class="reference external" href="genindex.html"><em>Index</em></a></li> +<li><a class="reference external" href="modindex.html"><em>Module Index</em></a></li> +<li><a class="reference external" href="search.html"><em>Search Page</em></a></li> +</ul> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href="">rdflib 2.5</a><ul> +<li><a class="reference external" href="#introduction">Introduction</a></li> +<li><a class="reference external" href="#contents">Contents</a><ul> +</ul> +</li> +<li><a class="reference external" href="#indices-and-tables">Indices and tables</a></li> +</ul> +</li> +</ul> + + <h4>Next topic</h4> + <p class="topless"><a href="gettingstarted.html" + title="next chapter">Getting started with rdflib</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="_sources/index.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="gettingstarted.html" title="Getting started with rdflib" + accesskey="N">next</a> |</li> + <li><a href="">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/modindex.html b/docs/_build/html/modindex.html new file mode 100644 index 00000000..f06627b8 --- /dev/null +++ b/docs/_build/html/modindex.html @@ -0,0 +1,175 @@ +<!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>Global Module Index — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="_static/default.css" type="text/css" /> + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="_static/jquery.js"></script> + <script type="text/javascript" src="_static/doctools.js"></script> + <link rel="index" title="Index" href="genindex.html" /> + <link rel="search" title="Search" href="search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="index.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="" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + + <h1 id="global-module-index">Global Module Index</h1> + <a href="#cap-R"><strong>R</strong></a> + <hr/> + + <table width="100%" class="indextable" cellspacing="0" cellpadding="2"><tr class="pcap"><td></td><td> </td><td></td></tr> + <tr class="cap"><td></td><td><a name="cap-R"><strong>R</strong></a></td><td></td></tr><tr> + <td><img src="_static/minus.png" id="toggle-1" + class="toggler" style="display: none" alt="-" /></td> + <td> + <tt class="xref">rdflib</tt></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="modules/others.html#module-rdflib.collection"><tt class="xref">rdflib.collection</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="modules/graphs/index.html#module-rdflib.graph"><tt class="xref">rdflib.graph</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="modules/others.html#module-rdflib.journal"><tt class="xref">rdflib.journal</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="namespace_utilities.html#module-rdflib.namespace"><tt class="xref">rdflib.namespace</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="modules/others.html#module-rdflib.parser"><tt class="xref">rdflib.parser</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="modules/others.html#module-rdflib.query"><tt class="xref">rdflib.query</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="modules/others.html#module-rdflib.query.result"><tt class="xref">rdflib.query.result</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="modules/others.html#module-rdflib.sparql"><tt class="xref">rdflib.sparql</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="modules/others.html#module-rdflib.store"><tt class="xref">rdflib.store</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="modules/others.html#module-rdflib.syntax"><tt class="xref">rdflib.syntax</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="gettingstarted.html#module-rdflib.syntax.parsers"><tt class="xref">rdflib.syntax.parsers</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="gettingstarted.html#module-rdflib.syntax.parsers.n3p"><tt class="xref">rdflib.syntax.parsers.n3p</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="gettingstarted.html#module-rdflib.syntax.parsers.N3Parser"><tt class="xref">rdflib.syntax.parsers.N3Parser</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="gettingstarted.html#module-rdflib.syntax.parsers.NTParser"><tt class="xref">rdflib.syntax.parsers.NTParser</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="gettingstarted.html#module-rdflib.syntax.parsers.ntriples"><tt class="xref">rdflib.syntax.parsers.ntriples</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="gettingstarted.html#module-rdflib.syntax.parsers.RDFXMLParser"><tt class="xref">rdflib.syntax.parsers.RDFXMLParser</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="gettingstarted.html#module-rdflib.syntax.parsers.TriXParser"><tt class="xref">rdflib.syntax.parsers.TriXParser</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="modules/others.html#module-rdflib.term"><tt class="xref">rdflib.term</tt></a></td><td> + <em></em></td></tr><tr class="cg-1"> + <td></td> + <td> + <a href="modules/others.html#module-rdflib.textindex"><tt class="xref">rdflib.textindex</tt></a></td><td> + <em></em></td></tr> + </table> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <div id="searchbox" style="display: none"> + <h3>Quick search</h3> + <form class="search" action="search.html" method="get"> + <input type="text" name="q" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/modules/graphs/conjunctive_graph.html b/docs/_build/html/modules/graphs/conjunctive_graph.html new file mode 100644 index 00000000..4ed9d454 --- /dev/null +++ b/docs/_build/html/modules/graphs/conjunctive_graph.html @@ -0,0 +1,354 @@ +<!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>rdflib.Graph.ConjunctiveGraph – ConjunctiveGraph class definition — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="../../_static/default.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '../../', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="../../_static/jquery.js"></script> + <script type="text/javascript" src="../../_static/doctools.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="../../index.html" /> + <link rel="up" title="Graphs" href="index.html" /> + <link rel="next" title="rdflib.graph.QuotedGraph – Quoted graphs" href="../nodes/quoted_graph.html" /> + <link rel="prev" title="rdflib.Graph.Graph – Graph class definition" href="graph.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="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="../nodes/quoted_graph.html" title="rdflib.graph.QuotedGraph – Quoted graphs" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="graph.html" title="rdflib.Graph.Graph – Graph class definition" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Graphs</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="rdflib-graph-conjunctivegraph-conjunctivegraph-class-definition"> +<h1><tt class="xref docutils literal"><span class="pre">rdflib.Graph.ConjunctiveGraph</span></tt> – ConjunctiveGraph class definition<a class="headerlink" href="#rdflib-graph-conjunctivegraph-conjunctivegraph-class-definition" title="Permalink to this headline">¶</a></h1> +<div class="section" id="module-rdflib.graph"> +<h2>Conjunctive Graph<a class="headerlink" href="#module-rdflib.graph" title="Permalink to this headline">¶</a></h2> +<p>Instantiating Graphs with default store (IOMemory) and default identifier (a BNode):</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span><span class="o">=</span><span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">__class__</span> +<span class="go"><class 'rdflib.store.IOMemory.IOMemory'></span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">identifier</span><span class="o">.</span><span class="n">__class__</span> +<span class="go"><class 'rdflib.term.BNode'></span> +</pre></div> +</div> +<p>Instantiating Graphs with a specific kind of store (IOMemory) and a default identifier (a BNode):</p> +<p>Other store kinds: Sleepycat, MySQL, ZODB, SQLite</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">store</span> <span class="o">=</span> <span class="n">plugin</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'IOMemory'</span><span class="p">,</span><span class="n">Store</span><span class="p">)()</span> +<span class="gp">>>> </span><span class="n">store</span><span class="o">.</span><span class="n">__class__</span><span class="o">.</span><span class="n">__name__</span> +<span class="go">'IOMemory'</span> +<span class="gp">>>> </span><span class="n">graph</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">store</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">graph</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">__class__</span> +<span class="go"><class 'rdflib.store.IOMemory.IOMemory'></span> +</pre></div> +</div> +<p>Instantiating Graphs with Sleepycat store and an identifier - <<a class="reference external" href="http://rdflib.net">http://rdflib.net</a>>:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span><span class="o">=</span><span class="n">Graph</span><span class="p">(</span><span class="s">'IOMemory'</span><span class="p">,</span><span class="n">URIRef</span><span class="p">(</span><span class="s">"http://rdflib.net"</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">identifier</span> +<span class="go">rdflib.term.URIRef('http://rdflib.net')</span> +<span class="gp">>>> </span><span class="nb">str</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">"<http://rdflib.net> a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']."</span> +</pre></div> +</div> +<p>Creating a ConjunctiveGraph - The top level container for all named Graphs in a ‘database’:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span><span class="o">=</span><span class="n">ConjunctiveGraph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="nb">str</span><span class="p">(</span><span class="n">g</span><span class="o">.</span><span class="n">default_context</span><span class="p">)</span> +<span class="go">"[a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']]."</span> +</pre></div> +</div> +<p>Adding / removing reified triples to Graph and iterating over it directly or via triple pattern:</p> +<blockquote> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span><span class="o">=</span><span class="n">Graph</span><span class="p">(</span><span class="s">'IOMemory'</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">statementId</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> +<span class="gp">>>> </span><span class="k">print</span> <span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">0</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">statementId</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">Statement</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">statementId</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">subject</span><span class="p">,</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'http://rdflib.net/store/ConjunctiveGraph'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">statementId</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">predicate</span><span class="p">,</span><span class="n">RDFS</span><span class="o">.</span><span class="n">label</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">statementId</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">object</span><span class="p">,</span><span class="n">Literal</span><span class="p">(</span><span class="s">"Conjunctive Graph"</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="k">print</span> <span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">4</span> +<span class="gp">>>> </span><span class="k">for</span> <span class="n">s</span><span class="p">,</span><span class="n">p</span><span class="p">,</span><span class="n">o</span> <span class="ow">in</span> <span class="n">g</span><span class="p">:</span> <span class="k">print</span> <span class="nb">type</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> +<span class="gp">...</span> +<span class="go"><class 'rdflib.term.BNode'></span> +<span class="go"><class 'rdflib.term.BNode'></span> +<span class="go"><class 'rdflib.term.BNode'></span> +<span class="go"><class 'rdflib.term.BNode'></span> +</pre></div> +</div> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">for</span> <span class="n">s</span><span class="p">,</span><span class="n">p</span><span class="p">,</span><span class="n">o</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">triples</span><span class="p">((</span><span class="bp">None</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">object</span><span class="p">,</span><span class="bp">None</span><span class="p">)):</span> <span class="k">print</span> <span class="n">o</span> +<span class="gp">...</span> +<span class="go">Conjunctive Graph</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">remove</span><span class="p">((</span><span class="n">statementId</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">Statement</span><span class="p">))</span> +<span class="gp">>>> </span><span class="k">print</span> <span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">3</span> +</pre></div> +</div> +</blockquote> +<p>None terms in calls to triple can be thought of as ‘open variables’</p> +<p>Graph Aggregation - ConjunctiveGraphs and ReadOnlyGraphAggregate within the same store:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">store</span> <span class="o">=</span> <span class="n">plugin</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'IOMemory'</span><span class="p">,</span><span class="n">Store</span><span class="p">)()</span> +<span class="gp">>>> </span><span class="n">g1</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">store</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">g2</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">store</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">g3</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">store</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">stmt1</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">stmt2</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">stmt3</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">g1</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt1</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">Statement</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g1</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt1</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">subject</span><span class="p">,</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'http://rdflib.net/store/ConjunctiveGraph'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">g1</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt1</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">predicate</span><span class="p">,</span><span class="n">RDFS</span><span class="o">.</span><span class="n">label</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g1</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt1</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">object</span><span class="p">,</span><span class="n">Literal</span><span class="p">(</span><span class="s">"Conjunctive Graph"</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">g2</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt2</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">Statement</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g2</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt2</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">subject</span><span class="p">,</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'http://rdflib.net/store/ConjunctiveGraph'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">g2</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt2</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">predicate</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g2</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt2</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">object</span><span class="p">,</span><span class="n">RDFS</span><span class="o">.</span><span class="n">Class</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g3</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt3</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">Statement</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g3</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt3</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">subject</span><span class="p">,</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'http://rdflib.net/store/ConjunctiveGraph'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">g3</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt3</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">predicate</span><span class="p">,</span><span class="n">RDFS</span><span class="o">.</span><span class="n">comment</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g3</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt3</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">object</span><span class="p">,</span><span class="n">Literal</span><span class="p">(</span><span class="s">"The top-level aggregate graph - The sum of all named graphs within a Store"</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">ConjunctiveGraph</span><span class="p">(</span><span class="n">store</span><span class="p">)</span><span class="o">.</span><span class="n">subjects</span><span class="p">(</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">Statement</span><span class="p">)))</span> +<span class="go">3</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">ReadOnlyGraphAggregate</span><span class="p">([</span><span class="n">g1</span><span class="p">,</span><span class="n">g2</span><span class="p">])</span><span class="o">.</span><span class="n">subjects</span><span class="p">(</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">Statement</span><span class="p">)))</span> +<span class="go">2</span> +</pre></div> +</div> +<p>ConjunctiveGraphs have a ‘quads’ method which returns quads instead of triples, where the fourth item +is the Graph (or subclass thereof) instance in which the triple was asserted:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">uniqueGraphNames</span> <span class="o">=</span> <span class="n">set</span><span class="p">([</span><span class="n">graph</span><span class="o">.</span><span class="n">identifier</span> <span class="k">for</span> <span class="n">s</span><span class="p">,</span><span class="n">p</span><span class="p">,</span><span class="n">o</span><span class="p">,</span><span class="n">graph</span> <span class="ow">in</span> <span class="n">ConjunctiveGraph</span><span class="p">(</span><span class="n">store</span><span class="p">)</span><span class="o">.</span><span class="n">quads</span><span class="p">((</span><span class="bp">None</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">predicate</span><span class="p">,</span><span class="bp">None</span><span class="p">))])</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">uniqueGraphNames</span><span class="p">)</span> +<span class="go">3</span> +<span class="gp">>>> </span><span class="n">unionGraph</span> <span class="o">=</span> <span class="n">ReadOnlyGraphAggregate</span><span class="p">([</span><span class="n">g1</span><span class="p">,</span><span class="n">g2</span><span class="p">])</span> +<span class="gp">>>> </span><span class="n">uniqueGraphNames</span> <span class="o">=</span> <span class="n">set</span><span class="p">([</span><span class="n">graph</span><span class="o">.</span><span class="n">identifier</span> <span class="k">for</span> <span class="n">s</span><span class="p">,</span><span class="n">p</span><span class="p">,</span><span class="n">o</span><span class="p">,</span><span class="n">graph</span> <span class="ow">in</span> <span class="n">unionGraph</span><span class="o">.</span><span class="n">quads</span><span class="p">((</span><span class="bp">None</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">predicate</span><span class="p">,</span><span class="bp">None</span><span class="p">))])</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">uniqueGraphNames</span><span class="p">)</span> +<span class="go">2</span> +</pre></div> +</div> +<p>Parsing N3 from StringIO</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g2</span><span class="o">=</span><span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">src</span> <span class="o">=</span> <span class="s">"""</span> +<span class="gp">... </span><span class="s">@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .</span> +<span class="gp">... </span><span class="s">@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .</span> +<span class="gp">... </span><span class="s">[ a rdf:Statement ;</span> +<span class="gp">... </span><span class="s"> rdf:subject <http://rdflib.net/store#ConjunctiveGraph>;</span> +<span class="gp">... </span><span class="s"> rdf:predicate rdfs:label;</span> +<span class="gp">... </span><span class="s"> rdf:object "Conjunctive Graph" ] """</span> +<span class="gp">>>> </span><span class="n">g2</span><span class="o">=</span><span class="n">g2</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">StringIO</span><span class="p">(</span><span class="n">src</span><span class="p">),</span><span class="n">format</span><span class="o">=</span><span class="s">'n3'</span><span class="p">)</span> +<span class="gp">>>> </span><span class="k">print</span> <span class="nb">len</span><span class="p">(</span><span class="n">g2</span><span class="p">)</span> +<span class="go">4</span> +</pre></div> +</div> +<p>Using Namespace class:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">RDFLib</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">(</span><span class="s">'http://rdflib.net'</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">RDFLib</span><span class="o">.</span><span class="n">ConjunctiveGraph</span> +<span class="go">rdflib.term.URIRef('http://rdflib.netConjunctiveGraph')</span> +<span class="gp">>>> </span><span class="n">RDFLib</span><span class="p">[</span><span class="s">'Graph'</span><span class="p">]</span> +<span class="go">rdflib.term.URIRef('http://rdflib.netGraph')</span> +</pre></div> +</div> +<p>SPARQL Queries</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">print</span> <span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">3</span> +<span class="gp">>>> </span><span class="n">q</span> <span class="o">=</span> <span class="s">'''</span> +<span class="gp">... </span><span class="s">PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?pred WHERE { ?stmt rdf:predicate ?pred. }</span> +<span class="gp">... </span><span class="s">'''</span> +<span class="gp">>>> </span><span class="k">for</span> <span class="n">pred</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">q</span><span class="p">):</span> <span class="k">print</span> <span class="n">pred</span> +<span class="go">(rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'),)</span> +</pre></div> +</div> +<p>SPARQL Queries with namespace bindings as argument</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">nsMap</span> <span class="o">=</span> <span class="p">{</span><span class="s">u"rdf"</span><span class="p">:</span><span class="n">RDF</span><span class="o">.</span><span class="n">RDFNS</span><span class="p">}</span> +<span class="gp">>>> </span><span class="k">for</span> <span class="n">pred</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="s">"SELECT ?pred WHERE { ?stmt rdf:predicate ?pred. }"</span><span class="p">,</span> <span class="n">initNs</span><span class="o">=</span><span class="n">nsMap</span><span class="p">):</span> <span class="k">print</span> <span class="n">pred</span> +<span class="go">(rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'),)</span> +</pre></div> +</div> +<p>Parameterized SPARQL Queries</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">rdflib.term</span> <span class="kn">import</span> <span class="n">Variable</span> +<span class="gp">>>> </span><span class="n">top</span> <span class="o">=</span> <span class="p">{</span> <span class="n">Variable</span><span class="p">(</span><span class="s">"?term"</span><span class="p">)</span> <span class="p">:</span> <span class="n">RDF</span><span class="o">.</span><span class="n">predicate</span> <span class="p">}</span> +<span class="gp">>>> </span><span class="k">for</span> <span class="n">pred</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="s">"SELECT ?pred WHERE { ?stmt ?term ?pred. }"</span><span class="p">,</span> <span class="n">initBindings</span><span class="o">=</span><span class="n">top</span><span class="p">):</span> <span class="k">print</span> <span class="n">pred</span> +<span class="go">(rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'),)</span> +</pre></div> +</div> +<div class="section" id="module-contents"> +<h3>Module Contents<a class="headerlink" href="#module-contents" title="Permalink to this headline">¶</a></h3> +<dl class="class"> +<dt id="rdflib.graph.ConjunctiveGraph"> +<!--[rdflib.graph.ConjunctiveGraph]-->class <tt class="descclassname">rdflib.graph.</tt><tt class="descname">ConjunctiveGraph</tt><big>(</big><em>store='default'</em>, <em>identifier=None</em><big>)</big><a class="headerlink" href="#rdflib.graph.ConjunctiveGraph" title="Permalink to this definition">¶</a></dt> +<dd><dl class="method"> +<dt id="rdflib.graph.ConjunctiveGraph.add"> +<!--[rdflib.graph.ConjunctiveGraph.add]--><tt class="descname">add</tt><big>(</big><em>(s</em>, <em>p</em>, <em>o)</em><big>)</big><a class="headerlink" href="#rdflib.graph.ConjunctiveGraph.add" title="Permalink to this definition">¶</a></dt> +<dd>Add the triple to the default context</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.ConjunctiveGraph.addN"> +<!--[rdflib.graph.ConjunctiveGraph.addN]--><tt class="descname">addN</tt><big>(</big><em>quads</em><big>)</big><a class="headerlink" href="#rdflib.graph.ConjunctiveGraph.addN" title="Permalink to this definition">¶</a></dt> +<dd>Add a sequence of triples with context</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.ConjunctiveGraph.context_id"> +<!--[rdflib.graph.ConjunctiveGraph.context_id]--><tt class="descname">context_id</tt><big>(</big><em>uri</em>, <em>context_id=None</em><big>)</big><a class="headerlink" href="#rdflib.graph.ConjunctiveGraph.context_id" title="Permalink to this definition">¶</a></dt> +<dd>URI#context</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.ConjunctiveGraph.contexts"> +<!--[rdflib.graph.ConjunctiveGraph.contexts]--><tt class="descname">contexts</tt><big>(</big><em>triple=None</em><big>)</big><a class="headerlink" href="#rdflib.graph.ConjunctiveGraph.contexts" title="Permalink to this definition">¶</a></dt> +<dd><p>Iterate over all contexts in the graph</p> +<p>If triple is specified, iterate over all contexts the triple is in.</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.ConjunctiveGraph.get_context"> +<!--[rdflib.graph.ConjunctiveGraph.get_context]--><tt class="descname">get_context</tt><big>(</big><em>identifier</em>, <em>quoted=False</em><big>)</big><a class="headerlink" href="#rdflib.graph.ConjunctiveGraph.get_context" title="Permalink to this definition">¶</a></dt> +<dd><p>Return a context graph for the given identifier</p> +<p>identifier must be a URIRef or BNode.</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.ConjunctiveGraph.parse"> +<!--[rdflib.graph.ConjunctiveGraph.parse]--><tt class="descname">parse</tt><big>(</big><em>source=None</em>, <em>publicID=None</em>, <em>format='xml'</em>, <em>location=None</em>, <em>file=None</em>, <em>data=None</em>, <em>**args</em><big>)</big><a class="headerlink" href="#rdflib.graph.ConjunctiveGraph.parse" title="Permalink to this definition">¶</a></dt> +<dd><p>Parse source adding the resulting triples to it’s own context +(sub graph of this graph).</p> +<p>See <cite>rdflib.graph.Graph.parse</cite> for documentation on arguments.</p> +<table class="docutils field-list" frame="void" rules="none"> +<col class="field-name" /> +<col class="field-body" /> +<tbody valign="top"> +<tr class="field"><th class="field-name">Returns:</th><td class="field-body"></td> +</tr> +</tbody> +</table> +<p>The graph into which the source was parsed. In the case of n3 +it returns the root context.</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.ConjunctiveGraph.quads"> +<!--[rdflib.graph.ConjunctiveGraph.quads]--><tt class="descname">quads</tt><big>(</big><em>(s</em>, <em>p</em>, <em>o)</em><big>)</big><a class="headerlink" href="#rdflib.graph.ConjunctiveGraph.quads" title="Permalink to this definition">¶</a></dt> +<dd>Iterate over all the quads in the entire conjunctive graph</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.ConjunctiveGraph.remove"> +<!--[rdflib.graph.ConjunctiveGraph.remove]--><tt class="descname">remove</tt><big>(</big><em>(s</em>, <em>p</em>, <em>o)</em><big>)</big><a class="headerlink" href="#rdflib.graph.ConjunctiveGraph.remove" title="Permalink to this definition">¶</a></dt> +<dd>Removes from all its contexts</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.ConjunctiveGraph.remove_context"> +<!--[rdflib.graph.ConjunctiveGraph.remove_context]--><tt class="descname">remove_context</tt><big>(</big><em>context</em><big>)</big><a class="headerlink" href="#rdflib.graph.ConjunctiveGraph.remove_context" title="Permalink to this definition">¶</a></dt> +<dd>Removes the given context from the graph</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.ConjunctiveGraph.triples"> +<!--[rdflib.graph.ConjunctiveGraph.triples]--><tt class="descname">triples</tt><big>(</big><em>(s</em>, <em>p</em>, <em>o)</em>, <em>context=None</em><big>)</big><a class="headerlink" href="#rdflib.graph.ConjunctiveGraph.triples" title="Permalink to this definition">¶</a></dt> +<dd>Iterate over all the triples in the entire conjunctive graph</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.ConjunctiveGraph.triples_choices"> +<!--[rdflib.graph.ConjunctiveGraph.triples_choices]--><tt class="descname">triples_choices</tt><big>(</big><em>(s</em>, <em>p</em>, <em>o)</em><big>)</big><a class="headerlink" href="#rdflib.graph.ConjunctiveGraph.triples_choices" title="Permalink to this definition">¶</a></dt> +<dd>Iterate over all the triples in the entire conjunctive graph</dd></dl> + +</dd></dl> + +</div> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="../../index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">rdflib.Graph.ConjunctiveGraph</span></tt> – ConjunctiveGraph class definition</a><ul> +<li><a class="reference external" href="#module-rdflib.graph">Conjunctive Graph</a><ul> +<li><a class="reference external" href="#module-contents">Module Contents</a></li> +</ul> +</li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="graph.html" + title="previous chapter"><tt class="docutils literal"><span class="pre">rdflib.Graph.Graph</span></tt> – Graph class definition</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="../nodes/quoted_graph.html" + title="next chapter"><tt class="docutils literal"><span class="pre">rdflib.graph.QuotedGraph</span></tt> – Quoted graphs</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="../../_sources/modules/graphs/conjunctive_graph.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="../nodes/quoted_graph.html" title="rdflib.graph.QuotedGraph – Quoted graphs" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="graph.html" title="rdflib.Graph.Graph – Graph class definition" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Graphs</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/modules/graphs/graph.html b/docs/_build/html/modules/graphs/graph.html new file mode 100644 index 00000000..7f7a3d72 --- /dev/null +++ b/docs/_build/html/modules/graphs/graph.html @@ -0,0 +1,562 @@ +<!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>rdflib.Graph.Graph – Graph class definition — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="../../_static/default.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '../../', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="../../_static/jquery.js"></script> + <script type="text/javascript" src="../../_static/doctools.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="../../index.html" /> + <link rel="up" title="Graphs" href="index.html" /> + <link rel="next" title="rdflib.Graph.ConjunctiveGraph – ConjunctiveGraph class definition" href="conjunctive_graph.html" /> + <link rel="prev" title="Graphs" href="index.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="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="conjunctive_graph.html" title="rdflib.Graph.ConjunctiveGraph – ConjunctiveGraph class definition" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="index.html" title="Graphs" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Graphs</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="rdflib-graph-graph-graph-class-definition"> +<h1><tt class="xref docutils literal"><span class="pre">rdflib.Graph.Graph</span></tt> – Graph class definition<a class="headerlink" href="#rdflib-graph-graph-graph-class-definition" title="Permalink to this headline">¶</a></h1> +<div class="section" id="graph"> +<h2>Graph<a class="headerlink" href="#graph" title="Permalink to this headline">¶</a></h2> +<div class="section" id="module-contents"> +<h3>Module Contents<a class="headerlink" href="#module-contents" title="Permalink to this headline">¶</a></h3> +<dl class="class"> +<dt id="rdflib.graph.Graph"> +<!--[rdflib.graph.Graph]-->class <tt class="descclassname">rdflib.graph.</tt><tt class="descname">Graph</tt><big>(</big><em>store='default'</em>, <em>identifier=None</em>, <em>namespace_manager=None</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph" title="Permalink to this definition">¶</a></dt> +<dd><p>An RDF Graph</p> +<p>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).</p> +<p>Stores can be context-aware or unaware. Unaware stores take up +(some) less space but cannot support features that require +context, such as true merging/demerging of sub-graphs and +provenance.</p> +<p>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: <a class="reference external" href="http://www.w3.org/2004/03/trix/">http://www.w3.org/2004/03/trix/</a></p> +<p>Ontology for __str__ provenance terms:</p> +<div class="highlight-python"><pre>@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . +@prefix : <http://rdflib.net/store#> . +@prefix rdfg: <http://www.w3.org/2004/03/trix/rdfg-1/>. +@prefix owl: <http://www.w3.org/2002/07/owl#>. +@prefix log: <http://www.w3.org/2000/10/swap/log#>. +@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. + +:Store a owl:Class; + rdfs:subClassOf <http://xmlns.com/wordnet/1.6/Electronic_database>; + rdfs:subClassOf + [a owl:Restriction; + owl:onProperty rdfs:label; + owl:allValuesFrom [a owl:DataRange; + owl:oneOf ("IOMemory" + "Sleepcat" + "MySQL" + "Redland" + "REGEXMatching" + "ZODB" + "AuditableStorage" + "Memory")] + ]. + +:ConjunctiveGraph a owl:Class; + rdfs:subClassOf rdfg:Graph; + rdfs:label "The top-level graph within the store - the union of all the Graphs within." + rdfs:seeAlso <http://rdflib.net/rdf_store/#ConjunctiveGraph>. + +:DefaultGraph a owl:Class; + rdfs:subClassOf rdfg:Graph; + rdfs:label "The 'default' subgraph of a conjunctive graph". + + +:identifier a owl:Datatypeproperty; + rdfs:label "The store-associated identifier of the formula. ". + rdfs:domain log:Formula + rdfs:range xsd:anyURI; + +:storage a owl:ObjectProperty; + rdfs:domain [ + a owl:Class; + owl:unionOf (log:Formula rdfg:Graph :ConjunctiveGraph) + ]; + rdfs:range :Store. + +:default_context a owl:FunctionalProperty; + rdfs:label "The default context for a conjunctive graph"; + rdfs:domain :ConjunctiveGraph; + rdfs:range :DefaultGraph. + + +{?cg a :ConjunctiveGraph;:storage ?store} + => {?cg owl:sameAs ?store}. + +{?subGraph rdfg:subGraphOf ?cg;a :DefaultGraph} + => {?cg a :ConjunctiveGraph;:default_context ?subGraphOf} .</pre> +</div> +<dl class="method"> +<dt id="rdflib.graph.Graph.absolutize"> +<!--[rdflib.graph.Graph.absolutize]--><tt class="descname">absolutize</tt><big>(</big><em>uri</em>, <em>defrag=1</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.absolutize" title="Permalink to this definition">¶</a></dt> +<dd>Turn uri into an absolute URI if it’s not one already</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.add"> +<!--[rdflib.graph.Graph.add]--><tt class="descname">add</tt><big>(</big><em>(s</em>, <em>p</em>, <em>o)</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.add" title="Permalink to this definition">¶</a></dt> +<dd>Add a triple with self as context</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.addN"> +<!--[rdflib.graph.Graph.addN]--><tt class="descname">addN</tt><big>(</big><em>quads</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.addN" title="Permalink to this definition">¶</a></dt> +<dd>Add a sequence of triple with context</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.bind"> +<!--[rdflib.graph.Graph.bind]--><tt class="descname">bind</tt><big>(</big><em>prefix</em>, <em>namespace</em>, <em>override=True</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.bind" title="Permalink to this definition">¶</a></dt> +<dd><p>Bind prefix to namespace</p> +<p>If override is True will bind namespace to given prefix if namespace +was already bound to a different prefix.</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.close"> +<!--[rdflib.graph.Graph.close]--><tt class="descname">close</tt><big>(</big><em>commit_pending_transaction=False</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.close" title="Permalink to this definition">¶</a></dt> +<dd><p>Close the graph store</p> +<p>Might be necessary for stores that require closing a connection to a +database or releasing some resource.</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.comment"> +<!--[rdflib.graph.Graph.comment]--><tt class="descname">comment</tt><big>(</big><em>subject</em>, <em>default=''</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.comment" title="Permalink to this definition">¶</a></dt> +<dd><p>Query for the RDFS.comment of the subject</p> +<p>Return default if no comment exists</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.commit"> +<!--[rdflib.graph.Graph.commit]--><tt class="descname">commit</tt><big>(</big><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.commit" title="Permalink to this definition">¶</a></dt> +<dd>Commits active transactions</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.connected"> +<!--[rdflib.graph.Graph.connected]--><tt class="descname">connected</tt><big>(</big><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.connected" title="Permalink to this definition">¶</a></dt> +<dd><p>Check if the Graph is connected</p> +<p>The Graph is considered undirectional.</p> +<p>Performs a search on the Graph, starting from a random node. Then +iteratively goes depth-first through the triplets where the node is +subject and object. Return True if all nodes have been visited and +False if it cannot continue and there are still unvisited nodes left.</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.destroy"> +<!--[rdflib.graph.Graph.destroy]--><tt class="descname">destroy</tt><big>(</big><em>configuration</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.destroy" title="Permalink to this definition">¶</a></dt> +<dd>Destroy the store identified by <cite>configuration</cite> if supported</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.items"> +<!--[rdflib.graph.Graph.items]--><tt class="descname">items</tt><big>(</big><em>list</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.items" title="Permalink to this definition">¶</a></dt> +<dd><p>Generator over all items in the resource specified by list</p> +<p>list is an RDF collection.</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.label"> +<!--[rdflib.graph.Graph.label]--><tt class="descname">label</tt><big>(</big><em>subject</em>, <em>default=''</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.label" title="Permalink to this definition">¶</a></dt> +<dd><p>Query for the RDFS.label of the subject</p> +<p>Return default if no label exists</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.n3"> +<!--[rdflib.graph.Graph.n3]--><tt class="descname">n3</tt><big>(</big><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.n3" title="Permalink to this definition">¶</a></dt> +<dd>return an n3 identifier for the Graph</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.namespaces"> +<!--[rdflib.graph.Graph.namespaces]--><tt class="descname">namespaces</tt><big>(</big><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.namespaces" title="Permalink to this definition">¶</a></dt> +<dd>Generator over all the prefix, namespace tuples</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.objects"> +<!--[rdflib.graph.Graph.objects]--><tt class="descname">objects</tt><big>(</big><em>subject=None</em>, <em>predicate=None</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.objects" title="Permalink to this definition">¶</a></dt> +<dd>A generator of objects with the given subject and predicate</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.open"> +<!--[rdflib.graph.Graph.open]--><tt class="descname">open</tt><big>(</big><em>configuration</em>, <em>create=False</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.open" title="Permalink to this definition">¶</a></dt> +<dd><p>Open the graph store</p> +<p>Might be necessary for stores that require opening a connection to a +database or acquiring some resource.</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.parse"> +<!--[rdflib.graph.Graph.parse]--><tt class="descname">parse</tt><big>(</big><em>source=None</em>, <em>publicID=None</em>, <em>format=None</em>, <em>location=None</em>, <em>file=None</em>, <em>data=None</em>, <em>**args</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.parse" title="Permalink to this definition">¶</a></dt> +<dd><p>Parse source adding the resulting triples to the Graph.</p> +<p>The source is specified using one of source, location, file or +data.</p> +<table class="docutils field-list" frame="void" rules="none"> +<col class="field-name" /> +<col class="field-body" /> +<tbody valign="top"> +<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> +<li><cite>source</cite>: An InputSource, file-like object, or string. In the case of a string the string is the location of the source.</li> +<li><cite>location</cite>: A string indicating the relative or absolute URL of the source. Graph’s absolutize method is used if a relative location is specified.</li> +<li><cite>file</cite>: A file-like object.</li> +<li><cite>data</cite>: A string containing the data to be parsed.</li> +<li><cite>format</cite>: Used if format can not be determined from source. Defaults to rdf/xml.</li> +<li><cite>publicID</cite>: 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).</li> +</ul> +</td> +</tr> +<tr class="field"><th class="field-name">Returns:</th><td class="field-body"></td> +</tr> +</tbody> +</table> +<p>self, the graph instance.</p> +<p>Examples:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">my_data</span> <span class="o">=</span> <span class="s">'''</span> +<span class="gp">... </span><span class="s"><rdf:RDF</span> +<span class="gp">... </span><span class="s"> xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'</span> +<span class="gp">... </span><span class="s"> xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'</span> +<span class="gp">... </span><span class="s">></span> +<span class="gp">... </span><span class="s"> <rdf:Description></span> +<span class="gp">... </span><span class="s"> <rdfs:label>Example</rdfs:label></span> +<span class="gp">... </span><span class="s"> <rdfs:comment>This is really just an example.</rdfs:comment></span> +<span class="gp">... </span><span class="s"> </rdf:Description></span> +<span class="gp">... </span><span class="s"></rdf:RDF></span> +<span class="gp">... </span><span class="s">'''</span> +<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">tempfile</span> +<span class="gp">>>> </span><span class="n">file_name</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mktemp</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="nb">file</span><span class="p">(</span><span class="n">file_name</span><span class="p">,</span> <span class="s">"w"</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">my_data</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> +</pre></div> +</div> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">g</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">my_data</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s">"application/rdf+xml"</span><span class="p">)</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">2</span> +</pre></div> +</div> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">g</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">location</span><span class="o">=</span><span class="n">file_name</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s">"application/rdf+xml"</span><span class="p">)</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">2</span> +</pre></div> +</div> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">g</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="nb">file</span><span class="o">=</span><span class="nb">file</span><span class="p">(</span><span class="n">file_name</span><span class="p">,</span> <span class="s">"r"</span><span class="p">),</span> <span class="n">format</span><span class="o">=</span><span class="s">"application/rdf+xml"</span><span class="p">)</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">2</span> +</pre></div> +</div> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.predicate_objects"> +<!--[rdflib.graph.Graph.predicate_objects]--><tt class="descname">predicate_objects</tt><big>(</big><em>subject=None</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.predicate_objects" title="Permalink to this definition">¶</a></dt> +<dd>A generator of (predicate, object) tuples for the given subject</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.predicates"> +<!--[rdflib.graph.Graph.predicates]--><tt class="descname">predicates</tt><big>(</big><em>subject=None</em>, <em>object=None</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.predicates" title="Permalink to this definition">¶</a></dt> +<dd>A generator of predicates with the given subject and object</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.query"> +<!--[rdflib.graph.Graph.query]--><tt class="descname">query</tt><big>(</big><em>strOrQuery</em>, <em>initBindings={}</em>, <em>initNs={}</em>, <em>DEBUG=False</em>, <em>PARSE_DEBUG=False</em>, <em>dataSetBase=None</em>, <em>processor='sparql'</em>, <em>extensionFunctions={rdflib.term.URIRef('http://www.w3.org/TR/rdf-sparql-query/#describe'): <function describe at 0x15ab130>}</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.query" title="Permalink to this definition">¶</a></dt> +<dd><p>Executes a SPARQL query (eventually will support Versa queries with +same method) against this Graph.</p> +<blockquote> +<ul> +<li><dl class="first docutils"> +<dt><cite>strOrQuery</cite>: Either a string consisting of the SPARQL query or</dt> +<dd><p class="first last">an instance of rdflib.sparql.bison.Query.Query</p> +</dd> +</dl> +</li> +<li><dl class="first docutils"> +<dt><cite>initBindings</cite>: A mapping from a Variable to an RDFLib term (used</dt> +<dd><p class="first last">as initial bindings for SPARQL query)</p> +</dd> +</dl> +</li> +<li><dl class="first docutils"> +<dt><cite>initNS</cite>: A mapping from a namespace prefix to an instance of</dt> +<dd><p class="first last">rdflib.Namespace (used for SPARQL query)</p> +</dd> +</dl> +</li> +<li><dl class="first docutils"> +<dt><cite>DEBUG</cite>: A boolean flag passed on to the SPARQL parser and</dt> +<dd><p class="first last">evaluation engine</p> +</dd> +</dl> +</li> +<li><dl class="first docutils"> +<dt><cite>processor</cite>: The kind of RDF query (must be ‘sparql’ until Versa</dt> +<dd><p class="first last">is ported)</p> +</dd> +</dl> +</li> +<li><dl class="first docutils"> +<dt><cite>USE_PYPARSING</cite>: A flag indicating whether to use the</dt> +<dd><p class="first last">experimental pyparsing parser for SPARQL</p> +</dd> +</dl> +</li> +</ul> +</blockquote> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.remove"> +<!--[rdflib.graph.Graph.remove]--><tt class="descname">remove</tt><big>(</big><em>(s</em>, <em>p</em>, <em>o)</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.remove" title="Permalink to this definition">¶</a></dt> +<dd><p>Remove a triple from the graph</p> +<p>If the triple does not provide a context attribute, removes the triple +from all contexts.</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.rollback"> +<!--[rdflib.graph.Graph.rollback]--><tt class="descname">rollback</tt><big>(</big><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.rollback" title="Permalink to this definition">¶</a></dt> +<dd>Rollback active transactions</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.seq"> +<!--[rdflib.graph.Graph.seq]--><tt class="descname">seq</tt><big>(</big><em>subject</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.seq" title="Permalink to this definition">¶</a></dt> +<dd><p>Check if subject is an rdf:Seq</p> +<p>If yes, it returns a Seq class instance, None otherwise.</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.serialize"> +<!--[rdflib.graph.Graph.serialize]--><tt class="descname">serialize</tt><big>(</big><em>destination=None</em>, <em>format='xml'</em>, <em>base=None</em>, <em>encoding=None</em>, <em>**args</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.serialize" title="Permalink to this definition">¶</a></dt> +<dd><p>Serialize the Graph to destination</p> +<p>If destination is None serialize method returns the serialization as a +string. Format defaults to xml (AKA rdf/xml).</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.set"> +<!--[rdflib.graph.Graph.set]--><tt class="descname">set</tt><big>(</big><em>(subject</em>, <em>predicate</em>, <em>object)</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.set" title="Permalink to this definition">¶</a></dt> +<dd><p>Convenience method to update the value of object</p> +<p>Remove any existing triples for subject and predicate before adding +(subject, predicate, object).</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.subject_objects"> +<!--[rdflib.graph.Graph.subject_objects]--><tt class="descname">subject_objects</tt><big>(</big><em>predicate=None</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.subject_objects" title="Permalink to this definition">¶</a></dt> +<dd>A generator of (subject, object) tuples for the given predicate</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.subject_predicates"> +<!--[rdflib.graph.Graph.subject_predicates]--><tt class="descname">subject_predicates</tt><big>(</big><em>object=None</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.subject_predicates" title="Permalink to this definition">¶</a></dt> +<dd>A generator of (subject, predicate) tuples for the given object</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.subjects"> +<!--[rdflib.graph.Graph.subjects]--><tt class="descname">subjects</tt><big>(</big><em>predicate=None</em>, <em>object=None</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.subjects" title="Permalink to this definition">¶</a></dt> +<dd>A generator of subjects with the given predicate and object</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.transitiveClosure"> +<!--[rdflib.graph.Graph.transitiveClosure]--><tt class="descname">transitiveClosure</tt><big>(</big><em>func</em>, <em>arg</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.transitiveClosure" title="Permalink to this definition">¶</a></dt> +<dd><p>Generates transitive closure of a user-defined +function against the graph</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">rdflib.collection</span> <span class="kn">import</span> <span class="n">Collection</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">=</span><span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">a</span><span class="o">=</span><span class="n">BNode</span><span class="p">(</span><span class="s">'foo'</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">b</span><span class="o">=</span><span class="n">BNode</span><span class="p">(</span><span class="s">'bar'</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">c</span><span class="o">=</span><span class="n">BNode</span><span class="p">(</span><span class="s">'baz'</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">a</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">first</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">a</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">rest</span><span class="p">,</span><span class="n">b</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">b</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">first</span><span class="p">,</span><span class="n">RDFS</span><span class="o">.</span><span class="n">label</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">b</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">rest</span><span class="p">,</span><span class="n">c</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">c</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">first</span><span class="p">,</span><span class="n">RDFS</span><span class="o">.</span><span class="n">comment</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">c</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">rest</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">nil</span><span class="p">))</span> +<span class="gp">>>> </span><span class="k">def</span> <span class="nf">topList</span><span class="p">(</span><span class="n">node</span><span class="p">,</span><span class="n">g</span><span class="p">):</span> +<span class="gp">... </span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">subjects</span><span class="p">(</span><span class="n">RDF</span><span class="o">.</span><span class="n">rest</span><span class="p">,</span><span class="n">node</span><span class="p">):</span> +<span class="gp">... </span> <span class="k">yield</span> <span class="n">s</span> +<span class="gp">>>> </span><span class="k">def</span> <span class="nf">reverseList</span><span class="p">(</span><span class="n">node</span><span class="p">,</span><span class="n">g</span><span class="p">):</span> +<span class="gp">... </span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">objects</span><span class="p">(</span><span class="n">node</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">first</span><span class="p">):</span> +<span class="gp">... </span> <span class="k">print</span> <span class="n">f</span> +<span class="gp">... </span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">subjects</span><span class="p">(</span><span class="n">RDF</span><span class="o">.</span><span class="n">rest</span><span class="p">,</span><span class="n">node</span><span class="p">):</span> +<span class="gp">... </span> <span class="k">yield</span> <span class="n">s</span> +</pre></div> +</div> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="p">[</span><span class="n">rt</span> <span class="k">for</span> <span class="n">rt</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">transitiveClosure</span><span class="p">(</span><span class="n">topList</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">nil</span><span class="p">)]</span> +<span class="go">[rdflib.term.BNode('baz'), rdflib.term.BNode('bar'), rdflib.term.BNode('foo')]</span> +</pre></div> +</div> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="p">[</span><span class="n">rt</span> <span class="k">for</span> <span class="n">rt</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">transitiveClosure</span><span class="p">(</span><span class="n">reverseList</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">nil</span><span class="p">)]</span> +<span class="go">http://www.w3.org/2000/01/rdf-schema#comment</span> +<span class="go">http://www.w3.org/2000/01/rdf-schema#label</span> +<span class="go">http://www.w3.org/1999/02/22-rdf-syntax-ns#type</span> +<span class="go">[rdflib.term.BNode('baz'), rdflib.term.BNode('bar'), rdflib.term.BNode('foo')]</span> +</pre></div> +</div> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.transitive_objects"> +<!--[rdflib.graph.Graph.transitive_objects]--><tt class="descname">transitive_objects</tt><big>(</big><em>subject</em>, <em>property</em>, <em>remember=None</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.transitive_objects" title="Permalink to this definition">¶</a></dt> +<dd><p>Transitively generate objects for the <cite>property</cite> relationship</p> +<p>Generated objects belong to the depth first transitive closure of the +<cite>property</cite> relationship starting at <cite>subject</cite>.</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.transitive_subjects"> +<!--[rdflib.graph.Graph.transitive_subjects]--><tt class="descname">transitive_subjects</tt><big>(</big><em>predicate</em>, <em>object</em>, <em>remember=None</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.transitive_subjects" title="Permalink to this definition">¶</a></dt> +<dd><p>Transitively generate objects for the <cite>property</cite> relationship</p> +<p>Generated objects belong to the depth first transitive closure of the +<cite>property</cite> relationship starting at <cite>subject</cite>.</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.triples"> +<!--[rdflib.graph.Graph.triples]--><tt class="descname">triples</tt><big>(</big><em>(s</em>, <em>p</em>, <em>o)</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.triples" title="Permalink to this definition">¶</a></dt> +<dd><p>Generator over the triple store</p> +<p>Returns triples that match the given triple pattern. If triple pattern +does not provide a context, all contexts will be searched.</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.Graph.value"> +<!--[rdflib.graph.Graph.value]--><tt class="descname">value</tt><big>(</big><em>subject=None</em>, <em>predicate=rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#value')</em>, <em>object=None</em>, <em>default=None</em>, <em>any=True</em><big>)</big><a class="headerlink" href="#rdflib.graph.Graph.value" title="Permalink to this definition">¶</a></dt> +<dd><p>Get a value for a pair of two criteria</p> +<p>Exactly one of subject, predicate, object must be None. Useful if one +knows that there may only be one value.</p> +<p>It is one of those situations that occur a lot, hence this +‘macro’ like utility</p> +<table class="docutils field-list" frame="void" rules="none"> +<col class="field-name" /> +<col class="field-body" /> +<tbody valign="top"> +<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"></td> +</tr> +</tbody> +</table> +<p>subject, predicate, object – exactly one must be None +default – value to be returned if no values found +any – if True: return any value in the case there is more than one</p> +<blockquote> +else: raise UniquenessError</blockquote> +</dd></dl> + +</dd></dl> + +</div> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="../../index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">rdflib.Graph.Graph</span></tt> – Graph class definition</a><ul> +<li><a class="reference external" href="#graph">Graph</a><ul> +<li><a class="reference external" href="#module-contents">Module Contents</a></li> +</ul> +</li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="index.html" + title="previous chapter">Graphs</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="conjunctive_graph.html" + title="next chapter"><tt class="docutils literal docutils literal"><span class="pre">rdflib.Graph.ConjunctiveGraph</span></tt> – ConjunctiveGraph class definition</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="../../_sources/modules/graphs/graph.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="conjunctive_graph.html" title="rdflib.Graph.ConjunctiveGraph – ConjunctiveGraph class definition" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="index.html" title="Graphs" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Graphs</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/modules/graphs/index.html b/docs/_build/html/modules/graphs/index.html new file mode 100644 index 00000000..570e88e2 --- /dev/null +++ b/docs/_build/html/modules/graphs/index.html @@ -0,0 +1,279 @@ +<!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>Graphs — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="../../_static/default.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '../../', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="../../_static/jquery.js"></script> + <script type="text/javascript" src="../../_static/doctools.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="../../index.html" /> + <link rel="up" title="Modules" href="../index.html" /> + <link rel="next" title="rdflib.Graph.Graph – Graph class definition" href="graph.html" /> + <link rel="prev" title="rdflib.graph.QuotedGraph – Quoted graphs" href="../nodes/quoted_graph.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="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="graph.html" title="rdflib.Graph.Graph – Graph class definition" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="../nodes/quoted_graph.html" title="rdflib.graph.QuotedGraph – Quoted graphs" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="module-rdflib.graph"> +<span id="graphs"></span><h1>Graphs<a class="headerlink" href="#module-rdflib.graph" title="Permalink to this headline">¶</a></h1> +<p>RDFLib defines the following kinds of Graphs:</p> +<ul class="simple"> +<li>‘Graph’(_’‘store’‘_,_’‘identifier’‘_)</li> +<li>‘QuotedGraph’(_’‘store’‘_,_’‘identifier’‘_)</li> +<li>‘ConjunctiveGraph’(_’‘store’‘_,_’‘default’‘_’‘identifier’‘_= ‘’None’‘)</li> +</ul> +<p>A Conjunctive Graph is the most relevant collection of graphs that are considered to be the boundary for closed world assumptions. This boundary is equivalent to that of the store instance (which is itself uniquely identified and distinct from other instances of <tt class="xref docutils literal"><span class="pre">Store</span></tt> that signify other Conjunctive Graphs). It is equivalent to all the named graphs within it and associated with a <tt class="docutils literal"><span class="pre">_default_</span></tt> graph which is automatically assigned a <tt class="xref docutils literal"><span class="pre">BNode</span></tt> for an identifier - if one isn’t given.</p> +<p>Instantiating Graphs with default store (IOMemory) and default identifier (a BNode):</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span><span class="o">=</span><span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">__class__</span> +<span class="go"><class 'rdflib.store.IOMemory.IOMemory'></span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">identifier</span><span class="o">.</span><span class="n">__class__</span> +<span class="go"><class 'rdflib.term.BNode'></span> +</pre></div> +</div> +<p>Instantiating Graphs with a specific kind of store (IOMemory) and a default identifier (a BNode):</p> +<p>Other store kinds: Sleepycat, MySQL, ZODB, SQLite</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">store</span> <span class="o">=</span> <span class="n">plugin</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'IOMemory'</span><span class="p">,</span><span class="n">Store</span><span class="p">)()</span> +<span class="gp">>>> </span><span class="n">store</span><span class="o">.</span><span class="n">__class__</span><span class="o">.</span><span class="n">__name__</span> +<span class="go">'IOMemory'</span> +<span class="gp">>>> </span><span class="n">graph</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">store</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">graph</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">__class__</span> +<span class="go"><class 'rdflib.store.IOMemory.IOMemory'></span> +</pre></div> +</div> +<p>Instantiating Graphs with Sleepycat store and an identifier - <<a class="reference external" href="http://rdflib.net">http://rdflib.net</a>>:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span><span class="o">=</span><span class="n">Graph</span><span class="p">(</span><span class="s">'IOMemory'</span><span class="p">,</span><span class="n">URIRef</span><span class="p">(</span><span class="s">"http://rdflib.net"</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">identifier</span> +<span class="go">rdflib.term.URIRef('http://rdflib.net')</span> +<span class="gp">>>> </span><span class="nb">str</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">"<http://rdflib.net> a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']."</span> +</pre></div> +</div> +<p>Creating a ConjunctiveGraph - The top level container for all named Graphs in a ‘database’:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span><span class="o">=</span><span class="n">ConjunctiveGraph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="nb">str</span><span class="p">(</span><span class="n">g</span><span class="o">.</span><span class="n">default_context</span><span class="p">)</span> +<span class="go">"[a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']]."</span> +</pre></div> +</div> +<p>Adding / removing reified triples to Graph and iterating over it directly or via triple pattern:</p> +<blockquote> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g</span><span class="o">=</span><span class="n">Graph</span><span class="p">(</span><span class="s">'IOMemory'</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">statementId</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> +<span class="gp">>>> </span><span class="k">print</span> <span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">0</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">statementId</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">Statement</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">statementId</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">subject</span><span class="p">,</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'http://rdflib.net/store/ConjunctiveGraph'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">statementId</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">predicate</span><span class="p">,</span><span class="n">RDFS</span><span class="o">.</span><span class="n">label</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">statementId</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">object</span><span class="p">,</span><span class="n">Literal</span><span class="p">(</span><span class="s">"Conjunctive Graph"</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="k">print</span> <span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">4</span> +<span class="gp">>>> </span><span class="k">for</span> <span class="n">s</span><span class="p">,</span><span class="n">p</span><span class="p">,</span><span class="n">o</span> <span class="ow">in</span> <span class="n">g</span><span class="p">:</span> <span class="k">print</span> <span class="nb">type</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> +<span class="gp">...</span> +<span class="go"><class 'rdflib.term.BNode'></span> +<span class="go"><class 'rdflib.term.BNode'></span> +<span class="go"><class 'rdflib.term.BNode'></span> +<span class="go"><class 'rdflib.term.BNode'></span> +</pre></div> +</div> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">for</span> <span class="n">s</span><span class="p">,</span><span class="n">p</span><span class="p">,</span><span class="n">o</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">triples</span><span class="p">((</span><span class="bp">None</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">object</span><span class="p">,</span><span class="bp">None</span><span class="p">)):</span> <span class="k">print</span> <span class="n">o</span> +<span class="gp">...</span> +<span class="go">Conjunctive Graph</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">remove</span><span class="p">((</span><span class="n">statementId</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">Statement</span><span class="p">))</span> +<span class="gp">>>> </span><span class="k">print</span> <span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">3</span> +</pre></div> +</div> +</blockquote> +<p>None terms in calls to triple can be thought of as ‘open variables’</p> +<p>Graph Aggregation - ConjunctiveGraphs and ReadOnlyGraphAggregate within the same store:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">store</span> <span class="o">=</span> <span class="n">plugin</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'IOMemory'</span><span class="p">,</span><span class="n">Store</span><span class="p">)()</span> +<span class="gp">>>> </span><span class="n">g1</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">store</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">g2</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">store</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">g3</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="n">store</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">stmt1</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">stmt2</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">stmt3</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">g1</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt1</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">Statement</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g1</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt1</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">subject</span><span class="p">,</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'http://rdflib.net/store/ConjunctiveGraph'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">g1</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt1</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">predicate</span><span class="p">,</span><span class="n">RDFS</span><span class="o">.</span><span class="n">label</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g1</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt1</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">object</span><span class="p">,</span><span class="n">Literal</span><span class="p">(</span><span class="s">"Conjunctive Graph"</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">g2</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt2</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">Statement</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g2</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt2</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">subject</span><span class="p">,</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'http://rdflib.net/store/ConjunctiveGraph'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">g2</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt2</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">predicate</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g2</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt2</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">object</span><span class="p">,</span><span class="n">RDFS</span><span class="o">.</span><span class="n">Class</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g3</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt3</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">Statement</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g3</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt3</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">subject</span><span class="p">,</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'http://rdflib.net/store/ConjunctiveGraph'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">g3</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt3</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">predicate</span><span class="p">,</span><span class="n">RDFS</span><span class="o">.</span><span class="n">comment</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g3</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">stmt3</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">object</span><span class="p">,</span><span class="n">Literal</span><span class="p">(</span><span class="s">"The top-level aggregate graph - The sum of all named graphs within a Store"</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">ConjunctiveGraph</span><span class="p">(</span><span class="n">store</span><span class="p">)</span><span class="o">.</span><span class="n">subjects</span><span class="p">(</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">Statement</span><span class="p">)))</span> +<span class="go">3</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">ReadOnlyGraphAggregate</span><span class="p">([</span><span class="n">g1</span><span class="p">,</span><span class="n">g2</span><span class="p">])</span><span class="o">.</span><span class="n">subjects</span><span class="p">(</span><span class="n">RDF</span><span class="o">.</span><span class="n">type</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">Statement</span><span class="p">)))</span> +<span class="go">2</span> +</pre></div> +</div> +<p>ConjunctiveGraphs have a ‘quads’ method which returns quads instead of triples, where the fourth item +is the Graph (or subclass thereof) instance in which the triple was asserted:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">uniqueGraphNames</span> <span class="o">=</span> <span class="n">set</span><span class="p">([</span><span class="n">graph</span><span class="o">.</span><span class="n">identifier</span> <span class="k">for</span> <span class="n">s</span><span class="p">,</span><span class="n">p</span><span class="p">,</span><span class="n">o</span><span class="p">,</span><span class="n">graph</span> <span class="ow">in</span> <span class="n">ConjunctiveGraph</span><span class="p">(</span><span class="n">store</span><span class="p">)</span><span class="o">.</span><span class="n">quads</span><span class="p">((</span><span class="bp">None</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">predicate</span><span class="p">,</span><span class="bp">None</span><span class="p">))])</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">uniqueGraphNames</span><span class="p">)</span> +<span class="go">3</span> +<span class="gp">>>> </span><span class="n">unionGraph</span> <span class="o">=</span> <span class="n">ReadOnlyGraphAggregate</span><span class="p">([</span><span class="n">g1</span><span class="p">,</span><span class="n">g2</span><span class="p">])</span> +<span class="gp">>>> </span><span class="n">uniqueGraphNames</span> <span class="o">=</span> <span class="n">set</span><span class="p">([</span><span class="n">graph</span><span class="o">.</span><span class="n">identifier</span> <span class="k">for</span> <span class="n">s</span><span class="p">,</span><span class="n">p</span><span class="p">,</span><span class="n">o</span><span class="p">,</span><span class="n">graph</span> <span class="ow">in</span> <span class="n">unionGraph</span><span class="o">.</span><span class="n">quads</span><span class="p">((</span><span class="bp">None</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">predicate</span><span class="p">,</span><span class="bp">None</span><span class="p">))])</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">uniqueGraphNames</span><span class="p">)</span> +<span class="go">2</span> +</pre></div> +</div> +<p>Parsing N3 from StringIO</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">g2</span><span class="o">=</span><span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">src</span> <span class="o">=</span> <span class="s">"""</span> +<span class="gp">... </span><span class="s">@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .</span> +<span class="gp">... </span><span class="s">@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .</span> +<span class="gp">... </span><span class="s">[ a rdf:Statement ;</span> +<span class="gp">... </span><span class="s"> rdf:subject <http://rdflib.net/store#ConjunctiveGraph>;</span> +<span class="gp">... </span><span class="s"> rdf:predicate rdfs:label;</span> +<span class="gp">... </span><span class="s"> rdf:object "Conjunctive Graph" ] """</span> +<span class="gp">>>> </span><span class="n">g2</span><span class="o">=</span><span class="n">g2</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">StringIO</span><span class="p">(</span><span class="n">src</span><span class="p">),</span><span class="n">format</span><span class="o">=</span><span class="s">'n3'</span><span class="p">)</span> +<span class="gp">>>> </span><span class="k">print</span> <span class="nb">len</span><span class="p">(</span><span class="n">g2</span><span class="p">)</span> +<span class="go">4</span> +</pre></div> +</div> +<p>Using Namespace class:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">RDFLib</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">(</span><span class="s">'http://rdflib.net'</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">RDFLib</span><span class="o">.</span><span class="n">ConjunctiveGraph</span> +<span class="go">rdflib.term.URIRef('http://rdflib.netConjunctiveGraph')</span> +<span class="gp">>>> </span><span class="n">RDFLib</span><span class="p">[</span><span class="s">'Graph'</span><span class="p">]</span> +<span class="go">rdflib.term.URIRef('http://rdflib.netGraph')</span> +</pre></div> +</div> +<p>SPARQL Queries</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">print</span> <span class="nb">len</span><span class="p">(</span><span class="n">g</span><span class="p">)</span> +<span class="go">3</span> +<span class="gp">>>> </span><span class="n">q</span> <span class="o">=</span> <span class="s">'''</span> +<span class="gp">... </span><span class="s">PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?pred WHERE { ?stmt rdf:predicate ?pred. }</span> +<span class="gp">... </span><span class="s">'''</span> +<span class="gp">>>> </span><span class="k">for</span> <span class="n">pred</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">q</span><span class="p">):</span> <span class="k">print</span> <span class="n">pred</span> +<span class="go">(rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'),)</span> +</pre></div> +</div> +<p>SPARQL Queries with namespace bindings as argument</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">nsMap</span> <span class="o">=</span> <span class="p">{</span><span class="s">u"rdf"</span><span class="p">:</span><span class="n">RDF</span><span class="o">.</span><span class="n">RDFNS</span><span class="p">}</span> +<span class="gp">>>> </span><span class="k">for</span> <span class="n">pred</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="s">"SELECT ?pred WHERE { ?stmt rdf:predicate ?pred. }"</span><span class="p">,</span> <span class="n">initNs</span><span class="o">=</span><span class="n">nsMap</span><span class="p">):</span> <span class="k">print</span> <span class="n">pred</span> +<span class="go">(rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'),)</span> +</pre></div> +</div> +<p>Parameterized SPARQL Queries</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">rdflib.term</span> <span class="kn">import</span> <span class="n">Variable</span> +<span class="gp">>>> </span><span class="n">top</span> <span class="o">=</span> <span class="p">{</span> <span class="n">Variable</span><span class="p">(</span><span class="s">"?term"</span><span class="p">)</span> <span class="p">:</span> <span class="n">RDF</span><span class="o">.</span><span class="n">predicate</span> <span class="p">}</span> +<span class="gp">>>> </span><span class="k">for</span> <span class="n">pred</span> <span class="ow">in</span> <span class="n">g</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="s">"SELECT ?pred WHERE { ?stmt ?term ?pred. }"</span><span class="p">,</span> <span class="n">initBindings</span><span class="o">=</span><span class="n">top</span><span class="p">):</span> <span class="k">print</span> <span class="n">pred</span> +<span class="go">(rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'),)</span> +</pre></div> +</div> +<ul> +<li class="toctree-l1"><a class="reference external" href="graph.html"><tt class="docutils literal"><span class="pre">rdflib.Graph.Graph</span></tt> – Graph class definition</a><ul> +<li class="toctree-l2"><a class="reference external" href="graph.html#graph">Graph</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="conjunctive_graph.html"><tt class="docutils literal"><span class="pre">rdflib.Graph.ConjunctiveGraph</span></tt> – ConjunctiveGraph class definition</a><ul> +<li class="toctree-l2"><a class="reference external" href="conjunctive_graph.html#module-rdflib.graph">Conjunctive Graph</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="../nodes/quoted_graph.html"><tt class="docutils literal"><span class="pre">rdflib.graph.QuotedGraph</span></tt> – Quoted graphs</a><ul> +<li class="toctree-l2"><a class="reference external" href="../nodes/quoted_graph.html#module-contents">Module Contents</a></li> +</ul> +</li> +</ul> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h4>Previous topic</h4> + <p class="topless"><a href="../nodes/quoted_graph.html" + title="previous chapter"><tt class="docutils literal docutils literal"><span class="pre">rdflib.graph.QuotedGraph</span></tt> – Quoted graphs</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="graph.html" + title="next chapter"><tt class="docutils literal docutils literal docutils literal"><span class="pre">rdflib.Graph.Graph</span></tt> – Graph class definition</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="../../_sources/modules/graphs/index.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="graph.html" title="rdflib.Graph.Graph – Graph class definition" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="../nodes/quoted_graph.html" title="rdflib.graph.QuotedGraph – Quoted graphs" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/modules/index.html b/docs/_build/html/modules/index.html new file mode 100644 index 00000000..7058b3d0 --- /dev/null +++ b/docs/_build/html/modules/index.html @@ -0,0 +1,191 @@ +<!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>Modules — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="../_static/default.css" type="text/css" /> + <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '../', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="../_static/jquery.js"></script> + <script type="text/javascript" src="../_static/doctools.js"></script> + <link rel="index" title="Index" href="../genindex.html" /> + <link rel="search" title="Search" href="../search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="../index.html" /> + <link rel="next" title="Nodes" href="nodes/index.html" /> + <link rel="prev" title="Additions" href="../addons.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="../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="nodes/index.html" title="Nodes" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="../addons.html" title="Additions" + accesskey="P">previous</a> |</li> + <li><a href="../index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="id1"> +<span id="modules"></span><h1>Modules<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h1> +<div class="section" id="contents"> +<h2>Contents:<a class="headerlink" href="#contents" title="Permalink to this headline">¶</a></h2> +<ul> +<li class="toctree-l1"><a class="reference external" href="nodes/index.html">Nodes</a><ul> +<li class="toctree-l2"><a class="reference external" href="nodes/node.html"><tt class="docutils literal"><span class="pre">rdflib.term.Node</span></tt> – Node class definition</a><ul> +<li class="toctree-l3"><a class="reference external" href="nodes/node.html#module-contents">Module Contents</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference external" href="nodes/identifier.html"><tt class="docutils literal"><span class="pre">rdflib.term.Identifier</span></tt> – Identifier class definition</a><ul> +<li class="toctree-l3"><a class="reference external" href="nodes/identifier.html#module-contents">Module Contents</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference external" href="nodes/bnode.html"><tt class="docutils literal"><span class="pre">rdflib.term.BNode</span></tt> – RDF blank node functions</a><ul> +<li class="toctree-l3"><a class="reference external" href="nodes/bnode.html#module-contents">Module Contents</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference external" href="nodes/uriref.html"><tt class="docutils literal"><span class="pre">rdflib.term.URIRef</span></tt> – URIRef class definition</a><ul> +<li class="toctree-l3"><a class="reference external" href="nodes/uriref.html#module-contents">Module Contents</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference external" href="nodes/literal.html"><tt class="docutils literal"><span class="pre">rdflib.term.Literal</span></tt> – Literal class definition</a><ul> +<li class="toctree-l3"><a class="reference external" href="nodes/literal.html#module-contents">Module Contents</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference external" href="nodes/variable.html"><tt class="docutils literal"><span class="pre">rdflib.term.Variable</span></tt> – Variable class definition</a><ul> +<li class="toctree-l3"><a class="reference external" href="nodes/variable.html#module-contents">Module Contents</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference external" href="nodes/quoted_graph.html"><tt class="docutils literal"><span class="pre">rdflib.graph.QuotedGraph</span></tt> – Quoted graphs</a><ul> +<li class="toctree-l3"><a class="reference external" href="nodes/quoted_graph.html#module-contents">Module Contents</a></li> +</ul> +</li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="graphs/index.html">Graphs</a><ul> +<li class="toctree-l2"><a class="reference external" href="graphs/graph.html"><tt class="docutils literal"><span class="pre">rdflib.Graph.Graph</span></tt> – Graph class definition</a><ul> +<li class="toctree-l3"><a class="reference external" href="graphs/graph.html#graph">Graph</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference external" href="graphs/conjunctive_graph.html"><tt class="docutils literal"><span class="pre">rdflib.Graph.ConjunctiveGraph</span></tt> – ConjunctiveGraph class definition</a><ul> +<li class="toctree-l3"><a class="reference external" href="graphs/conjunctive_graph.html#module-rdflib.graph">Conjunctive Graph</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference external" href="nodes/quoted_graph.html"><tt class="docutils literal"><span class="pre">rdflib.graph.QuotedGraph</span></tt> – Quoted graphs</a><ul> +<li class="toctree-l3"><a class="reference external" href="nodes/quoted_graph.html#module-contents">Module Contents</a></li> +</ul> +</li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="others.html">Other modules</a><ul> +<li class="toctree-l2"><a class="reference external" href="others.html#module-rdflib.collection">Collection</a></li> +<li class="toctree-l2"><a class="reference external" href="others.html#module-rdflib.journal">Journal</a></li> +<li class="toctree-l2"><a class="reference external" href="others.html#module-rdflib.query.result">QueryResult</a></li> +<li class="toctree-l2"><a class="reference external" href="others.html#module-rdflib.term">Statement</a></li> +<li class="toctree-l2"><a class="reference external" href="others.html#module-rdflib.parser">StringInputSource</a></li> +<li class="toctree-l2"><a class="reference external" href="others.html#module-rdflib.textindex">TextIndex</a></li> +<li class="toctree-l2"><a class="reference external" href="others.html#triplestore">TripleStore</a></li> +<li class="toctree-l2"><a class="reference external" href="others.html#urlinputsource">URLInputSource</a></li> +<li class="toctree-l2"><a class="reference external" href="others.html#module-rdflib.query">query</a></li> +<li class="toctree-l2"><a class="reference external" href="others.html#module-rdflib.store">store</a></li> +<li class="toctree-l2"><a class="reference external" href="others.html#module-rdflib.sparql">sparql</a><ul> +<li class="toctree-l3"><a class="reference external" href="others.html#variables-imports">Variables, Imports</a></li> +<li class="toctree-l3"><a class="reference external" href="others.html#history">History</a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference external" href="others.html#module-rdflib.syntax">syntax</a></li> +</ul> +</li> +</ul> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="../index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href="">Modules</a><ul> +<li><a class="reference external" href="#contents">Contents:</a><ul> +</ul> +</li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="../addons.html" + title="previous chapter">Additions</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="nodes/index.html" + title="next chapter">Nodes</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="../_sources/modules/index.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="nodes/index.html" title="Nodes" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="../addons.html" title="Additions" + accesskey="P">previous</a> |</li> + <li><a href="../index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/modules/nodes/bnode.html b/docs/_build/html/modules/nodes/bnode.html new file mode 100644 index 00000000..1bdcf804 --- /dev/null +++ b/docs/_build/html/modules/nodes/bnode.html @@ -0,0 +1,143 @@ +<!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>rdflib.term.BNode – RDF blank node functions — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="../../_static/default.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '../../', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="../../_static/jquery.js"></script> + <script type="text/javascript" src="../../_static/doctools.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="../../index.html" /> + <link rel="up" title="Nodes" href="index.html" /> + <link rel="next" title="rdflib.term.URIRef – URIRef class definition" href="uriref.html" /> + <link rel="prev" title="rdflib.term.Identifier – Identifier class definition" href="identifier.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="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="uriref.html" title="rdflib.term.URIRef – URIRef class definition" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="identifier.html" title="rdflib.term.Identifier – Identifier class definition" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Nodes</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="module-rdflib.term"> +<h1><tt class="xref docutils literal"><span class="pre">rdflib.term.BNode</span></tt> – RDF blank node functions<a class="headerlink" href="#module-rdflib.term" title="Permalink to this headline">¶</a></h1> +<p>This module defines the different types of terms...</p> +<div class="section" id="module-contents"> +<h2>Module Contents<a class="headerlink" href="#module-contents" title="Permalink to this headline">¶</a></h2> +<dl class="class"> +<dt id="rdflib.term.BNode"> +<!--[rdflib.term.BNode]-->class <tt class="descclassname">rdflib.term.</tt><tt class="descname">BNode</tt><a class="headerlink" href="#rdflib.term.BNode" title="Permalink to this definition">¶</a></dt> +<dd><p>Blank Node: <a class="reference external" href="http://www.w3.org/TR/rdf-concepts/#section-blank-nodes">http://www.w3.org/TR/rdf-concepts/#section-blank-nodes</a></p> +<p>“In non-persistent O-O software construction, support for object +identity is almost accidental: in the simplest implementation, +each object resides at a certain address, and a reference to the +object uses that address, which serves as immutable object +identity.</p> +<p>...</p> +<p>Maintaining object identity in shared databases raises problems: +every client that needs to create objects must obtain a unique +identity for them; ” – Bertand Meyer</p> +</dd></dl> + +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="../../index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">rdflib.term.BNode</span></tt> – RDF blank node functions</a><ul> +<li><a class="reference external" href="#module-contents">Module Contents</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="identifier.html" + title="previous chapter"><tt class="docutils literal"><span class="pre">rdflib.term.Identifier</span></tt> – Identifier class definition</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="uriref.html" + title="next chapter"><tt class="docutils literal"><span class="pre">rdflib.term.URIRef</span></tt> – URIRef class definition</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="../../_sources/modules/nodes/bnode.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="uriref.html" title="rdflib.term.URIRef – URIRef class definition" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="identifier.html" title="rdflib.term.Identifier – Identifier class definition" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Nodes</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/modules/nodes/identifier.html b/docs/_build/html/modules/nodes/identifier.html new file mode 100644 index 00000000..ea150f10 --- /dev/null +++ b/docs/_build/html/modules/nodes/identifier.html @@ -0,0 +1,134 @@ +<!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>rdflib.term.Identifier – Identifier class definition — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="../../_static/default.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '../../', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="../../_static/jquery.js"></script> + <script type="text/javascript" src="../../_static/doctools.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="../../index.html" /> + <link rel="up" title="Nodes" href="index.html" /> + <link rel="next" title="rdflib.term.BNode – RDF blank node functions" href="bnode.html" /> + <link rel="prev" title="rdflib.term.Node – Node class definition" href="node.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="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="bnode.html" title="rdflib.term.BNode – RDF blank node functions" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="node.html" title="rdflib.term.Node – Node class definition" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Nodes</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="module-rdflib.term"> +<h1><tt class="xref docutils literal"><span class="pre">rdflib.term.Identifier</span></tt> – Identifier class definition<a class="headerlink" href="#module-rdflib.term" title="Permalink to this headline">¶</a></h1> +<p>This module defines the different types of terms...</p> +<div class="section" id="module-contents"> +<h2>Module Contents<a class="headerlink" href="#module-contents" title="Permalink to this headline">¶</a></h2> +<dl class="class"> +<dt id="rdflib.term.Identifier"> +<!--[rdflib.term.Identifier]-->class <tt class="descclassname">rdflib.term.</tt><tt class="descname">Identifier</tt><a class="headerlink" href="#rdflib.term.Identifier" title="Permalink to this definition">¶</a></dt> +<dd>See <a class="reference external" href="http://www.w3.org/2002/07/rdf-identifer-terminology/">http://www.w3.org/2002/07/rdf-identifer-terminology/</a> +regarding choice of terminology.</dd></dl> + +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="../../index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">rdflib.term.Identifier</span></tt> – Identifier class definition</a><ul> +<li><a class="reference external" href="#module-contents">Module Contents</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="node.html" + title="previous chapter"><tt class="docutils literal"><span class="pre">rdflib.term.Node</span></tt> – Node class definition</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="bnode.html" + title="next chapter"><tt class="docutils literal docutils literal"><span class="pre">rdflib.term.BNode</span></tt> – RDF blank node functions</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="../../_sources/modules/nodes/identifier.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="bnode.html" title="rdflib.term.BNode – RDF blank node functions" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="node.html" title="rdflib.term.Node – Node class definition" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Nodes</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/modules/nodes/index.html b/docs/_build/html/modules/nodes/index.html new file mode 100644 index 00000000..dc063355 --- /dev/null +++ b/docs/_build/html/modules/nodes/index.html @@ -0,0 +1,145 @@ +<!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>Nodes — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="../../_static/default.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '../../', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="../../_static/jquery.js"></script> + <script type="text/javascript" src="../../_static/doctools.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="../../index.html" /> + <link rel="up" title="Modules" href="../index.html" /> + <link rel="next" title="rdflib.term.Node – Node class definition" href="node.html" /> + <link rel="prev" title="Modules" href="../index.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="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="node.html" title="rdflib.term.Node – Node class definition" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="../index.html" title="Modules" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="id1"> +<span id="nodes"></span><h1>Nodes<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h1> +<p>The RDFLib classes listed below model RDF <a class="reference external" href="univrdfstore.html#Terms">terms</a> in a graph and inherit from a common <a class="reference external" href="http://www.w3.org/2002/07/rdf-identifer-terminology/">Identifier</a> class, which extends Python unicode. Instances of these are nodes in an RDF graph.</p> +<ul> +<li class="toctree-l1"><a class="reference external" href="node.html"><tt class="docutils literal"><span class="pre">rdflib.term.Node</span></tt> – Node class definition</a><ul> +<li class="toctree-l2"><a class="reference external" href="node.html#module-contents">Module Contents</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="identifier.html"><tt class="docutils literal"><span class="pre">rdflib.term.Identifier</span></tt> – Identifier class definition</a><ul> +<li class="toctree-l2"><a class="reference external" href="identifier.html#module-contents">Module Contents</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="bnode.html"><tt class="docutils literal"><span class="pre">rdflib.term.BNode</span></tt> – RDF blank node functions</a><ul> +<li class="toctree-l2"><a class="reference external" href="bnode.html#module-contents">Module Contents</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="uriref.html"><tt class="docutils literal"><span class="pre">rdflib.term.URIRef</span></tt> – URIRef class definition</a><ul> +<li class="toctree-l2"><a class="reference external" href="uriref.html#module-contents">Module Contents</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="literal.html"><tt class="docutils literal"><span class="pre">rdflib.term.Literal</span></tt> – Literal class definition</a><ul> +<li class="toctree-l2"><a class="reference external" href="literal.html#module-contents">Module Contents</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="variable.html"><tt class="docutils literal"><span class="pre">rdflib.term.Variable</span></tt> – Variable class definition</a><ul> +<li class="toctree-l2"><a class="reference external" href="variable.html#module-contents">Module Contents</a></li> +</ul> +</li> +<li class="toctree-l1"><a class="reference external" href="quoted_graph.html"><tt class="docutils literal"><span class="pre">rdflib.graph.QuotedGraph</span></tt> – Quoted graphs</a><ul> +<li class="toctree-l2"><a class="reference external" href="quoted_graph.html#module-contents">Module Contents</a></li> +</ul> +</li> +</ul> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h4>Previous topic</h4> + <p class="topless"><a href="../index.html" + title="previous chapter">Modules</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="node.html" + title="next chapter"><tt class="docutils literal docutils literal"><span class="pre">rdflib.term.Node</span></tt> – Node class definition</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="../../_sources/modules/nodes/index.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="node.html" title="rdflib.term.Node – Node class definition" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="../index.html" title="Modules" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/modules/nodes/literal.html b/docs/_build/html/modules/nodes/literal.html new file mode 100644 index 00000000..5502a928 --- /dev/null +++ b/docs/_build/html/modules/nodes/literal.html @@ -0,0 +1,175 @@ +<!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>rdflib.term.Literal – Literal class definition — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="../../_static/default.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '../../', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="../../_static/jquery.js"></script> + <script type="text/javascript" src="../../_static/doctools.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="../../index.html" /> + <link rel="up" title="Nodes" href="index.html" /> + <link rel="next" title="rdflib.term.Variable – Variable class definition" href="variable.html" /> + <link rel="prev" title="rdflib.term.URIRef – URIRef class definition" href="uriref.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="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="variable.html" title="rdflib.term.Variable – Variable class definition" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="uriref.html" title="rdflib.term.URIRef – URIRef class definition" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Nodes</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="module-rdflib.term"> +<h1><tt class="xref docutils literal"><span class="pre">rdflib.term.Literal</span></tt> – Literal class definition<a class="headerlink" href="#module-rdflib.term" title="Permalink to this headline">¶</a></h1> +<p>This module defines the different types of terms...</p> +<div class="section" id="module-contents"> +<h2>Module Contents<a class="headerlink" href="#module-contents" title="Permalink to this headline">¶</a></h2> +<dl class="class"> +<dt id="rdflib.term.Literal"> +<!--[rdflib.term.Literal]-->class <tt class="descclassname">rdflib.term.</tt><tt class="descname">Literal</tt><a class="headerlink" href="#rdflib.term.Literal" title="Permalink to this definition">¶</a></dt> +<dd><p>RDF Literal: <a class="reference external" href="http://www.w3.org/TR/rdf-concepts/#section-Graph-Literal">http://www.w3.org/TR/rdf-concepts/#section-Graph-Literal</a></p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">Literal</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span><span class="o">.</span><span class="n">toPython</span><span class="p">()</span> +<span class="go">1L</span> +<span class="gp">>>> </span><span class="nb">cmp</span><span class="p">(</span><span class="n">Literal</span><span class="p">(</span><span class="s">"adsf"</span><span class="p">),</span> <span class="mf">1</span><span class="p">)</span> +<span class="go">1</span> +<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">rdflib.namespace</span> <span class="kn">import</span> <span class="n">_XSD_NS</span> +<span class="gp">>>> </span><span class="n">lit2006</span> <span class="o">=</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'2006-01-01'</span><span class="p">,</span><span class="n">datatype</span><span class="o">=</span><span class="n">_XSD_NS</span><span class="o">.</span><span class="n">date</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">lit2006</span><span class="o">.</span><span class="n">toPython</span><span class="p">()</span> +<span class="go">datetime.date(2006, 1, 1)</span> +<span class="gp">>>> </span><span class="n">lit2006</span> <span class="o"><</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'2007-01-01'</span><span class="p">,</span><span class="n">datatype</span><span class="o">=</span><span class="n">_XSD_NS</span><span class="o">.</span><span class="n">date</span><span class="p">)</span> +<span class="go">True</span> +<span class="gp">>>> </span><span class="n">Literal</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">utcnow</span><span class="p">())</span><span class="o">.</span><span class="n">datatype</span> +<span class="go">rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#dateTime')</span> +<span class="gp">>>> </span><span class="n">oneInt</span> <span class="o">=</span> <span class="n">Literal</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">twoInt</span> <span class="o">=</span> <span class="n">Literal</span><span class="p">(</span><span class="mf">2</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">twoInt</span> <span class="o"><</span> <span class="n">oneInt</span> +<span class="go">False</span> +<span class="gp">>>> </span><span class="n">Literal</span><span class="p">(</span><span class="s">'1'</span><span class="p">)</span> <span class="o"><</span> <span class="n">Literal</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span> +<span class="go">False</span> +<span class="gp">>>> </span><span class="n">Literal</span><span class="p">(</span><span class="s">'1'</span><span class="p">)</span> <span class="o"><</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'1'</span><span class="p">)</span> +<span class="go">False</span> +<span class="gp">>>> </span><span class="n">Literal</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span> <span class="o"><</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'1'</span><span class="p">)</span> +<span class="go">True</span> +<span class="gp">>>> </span><span class="n">Literal</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span> <span class="o"><</span> <span class="n">Literal</span><span class="p">(</span><span class="mf">2.0</span><span class="p">)</span> +<span class="go">True</span> +<span class="gp">>>> </span><span class="n">Literal</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span> <span class="o"><</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'foo'</span><span class="p">)</span> +<span class="go">True</span> +<span class="gp">>>> </span><span class="n">Literal</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span> <span class="o"><</span> <span class="mf">2.0</span> +<span class="go">True</span> +<span class="gp">>>> </span><span class="n">Literal</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span> <span class="o"><</span> <span class="nb">object</span> +<span class="go">True</span> +<span class="gp">>>> </span><span class="n">lit2006</span> <span class="o"><</span> <span class="s">"2007"</span> +<span class="go">True</span> +<span class="gp">>>> </span><span class="s">"2005"</span> <span class="o"><</span> <span class="n">lit2006</span> +<span class="go">True</span> +</pre></div> +</div> +<dl class="method"> +<dt id="rdflib.term.Literal.toPython"> +<!--[rdflib.term.Literal.toPython]--><tt class="descname">toPython</tt><big>(</big><big>)</big><a class="headerlink" href="#rdflib.term.Literal.toPython" title="Permalink to this definition">¶</a></dt> +<dd>Returns an appropriate python datatype derived from this RDF Literal</dd></dl> + +</dd></dl> + +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="../../index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">rdflib.term.Literal</span></tt> – Literal class definition</a><ul> +<li><a class="reference external" href="#module-contents">Module Contents</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="uriref.html" + title="previous chapter"><tt class="docutils literal docutils literal"><span class="pre">rdflib.term.URIRef</span></tt> – URIRef class definition</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="variable.html" + title="next chapter"><tt class="docutils literal"><span class="pre">rdflib.term.Variable</span></tt> – Variable class definition</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="../../_sources/modules/nodes/literal.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="variable.html" title="rdflib.term.Variable – Variable class definition" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="uriref.html" title="rdflib.term.URIRef – URIRef class definition" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Nodes</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/modules/nodes/node.html b/docs/_build/html/modules/nodes/node.html new file mode 100644 index 00000000..84a4330b --- /dev/null +++ b/docs/_build/html/modules/nodes/node.html @@ -0,0 +1,133 @@ +<!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>rdflib.term.Node – Node class definition — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="../../_static/default.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '../../', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="../../_static/jquery.js"></script> + <script type="text/javascript" src="../../_static/doctools.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="../../index.html" /> + <link rel="up" title="Nodes" href="index.html" /> + <link rel="next" title="rdflib.term.Identifier – Identifier class definition" href="identifier.html" /> + <link rel="prev" title="Nodes" href="index.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="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="identifier.html" title="rdflib.term.Identifier – Identifier class definition" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="index.html" title="Nodes" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Nodes</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="module-rdflib.term"> +<h1><tt class="xref docutils literal"><span class="pre">rdflib.term.Node</span></tt> – Node class definition<a class="headerlink" href="#module-rdflib.term" title="Permalink to this headline">¶</a></h1> +<p>This module defines the different types of terms...</p> +<div class="section" id="module-contents"> +<h2>Module Contents<a class="headerlink" href="#module-contents" title="Permalink to this headline">¶</a></h2> +<dl class="class"> +<dt id="rdflib.term.Node"> +<!--[rdflib.term.Node]-->class <tt class="descclassname">rdflib.term.</tt><tt class="descname">Node</tt><a class="headerlink" href="#rdflib.term.Node" title="Permalink to this definition">¶</a></dt> +<dd>A Node in the Graph.</dd></dl> + +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="../../index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">rdflib.term.Node</span></tt> – Node class definition</a><ul> +<li><a class="reference external" href="#module-contents">Module Contents</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="index.html" + title="previous chapter">Nodes</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="identifier.html" + title="next chapter"><tt class="docutils literal docutils literal docutils literal"><span class="pre">rdflib.term.Identifier</span></tt> – Identifier class definition</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="../../_sources/modules/nodes/node.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="identifier.html" title="rdflib.term.Identifier – Identifier class definition" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="index.html" title="Nodes" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Nodes</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/modules/nodes/quoted_graph.html b/docs/_build/html/modules/nodes/quoted_graph.html new file mode 100644 index 00000000..7279219d --- /dev/null +++ b/docs/_build/html/modules/nodes/quoted_graph.html @@ -0,0 +1,134 @@ +<!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>rdflib.graph.QuotedGraph – Quoted graphs — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="../../_static/default.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '../../', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="../../_static/jquery.js"></script> + <script type="text/javascript" src="../../_static/doctools.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="../../index.html" /> + <link rel="up" title="Graphs" href="../graphs/index.html" /> + <link rel="next" title="Other modules" href="../others.html" /> + <link rel="prev" title="rdflib.Graph.ConjunctiveGraph – ConjunctiveGraph class definition" href="../graphs/conjunctive_graph.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="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="../others.html" title="Other modules" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="../graphs/conjunctive_graph.html" title="rdflib.Graph.ConjunctiveGraph – ConjunctiveGraph class definition" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="../graphs/index.html" accesskey="U">Graphs</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="rdflib-graph-quotedgraph-quoted-graphs"> +<h1><tt class="xref docutils literal"><span class="pre">rdflib.graph.QuotedGraph</span></tt> – Quoted graphs<a class="headerlink" href="#rdflib-graph-quotedgraph-quoted-graphs" title="Permalink to this headline">¶</a></h1> +<p>RDFLib graphs support an additional extension of RDF semantics for formulae. For the academically inclined, Graham Kyles <a class="reference external" href="http://ninebynine.org/RDFNotes/UsingContextsWithRDF.html#xtocid-6303976">formal extension</a> is probably a good read.</p> +<p>Formulae are represented formally by the <tt class="xref docutils literal"><span class="pre">rdflib.Graph.QuotedGraph</span></tt> class and are disjoint from regular RDF graphs in that their statements are quoted.</p> +<div class="section" id="module-contents"> +<h2>Module Contents<a class="headerlink" href="#module-contents" title="Permalink to this headline">¶</a></h2> +<dl class="class"> +<dt id="rdflib.graph.QuotedGraph"> +<!--[rdflib.graph.QuotedGraph]-->class <tt class="descclassname">rdflib.graph.</tt><tt class="descname">QuotedGraph</tt><big>(</big><em>store</em>, <em>identifier</em><big>)</big><a class="headerlink" href="#rdflib.graph.QuotedGraph" title="Permalink to this definition">¶</a></dt> +<dd></dd></dl> + +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="../../index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">rdflib.graph.QuotedGraph</span></tt> – Quoted graphs</a><ul> +<li><a class="reference external" href="#module-contents">Module Contents</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="../graphs/conjunctive_graph.html" + title="previous chapter"><tt class="docutils literal docutils literal docutils literal"><span class="pre">rdflib.Graph.ConjunctiveGraph</span></tt> – ConjunctiveGraph class definition</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="../others.html" + title="next chapter">Other modules</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="../../_sources/modules/nodes/quoted_graph.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="../others.html" title="Other modules" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="../graphs/conjunctive_graph.html" title="rdflib.Graph.ConjunctiveGraph – ConjunctiveGraph class definition" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="../graphs/index.html" accesskey="U">Graphs</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/modules/nodes/uriref.html b/docs/_build/html/modules/nodes/uriref.html new file mode 100644 index 00000000..7d291e01 --- /dev/null +++ b/docs/_build/html/modules/nodes/uriref.html @@ -0,0 +1,133 @@ +<!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>rdflib.term.URIRef – URIRef class definition — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="../../_static/default.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '../../', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="../../_static/jquery.js"></script> + <script type="text/javascript" src="../../_static/doctools.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="../../index.html" /> + <link rel="up" title="Nodes" href="index.html" /> + <link rel="next" title="rdflib.term.Literal – Literal class definition" href="literal.html" /> + <link rel="prev" title="rdflib.term.BNode – RDF blank node functions" href="bnode.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="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="literal.html" title="rdflib.term.Literal – Literal class definition" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="bnode.html" title="rdflib.term.BNode – RDF blank node functions" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Nodes</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="module-rdflib.term"> +<h1><tt class="xref docutils literal"><span class="pre">rdflib.term.URIRef</span></tt> – URIRef class definition<a class="headerlink" href="#module-rdflib.term" title="Permalink to this headline">¶</a></h1> +<p>This module defines the different types of terms...</p> +<div class="section" id="module-contents"> +<h2>Module Contents<a class="headerlink" href="#module-contents" title="Permalink to this headline">¶</a></h2> +<dl class="class"> +<dt id="rdflib.term.URIRef"> +<!--[rdflib.term.URIRef]-->class <tt class="descclassname">rdflib.term.</tt><tt class="descname">URIRef</tt><a class="headerlink" href="#rdflib.term.URIRef" title="Permalink to this definition">¶</a></dt> +<dd>RDF URI Reference: <a class="reference external" href="http://www.w3.org/TR/rdf-concepts/#section-Graph-URIref">http://www.w3.org/TR/rdf-concepts/#section-Graph-URIref</a></dd></dl> + +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="../../index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">rdflib.term.URIRef</span></tt> – URIRef class definition</a><ul> +<li><a class="reference external" href="#module-contents">Module Contents</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="bnode.html" + title="previous chapter"><tt class="docutils literal docutils literal docutils literal"><span class="pre">rdflib.term.BNode</span></tt> – RDF blank node functions</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="literal.html" + title="next chapter"><tt class="docutils literal docutils literal"><span class="pre">rdflib.term.Literal</span></tt> – Literal class definition</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="../../_sources/modules/nodes/uriref.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="literal.html" title="rdflib.term.Literal – Literal class definition" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="bnode.html" title="rdflib.term.BNode – RDF blank node functions" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Nodes</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/modules/nodes/variable.html b/docs/_build/html/modules/nodes/variable.html new file mode 100644 index 00000000..18f2cc50 --- /dev/null +++ b/docs/_build/html/modules/nodes/variable.html @@ -0,0 +1,133 @@ +<!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>rdflib.term.Variable – Variable class definition — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="../../_static/default.css" type="text/css" /> + <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '../../', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="../../_static/jquery.js"></script> + <script type="text/javascript" src="../../_static/doctools.js"></script> + <link rel="index" title="Index" href="../../genindex.html" /> + <link rel="search" title="Search" href="../../search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="../../index.html" /> + <link rel="up" title="Nodes" href="index.html" /> + <link rel="next" title="rdflib.graph.QuotedGraph – Quoted graphs" href="quoted_graph.html" /> + <link rel="prev" title="rdflib.term.Literal – Literal class definition" href="literal.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="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="quoted_graph.html" title="rdflib.graph.QuotedGraph – Quoted graphs" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="literal.html" title="rdflib.term.Literal – Literal class definition" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Nodes</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="module-rdflib.term"> +<h1><tt class="xref docutils literal"><span class="pre">rdflib.term.Variable</span></tt> – Variable class definition<a class="headerlink" href="#module-rdflib.term" title="Permalink to this headline">¶</a></h1> +<p>This module defines the different types of terms...</p> +<div class="section" id="module-contents"> +<h2>Module Contents<a class="headerlink" href="#module-contents" title="Permalink to this headline">¶</a></h2> +<dl class="class"> +<dt id="rdflib.term.Variable"> +<!--[rdflib.term.Variable]-->class <tt class="descclassname">rdflib.term.</tt><tt class="descname">Variable</tt><a class="headerlink" href="#rdflib.term.Variable" title="Permalink to this definition">¶</a></dt> +<dd></dd></dl> + +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="../../index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href=""><tt class="docutils literal"><span class="pre">rdflib.term.Variable</span></tt> – Variable class definition</a><ul> +<li><a class="reference external" href="#module-contents">Module Contents</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="literal.html" + title="previous chapter"><tt class="docutils literal docutils literal docutils literal"><span class="pre">rdflib.term.Literal</span></tt> – Literal class definition</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="quoted_graph.html" + title="next chapter"><tt class="docutils literal docutils literal docutils literal docutils literal"><span class="pre">rdflib.graph.QuotedGraph</span></tt> – Quoted graphs</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="../../_sources/modules/nodes/variable.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="../../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="quoted_graph.html" title="rdflib.graph.QuotedGraph – Quoted graphs" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="literal.html" title="rdflib.term.Literal – Literal class definition" + accesskey="P">previous</a> |</li> + <li><a href="../../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="../index.html" accesskey="U">Modules</a> »</li> + <li><a href="index.html" accesskey="U">Nodes</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/modules/others.html b/docs/_build/html/modules/others.html new file mode 100644 index 00000000..7097e2ea --- /dev/null +++ b/docs/_build/html/modules/others.html @@ -0,0 +1,548 @@ +<!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>Other modules — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="../_static/default.css" type="text/css" /> + <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '../', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="../_static/jquery.js"></script> + <script type="text/javascript" src="../_static/doctools.js"></script> + <link rel="index" title="Index" href="../genindex.html" /> + <link rel="search" title="Search" href="../search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="../index.html" /> + <link rel="up" title="Modules" href="index.html" /> + <link rel="prev" title="rdflib.graph.QuotedGraph – Quoted graphs" href="nodes/quoted_graph.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="../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="nodes/quoted_graph.html" title="rdflib.graph.QuotedGraph – Quoted graphs" + accesskey="P">previous</a> |</li> + <li><a href="../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="index.html" accesskey="U">Modules</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="other-modules"> +<h1>Other modules<a class="headerlink" href="#other-modules" title="Permalink to this headline">¶</a></h1> +<div class="section" id="module-rdflib.collection"> +<h2>Collection<a class="headerlink" href="#module-rdflib.collection" title="Permalink to this headline">¶</a></h2> +<dl class="class"> +<dt id="rdflib.collection.Collection"> +<!--[rdflib.collection.Collection]-->class <tt class="descclassname">rdflib.collection.</tt><tt class="descname">Collection</tt><big>(</big><em>graph</em>, <em>uri</em>, <em>seq=</em><span class="optional">[</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#rdflib.collection.Collection" title="Permalink to this definition">¶</a></dt> +<dd><p>See 3.3.5 Emulating container types: <a class="reference external" href="http://docs.python.org/ref/sequence-types.html#l2h-232">http://docs.python.org/ref/sequence-types.html#l2h-232</a></p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">rdflib.graph</span> <span class="kn">import</span> <span class="n">Graph</span> +<span class="gp">>>> </span><span class="n">listName</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="s">'IOMemory'</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">listItem1</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">listItem2</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">listName</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">first</span><span class="p">,</span><span class="n">Literal</span><span class="p">(</span><span class="mf">1</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">listName</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">rest</span><span class="p">,</span><span class="n">listItem1</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">listItem1</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">first</span><span class="p">,</span><span class="n">Literal</span><span class="p">(</span><span class="mf">2</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">listItem1</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">rest</span><span class="p">,</span><span class="n">listItem2</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">listItem2</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">rest</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">nil</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">listItem2</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">first</span><span class="p">,</span><span class="n">Literal</span><span class="p">(</span><span class="mf">3</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">c</span><span class="o">=</span><span class="n">Collection</span><span class="p">(</span><span class="n">g</span><span class="p">,</span><span class="n">listName</span><span class="p">)</span> +<span class="gp">>>> </span><span class="k">print</span> <span class="nb">list</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> +<span class="go">[rdflib.term.Literal(u'1', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#integer')), rdflib.term.Literal(u'2', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#integer')), rdflib.term.Literal(u'3', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#integer'))]</span> +<span class="gp">>>> </span><span class="mf">1</span> <span class="ow">in</span> <span class="n">c</span> +<span class="go">True</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> +<span class="go">3</span> +<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">_get_container</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span> <span class="o">==</span> <span class="n">listItem1</span> +<span class="go">True</span> +<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">Literal</span><span class="p">(</span><span class="mf">2</span><span class="p">))</span> <span class="o">==</span> <span class="mf">1</span> +<span class="go">True</span> +</pre></div> +</div> +<dl class="method"> +<dt id="rdflib.collection.Collection.append"> +<!--[rdflib.collection.Collection.append]--><tt class="descname">append</tt><big>(</big><em>item</em><big>)</big><a class="headerlink" href="#rdflib.collection.Collection.append" title="Permalink to this definition">¶</a></dt> +<dd><div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">rdflib.graph</span> <span class="kn">import</span> <span class="n">Graph</span> +<span class="gp">>>> </span><span class="n">listName</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">c</span><span class="o">=</span><span class="n">Collection</span><span class="p">(</span><span class="n">g</span><span class="p">,</span><span class="n">listName</span><span class="p">,[</span><span class="n">Literal</span><span class="p">(</span><span class="mf">1</span><span class="p">),</span><span class="n">Literal</span><span class="p">(</span><span class="mf">2</span><span class="p">)])</span> +<span class="gp">>>> </span><span class="n">links</span> <span class="o">=</span> <span class="p">[</span><span class="nb">list</span><span class="p">(</span><span class="n">g</span><span class="o">.</span><span class="n">subjects</span><span class="p">(</span><span class="nb">object</span><span class="o">=</span><span class="n">i</span><span class="p">,</span><span class="n">predicate</span><span class="o">=</span><span class="n">RDF</span><span class="o">.</span><span class="n">first</span><span class="p">))[</span><span class="mf">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">c</span><span class="p">]</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">([</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">links</span> <span class="k">if</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">rest</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">nil</span><span class="p">)</span> <span class="ow">in</span> <span class="n">g</span><span class="p">])</span> +<span class="go">1</span> +</pre></div> +</div> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.collection.Collection.index"> +<!--[rdflib.collection.Collection.index]--><tt class="descname">index</tt><big>(</big><em>item</em><big>)</big><a class="headerlink" href="#rdflib.collection.Collection.index" title="Permalink to this definition">¶</a></dt> +<dd>Returns the 0-based numerical index of the item in the list</dd></dl> + +<dl class="method"> +<dt id="rdflib.collection.Collection.n3"> +<!--[rdflib.collection.Collection.n3]--><tt class="descname">n3</tt><big>(</big><big>)</big><a class="headerlink" href="#rdflib.collection.Collection.n3" title="Permalink to this definition">¶</a></dt> +<dd><div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">rdflib.graph</span> <span class="kn">import</span> <span class="n">Graph</span> +<span class="gp">>>> </span><span class="n">listName</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">Graph</span><span class="p">(</span><span class="s">'IOMemory'</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">listItem1</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">listItem2</span> <span class="o">=</span> <span class="n">BNode</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">listName</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">first</span><span class="p">,</span><span class="n">Literal</span><span class="p">(</span><span class="mf">1</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">listName</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">rest</span><span class="p">,</span><span class="n">listItem1</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">listItem1</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">first</span><span class="p">,</span><span class="n">Literal</span><span class="p">(</span><span class="mf">2</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">listItem1</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">rest</span><span class="p">,</span><span class="n">listItem2</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">listItem2</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">rest</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">nil</span><span class="p">))</span> +<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">listItem2</span><span class="p">,</span><span class="n">RDF</span><span class="o">.</span><span class="n">first</span><span class="p">,</span><span class="n">Literal</span><span class="p">(</span><span class="mf">3</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">c</span><span class="o">=</span><span class="n">Collection</span><span class="p">(</span><span class="n">g</span><span class="p">,</span><span class="n">listName</span><span class="p">)</span> +<span class="gp">>>> </span><span class="k">print</span> <span class="n">c</span><span class="o">.</span><span class="n">n3</span><span class="p">()</span> +<span class="go">( "1"^^<http://www.w3.org/2001/XMLSchema#integer> "2"^^<http://www.w3.org/2001/XMLSchema#integer> "3"^^<http://www.w3.org/2001/XMLSchema#integer> )</span> +</pre></div> +</div> +</dd></dl> + +</dd></dl> + +</div> +<div class="section" id="module-rdflib.journal"> +<h2>Journal<a class="headerlink" href="#module-rdflib.journal" title="Permalink to this headline">¶</a></h2> +<dl class="class"> +<dt id="rdflib.journal.JournalWriter"> +<!--[rdflib.journal.JournalWriter]-->class <tt class="descclassname">rdflib.journal.</tt><tt class="descname">JournalWriter</tt><big>(</big><em>store</em>, <em>stream=None</em>, <em>filename=None</em><big>)</big><a class="headerlink" href="#rdflib.journal.JournalWriter" title="Permalink to this definition">¶</a></dt> +<dd>Writes a journal of the store events.</dd></dl> + +<dl class="class"> +<dt id="rdflib.journal.JournalReader"> +<!--[rdflib.journal.JournalReader]-->class <tt class="descclassname">rdflib.journal.</tt><tt class="descname">JournalReader</tt><big>(</big><em>store</em>, <em>filename</em><big>)</big><a class="headerlink" href="#rdflib.journal.JournalReader" title="Permalink to this definition">¶</a></dt> +<dd>Reads a journal of store events into a store.</dd></dl> + +</div> +<div class="section" id="module-rdflib.query.result"> +<h2>QueryResult<a class="headerlink" href="#module-rdflib.query.result" title="Permalink to this headline">¶</a></h2> +<dl class="class"> +<dt id="rdflib.query.result.QueryResult"> +<!--[rdflib.query.result.QueryResult]-->class <tt class="descclassname">rdflib.query.result.</tt><tt class="descname">QueryResult</tt><big>(</big><em>pythonResult</em><big>)</big><a class="headerlink" href="#rdflib.query.result.QueryResult" title="Permalink to this definition">¶</a></dt> +<dd><p>A common class for representing query result in a variety of formats, namely:</p> +<p>xml : as an XML string using the XML result format of the query language +python: as Python objects +json : as JSON</p> +</dd></dl> + +</div> +<div class="section" id="module-rdflib.term"> +<h2>Statement<a class="headerlink" href="#module-rdflib.term" title="Permalink to this headline">¶</a></h2> +<p>This module defines the different types of terms...</p> +<dl class="class"> +<dt id="rdflib.term.Statement"> +<!--[rdflib.term.Statement]-->class <tt class="descclassname">rdflib.term.</tt><tt class="descname">Statement</tt><a class="headerlink" href="#rdflib.term.Statement" title="Permalink to this definition">¶</a></dt> +<dd></dd></dl> + +<dl class="staticmethod"> +<dt id="rdflib.term.Statement.__new__"> +<!--[rdflib.term.Statement.__new__]--><em class="property"> +static </em><tt class="descclassname">Statement.</tt><tt class="descname">__new__</tt><big>(</big><em>(subject</em>, <em>predicate</em>, <em>object)</em>, <em>context</em><big>)</big><a class="headerlink" href="#rdflib.term.Statement.__new__" title="Permalink to this definition">¶</a></dt> +<dd></dd></dl> + +<dl class="method"> +<dt id="rdflib.term.Statement.__reduce__"> +<!--[rdflib.term.Statement.__reduce__]--><tt class="descclassname">Statement.</tt><tt class="descname">__reduce__</tt><big>(</big><big>)</big><a class="headerlink" href="#rdflib.term.Statement.__reduce__" title="Permalink to this definition">¶</a></dt> +<dd></dd></dl> + +</div> +<div class="section" id="module-rdflib.parser"> +<h2>StringInputSource<a class="headerlink" href="#module-rdflib.parser" title="Permalink to this headline">¶</a></h2> +<p>This module defines the parser plugin interface and contains other +related parser support code.</p> +<p>The module is mainly useful for those wanting to write a parser that +can plugin to rdflib. If you are wanting to invoke a parser you likely +want to do so through the Graph class parse method.</p> +<dl class="class"> +<dt id="rdflib.parser.StringInputSource"> +<!--[rdflib.parser.StringInputSource]-->class <tt class="descclassname">rdflib.parser.</tt><tt class="descname">StringInputSource</tt><big>(</big><em>value</em>, <em>system_id=None</em><big>)</big><a class="headerlink" href="#rdflib.parser.StringInputSource" title="Permalink to this definition">¶</a></dt> +<dd>TODO:</dd></dl> + +</div> +<div class="section" id="module-rdflib.textindex"> +<h2>TextIndex<a class="headerlink" href="#module-rdflib.textindex" title="Permalink to this headline">¶</a></h2> +<dl class="class"> +<dt id="rdflib.textindex.TextIndex"> +<!--[rdflib.textindex.TextIndex]-->class <tt class="descclassname">rdflib.textindex.</tt><tt class="descname">TextIndex</tt><big>(</big><em>store='default'</em><big>)</big><a class="headerlink" href="#rdflib.textindex.TextIndex" title="Permalink to this definition">¶</a></dt> +<dd><p>An rdflib graph event handler than indexes text literals that are +added to a another graph.</p> +<p>This class lets you ‘search’ the text literals in an RDF graph. +Typically in RDF to search for a substring in an RDF graph you +would have to ‘brute force’ search every literal string looking +for your substring.</p> +<p>Instead, this index stores the words in literals into another +graph whose structure makes searching for terms much less +expensive. It does this by chopping up the literals into words, +removing very common words (currently only in English) and then +adding each of those words into an RDF graph that describes the +statements in the original graph that the word came from.</p> +<p>First, let’s create a graph that will transmit events and a text +index that will receive those events, and then subscribe the text +index to the event graph:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">e</span> <span class="o">=</span> <span class="n">ConjunctiveGraph</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">t</span> <span class="o">=</span> <span class="n">TextIndex</span><span class="p">()</span> +<span class="gp">>>> </span><span class="n">t</span><span class="o">.</span><span class="n">subscribe_to</span><span class="p">(</span><span class="n">e</span><span class="p">)</span> +</pre></div> +</div> +<p>When triples are added to the event graph (e) events will be fired +that trigger event handlers in subscribers. In this case our only +subscriber is a text index and its action is to index triples that +contain literal RDF objects. Here are 3 such triples:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">e</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'a'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'one two three'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">e</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'b'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'two three four'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">e</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'c'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'three four five'</span><span class="p">)))</span> +</pre></div> +</div> +<p>Of the three literal objects that were added, they all contain +five unique terms. These terms can be queried directly from the +text index:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">t</span><span class="o">.</span><span class="n">term_strings</span><span class="p">()</span> <span class="o">==</span> <span class="n">set</span><span class="p">([</span><span class="s">'four'</span><span class="p">,</span> <span class="s">'five'</span><span class="p">,</span> <span class="s">'three'</span><span class="p">,</span> <span class="s">'two'</span><span class="p">,</span> <span class="s">'one'</span><span class="p">])</span> +<span class="go">True</span> +</pre></div> +</div> +<p>Now we can search for statement that contain certain terms. Let’s +search for ‘one’ which occurs in only one of the literals +provided, ‘a’. This can be queried for:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'one'</span><span class="p">)</span><span class="o">==</span><span class="n">set</span><span class="p">([(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'a'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="bp">None</span><span class="p">)])</span> +<span class="go">True</span> +</pre></div> +</div> +<p>‘one’ and ‘five’ only occur in one statement each, ‘two’ and +‘four’ occur in two, and ‘three’ occurs in three statements:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'one'</span><span class="p">)))</span> +<span class="go">1</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'two'</span><span class="p">)))</span> +<span class="go">2</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'three'</span><span class="p">)))</span> +<span class="go">3</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'four'</span><span class="p">)))</span> +<span class="go">2</span> +<span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'five'</span><span class="p">)))</span> +<span class="go">1</span> +</pre></div> +</div> +<p>Lets add some more statements with different predicates.</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">e</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'a'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'creator'</span><span class="p">),</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'michel'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">e</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'b'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'creator'</span><span class="p">),</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'Atilla the one Hun'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">e</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'c'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'creator'</span><span class="p">),</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'michel'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">e</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'d'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'creator'</span><span class="p">),</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'Hun Mung two'</span><span class="p">)))</span> +</pre></div> +</div> +<p>Now ‘one’ occurs in two statements:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'one'</span><span class="p">)))</span> <span class="o">==</span> <span class="mf">2</span> +</pre></div> +</div> +<p>And ‘two’ occurs in three statements, here they are:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'two'</span><span class="p">)</span><span class="o">==</span><span class="n">set</span><span class="p">([(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'d'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'creator'</span><span class="p">),</span> <span class="bp">None</span><span class="p">),</span> <span class="p">(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'a'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="bp">None</span><span class="p">),</span> <span class="p">(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'b'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="bp">None</span><span class="p">)])</span> +<span class="go">True</span> +</pre></div> +</div> +<p>The predicates that are searched can be restricted by provding an +argument to ‘search()’:</p> +<blockquote> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'two'</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'creator'</span><span class="p">))</span><span class="o">==</span><span class="n">set</span><span class="p">([(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'d'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'creator'</span><span class="p">),</span> <span class="bp">None</span><span class="p">)])</span> +<span class="go">True</span> +</pre></div> +</div> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'two'</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">u'title'</span><span class="p">))</span><span class="o">==</span><span class="n">set</span><span class="p">([(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'a'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="bp">None</span><span class="p">),</span> <span class="p">(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'b'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="bp">None</span><span class="p">)])</span> +<span class="go">True</span> +</pre></div> +</div> +</blockquote> +<p>You can search for more than one term by simply including it in +the query:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'two three'</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">u'title'</span><span class="p">))</span><span class="o">==</span><span class="n">set</span><span class="p">([(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'c'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="bp">None</span><span class="p">),</span> <span class="p">(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'a'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="bp">None</span><span class="p">),</span> <span class="p">(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'b'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="bp">None</span><span class="p">)])</span> +<span class="go">True</span> +</pre></div> +</div> +<p>The above query returns all the statements that contain ‘two’ OR +‘three’. For the documents that contain ‘two’ AND ‘three’, do an +intersection of two queries:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'two'</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">u'title'</span><span class="p">))</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">u'three'</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">u'title'</span><span class="p">)))</span><span class="o">==</span><span class="n">set</span><span class="p">([(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'a'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="bp">None</span><span class="p">),</span> <span class="p">(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'b'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="bp">None</span><span class="p">)])</span> +<span class="go">True</span> +</pre></div> +</div> +<p>Intersection two queries like this is probably not the most +efficient way to do it, but for reasonable data sets this isn’t a +problem. Larger data sets will want to query the graph with +sparql or something else more efficient.</p> +<p>In all the above queries, the object of each statement was always +‘None’. This is because the index graph does not store the object +data, that would make it very large, and besides the data is +available in the original data graph. For convenience, a method +is provides to ‘link’ an index graph to a data graph. This allows +the index to also provide object data in query results.</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">t</span><span class="o">.</span><span class="n">link_to</span><span class="p">(</span><span class="n">e</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">set</span><span class="p">([</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">[</span><span class="mf">2</span><span class="p">])</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'two'</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">u'title'</span><span class="p">))</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">u'three'</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">u'title'</span><span class="p">)))])</span> <span class="o">==</span> <span class="n">set</span><span class="p">([</span><span class="s">'two three four'</span><span class="p">,</span> <span class="s">'one two three'</span><span class="p">])</span> +<span class="go">True</span> +</pre></div> +</div> +<p>You can remove the link by assigning None:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">t</span><span class="o">.</span><span class="n">link_to</span><span class="p">(</span><span class="bp">None</span><span class="p">)</span> +</pre></div> +</div> +<p>Unindexing means to remove statments from the index graph that +corespond to a statement in the data graph. Note that while it is +possible to remove the index information of the occurances of +terms in statements, it is not possible to remove the terms +themselves, terms are ‘absolute’ and are never removed from the +index graph. This is not a problem since languages have finite +terms:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">e</span><span class="o">.</span><span class="n">remove</span><span class="p">((</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'a'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'creator'</span><span class="p">),</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'michel'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">e</span><span class="o">.</span><span class="n">remove</span><span class="p">((</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'b'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'creator'</span><span class="p">),</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'Atilla the one Hun'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">e</span><span class="o">.</span><span class="n">remove</span><span class="p">((</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'c'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'creator'</span><span class="p">),</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'michel'</span><span class="p">)))</span> +<span class="gp">>>> </span><span class="n">e</span><span class="o">.</span><span class="n">remove</span><span class="p">((</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'d'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'creator'</span><span class="p">),</span> <span class="n">Literal</span><span class="p">(</span><span class="s">'Hun Mung two'</span><span class="p">)))</span> +</pre></div> +</div> +<p>Now ‘one’ only occurs in one statement:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'one'</span><span class="p">)))</span> <span class="o">==</span> <span class="mf">1</span> +</pre></div> +</div> +<p>And ‘two’ only occurs in two statements, here they are:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'two'</span><span class="p">)</span><span class="o">==</span><span class="n">set</span><span class="p">([(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'a'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="bp">None</span><span class="p">),</span> <span class="p">(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'b'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="bp">None</span><span class="p">)])</span> +<span class="go">True</span> +</pre></div> +</div> +<p>The predicates that are searched can be restricted by provding an +argument to ‘search()’:</p> +<blockquote> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'two'</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">u'creator'</span><span class="p">))</span> +<span class="go">set([])</span> +</pre></div> +</div> +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">t</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s">'two'</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">u'title'</span><span class="p">))</span><span class="o">==</span><span class="n">set</span><span class="p">([(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'a'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="bp">None</span><span class="p">),</span> <span class="p">(</span><span class="n">URIRef</span><span class="p">(</span><span class="s">'b'</span><span class="p">),</span> <span class="n">URIRef</span><span class="p">(</span><span class="s">'title'</span><span class="p">),</span> <span class="bp">None</span><span class="p">)])</span> +<span class="go">True</span> +</pre></div> +</div> +</blockquote> +<dl class="method"> +<dt id="rdflib.textindex.TextIndex.index_graph"> +<!--[rdflib.textindex.TextIndex.index_graph]--><tt class="descname">index_graph</tt><big>(</big><em>graph</em><big>)</big><a class="headerlink" href="#rdflib.textindex.TextIndex.index_graph" title="Permalink to this definition">¶</a></dt> +<dd>Index a whole graph. Must be a conjunctive graph.</dd></dl> + +<dl class="method"> +<dt id="rdflib.textindex.TextIndex.link_to"> +<!--[rdflib.textindex.TextIndex.link_to]--><tt class="descname">link_to</tt><big>(</big><em>graph</em><big>)</big><a class="headerlink" href="#rdflib.textindex.TextIndex.link_to" title="Permalink to this definition">¶</a></dt> +<dd>Link to a graph</dd></dl> + +<dl class="method"> +<dt id="rdflib.textindex.TextIndex.search"> +<!--[rdflib.textindex.TextIndex.search]--><tt class="descname">search</tt><big>(</big><em>terms</em>, <em>predicate=None</em><big>)</big><a class="headerlink" href="#rdflib.textindex.TextIndex.search" title="Permalink to this definition">¶</a></dt> +<dd>Returns a set of all the statements the term occurs in.</dd></dl> + +<dl class="method"> +<dt id="rdflib.textindex.TextIndex.subscribe_to"> +<!--[rdflib.textindex.TextIndex.subscribe_to]--><tt class="descname">subscribe_to</tt><big>(</big><em>graph</em><big>)</big><a class="headerlink" href="#rdflib.textindex.TextIndex.subscribe_to" title="Permalink to this definition">¶</a></dt> +<dd>Subscribe this index to a graph.</dd></dl> + +<dl class="method"> +<dt id="rdflib.textindex.TextIndex.term_strings"> +<!--[rdflib.textindex.TextIndex.term_strings]--><tt class="descname">term_strings</tt><big>(</big><big>)</big><a class="headerlink" href="#rdflib.textindex.TextIndex.term_strings" title="Permalink to this definition">¶</a></dt> +<dd>Return a list of term strings.</dd></dl> + +<dl class="method"> +<dt id="rdflib.textindex.TextIndex.terms"> +<!--[rdflib.textindex.TextIndex.terms]--><tt class="descname">terms</tt><big>(</big><big>)</big><a class="headerlink" href="#rdflib.textindex.TextIndex.terms" title="Permalink to this definition">¶</a></dt> +<dd>Returns a generator that yields all of the term literals in the graph.</dd></dl> + +</dd></dl> + +</div> +<div class="section" id="triplestore"> +<h2>TripleStore<a class="headerlink" href="#triplestore" title="Permalink to this headline">¶</a></h2> +</div> +<div class="section" id="urlinputsource"> +<h2>URLInputSource<a class="headerlink" href="#urlinputsource" title="Permalink to this headline">¶</a></h2> +<dl class="class"> +<dt id="rdflib.parser.URLInputSource"> +<!--[rdflib.parser.URLInputSource]-->class <tt class="descclassname">rdflib.parser.</tt><tt class="descname">URLInputSource</tt><big>(</big><em>system_id=None</em><big>)</big><a class="headerlink" href="#rdflib.parser.URLInputSource" title="Permalink to this definition">¶</a></dt> +<dd>TODO:</dd></dl> + +</div> +<div class="section" id="module-rdflib.query"> +<h2>query<a class="headerlink" href="#module-rdflib.query" title="Permalink to this headline">¶</a></h2> +</div> +<div class="section" id="module-rdflib.store"> +<h2>store<a class="headerlink" href="#module-rdflib.store" title="Permalink to this headline">¶</a></h2> +</div> +<div class="section" id="module-rdflib.sparql"> +<h2>sparql<a class="headerlink" href="#module-rdflib.sparql" title="Permalink to this headline">¶</a></h2> +<p>TODO: merge this first bit from sparql.sparql.py into rest of doc... +updating all along the way.</p> +<p>SPARQL implementation on top of RDFLib</p> +<p>Implementation of the <a class="reference external" href="http://www.w3.org/TR/rdf-sparql-query/">W3C SPARQL</a> +language (version April 2005). The basic class here is supposed to be a +superclass of rdflib.sparql.sparqlGraph; it has been separated only for +a better maintainability.</p> +<p>There is a separate +<a class="reference external" href="http://dev.w3.org/cvsweb/%7Echeckout%7E/2004/PythonLib-IH/Doc/sparqlDesc.html">description</a> +for the functionalities.</p> +<p>For a general description of the SPARQL API, see the separate, more complete +<a class="reference external" href="http://dev.w3.org/cvsweb/%7Echeckout%7E/2004/PythonLib-IH/Doc/sparqlDesc.html">description</a>.</p> +<div class="section" id="variables-imports"> +<h3>Variables, Imports<a class="headerlink" href="#variables-imports" title="Permalink to this headline">¶</a></h3> +<p>The top level (__init__.py) module of the Package imports the +important classes. In other words, the user may choose to use the +following imports only:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">myTripleStore</span> +<span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">retrieveRDFFiles</span> +<span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">SPARQLError</span> +<span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">GraphPattern</span> +</pre></div> +</div> +<p>The module imports and/or creates some frequently used Namespaces, and +these can then be imported by the user like:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">ns_rdf</span> +</pre></div> +</div> +<p>Finally, the package also has a set of convenience string defines for +XML Schema datatypes (ie, the URI-s of the datatypes); ie, one can +use:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">type_string</span> +<span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">type_integer</span> +<span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">type_long</span> +<span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">type_double</span> +<span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">type_float</span> +<span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">type_decimal</span> +<span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">type_dateTime</span> +<span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">type_date</span> +<span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">type_time</span> +<span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">type_duration</span> +</pre></div> +</div> +<p>These are used, for example, in the sparql-p implementation.</p> +<p>The three most important classes in RDFLib for the average user are +Namespace, URIRef and Literal; these are also imported, so the user +can also use, eg:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">rdflibUtils</span> <span class="kn">import</span> <span class="n">Namespace</span><span class="p">,</span> <span class="n">URIRef</span><span class="p">,</span> <span class="n">Literal</span> +</pre></div> +</div> +</div> +<div class="section" id="history"> +<h3>History<a class="headerlink" href="#history" title="Permalink to this headline">¶</a></h3> +<blockquote> +<ul class="simple"> +<li>Version 1.0: based on an earlier version of the SPARQL, first released implementation</li> +<li>Version 2.0: version based on the March 2005 SPARQL document, +also a major change of the core code (introduction of the separate +<tt class="docutils literal"><span class="pre">GraphPattern</span></tt> <tt class="xref docutils literal"><span class="pre">rdflibUtils.graphPattern.GraphPattern</span></tt> class, etc).</li> +<li>Version 2.01: minor changes only: - switch to epydoc as a documentation tool, +it gives a much better overview of the classes - addition of the +SELECT * feature to sparql-p</li> +<li>Version 2.02: - added some methods to +<tt class="docutils literal"><span class="pre">myTripleStore</span></tt> <tt class="xref docutils literal"><span class="pre">rdflibUtils.myTripleStore.myTripleStore</span></tt> to handle +<tt class="docutils literal"><span class="pre">Alt</span></tt> and <tt class="docutils literal"><span class="pre">Bag</span></tt> the same way as <tt class="docutils literal"><span class="pre">Seq</span></tt> - added also methods to +<tt class="xref docutils literal"><span class="pre">add()</span></tt> collections and containers to the triple store, not only +retrieve them</li> +<li>Version 2.1: adapted to the inclusion of the code into rdflib, thanks to Michel Pelletier</li> +<li>Version 2.2: added the sorting possibilities; introduced the Unbound class and have a better +interface to patterns using this (in the BasicGraphPattern class)</li> +</ul> +</blockquote> +<p>@author: <a class="reference external" href="http://www.ivan-herman.net">Ivan Herman</a></p> +<p>@license: This software is available for use under the +<a class="reference external" href="http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231">W3C Software License</a></p> +<p>@contact: Ivan Herman, <a class="reference external" href="mailto:ivan%40ivan-herman.net">ivan<span>@</span>ivan-herman<span>.</span>net</a></p> +<p>@version: 2.2</p> +</div> +</div> +<div class="section" id="module-rdflib.syntax"> +<h2>syntax<a class="headerlink" href="#module-rdflib.syntax" title="Permalink to this headline">¶</a></h2> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="../index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href="">Other modules</a><ul> +<li><a class="reference external" href="#module-rdflib.collection">Collection</a></li> +<li><a class="reference external" href="#module-rdflib.journal">Journal</a></li> +<li><a class="reference external" href="#module-rdflib.query.result">QueryResult</a></li> +<li><a class="reference external" href="#module-rdflib.term">Statement</a></li> +<li><a class="reference external" href="#module-rdflib.parser">StringInputSource</a></li> +<li><a class="reference external" href="#module-rdflib.textindex">TextIndex</a></li> +<li><a class="reference external" href="#triplestore">TripleStore</a></li> +<li><a class="reference external" href="#urlinputsource">URLInputSource</a></li> +<li><a class="reference external" href="#module-rdflib.query">query</a></li> +<li><a class="reference external" href="#module-rdflib.store">store</a></li> +<li><a class="reference external" href="#module-rdflib.sparql">sparql</a><ul> +<li><a class="reference external" href="#variables-imports">Variables, Imports</a></li> +<li><a class="reference external" href="#history">History</a></li> +</ul> +</li> +<li><a class="reference external" href="#module-rdflib.syntax">syntax</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="nodes/quoted_graph.html" + title="previous chapter"><tt class="docutils literal docutils literal docutils literal docutils literal docutils literal"><span class="pre">rdflib.graph.QuotedGraph</span></tt> – Quoted graphs</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="../_sources/modules/others.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="../modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="nodes/quoted_graph.html" title="rdflib.graph.QuotedGraph – Quoted graphs" + accesskey="P">previous</a> |</li> + <li><a href="../index.html">rdflib v2.5.0 documentation</a> »</li> + <li><a href="index.html" accesskey="U">Modules</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/namespace_utilities.html b/docs/_build/html/namespace_utilities.html new file mode 100644 index 00000000..54ff10a3 --- /dev/null +++ b/docs/_build/html/namespace_utilities.html @@ -0,0 +1,136 @@ +<!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>Namespace Utilities — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="_static/default.css" type="text/css" /> + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="_static/jquery.js"></script> + <script type="text/javascript" src="_static/doctools.js"></script> + <link rel="index" title="Index" href="genindex.html" /> + <link rel="search" title="Search" href="search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="index.html" /> + <link rel="next" title="Graph utilities" href="graph_utilities.html" /> + <link rel="prev" title="RDF Graph Terms" href="graphterms.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="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="graph_utilities.html" title="Graph utilities" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="graphterms.html" title="RDF Graph Terms" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="module-rdflib.namespace"> +<span id="namespace-utilities"></span><h1>Namespace Utilities<a class="headerlink" href="#module-rdflib.namespace" title="Permalink to this headline">¶</a></h1> +<p>RDFLib provides mechanisms for managing Namespaces. In particular, there is a [<a class="reference external" href="http://svn.rdflib.net/trunk/rdflib/Namespace.py">http://svn.rdflib.net/trunk/rdflib/Namespace.py</a> Namespace] class which takes (as its only argument) the Base URI of the namespace. Fully qualified URIs in the namespace can be constructed by attribute / dictionary access on Namespace instances:</p> +<div class="highlight-pycon"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">rdflib.namespace</span> <span class="kn">import</span> <span class="n">Namespace</span> +<span class="gp">>>> </span><span class="n">fuxi</span> <span class="o">=</span> <span class="n">Namespace</span><span class="p">(</span><span class="s">'http://metacognition.info/ontologies/FuXi.n3#'</span><span class="p">)</span> +<span class="gp">>>> </span><span class="n">fuxi</span><span class="o">.</span><span class="n">ruleBase</span> +<span class="go">u'http://metacognition.info/ontologies/FuXi.n3#ruleBase'</span> +<span class="gp">>>> </span><span class="n">fuxi</span><span class="p">[</span><span class="s">'ruleBase'</span><span class="p">]</span> +<span class="go">u'http://metacognition.info/ontologies/FuXi.n3#ruleBase'</span> +</pre></div> +</div> +<div class="section" id="contents"> +<h2>Contents<a class="headerlink" href="#contents" title="Permalink to this headline">¶</a></h2> +<dl class="class"> +<dt id="rdflib.namespace.Namespace"> +<!--[rdflib.namespace.Namespace]-->class <tt class="descclassname">rdflib.namespace.</tt><tt class="descname">Namespace</tt><a class="headerlink" href="#rdflib.namespace.Namespace" title="Permalink to this definition">¶</a></dt> +<dd></dd></dl> + +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href="">Namespace Utilities</a><ul> +<li><a class="reference external" href="#contents">Contents</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="graphterms.html" + title="previous chapter">RDF Graph Terms</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="graph_utilities.html" + title="next chapter">Graph utilities</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="_sources/namespace_utilities.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="graph_utilities.html" title="Graph utilities" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="graphterms.html" title="RDF Graph Terms" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/objects.inv b/docs/_build/html/objects.inv new file mode 100644 index 00000000..f17e0d72 --- /dev/null +++ b/docs/_build/html/objects.inv @@ -0,0 +1,116 @@ +# Sphinx inventory version 1 +# Project: rdflib +# Version: 2.5.0 +rdflib.syntax.parsers.TriXParser mod gettingstarted.html +rdflib.term mod modules/others.html +rdflib.syntax.parsers.RDFXMLParser mod gettingstarted.html +rdflib.syntax mod modules/others.html +rdflib.syntax.parsers.N3Parser mod gettingstarted.html +rdflib.syntax.parsers.ntriples mod gettingstarted.html +rdflib.journal mod modules/others.html +rdflib.namespace mod namespace_utilities.html +rdflib.query.result mod modules/others.html +rdflib.syntax.parsers.NTParser mod gettingstarted.html +rdflib.sparql mod modules/others.html +rdflib.store mod modules/others.html +rdflib.syntax.parsers mod gettingstarted.html +rdflib.textindex mod modules/others.html +rdflib.query mod modules/others.html +rdflib.graph mod modules/graphs/index.html +rdflib.collection mod modules/others.html +rdflib.parser mod modules/others.html +rdflib.syntax.parsers.n3p mod gettingstarted.html +rdflib.graph.Graph.subject_objects method modules/graphs/graph.html +rdflib.textindex.TextIndex.index_graph method modules/others.html +rdflib.term.Variable class modules/nodes/variable.html +rdflib.graph.Seq class graphterms.html +rdflib.term.Statement.__new__ staticmethod modules/others.html +rdflib.parser.StringInputSource class modules/others.html +rdflib.store.Store.open method univrdfstore.html +rdflib.store.Store.triples method univrdfstore.html +rdflib.term.Statement class modules/others.html +rdflib.term.URIRef class modules/nodes/uriref.html +rdflib.graph.Graph.parse method modules/graphs/graph.html +rdflib.graph.Graph.serialize method modules/graphs/graph.html +rdflib.store.Store.__len__ method univrdfstore.html +rdflib.term.BNode class modules/nodes/bnode.html +rdflib.collection.Collection.append method modules/others.html +rdflib.graph.ConjunctiveGraph.remove_context method univrdfstore.html +rdflib.graph.ConjunctiveGraph.quads method univrdfstore.html +rdflib.graph.Graph.namespaces method modules/graphs/graph.html +rdflib.journal.JournalReader class modules/others.html +rdflib.graph.Graph.rollback method modules/graphs/graph.html +rdflib.syntax.parsers.NTParser.NTParser class gettingstarted.html +rdflib.graph.Graph.subjects method modules/graphs/graph.html +rdflib.graph.Graph.transitive_subjects method modules/graphs/graph.html +rdflib.graph.ReadOnlyGraphAggregate class graphterms.html +rdflib.parser.URLInputSource class modules/others.html +rdflib.graph.ConjunctiveGraph.triples method modules/graphs/conjunctive_graph.html +rdflib.journal.JournalWriter class modules/others.html +rdflib.store.Store.destroy method univrdfstore.html +rdflib.syntax.parsers.TriXParser.TriXParser class gettingstarted.html +rdflib.graph.Graph.predicates method modules/graphs/graph.html +rdflib.graph.Graph.transitiveClosure method modules/graphs/graph.html +rdflib.graph.Graph.commit method modules/graphs/graph.html +rdflib.collection.Collection.n3 method modules/others.html +rdflib.graph.Graph.triples method modules/graphs/graph.html +rdflib.graph.Graph.addN method modules/graphs/graph.html +rdflib.term.Literal.toPython method modules/nodes/literal.html +rdflib.textindex.TextIndex class modules/others.html +rdflib.syntax.parsers.RDFXMLParser.RDFXMLParser class gettingstarted.html +rdflib.textindex.TextIndex.term_strings method modules/others.html +rdflib.store.Store.close method univrdfstore.html +rdflib.graph.Graph.transitive_objects method modules/graphs/graph.html +rdflib.graph.Graph.value method modules/graphs/graph.html +rdflib.store.Store.prefix method univrdfstore.html +rdflib.graph.Graph.absolutize method modules/graphs/graph.html +rdflib.graph.Graph.query method modules/graphs/graph.html +rdflib.store.Store.remove method univrdfstore.html +rdflib.graph.Graph.remove method modules/graphs/graph.html +rdflib.graph.Graph.add method modules/graphs/graph.html +rdflib.graph.ConjunctiveGraph.contexts method univrdfstore.html +rdflib.textindex.TextIndex.terms method modules/others.html +rdflib.graph.ConjunctiveGraph.get_context method modules/graphs/conjunctive_graph.html +rdflib.graph.Graph.items method modules/graphs/graph.html +rdflib.graph.Graph.destroy method modules/graphs/graph.html +rdflib.graph.QuotedGraph class modules/nodes/quoted_graph.html +rdflib.store.Store.add method univrdfstore.html +rdflib.graph.ConjunctiveGraph class modules/graphs/conjunctive_graph.html +rdflib.term.Identifier class modules/nodes/identifier.html +rdflib.textindex.TextIndex.search method modules/others.html +rdflib.textindex.TextIndex.link_to method modules/others.html +rdflib.syntax.parsers.N3Parser.N3Parser class gettingstarted.html +rdflib.store.Store.bind method univrdfstore.html +rdflib.graph.Graph.label method modules/graphs/graph.html +rdflib.graph.ConjunctiveGraph.triples_choices method modules/graphs/conjunctive_graph.html +rdflib.graph.ConjunctiveGraph.addN method modules/graphs/conjunctive_graph.html +rdflib.term.Literal class modules/nodes/literal.html +rdflib.syntax.parsers.ntriples.NTriplesParser.readline method gettingstarted.html +rdflib.graph.Graph.objects method modules/graphs/graph.html +rdflib.syntax.parsers.ntriples.NTriplesParser class gettingstarted.html +rdflib.textindex.TextIndex.subscribe_to method modules/others.html +rdflib.collection.Collection class modules/others.html +rdflib.graph.Graph.connected method modules/graphs/graph.html +rdflib.store.Store.namespaces method univrdfstore.html +rdflib.term.Node class modules/nodes/node.html +rdflib.graph.Graph.subject_predicates method modules/graphs/graph.html +rdflib.graph.ConjunctiveGraph.parse method modules/graphs/conjunctive_graph.html +rdflib.graph.Graph.comment method modules/graphs/graph.html +rdflib.query.result.QueryResult class modules/others.html +rdflib.graph.Graph.bind method modules/graphs/graph.html +rdflib.graph.Graph class modules/graphs/graph.html +rdflib.store.Store.namespace method univrdfstore.html +rdflib.graph.Graph.predicate_objects method modules/graphs/graph.html +rdflib.graph.Graph.open method modules/graphs/graph.html +rdflib.collection.Collection.index method modules/others.html +rdflib.namespace.Namespace class namespace_utilities.html +rdflib.graph.Graph.n3 method modules/graphs/graph.html +rdflib.graph.ConjunctiveGraph.remove method modules/graphs/conjunctive_graph.html +rdflib.syntax.parsers.ntriples.NTriplesParser.parsestring method gettingstarted.html +rdflib.graph.ConjunctiveGraph.context_id method modules/graphs/conjunctive_graph.html +rdflib.term.Statement.__reduce__ method modules/others.html +rdflib.graph.Graph.seq method modules/graphs/graph.html +rdflib.graph.Graph.set method modules/graphs/graph.html +rdflib.graph.Graph.close method modules/graphs/graph.html +rdflib.syntax.parsers.ntriples.NTriplesParser.parse method gettingstarted.html +rdflib.graph.ConjunctiveGraph.add method modules/graphs/conjunctive_graph.html diff --git a/docs/_build/html/persistence.html b/docs/_build/html/persistence.html new file mode 100644 index 00000000..f9440920 --- /dev/null +++ b/docs/_build/html/persistence.html @@ -0,0 +1,126 @@ +<!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>Persistence — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="_static/default.css" type="text/css" /> + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="_static/jquery.js"></script> + <script type="text/javascript" src="_static/doctools.js"></script> + <link rel="index" title="Index" href="genindex.html" /> + <link rel="search" title="Search" href="search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="index.html" /> + <link rel="next" title="Persisting Notation 3 Terms" href="persisting_n3_terms.html" /> + <link rel="prev" title="Graph utilities" href="graph_utilities.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="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="persisting_n3_terms.html" title="Persisting Notation 3 Terms" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="graph_utilities.html" title="Graph utilities" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="id1"> +<span id="persistence"></span><h1>Persistence<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h1> +<p>RDFLib provides an abstracted Store API for persistence of RDF and Notation 3. The <tt class="xref docutils literal"><span class="pre">Graph</span></tt> class works with instances of this API (as the first argument to its constructor) for triple-based management of an RDF store including: garbage collection, transaction management, update, pattern matching, removal, length, and database management (<tt class="xref docutils literal"><span class="pre">open()</span></tt> / <tt class="xref docutils literal"><span class="pre">close()</span></tt> / <tt class="xref docutils literal"><span class="pre">destroy()</span></tt>) . Additional persistence mechanisms can be supported by implementing this API for a different store.</p> +<p>Currently supported databases:</p> +<ul class="simple"> +<li>MySQL</li> +<li>SQLite</li> +<li>Berkeley DB</li> +<li>Zope Object Database</li> +<li>Random access memory</li> +<li>Redland RDF Application Framework</li> +</ul> +<p>Store instances can be created with the <tt class="xref docutils literal"><span class="pre">plugin()</span></tt> function:</p> +<div class="highlight-python"><pre>from rdflib import plugin +from rdflib.store import Store +plugin.get('.. one of the supported Stores ..',Store)(identifier=.. id of conjunctive graph ..)</pre> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h4>Previous topic</h4> + <p class="topless"><a href="graph_utilities.html" + title="previous chapter">Graph utilities</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="persisting_n3_terms.html" + title="next chapter">Persisting Notation 3 Terms</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="_sources/persistence.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="persisting_n3_terms.html" title="Persisting Notation 3 Terms" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="graph_utilities.html" title="Graph utilities" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/persisting_n3_terms.html b/docs/_build/html/persisting_n3_terms.html new file mode 100644 index 00000000..215261f6 --- /dev/null +++ b/docs/_build/html/persisting_n3_terms.html @@ -0,0 +1,190 @@ +<!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>Persisting Notation 3 Terms — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="_static/default.css" type="text/css" /> + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="_static/jquery.js"></script> + <script type="text/javascript" src="_static/doctools.js"></script> + <link rel="index" title="Index" href="genindex.html" /> + <link rel="search" title="Search" href="search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="index.html" /> + <link rel="next" title="Merging graphs" href="graph_merging.html" /> + <link rel="prev" title="Persistence" href="persistence.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="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="graph_merging.html" title="Merging graphs" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="persistence.html" title="Persistence" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="persisting-notation-3-terms"> +<span id="persisting-n3-terms"></span><h1>Persisting Notation 3 Terms<a class="headerlink" href="#persisting-notation-3-terms" title="Permalink to this headline">¶</a></h1> +<div class="section" id="using-n3-syntax-for-persistence"> +<h2>Using N3 Syntax for Persistence<a class="headerlink" href="#using-n3-syntax-for-persistence" title="Permalink to this headline">¶</a></h2> +<p>Blank Nodes, Literals, URI References, and Variables can be distinguished in persistence by relying on Notation 3 syntax convention.</p> +<p>All URI References can be expanded and persisted as:</p> +<div class="highlight-text"><div class="highlight"><pre><..URI..> +</pre></div> +</div> +<p>All Literals can be expanded and persisted as:</p> +<div class="highlight-text"><div class="highlight"><pre>"..value.."@lang or "..value.."^^dtype_uri +</pre></div> +</div> +<div class="admonition note"> +<p class="first admonition-title">Note</p> +<p class="last"><tt class="docutils literal"><span class="pre">@lang</span></tt> is a language tag and <tt class="docutils literal"><span class="pre">^^dtype_uri</span></tt> is the URI of a data type associated with the Literal</p> +</div> +<p>Blank Nodes can be expanded and persisted as:</p> +<div class="highlight-text"><div class="highlight"><pre>_:Id +</pre></div> +</div> +<div class="admonition note"> +<p class="first admonition-title">Note</p> +<p class="last">where Id is an identifier as determined by skolemization. Skolemization is a syntactic transformation routinely used in automatic inference systems in which existential variables are replaced by ‘new’ functions - function names not used elsewhere - applied to any enclosing universal variables. In RDF, Skolemization amounts to replacing every blank node in a graph by a ‘new’ name, i.e. a URI reference which is guaranteed to not occur anywhere else. In effect, it gives ‘arbitrary’ names to the anonymous entities whose existence was asserted by the use of blank nodes: the arbitrariness of the names ensures that nothing can be inferred that would not follow from the bare assertion of existence represented by the blank node. (Using a literal would not do. Literals are never ‘new’ in the required sense.)</p> +</div> +<p>Variables can be persisted as they appear in their serialization <tt class="docutils literal"><span class="pre">(?varName)</span></tt> - since they only need be unique within their scope (the context of their associated statements)</p> +<p>These syntactic conventions can facilitate term round-tripping.</p> +</div> +<div class="section" id="variables-by-scope"> +<h2>Variables by Scope<a class="headerlink" href="#variables-by-scope" title="Permalink to this headline">¶</a></h2> +<p>Would an interface be needed in order to facilitate a quick way to aggregate all the variables in a scope (given by a formula identifier)? An interface such as:</p> +<div class="highlight-python"><pre>def variables(formula_identifier)</pre> +</div> +</div> +<div class="section" id="the-need-to-skolemize-formula-identifiers"> +<h2>The Need to Skolemize Formula Identifiers<a class="headerlink" href="#the-need-to-skolemize-formula-identifiers" title="Permalink to this headline">¶</a></h2> +<p>It would seem reasonable to assume that a formula-aware store would assign Blank Node identifiers as names of formulae that appear in a N3 serialization. So for instance, the following bit of N3:</p> +<div class="highlight-n3"><pre>{?x a :N3Programmer} => {?x :has :Migrane}</pre> +</div> +<p>Could be interpreted as the assertion of the following statement:</p> +<div class="highlight-n3"><div class="highlight"><pre><span class="nc">_:a </span><span class="o">log:implies </span><span class="na">_:b</span> +</pre></div> +</div> +<p>However, how are <tt class="docutils literal"><span class="pre">_:a</span></tt> and <tt class="docutils literal"><span class="pre">_:b</span></tt> distinguished from other Blank Nodes? A formula-aware store would be expected to persist the first set of statements as quoted statements in a formula named <tt class="docutils literal"><span class="pre">_:a</span></tt> and the second set as quoted statements in a formula named <tt class="docutils literal"><span class="pre">_:b</span></tt>, but it would not be cost-effective for a serializer to have to query the store for all statements in a context named <tt class="docutils literal"><span class="pre">_:a</span></tt> in order to determine if <tt class="docutils literal"><span class="pre">_:a</span></tt> was associated with a formula (so that it could be serialized properly).</p> +</div> +<div class="section" id="relying-on-log-formula-membership"> +<h2>Relying on <tt class="docutils literal"><span class="pre">log:Formula</span></tt> Membership<a class="headerlink" href="#relying-on-log-formula-membership" title="Permalink to this headline">¶</a></h2> +<p>The store could rely on explicit <tt class="docutils literal"><span class="pre">log:Formula</span></tt> membership (via <tt class="docutils literal"><span class="pre">rdf:type</span></tt> statements) to model the distinction of Blank Nodes associated with formulae. However, would these statements be expected from an N3 parser or known implicitly by the store? i.e., would all such Blank Nodes match the following pattern:</p> +<div class="highlight-text"><div class="highlight"><pre>?formula rdf:type log:Formula +</pre></div> +</div> +</div> +<div class="section" id="relying-on-an-explicit-interface"> +<h2>Relying on an Explicit Interface<a class="headerlink" href="#relying-on-an-explicit-interface" title="Permalink to this headline">¶</a></h2> +<p>A formula-aware store could also support the persistence of this distinction by implementing a method that returns an iterator over all the formulae in the store:</p> +<div class="highlight-python"><pre>def formulae(triple=None)</pre> +</div> +<p>This function would return all the Blank Node identifiers assigned to formulae or just those that contain statements matching the given triple pattern and would be the way a serializer determines if a term refers to a formula (in order to properly serializer it).</p> +<p>How much would such an interface reduce the need to model formulae terms as first class objects (perhaps to be returned by the <tt class="xref docutils literal"><span class="pre">triple()</span></tt> function)? Would it be more useful for the <tt class="xref docutils literal"><span class="pre">Graph</span></tt> (or the store itself) to return a Context object in place of a formula term (using the formulae interface to make this determination)?</p> +<p>Conversely, would these interfaces (variables and formulae) be considered optimizations only since you have the distinction by the kinds of terms triples returns (which would be expanded to include variables and formulae)?</p> +</div> +<div class="section" id="persisting-formula-identifiers"> +<h2>Persisting Formula Identifiers<a class="headerlink" href="#persisting-formula-identifiers" title="Permalink to this headline">¶</a></h2> +<p>This is the most straight forward way to maintain this distinction - without relying on extra interfaces. Formula identifiers could be persisted distinctly from other terms by using the following notation:</p> +<div class="highlight-n3"><pre>{_:bnode} or {<.. URI ..>}</pre> +</div> +<p>This would facilitate their persistence round-trip - same as the other terms that rely on N3 syntax to distinguish between each other.</p> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href="">Persisting Notation 3 Terms</a><ul> +<li><a class="reference external" href="#using-n3-syntax-for-persistence">Using N3 Syntax for Persistence</a></li> +<li><a class="reference external" href="#variables-by-scope">Variables by Scope</a></li> +<li><a class="reference external" href="#the-need-to-skolemize-formula-identifiers">The Need to Skolemize Formula Identifiers</a></li> +<li><a class="reference external" href="#relying-on-log-formula-membership">Relying on <tt class="docutils literal"><span class="pre">log:Formula</span></tt> Membership</a></li> +<li><a class="reference external" href="#relying-on-an-explicit-interface">Relying on an Explicit Interface</a></li> +<li><a class="reference external" href="#persisting-formula-identifiers">Persisting Formula Identifiers</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="persistence.html" + title="previous chapter">Persistence</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="graph_merging.html" + title="next chapter">Merging graphs</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="_sources/persisting_n3_terms.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="graph_merging.html" title="Merging graphs" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="persistence.html" title="Persistence" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/search.html b/docs/_build/html/search.html new file mode 100644 index 00000000..1decd96e --- /dev/null +++ b/docs/_build/html/search.html @@ -0,0 +1,98 @@ +<!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>Search — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="_static/default.css" type="text/css" /> + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="_static/jquery.js"></script> + <script type="text/javascript" src="_static/doctools.js"></script> + <script type="text/javascript" src="_static/searchtools.js"></script> + <link rel="index" title="Index" href="genindex.html" /> + <link rel="search" title="Search" href="" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="index.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="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <h1 id="search-documentation">Search</h1> + <div id="fallback" class="admonition warning"> + <script type="text/javascript">$('#fallback').hide();</script> + <p> + Please activate JavaScript to enable the search + functionality. + </p> + </div> + <p> + From here you can search these documents. Enter your search + words into the box below and click "search". Note that the search + function will automatically search for all of the words. Pages + containing fewer words won't appear in the result list. + </p> + <form action="" method="get"> + <input type="text" name="q" value="" /> + <input type="submit" value="search" /> + <span id="search-progress" style="padding-left: 10px"></span> + </form> + + <div id="search-results"> + + </div> + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + </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" + accesskey="I">index</a></li> + <li class="right" > + <a href="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + <script type="text/javascript" src="searchindex.js"></script> + + </body> +</html>
\ No newline at end of file diff --git a/docs/_build/html/searchindex.js b/docs/_build/html/searchindex.js new file mode 100644 index 00000000..69dabe32 --- /dev/null +++ b/docs/_build/html/searchindex.js @@ -0,0 +1 @@ +Search.setIndex({desctypes:{"0":"method","1":"class","2":"staticmethod"},terms:{all:[5,15,8,2,16,3,10,22,18,23,24],interchang:24,four:10,profilesinterror:8,prefix:[5,8,2,3,18,24],articul:[23,24],whose:[15,8,10,23,24],accur:23,aug:22,pprint:5,swap:[2,24],allvari:22,under:[1,8,22,10,23],worth:24,merchant:1,everi:[5,12,15,8,10,23],newuri:8,quantif:24,xmlschema:[20,8,22,2,10],ns_rdf:10,cmp:20,miller:5,seper:23,direct:[14,8],consequ:23,second:[15,8,23],aggreg:[15,3,18,23,24],readonlygraphaggreg:[3,18,23,0],even:[1,8,23,5],prettyxmlseri:22,inputfilename2:1,inputfilename1:1,"new":[5,1,8,15,22,23],symmetr:8,ever:8,metadata:23,"_default_":3,xfn:8,never:[15,22,10,23],drew:5,met:8,path:[8,24],interpret:[5,24,15,14],atom_:8,trixpars:5,stmt3:[3,18],stmt2:[3,18],stmt1:[3,18],precis:23,datetim:[20,8,16],aka:[2,24],substr:10,type_dur:10,defaultgraph:2,describ:[5,2,10],would:[15,8,10,23,24],twoint:20,vljqilch4:23,vljqilch3:23,call:[5,8,16,3,18,23,24],recommend:23,type:[5,6,14,0,1,8,24,2,20,3,10,21,15,4,22,13,18,23,12],until:[5,2,23],relat:[8,10,23],warn:[1,8],"__iter__":16,hold:23,berner:5,vcard:1,must:[5,12,2,10,22,18,23,24],word:10,setup:23,work:[14,8,11,22,23,24],root:[14,22,18],pythonresult:10,undirect:2,overrid:[2,16],wang:8,give:[15,8,10,23,24],indic:[5,24,2,16,14],want:[5,8,10,23,24],predicate1:14,keep:24,end:8,quot:[7,15,19,3,17,18,24],ordinari:14,how:[5,8,24,23,15],hasnam:8,env:8,answer:[5,23],ancestor:8,perspect:24,collaps:8,predicaten:14,after:5,lump:23,diagram:24,befor:[5,24,2,23,14],demonstr:1,contenthandl:22,attempt:24,sparql:[14,5,8,2,3,10,17,22,18,23],third:23,exclud:23,perform:[2,24],journalwrit:10,maintain:[14,12,15,10,23,24],exclus:24,mechan:[23,24,16,11,9],lambda:[22,16],order:[5,14,15,0,16,22,23,24],oper:[14,5,1,8,0,16,24],normalizedstr:16,over:[0,15,8,2,16,3,18,24],becaus:[10,23],dijkstra:8,transitiveclosur:2,sha1sum:8,uuid:24,fit:1,fix:22,"__class__":[22,3,18],better:[10,23,24],persist:[14,12,15,11,23,24],easier:8,split:[1,8],them:[14,8,10,23,12],thei:[5,14,15,8,16,10,23,24],mccloski:5,statementid:[3,18],choic:[4,23],odbc:24,getvalu:22,each:[12,15,8,16,10,23,24],debug:[5,8,2],mean:[22,10,23],movieuri:8,dawg:23,extract:8,unbound:[10,24],goe:[22,2],content:[14,6,13,7,21,0,2,19,20,3,9,17,4,22,18,12],daniel:14,adapt:[14,10],got:8,mccarthi:23,streamhandl:8,situat:[2,23,24],free:[1,8,23],standard:[8,23,24],jennif:5,md5:24,filter:8,ruleml:24,iso:22,isn:[3,10,23,24],my_data:[5,2,16],rang:[2,24],nigel:5,rdfapars:5,render:24,thereof:[3,18],restrict:[2,10,16],alreadi:[5,2,23,24],datasetbas:[5,2],graphpattern:[8,10],predicate_object:2,primari:24,top:[3,24,2,10,18],timothi:5,rdflib:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,18,19,20,21,22,23],tt0105236:8,too:[8,23],similarli:16,john:[1,8,22,23],"_strtotim":16,namespac:[14,5,1,8,9,2,20,3,10,22,18,24],tool:[8,10],xml_name:22,lower:16,binzac:5,datatypeproperti:2,somewhat:23,corrupted_stor:24,technic:8,provid:[5,9,2,16,23,10,11,24],tree:[5,8,22],rate:8,max_depth:8,regexliter:24,concensu:23,ran:23,boston:1,mind:22,kyle:[23,19],raw:8,manner:24,increment:8,"__main__":8,seem:[5,24,23,15],mint:23,"__new__":10,latter:24,subjectn:14,client:12,transmit:10,though:23,usernam:5,object:[14,12,5,15,8,2,16,20,23,3,10,18,11,24],regular:[24,19],bsd:5,"04t04":8,don:[22,23],doc:[5,8,10],dog:8,doe:[8,2,16,10,22,23,24],triplestor:[1,10,17],subject1:14,index_graph:10,declar:[22,23],tech:8,wildcard:16,section:[20,24,6,12],dot:1,unsignedlong:16,link_to:10,"__str__":2,random:[2,11],syntax:[14,5,1,8,17,2,16,3,10,15,22,18,23,24],unsignedshort:16,quad:[3,2,18,24],identifi:[5,17,14,0,1,8,7,2,19,3,23,15,4,22,18,11,24],absolut:[5,2,10,16,24],acquir:2,terror_old:8,configur:[8,2,24],new_review:8,klein:5,new_movi:8,chimezi:[23,24],baz:2,method:[14,5,15,8,2,16,3,10,18,23,24],bag:10,n3parser:5,xsdtopython:16,nuutti:23,new_context:1,context_id:18,bname:5,datatyp:[5,16,20,10,22,24],full:[5,8],result:[5,8,2,16,10,22,18,23],parse_debug:[5,2],respons:24,corrupt:5,best:14,subject:[5,14,8,0,2,16,3,10,18,24],awar:[15,2,24],said:24,cjohn:8,databas:[14,12,2,3,18,11,24],wikipedia:8,finger:[14,8],simplest:[5,12],irc:23,approach:[8,23],attribut:[8,22,2,16,9],accord:[8,22],triplet:[8,2],extend:[24,7,0],contort:23,extens:[24,23,19],here:[5,10,23],accident:12,howev:[15,24],against:[5,2,23,24],resultselem:22,logic:[5,2,16,24],com:[5,1,8,2,22,23],ontolog:[24,2,9],r_who:8,diff:22,assum:[15,23,24],summar:24,nake:23,union:2,three:10,been:[8,2,10],trigger:[10,23],interest:8,basic:[14,10,16,24],"__doc__":8,"__len__":[23,24],life:23,rdfnote:23,subject_pred:2,ani:[1,2,15,22,23,24],ident:[12,23],gnu:1,properti:[8,2,24],air:23,weren:24,tabl:14,need:[14,12,15,8,23,24],storeuri:8,sever:23,livejourn:5,default_context:[3,2,18],incorrectli:23,receiv:[1,10,23],suggest:[23,24],make:[14,15,8,10,23,24],transpar:24,descend:8,complet:[14,10,24],nil:[2,10],hang:24,hand:22,rais:[8,2,12,24],functionalproperti:2,redefin:14,scenario:23,hypothet:24,inherit:[7,23,0],contact:10,thi:[5,6,14,0,1,8,24,2,16,20,23,3,10,21,15,4,22,13,18,11,12],programm:14,setformatt:8,left:2,protocol:[16,24],just:[5,15,2,16,23,24],human:8,yet:[5,24,23,14],languag:[5,14,15,16,10,22,23,24],previous:5,easi:[5,23],cyganiak:23,defrag:2,had:8,hay:23,els:[5,1,8,2,10,15,22],save:8,uniongraph:[3,18],applic:[5,23,2,16,11],johnsmith:1,unindex:10,specif:[14,3,18,23,24],arbitrari:[14,24,15],manual:8,instanci:23,underli:[5,24],www:[5,6,1,8,24,2,16,20,3,10,4,22,18,23,12],old:[1,8],deal:24,somehow:23,initialbind:8,toctre:14,personnam:8,positiveinteg:16,conjunctivegraph:[5,0,8,2,3,10,17,22,18,23,24],rdfx:23,subclass:[3,18,24],existenti:[15,23,24],track:23,rdfg:[3,22,2,18],rdfn:[22,3,18],foo:[20,8,2,24],type_integ:10,localhost:[5,8],givennam:8,core:[10,23,24],plu:14,discount:23,peer:8,post:23,"super":22,meyer:12,slightli:24,literatur:24,"_strtodatetim":16,commit:[5,2,24],attrib:22,produc:[5,24],"float":16,encod:[8,22,2],bound:[8,2],down:23,parsererror:22,jena:[1,23],amsterdam:8,samea:2,bool:16,storag:[3,22,2,18],accordingli:23,wai:[5,14,15,8,16,10,23,24],support:[5,12,14,15,8,0,2,16,19,23,10,11,24],transform:[15,8],why:23,avail:[8,22,10],reli:[14,22,15],jane:5,librdf:23,"__isub__":16,head:22,form:8,offer:23,forc:10,"true":[5,1,2,16,20,10,24],autoclass:5,tell:8,sparqldesc:8,fundament:24,unrel:24,setlevel:8,featur:[2,10],"abstract":[1,11],proven:2,exist:[5,15,8,2,23,24],trix:[5,22,2],ship:2,trip:[15,22,24],when:[10,23,24],elementtre:22,actor:8,dadofmom:8,test:[5,8,22,24,14],tia:23,node:[14,12,13,7,15,8,0,2,17,23,24],stringio:[22,3,18],glapizco:8,consid:[15,2,16,3,23,24],sql:5,pelleti:10,anywher:[15,8],seaborn:23,default_graph_uri:5,time:[5,8,23,16,24],backward:8,inc:1,concept:[20,24,6,12],hcbubhjy0:5,skip:[1,8],row:[5,22],decid:23,depend:[23,24],graph:[5,17,6,14,0,1,8,7,2,16,19,20,23,3,10,15,22,13,18,11,24],decim:16,wasab:8,terror:8,isinst:[1,8,22],sourc:[5,1,8,2,16,18,23,24],string:[5,2,10,16,24],seemingli:23,seealso:2,level:[3,24,2,10,18],iter:[14,15,8,2,16,3,18,24],item:[14,0,2,3,10,18,24],unsupport:8,quick:15,round:[15,22,24],sparql_xml_namespac:22,mysink:5,cost:15,port:[5,2],explictli:23,danbri:5,appear:[15,24],drewp:5,current:[5,11,2,10,23,24],addn:[22,2,18],resultelem:22,slot:24,deriv:20,gener:[1,2,16,10,23,24],stmt:[5,3,18],configstr:5,bnode:[12,7,1,8,17,2,3,10,15,22,18,23,24],address:[12,23,24],along:[1,22,10,24],somegraph:16,t3433325:22,textindex:[10,17],netgraph:[3,18],behav:[14,23,16,24],gmari:8,type_long:10,bob:[5,8,23],commonli:23,semant:[8,24,23,19],love:8,extra:15,modul:[14,6,13,7,8,0,2,19,20,3,10,21,17,4,18,12],n3programm:[15,24],unknownorigin:23,regex:24,andi:23,provd:10,memori:[14,2,11],sake:24,pred:[3,18],univers:[14,24,23,15],visit:2,stylesheet:22,handler:[22,10],criteria:2,scope:[14,24,23,15],checkout:8,tightli:23,peopl:[5,8,23],finit:10,fold_sha1:8,use_pypars:[5,2],subel:22,uniqu:[15,3,10,23,12],can:[14,5,1,8,9,2,16,23,3,10,15,18,11,24],purpos:[1,23,24],problemat:24,markupwrit:22,predict:14,cwru:22,levelnam:8,crazi:22,occur:[15,2,10],alwai:[10,23,24],multipl:23,distinctli:15,write:[5,1,8,2,16,10,22],mindswap:8,anyon:22,fourth:[3,18,23],parameter:[3,18],purl:8,map:[5,2,16],type_datetim:10,membership:[14,15],"4th":24,date:[20,8,16,24],data:[5,14,15,8,2,16,10,18,23],grow:8,abdn:8,practic:23,explicit:[14,24,23,15,0],predic:[5,14,8,0,2,16,3,10,22,18,24],inform:[14,8,10,23,24],"switch":10,combin:8,anoth:[8,10,24],skolem:[14,15],talk:8,epydoc:10,endel:22,still:[8,2,23],mainli:10,bigasterisk:5,entiti:15,conjunct:[14,8,2,3,10,17,18,11,24],subgraphof:2,group:[8,24],thank:10,main:[8,24],non:[8,12,24],nabbl:22,initn:[3,8,2,18,5],initi:[5,8,2],now:[5,8,10,23],discuss:23,introduct:[5,10,14],term:[5,17,6,14,0,1,7,2,16,20,3,10,21,15,4,24,13,18,12],name:[5,14,15,8,0,2,16,3,10,22,18,23,24],readfil:8,plainliter:22,didn:23,separ:[8,10,23,24],wong:1,updat:[14,8,2,10,11],compil:8,domain:[8,2],replac:[1,8,15],individu:[23,24],continu:[1,8,2,14],contributor:14,redistribut:1,year:8,happen:[22,24],space:[2,23],internet:1,formula:[14,15,2,19,23,24],correct:[22,23],integr:[23,24],earlier:[10,23],jlc6:22,argv:8,migran:[15,24],theori:23,transitive_subject:[8,2],org:[5,6,1,8,24,2,16,20,3,10,4,22,18,23,12],"byte":16,card:5,care:[22,23],thing:23,selectionf:22,place:[1,16,15],imposs:23,frequent:10,first:[15,8,2,16,23,10,22,11,24],origin:[10,23],directli:[3,10,23,18],oppos:8,open:[14,5,2,3,23,18,11,24],size:24,given:[1,2,16,3,15,18,23,24],convent:15,assort:[14,8],necessarili:24,draft:22,averag:10,conveni:[2,10],friend:8,onproperti:2,hun:10,copi:[1,22],get_movi:8,specifi:[5,2,16,22,18,23,24],res_it:22,enclos:15,mostli:23,redland:[2,23,11],than:[2,10],serv:[12,24],oneint:20,were:[10,23],pre:[6,13,2,19,20,21,4,18,12],sai:[5,8,23,24],sparqlgrph:8,argument:[5,9,8,2,16,23,3,10,18,11,24],sax:22,engin:[5,2],destroi:[2,11,24],note:[15,8,22,10,24],rozet:8,take:[22,2,23,9],noth:[1,23,15],sure:[23,24],normal:[8,24],buffer:5,formulab:24,formulaa:24,net:[5,9,8,2,3,10,18,23],pair:[1,8,2],homepag:8,synonym:5,later:[1,8,23],show:[1,8,5],permiss:24,hack:5,rountrip:24,xml:[5,14,8,2,16,10,22,18],onli:[5,9,15,8,0,2,10,22,23,24],explicitli:23,transact:[2,11,24],activ:2,state:22,dict:5,startswith:[1,8],variou:[5,16,14],get:[14,5,8,2,3,23,18,11],mung:10,cannot:[1,2,23],requir:[15,8,2,23,24],anyuri:[2,16],yield:[22,2,10,24],hasreview:8,cmari:8,bison:[5,8,2],where:[5,15,8,2,16,3,18,23,24],whoami:8,wiki:8,sean:5,xml_namespac:22,wonder:23,detect:8,review:8,enumer:8,label:[5,8,2,16,3,22,18,23],between:[15,8,23,24],"import":[5,9,1,8,2,16,20,23,3,10,17,22,18,11],across:[23,24],assumpt:[3,24],parent:8,uriref:[5,6,7,1,8,2,20,3,10,17,22,18,23,24],parentag:8,pythonlib:8,come:[8,23],tue:22,rdfstore:5,ninebynin:23,tutori:1,basestr:16,mani:[5,23,16],overview:10,pop:23,"_strtodat":16,coupl:23,mari:8,valueerror:[1,8],"__eq__":16,those:[15,8,2,10,23,24],"case":[5,14,2,16,10,18,23,24],serializexml:22,res_var:22,invok:[10,23],base64:16,mikael:22,advantag:8,henc:[2,23,0],destin:[1,2],"__init__":[8,22,10],dumbil:5,develop:14,inamidst:5,author:[5,8,10],same:[5,15,8,2,3,10,18,23,24],check:2,html:[5,8,22,10,23],document:[5,14,8,2,16,10,18,24],foaf:[5,8,14],closest:23,someon:5,director:8,capabl:24,fruit:24,enddocu:22,appropri:[20,14,23,24],macro:2,without:[1,8,24,23,15],model:[14,7,1,0,15,23,24],execut:[5,2],rest:[2,10],aspect:24,maxrat:8,strorqueri:[5,2],except:[1,8,22,24],littl:22,desktop:8,blog:[8,23],ogbuji:23,kotivuori:23,exercis:[14,8,22],real:24,around:[22,0],read:[5,14,8,0,19,10,23],simpleel:22,swig:23,grid:22,dispatch:23,mom:8,world:[5,3,23,24],type_tim:10,storefn:8,integ:[22,10,16],benefit:[23,24],either:[1,24,2,23,5],output:[5,8,22],manag:[14,9,8,16,11,24],yyyi:8,mytriplestor:10,base64binari:16,bisonsparql:8,definit:[6,13,7,8,2,20,3,21,17,4,18,23,24],achiev:16,freek:8,smush:[14,8],corespond:10,complic:24,refer:[15,24,6,23,12],power:14,garbag:11,gjohn:8,found:[8,2,24],"__name__":[8,3,18],src:[3,18],krech:14,chop:10,act:5,processor:[5,2],routin:15,minrat:8,effici:10,terminolog:[4,24,14],isoformat:16,queryabl:23,strip:1,your:[14,5,1,8,10,23],log:[14,1,8,2,15,24],aren:[23,24],brute:10,start:[5,8,2,14],interfac:[14,24,10,23,15],low:24,lot:2,unam:23,svn:9,typedliter:22,tupl:[5,8,2,24],regard:[4,24],notat:[14,15,16,11,23,24],tripl:[14,5,15,8,2,16,23,3,10,22,18,11,24],possibl:[10,23],"default":[5,0,1,2,16,3,10,18,23,24],trixseri:[14,22],expect:[15,23,24],"2006julsep":23,creat:[14,12,5,8,2,23,3,10,18,11,24],certain:[14,10,23,12],adsf:20,file:[14,5,1,8,2,16,22,18],type_str:10,film:[14,8],fill:5,again:23,idiom:14,copyright:1,you:[14,5,1,8,10,15,23,24],poor:5,discours:[14,23],formula_identifi:15,sequenc:[18,2,10,0],reduc:15,ewan:5,directori:5,descript:[5,1,8,2,16,10,24],tricki:23,potenti:24,qediviua11:22,term_str:10,lack:23,publish:[1,8],follow:[15,8,16,3,10,24],alt:10,disk:5,strptime:8,equivalentproperti:5,program:[1,23,5],introduc:[14,10,24],liter:[1,2,3,4,5,6,7,8,10,12,13,14,15,16,17,18,19,20,21,22,23,24],fals:[5,1,2,20,22,18,24],util:[14,9,0,2,16,24],demerg:2,quantifi:24,veri:[10,23,24],fale:8,list:[7,1,8,0,2,3,10,22,18,23,24],emul:[14,10],anam:5,swdev:5,enterpris:24,biolog:8,design:24,"__iadd__":16,pass:[5,22,2,23],further:23,what:23,sub:[2,18,24],richard:23,sum:[3,18],abl:[23,24],brief:8,version:[1,8,22,10],intersect:[22,10],"public":[1,8,23,24],hasn:14,rdflibutil:10,themselv:[5,10],berkelei:[11,24],cvsweb:8,trunk:9,dtype_uri:15,modifi:1,valu:[5,1,2,10,15,23,24],search:[14,2,10,16,24],subscribe_to:10,amount:15,action:10,via:[15,3,18],transit:[14,8,2],vin:[14,23],filenam:[8,10],href:22,famili:1,select:[5,8,3,10,22,18,23],distinct:[15,22,3,23,24],etc:[5,24,10,0],regist:22,two:[14,5,1,8,2,16,10,23,24],taken:[22,23],minor:10,more:[1,8,2,10,15,23],flat:23,wrapper:[8,0],negativeinteg:16,astrogrid:22,flag:[5,2],particular:[1,8,9],known:[15,8,23,24],none:[5,15,8,2,16,3,10,22,18,23,24],outlin:[23,24],dev:[8,22,23],histori:[10,17],orderbi:22,def:[15,8,22,2],trixhandl:22,share:[12,23],accept:2,rather:23,csd:8,wordnet:2,simpl:[14,8,22],resourc:[0,1,8,2,22,24],referenc:24,type_d:10,variant:23,okai:23,pat:23,associ:[3,24,2,23,15],"short":16,customsparql:8,caus:24,initbind:[3,2,18,5],morten:8,help:[5,8,23],reservoir:8,perttula:5,singleton:23,through:[2,10,23],topython:[20,16],paramet:[5,2,23,16,24],wrt:23,pend:24,might:[5,8,2,23],wouldn:[8,23],good:[8,23,19],"return":[5,14,15,8,0,2,16,20,3,10,22,18,23,24],framework:[11,24],connolli:5,eventu:[5,2],reverselist:2,easili:23,token:16,ifa:8,ifb:8,fulli:[5,9],unicod:[22,7,16,0],hard:23,realli:[5,1,8,2,16,23],connect:[2,24],beyond:24,todo:10,event:10,agre:23,stringinputsourc:[22,10,17],ggrimn:8,type_float:10,print:[5,1,8,2,3,10,22,18],urlinputsourc:[10,17],file_nam:[5,2,16],qualifi:9,postgr:24,gf0:8,gf1:8,guess:23,reason:[15,10,23],base:[5,0,8,9,2,16,10,22,11,24],retrieverdffil:10,put:8,atilla:10,basi:23,"_writetripl":22,thread:23,omit:23,perhap:[15,24],assign:[3,2,10,23,15],major:10,feel:8,nonnegativeinteg:16,number:[14,23,24],construct:[24,12,23,9],blank:[14,12,7,15,17,23,24],stabl:8,remove_context:[1,18,24],miss:23,gpl:5,differ:[6,13,0,1,8,2,20,23,10,21,4,24,11,12],script:[8,22],interact:5,least:[5,14,2,16,23,24],parsetyp:1,statement:[5,15,19,3,10,17,18,23,24],l2h:10,master:14,b983bb397fb71849da910996741752ace8369b:8,store:[5,17,14,1,8,0,2,16,19,23,3,10,15,22,18,11,24],schema:[5,8,2,16,3,10,18,24],adher:24,xmln:[5,1,8,2,16,22],option:[1,8,23],relationship:[2,24],part:[22,24],pars:[14,5,8,2,16,3,10,22,18,24],startdocu:22,kind:[5,15,2,16,3,18,23,24],celementtre:22,remot:5,remov:[1,8,2,16,3,10,22,18,11,24],str:[22,3,10,18],result_list:22,formulabcontext:24,bertand:12,packag:[2,10],"_writegraph":22,lie:24,built:[14,16],equival:[3,23,16],self:[5,8,22,2,16],also:[5,14,15,16,10,23,24],redfoot_curr:1,distribut:1,copia:23,choos:[10,23],most:[15,16,3,10,23,24],automodul:5,mortenf:8,cover:24,universiteit:8,clean:22,think:23,reific:24,session:23,fine:8,find:[5,8],pretti:[8,22],writer:[8,22],solut:23,express:[23,24],"__copyright__":8,common:[5,7,0,16,10,23,24],wrote:23,set:[5,14,15,8,0,2,16,3,10,22,18,23,24],seq:[2,10,0],sep:23,see:[5,1,8,2,10,4,18,24],signifi:3,arg:[5,1,2,16,22,18],reserv:23,someth:[8,10],grandmoth:8,counterterror:8,ntripl:[5,8,16],syntact:[15,23],numer:[10,24],len:[5,8,2,16,3,10,22,18,24],toplist:2,solv:23,no_stor:[5,24],popul:24,both:[14,16],last:23,commit_pending_transact:[2,24],context:[14,1,8,2,16,10,15,22,18,23,24],whole:10,load:[1,8],sparqlgraph:[8,10],markdown:8,simpli:[10,23,24],point:23,etre:22,rdfgraphsyntax:23,header:22,throughout:23,coincid:23,backend:14,identif:[4,23],uniquenesserror:2,due:[22,24],empti:5,versa:[5,2],fire:10,coordin:23,gibbin:5,func:2,dadofdad:8,gac:22,look:10,triples_choic:18,simplelookup:8,straight:15,formatt:8,"while":[8,10,23],abov:[10,23],error:[22,24],anonym:15,mbox:8,loop:1,itself:[15,3,24],addhandl:8,belong:2,zope:11,higher:[8,24],optim:[15,24],rdfxmlparser:5,user:[5,2,10,23],typic:10,basicgraphpattern:10,travers:[14,8],sha1:24,eleg:23,type_decim:10,fuxi:9,elem:22,person:[5,8],expens:10,academ:19,queryresult:[10,17],mbox_sha1sum:8,mysql:[5,2,3,11,18,23,24],whileloop:1,ihmc:23,theoret:23,input:[5,23],pythontoxsd:16,bin:8,march:10,format:[5,8,2,16,3,10,22,18],bit:[15,22,10],formal:[8,24,23,19],abstractsqlstor:24,extensionfunct:[5,2],semi:8,docutil:[6,13,2,19,20,21,4,18,12],collect:[2,3,10,17,11,24],"boolean":[5,2,16],donna:8,ivan:10,admittedli:23,often:24,ntparser:5,some:[5,8,2,16,10,23,24],understood:24,instal:[5,8,22],transitive_object:[8,2],larg:[5,10],proj:5,run:5,palmer:5,subtract:16,zip:22,preclud:24,rulebas:9,matern:8,primarili:24,within:[15,2,3,18,23,24],statment:10,ensur:[15,22,24],inclus:10,span:[6,13,2,19,20,21,4,18,12],question:[14,23],"long":[16,24],includ:[11,15,10,22,23,24],suit:1,forward:[15,8],properli:[15,24],subgraph:[22,2,24],link:[8,10],line:[1,5],info:[1,9],utf:[8,22],consist:[5,2,23,24],cid:8,nothing_merg:1,readlin:5,similar:[8,23,24],"04z":8,startel:22,metacognit:9,parser:[5,14,15,8,2,10,22,23,24],doesn:[5,8,23,24],repres:[5,14,15,19,10,23,24],varelem:22,home:8,unionof:2,graham:[23,19],quotedgraph:[7,0,19,3,17,23,24],titl:[8,10],nick:8,nice:23,regexmatch:2,elsewher:15,meaning:[8,23],lang:[15,8,22],allvaluesfrom:2,confirm:23,depth:2,came:10,hello:5,code:[5,8,10,22,23,24],edd:5,queri:[14,5,15,8,2,3,10,17,18,23,24],daterang:24,edt:22,edu:22,simon:8,xsd_n:16,ntserial:22,"h\u00f6gqvist":22,sens:15,strictvers:8,rollback:2,nichola:5,uniquegraphnam:[3,18],implicitli:15,relev:[3,24],tri:24,magic:23,unsignedbyt:16,inclin:19,"try":[1,8,22,5],pleas:[5,23],impli:[1,24,15],sparqlerror:10,natur:0,object1:14,download:8,append:[1,8,10],mktemp:[5,2,16],index:[14,22,10],bricklei:5,compar:[23,16,24],iomemori:[8,2,3,10,22,18,24],access:[8,23,11,9],experiment:[5,2],type_doubl:10,whatev:23,lee:5,leg:23,gmpg:8,objectn:14,closur:2,let:[8,10],sink:5,rdflibdemo:8,becom:23,sinc:[1,8,10,15,23,24],convert:16,survei:23,convers:[15,16],broken:[22,16],larger:[10,24],rdf:[0,1,2,3,4,5,6,7,8,10,11,12,14,15,16,17,18,19,20,22,23,24],chang:[5,8,10,23],"_xsd_n":20,clark:22,appli:[15,23,24],parsestr:5,foundat:1,api:[23,10,11],immut:12,from:[5,7,1,8,0,2,16,19,20,23,3,10,9,15,22,18,11,24],stream:[22,10],usa:1,doubl:16,next:8,implic:23,few:[5,8,23],zib:22,usr:8,sort:[14,10],expandus:8,sleepcat:2,account:24,retriev:[10,24],raw_input:8,alic:[8,23],trix_n:22,obvious:23,meet:8,rdf_store:2,sqlite:[3,18,11],quickstart:14,namespace_manag:[1,2],process:[8,24],tag:[15,24],serial:[14,5,1,8,2,16,15,22,24],atoni:8,publicid:[5,2,18,16],instead:[24,3,10,18],processinginstruct:22,overridden:16,lit2006:20,redund:24,is_ncnam:22,movieid:8,bind:[5,8,2,3,22,18,24],correspond:[24,0],element:[8,22],issu:[14,23,24],allow:[10,23],subject_object:[8,2],elif:[1,8,22],listnam:10,movi:8,utcnow:20,"65b983bb397fb71849da910996741752ace8369b":8,regexterm:24,infrastructur:5,dad:8,handl:[8,10,23],dan:5,nokia:5,nonpositiveinteg:16,mention:23,facilit:[15,24],bar:2,"_hdlr":8,somewher:1,anyth:23,truth:24,disregard:23,subset:[24,23,0],intellig:24,chunk:23,"static":[22,10],our:10,patch:22,chimenzi:23,special:[23,24],out:[5,8,22,23],variabl:[5,17,7,14,0,2,3,10,21,15,22,18,23,24],electronic_databas:2,rev:8,stub:24,rel:[5,2,16],get_context:[8,18],ref:10,clarifi:23,insid:23,manipul:[23,24],templ:1,zodb:[3,2,18],dictionari:[5,16,9],releas:[2,10],indent:22,could:[1,24,23,15],david:5,length:[5,11,24],outsid:[23,24],softwar:[1,22,10,12],redfoot:[1,8],"0x15ab130":[5,2],someiri:23,mai:[5,14,2,16,10,23,24],owner:23,facil:23,test_trixseri:22,unknown:23,licens:[1,22,10,5],creator:10,system:[15,24],messag:[5,8],attach:22,man:5,"final":[5,22,10,24],"_logger":[1,8],unsignedint:16,terroront:8,aggregategraph:23,essenti:[24,16,0],exactli:[2,23],bindingelem:22,structur:[10,23],charact:16,auditablestorag:2,lover:8,bare:[15,24],momofmom:8,peernam:8,clearli:24,unvisit:2,fail:24,imdb:8,have:[14,5,1,8,2,3,10,15,22,18,23,24],close:[5,1,2,16,3,23,11,24],disjoint:19,member_nam:5,turn:[22,2],terrororginst:8,sanest:23,probabl:[24,10,23,19],rout:23,unawar:2,graph1:23,which:[5,12,7,15,8,0,2,16,3,10,9,22,18,23,24],mit:5,singl:[5,23,0],who:[14,8],oracl:24,herman:10,url:[5,2,16],urn:24,nsmap:[3,18],uri:[5,6,9,15,8,2,16,10,22,18,23,24],michel:10,determin:[5,2,16,15],fact:24,text:[8,22,10,24],momofdad:8,fear:23,varnam:15,locat:[5,2,18,16,24],obj_:16,should:[1,24,22,23,14],suppos:[8,10],sylvia:1,local:23,hope:1,meant:23,contribut:8,"_get_contain":10,cstringio:22,stuff:8,she:8,partit:[23,24],contain:[5,14,15,0,2,16,3,10,18,23,24],view:[8,23],conform:14,knowledg:24,trixn:22,pattern:[15,2,16,3,10,18,11,24],boundari:[3,24],below:[24,7,23,0],tend:23,written:[8,22,24],email:[1,8,22],tempfil:[5,2,16],entir:[24,18,23,0],golbeck:5,problem:[24,10,23,12],addit:[14,11,19,10,22,23,24],plugin:[5,3,10,22,18,11],april:[8,10],instanc:[5,7,15,0,2,16,3,23,9,18,11,24],atleast:23,subclassof:2,comment:[5,8,2,16,3,18],walk:8,distinguish:[15,24],quit:[1,23],insuffici:24,compon:[22,24],json:10,besid:10,treat:[23,16,0],xtocid:23,listitem2:10,listitem1:10,assert:[5,15,8,16,3,10,18,23,24],hmm:23,togeth:[1,8],vanilla:23,contextu:24,defin:[6,13,0,2,16,20,3,10,21,4,24,12],almost:12,demo:[5,8],"__reduce__":10,archiv:[8,23],motiv:24,decodestr:16,incom:8,revis:[14,22],member:5,python:[5,7,14,8,0,16,20,10,22],"__version__":8,infer:15,difficult:23,swrl:24,oneof:2,http:[5,6,9,1,8,24,2,16,20,3,10,4,22,18,23,12],effect:15,effeci:23,persistedbi:24,distutil:8,expand:[5,15],off:8,phay:23,well:[22,23,24],valid_stor:[5,24],thought:[14,3,18,23,24],weblog:8,exampl:[14,5,1,8,2,16,10,23,24],command:5,english:10,inputsourc:[5,2,16],less:[2,10,23],obtain:12,web:24,wed:[14,23],smith:1,instanti:[3,18,23,24],add:[14,5,1,8,2,16,3,10,22,18,23,24],lookup:8,logger:8,objectproperti:2,match:[14,15,8,2,16,23,11,24],datarang:2,five:[8,10],know:[5,2,23,24],desk:8,password:5,graphinst:23,journalread:10,resid:[12,24],like:[14,5,1,8,2,16,10,23],corpor:24,unord:24,necessari:[2,24],xsd:[8,2],lose:8,gm1:8,gm0:8,page:[14,24],xsl:22,reifi:[3,18],usingcontextswithrdf:23,superclass:10,guarante:15,librari:[5,14],feder:24,avoid:1,overlap:23,importerror:[8,22],journal:[10,17],usag:[5,8,23],host:5,although:[8,24],ntriplespars:5,about:[1,8,24,23,5],pypars:[5,2],actual:[8,23,24],constructor:[2,23,11],sleepycat:[3,18],owl:[5,8,2,24],own:[18,23],automat:[15,3],dataset:23,warranti:1,merg:[14,1,8,2,10,23],w3c:[5,10],shadbolt:5,van:8,val:22,much:[15,10],"var":22,"function":[5,12,7,15,8,2,16,10,17,11,24],unexpect:1,subscrib:10,bug:22,made:[5,24],whether:[5,2,24],displai:[5,8],netconjunctivegraph:[3,18],limit:24,otherwis:[2,24],higherorderstat:24,evalu:[5,2],"int":[8,16],pic:5,implement:[12,0,15,16,23,10,1,22,11,24],workabl:23,inf:1,eric:5,squirrel:5,mutual:24,guidanc:24,detail:1,other:[5,14,15,8,16,3,10,17,18,23,24],system_id:10,rememb:2,varieti:10,"class":[0,2,3,4,5,6,7,8,10,11,12,13,9,15,16,17,18,19,20,21,22,23,24],sphinx:14,movie_is_in:8,klass:24,getlogg:[1,8]},titles:["RDF Graph Terms","Merging graphs","<tt class=\"docutils literal docutils literal\"><span class=\"pre\">rdflib.Graph.Graph</span></tt> – Graph class definition","Graphs","<tt class=\"docutils literal docutils literal\"><span class=\"pre\">rdflib.term.Identifier</span></tt> – Identifier class definition","Getting started with rdflib","<tt class=\"docutils literal docutils literal docutils literal\"><span class=\"pre\">rdflib.term.URIRef</span></tt> – URIRef class definition","Nodes","Assorted examples","Namespace Utilities","Other modules","Persistence","<tt class=\"docutils literal\"><span class=\"pre\">rdflib.term.BNode</span></tt> – RDF blank node functions","<tt class=\"docutils literal docutils literal docutils literal\"><span class=\"pre\">rdflib.term.Node</span></tt> – Node class definition","rdflib 2.5","Persisting Notation 3 Terms","Graph utilities","Modules","<tt class=\"docutils literal\"><span class=\"pre\">rdflib.Graph.ConjunctiveGraph</span></tt> – ConjunctiveGraph class definition","<tt class=\"docutils literal docutils literal docutils literal\"><span class=\"pre\">rdflib.graph.QuotedGraph</span></tt> – Quoted graphs","<tt class=\"docutils literal\"><span class=\"pre\">rdflib.term.Literal</span></tt> – Literal class definition","<tt class=\"docutils literal docutils literal\"><span class=\"pre\">rdflib.term.Variable</span></tt> – Variable class definition","Additions","Graphs, Named Graphs and Blank Nodes","A Universal RDF Store Interface"],modules:{"rdflib.syntax.parsers.TriXParser":5,"rdflib.term":10,"rdflib.syntax.parsers.RDFXMLParser":5,"rdflib.syntax":10,"rdflib.syntax.parsers.N3Parser":5,"rdflib.syntax.parsers.ntriples":5,"rdflib.journal":10,"rdflib.namespace":9,"rdflib.query.result":10,"rdflib.syntax.parsers.NTParser":5,"rdflib.store":10,"rdflib.syntax.parsers":5,"rdflib.syntax.parsers.n3p":5,"rdflib.query":10,"rdflib.sparql":10,"rdflib.collection":10,"rdflib.parser":10,"rdflib.textindex":10,"rdflib.graph":3},descrefs:{"rdflib.term":{Node:[13,1],BNode:[12,1],URIRef:[6,1],Literal:[20,1],Statement:[10,1],Variable:[21,1],Identifier:[4,1]},"rdflib.syntax.parsers.TriXParser":{TriXParser:[5,1]},"rdflib.syntax.parsers.ntriples":{NTriplesParser:[5,1]},"rdflib.syntax.parsers.RDFXMLParser":{RDFXMLParser:[5,1]},"rdflib.syntax.parsers.N3Parser":{N3Parser:[5,1]},"rdflib.textindex.TextIndex":{search:[10,0],link_to:[10,0],terms:[10,0],term_strings:[10,0],subscribe_to:[10,0],index_graph:[10,0]},"rdflib.journal":{JournalReader:[10,1],JournalWriter:[10,1]},"rdflib.syntax.parsers.ntriples.NTriplesParser":{parse:[5,0],readline:[5,0],parsestring:[5,0]},"rdflib.namespace":{Namespace:[9,1]},"rdflib.graph.Graph":{comment:[2,0],predicate_objects:[2,0],namespaces:[2,0],seq:[2,0],serialize:[2,0],subject_predicates:[2,0],parse:[2,0],set:[2,0],remove:[2,0],query:[2,0],close:[2,0],triples:[2,0],open:[2,0],transitive_subjects:[2,0],label:[2,0],add:[2,0],subjects:[2,0],addN:[2,0],destroy:[2,0],transitive_objects:[2,0],rollback:[2,0],objects:[2,0],connected:[2,0],value:[2,0],subject_objects:[2,0],predicates:[2,0],items:[2,0],absolutize:[2,0],transitiveClosure:[2,0],bind:[2,0],commit:[2,0],n3:[2,0]},"rdflib.term.Literal":{toPython:[20,0]},"rdflib.syntax.parsers.NTParser":{NTParser:[5,1]},"rdflib.query.result":{QueryResult:[10,1]},"rdflib.graph.ConjunctiveGraph":{quads:[24,0],triples:[18,0],contexts:[24,0],context_id:[18,0],triples_choices:[18,0],remove:[18,0],parse:[18,0],add:[18,0],addN:[18,0],remove_context:[24,0],get_context:[18,0]},"rdflib.textindex":{TextIndex:[10,1]},"rdflib.graph":{ConjunctiveGraph:[18,1],ReadOnlyGraphAggregate:[0,1],Graph:[2,1],Seq:[0,1],QuotedGraph:[19,1]},"rdflib.collection":{Collection:[10,1]},"rdflib.parser":{URLInputSource:[10,1],StringInputSource:[10,1]},"rdflib.store.Store":{triples:[24,0],bind:[24,0],namespace:[24,0],add:[24,0],remove:[24,0],prefix:[24,0],namespaces:[24,0],destroy:[24,0],close:[24,0],open:[24,0],"__len__":[24,0]},"rdflib.collection.Collection":{index:[10,0],n3:[10,0],append:[10,0]},"rdflib.term.Statement":{"__reduce__":[10,0],"__new__":[10,2]}},filenames:["graphterms","graph_merging","modules/graphs/graph","modules/graphs/index","modules/nodes/identifier","gettingstarted","modules/nodes/uriref","modules/nodes/index","assorted_examples","namespace_utilities","modules/others","persistence","modules/nodes/bnode","modules/nodes/node","index","persisting_n3_terms","graph_utilities","modules/index","modules/graphs/conjunctive_graph","modules/nodes/quoted_graph","modules/nodes/literal","modules/nodes/variable","addons","graphs_bnodes","univrdfstore"]})
\ No newline at end of file diff --git a/docs/_build/html/univrdfstore.html b/docs/_build/html/univrdfstore.html new file mode 100644 index 00000000..ffc2357a --- /dev/null +++ b/docs/_build/html/univrdfstore.html @@ -0,0 +1,502 @@ +<!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>A Universal RDF Store Interface — rdflib v2.5.0 documentation</title> + <link rel="stylesheet" href="_static/default.css" type="text/css" /> + <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> + <script type="text/javascript"> + var DOCUMENTATION_OPTIONS = { + URL_ROOT: '', + VERSION: '2.5.0', + COLLAPSE_MODINDEX: false, + FILE_SUFFIX: '.html', + HAS_SOURCE: true + }; + </script> + <script type="text/javascript" src="_static/jquery.js"></script> + <script type="text/javascript" src="_static/doctools.js"></script> + <link rel="index" title="Index" href="genindex.html" /> + <link rel="search" title="Search" href="search.html" /> + <link rel="top" title="rdflib v2.5.0 documentation" href="index.html" /> + <link rel="next" title="RDF Graph Terms" href="graphterms.html" /> + <link rel="prev" title="Getting started with rdflib" href="gettingstarted.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="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="graphterms.html" title="RDF Graph Terms" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="gettingstarted.html" title="Getting started with rdflib" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body"> + + <div class="section" id="a-universal-rdf-store-interface"> +<span id="univrdfstore"></span><h1>A Universal RDF Store Interface<a class="headerlink" href="#a-universal-rdf-store-interface" title="Permalink to this headline">¶</a></h1> +<p>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 <a class="reference external" href="http://www.w3.org/TR/rdf-concepts/#dfn-rdf-graph">RDF Graph</a> in a way that is universal and not tied to any specific implementation.</p> +<p>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 <a class="reference external" href="http://www.w3.org/2000/10/swap/Primer">Notation 3</a> that go beyond the RDF model to provide a framework for <a class="reference external" href="http://en.wikipedia.org/wiki/First-order_predicate_logic">First Order Predicate Logic</a> processing and persistence.</p> +<div class="section" id="terminology"> +<h2>Terminology<a class="headerlink" href="#terminology" title="Permalink to this headline">¶</a></h2> +<div class="topic"> +<p class="topic-title first"><strong>Context</strong></p> +<p>A named, unordered set of statements (that could also be called a sub-graph). The <em class="xref">named graph</em> <a class="reference external" href="http://www.w3.org/2004/03/trix/">literature</a> and <a class="reference external" href="http://metacognition.info/Triclops/?xslt=Triclops.xslt&query=type(list(rdfs:Class,owl:Class,rdf:Property))&queryType=Graph&remoteGraph=http://www.w3.org/2004/03/trix/rdfg-1/">ontology</a> are relevant to this concept. The term <em class="xref">context</em> could be thought of as either the sub-graph itself or the relationship between an RDF triple and a sub-graph in which it is found (this latter is how the term context is used in the <a class="reference external" href="http://www.w3.org/DesignIssues/Notation3.html">Notation 3 Design Issues page</a>).</p> +<p>It is worth noting that the concept of logically grouping <a class="reference external" href="http://www.w3.org/TR/rdf-concepts/#section-triples">triples</a> within an addressable ‘set’ or ‘subgraph’ is just barely beyond the scope of the RDF model. The RDF model defines a graph to be an arbitrary collection of triples and the semantics of these triples — but doesn’t give guidance on how to address such arbitrary collections in a consistent manner. Although a collection of triples can be thought of as a resource itself, the association between a triple and the collection (of which it is a part) is not covered. <a class="reference external" href="http://laurentszyster.be/blog/public-rdf/">Public RDF</a> is an example of an attempt to formally model this relationship - and includes one other unrelated extension: Articulated Text</p> +</div> +<div class="topic"> +<p class="topic-title first"><strong>Conjunctive Graph</strong></p> +<p>This refers to the ‘top-level’ Graph. It is the aggregation of all the contexts within it and is also the appropriate, absolute boundary for <a class="reference external" href="http://cs.wwc.edu/~aabyan/Logic/CWA.html">closed world assumptions</a> / models. This distinction is the low-hanging fruit of RDF along the path to the semantic web and most of its value is in (corporate/enterprise) real-world problems:</p> +<blockquote class="pull-quote"> +There are at least two situations where the closed world assumption is used. The first is where it is assumed that a knowledge base contains all relevant facts. This is common in corporate databases. That is, the information it contains is assumed to be complete</blockquote> +<p>From a store perspective, closed world assumptions also provide the benefit of better query response times, due to the explicit closed world boundaries. Closed world boundaries can be made transparent by federated queries that assume each <tt class="xref docutils literal"><span class="pre">ConjunctiveGraph</span></tt> is a section of a larger, unbounded universe. So a closed world assumption does not preclude you from an open world assumption.</p> +<p>For the sake of persistence, Conjunctive Graphs must be distinguished by identifiers (which may not necessarily be RDF <a class="reference external" href="http://www.w3.org/2002/07/rdf-identifer-terminology/">identifiers</a> or may be an RDF identifier normalized - SHA1/MD5 perhaps - for database naming purposes) that could be referenced to indicate conjunctive queries (queries made across the entire conjunctive graph) or appear as nodes in asserted statements. In this latter case, such statements could be interpreted as being made about the entire ‘known’ universe. For example:</p> +<div class="highlight-xml"><div class="highlight"><pre><span class="nt"><urn:uuid:conjunctive-graph-foo></span> rdf:type :ConjunctiveGraph +<span class="nt"><urn:uuid:conjunctive-graph-foo></span> rdf:type log:Truth +<span class="nt"><urn:uuid:conjunctive-graph-foo></span> :persistedBy :MySQL +</pre></div> +</div> +</div> +<div class="topic"> +<p class="topic-title first"><strong>Quoted Statement</strong></p> +<p>A statement that isn’t asserted but is referred to in some manner. Most often, this happens when we want to make a statement about another statement (or set of statements) without necessarily saying these quoted statements (are true). For example:</p> +<div class="highlight-text"><div class="highlight"><pre>Chimezie said "higher-order statements are complicated" +</pre></div> +</div> +<p>Which can be written (in N3) as:</p> +<div class="highlight-n3"><pre>:chimezie :said {:higherOrderStatements rdf:type :complicated}</pre> +</div> +</div> +<div class="topic"> +<p class="topic-title first"><strong>Formula</strong></p> +<p>A context whose statements are quoted or hypothetical.</p> +<p>Context quoting can be thought of as very similar to <a class="reference external" href="http://www.w3.org/TR/rdf-mt/#Reif">reification</a>. The main difference is that quoted statements are not asserted or considered as statements of truth about the universe and can be referenced as a group: a hypothetical RDF Graph</p> +</div> +<div class="topic"> +<p class="topic-title first"><strong>Universal Quantifiers / Variables</strong></p> +<p>(relevant references):</p> +<blockquote> +<ul class="simple"> +<li>OWL <a class="reference external" href="http://www.w3.org/Submission/SWRL/swrl.owl">Definition</a> of <a class="reference external" href="http://www.w3.org/Submission/SWRL/">SWRL</a>.</li> +<li>SWRL/RuleML <a class="reference external" href="http://www.w3.org/Submission/SWRL/#owls_Variable">Variable</a></li> +</ul> +</blockquote> +</div> +<div class="topic"> +<p class="topic-title first"><strong>Terms</strong></p> +<p>Terms are the kinds of objects that can appear in a quoted/asserted triple.</p> +<p>This includes those that are core to RDF:</p> +<blockquote> +<ul class="simple"> +<li>Blank Nodes</li> +<li>URI References</li> +<li>Literals (which consist of a literal value, datatype and language tag)</li> +</ul> +</blockquote> +<p>Those that extend the RDF model into N3:</p> +<blockquote> +<ul class="simple"> +<li>Formulae</li> +<li>Universal Quantifications (Variables)</li> +</ul> +</blockquote> +<p>And those that are primarily for matching against ‘Nodes’ in the underlying Graph:</p> +<blockquote> +<ul class="simple"> +<li>REGEX Expressions</li> +<li>Date Ranges</li> +<li>Numerical Ranges</li> +</ul> +</blockquote> +</div> +<div class="topic"> +<p class="topic-title first"><strong>Nodes</strong></p> +<p>Nodes are a subset of the Terms that the underlying store actually persists. The set of such Terms depends on whether or not the store is formula-aware. Stores that aren’t formula-aware would only persist those terms core to the RDF Model, and those that are formula-aware would be able to persist the N3 extensions as well. However, utility terms that only serve the purpose for matching nodes by term-patterns probably will only be terms and not nodes.</p> +<p>The set of nodes of an RDF graph is the set of subjects and objects of triples in the graph.</p> +</div> +<div class="topic"> +<p class="topic-title first"><strong>Context-aware</strong></p> +<p>An RDF store capable of storing statements within contexts is considered context-aware. Essentially, such a store is able to partition the RDF model it represents into individual, named, and addressable sub-graphs.</p> +</div> +<div class="topic"> +<p class="topic-title first"><strong>Formula-aware</strong></p> +<p>An RDF store capable of distinguishing between statements that are asserted and statements that are quoted is considered formula-aware.</p> +<p>Such a store is responsible for maintaining this separation and ensuring that queries against the entire model (the aggregation of all the contexts - specified by not limiting a ‘query’ to a specifically name context) do not include quoted statements. Also, it is responsible for distinguishing universal quantifiers (variables).</p> +<div class="admonition note"> +<p class="first admonition-title">Note</p> +<p class="last">These 2 additional concepts (formulae and variables) must be thought of as core extensions and distinguishable from the other terms of a triple (for the sake of the persistence rountrip - at the very least). It’s worth noting that the ‘scope’ of universal quantifiers (variables) and existential quantifiers (BNodes) is the formula (or context - to be specific) in which their statements reside. Beyond this, a Formula-aware store behaves the same as a Context-aware store.</p> +</div> +</div> +<div class="topic"> +<p class="topic-title first"><strong>Conjunctive Query</strong></p> +<p>Any query that doesn’t limit the store to search within a named context only. Such a query expects a context-aware store to search the entire asserted universe (the conjunctive graph). A formula-aware store is expected not to include quoted statements when matching such a query.</p> +</div> +<div class="topic"> +<p class="topic-title first"><strong>N3 Round Trip</strong></p> +<p>This refers to the requirements on a formula-aware RDF store’s persistence mechanism necessary for it to be properly populated by a N3 parser and rendered as syntax by a N3 serializer.</p> +</div> +<div class="topic"> +<p class="topic-title first"><strong>Transactional Store</strong></p> +<p>An RDF store capable of providing transactional integrity to the RDF operations performed on it.</p> +</div> +</div> +<div class="section" id="interpreting-syntax"> +<h2>Interpreting Syntax<a class="headerlink" href="#interpreting-syntax" title="Permalink to this headline">¶</a></h2> +<p>The following Notation 3 <a class="reference external" href="http://metacognition.info/Triclops/?xslt=Triclops.xslt&query=log:N3Document&queryType=Triple&remoteGraph=http://www.w3.org/2000/10/swap/log#">document</a>:</p> +<div class="highlight-n3"><pre>{?x a :N3Programmer} => {?x :has [a :Migrane]}</pre> +</div> +<p>Could cause the following statements to be asserted in the store:</p> +<div class="highlight-n3"><div class="highlight"><pre><span class="nc">_:a </span><span class="o">log:implies </span><span class="na">_:b</span> +</pre></div> +</div> +<p>This statement would be asserted in the partition associated with quoted statements (in a formula named <tt class="docutils literal"><span class="pre">_:a</span></tt>)</p> +<div class="highlight-n3"><pre>?x rdf:type :N3Programmer</pre> +</div> +<p>Finally, these statements would be asserted in the same partition (in a formula named _:b)</p> +<div class="highlight-n3"><pre>?x :has _:c + +_:c rdf:type :Migrane</pre> +</div> +</div> +<div class="section" id="formulae-and-variables-as-terms"> +<h2>Formulae and Variables as Terms<a class="headerlink" href="#formulae-and-variables-as-terms" title="Permalink to this headline">¶</a></h2> +<p>Formulae and variables are distinguishable from URI references, Literals, and BNodes by the following syntax:</p> +<div class="highlight-text"><div class="highlight"><pre>{ .. } - Formula ?x - Variable +</pre></div> +</div> +<p>They must also be distinguishable in persistence to ensure they can be round-tripped.</p> +<div class="admonition note"> +<p class="first admonition-title">Note</p> +<p class="last">There are a number of other issues regarding the <a class="reference external" href="persisting_n3_terms.html">persisting of N3 terms</a>.</p> +</div> +</div> +<div class="section" id="database-management"> +<h2>Database Management<a class="headerlink" href="#database-management" title="Permalink to this headline">¶</a></h2> +<p>An RDF store should provide standard interfaces for the management of database connections. Such interfaces are standard to most database management systems (Oracle, MySQL, Berkeley DB, Postgres, etc..)</p> +<p>The following methods are defined to provide this capability (see below for description of the <em class="xref">configuration</em> string):</p> +<dl class="method"> +<dt id="rdflib.store.Store.open"> +<!--[rdflib.store.Store.open]--><tt class="descclassname">Store.</tt><tt class="descname">open</tt><big>(</big><em>configuration</em>, <em>create=False</em><big>)</big><a class="headerlink" href="#rdflib.store.Store.open" title="Permalink to this definition">¶</a></dt> +<dd>Opens the store specified by the configuration string. If +create is True a store will be created if it does not already +exist. If create is False and a store does not already exist +an exception is raised. An exception is also raised if a store +exists, but there is insufficient permissions to open the +store. This should return one of VALID_STORE,CORRUPTED_STORE,or NO_STORE</dd></dl> + +<dl class="method"> +<dt id="rdflib.store.Store.close"> +<!--[rdflib.store.Store.close]--><tt class="descclassname">Store.</tt><tt class="descname">close</tt><big>(</big><em>commit_pending_transaction=False</em><big>)</big><a class="headerlink" href="#rdflib.store.Store.close" title="Permalink to this definition">¶</a></dt> +<dd>This closes the database connection. The commit_pending_transaction parameter specifies whether to +commit all pending transactions before closing (if the store is transactional).</dd></dl> + +<dl class="method"> +<dt id="rdflib.store.Store.destroy"> +<!--[rdflib.store.Store.destroy]--><tt class="descclassname">Store.</tt><tt class="descname">destroy</tt><big>(</big><em>configuration</em><big>)</big><a class="headerlink" href="#rdflib.store.Store.destroy" title="Permalink to this definition">¶</a></dt> +<dd>This destroys the instance of the store identified by the configuration string.</dd></dl> + +<p>The <em>configuration</em> string is understood by the store implementation and represents all the parameters needed to locate an individual instance of a store. This could be similar to an ODBC string or in fact be an ODBC string, if the connection protocol to the underlying database is ODBC. The <tt class="xref docutils literal"><span class="pre">open()</span></tt> function needs to fail intelligently in order to clearly express that a store (identified by the given configuration string) already exists or that there is no store (at the location specified by the configuration string) depending on the value of <tt class="xref docutils literal"><span class="pre">create</span></tt>.</p> +</div> +<div class="section" id="triple-interfaces"> +<h2>Triple Interfaces<a class="headerlink" href="#triple-interfaces" title="Permalink to this headline">¶</a></h2> +<p>An RDF store could provide a standard set of interfaces for the manipulation, management, and/or retrieval of its contained triples (asserted or quoted):</p> +<dl class="method"> +<dt id="rdflib.store.Store.add"> +<!--[rdflib.store.Store.add]--><tt class="descclassname">Store.</tt><tt class="descname">add</tt><big>(</big><em>(subject</em>, <em>predicate</em>, <em>object)</em>, <em>context</em>, <em>quoted=False</em><big>)</big><a class="headerlink" href="#rdflib.store.Store.add" title="Permalink to this definition">¶</a></dt> +<dd>Adds the given statement to a specific context or to the model. The quoted argument +is interpreted by formula-aware stores to indicate this statement is quoted/hypothetical +It should be an error to not specify a context and have the quoted argument be True. +It should also be an error for the quoted argument to be True when the store is not formula-aware.</dd></dl> + +<dl class="method"> +<dt id="rdflib.store.Store.remove"> +<!--[rdflib.store.Store.remove]--><tt class="descclassname">Store.</tt><tt class="descname">remove</tt><big>(</big><em>(subject</em>, <em>predicate</em>, <em>object)</em>, <em>context=None</em><big>)</big><a class="headerlink" href="#rdflib.store.Store.remove" title="Permalink to this definition">¶</a></dt> +<dd>Remove the set of triples matching the pattern from the store</dd></dl> + +<dl class="method"> +<dt id="rdflib.store.Store.triples"> +<!--[rdflib.store.Store.triples]--><tt class="descclassname">Store.</tt><tt class="descname">triples</tt><big>(</big><em>(subject</em>, <em>predicate</em>, <em>object)</em>, <em>context=None</em><big>)</big><a class="headerlink" href="#rdflib.store.Store.triples" title="Permalink to this definition">¶</a></dt> +<dd><p>A generator over all the triples matching the pattern. Pattern can +include any objects for used for comparing against nodes in the store, for +example, REGEXTerm, URIRef, Literal, BNode, Variable, Graph, QuotedGraph, Date? DateRange?</p> +<p>A conjunctive query can be indicated by either providing a value of None +for the context or the identifier associated with the Conjunctive Graph (if it’s context aware).</p> +<div class="admonition note"> +<p class="first admonition-title">Note</p> +<p class="last">The <tt class="xref docutils literal"><span class="pre">triples()</span></tt> method can be thought of as the primary mechanism for producing triples with nodes that match the corresponding terms in the <em>(s, p, o)</em> term pattern provided. The term pattern <tt class="docutils literal"><span class="pre">(None,</span> <span class="pre">None,</span> <span class="pre">None)</span></tt> matches all nodes.</p> +</div> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.store.Store.__len__"> +<!--[rdflib.store.Store.__len__]--><tt class="descclassname">Store.</tt><tt class="descname">__len__</tt><big>(</big><em>context=None</em><big>)</big><a class="headerlink" href="#rdflib.store.Store.__len__" title="Permalink to this definition">¶</a></dt> +<dd>Number of statements in the store. This should only account for non-quoted (asserted) statements +if the context is not specified, otherwise it should return the number of statements in the formula or context given.</dd></dl> + +</div> +<div class="section" id="formula-context-interfaces"> +<h2>Formula / Context Interfaces<a class="headerlink" href="#formula-context-interfaces" title="Permalink to this headline">¶</a></h2> +<p>These interfaces work on contexts and formulae (for stores that are formula-aware) interchangeably.</p> +<dl class="method"> +<dt id="rdflib.graph.ConjunctiveGraph.contexts"> +<!--[rdflib.graph.ConjunctiveGraph.contexts]--><tt class="descclassname">ConjunctiveGraph.</tt><tt class="descname">contexts</tt><big>(</big><em>triple=None</em><big>)</big><a class="headerlink" href="#rdflib.graph.ConjunctiveGraph.contexts" title="Permalink to this definition">¶</a></dt> +<dd><p>Iterate over all contexts in the graph</p> +<p>If triple is specified, iterate over all contexts the triple is in.</p> +</dd></dl> + +<dl class="method"> +<dt id="rdflib.graph.ConjunctiveGraph.remove_context"> +<!--[rdflib.graph.ConjunctiveGraph.remove_context]--><tt class="descclassname">ConjunctiveGraph.</tt><tt class="descname">remove_context</tt><big>(</big><em>context</em><big>)</big><a class="headerlink" href="#rdflib.graph.ConjunctiveGraph.remove_context" title="Permalink to this definition">¶</a></dt> +<dd>Removes the given context from the graph</dd></dl> + +</div> +<div class="section" id="interface-test-cases"> +<h2>Interface Test Cases<a class="headerlink" href="#interface-test-cases" title="Permalink to this headline">¶</a></h2> +<div class="section" id="basic"> +<h3>Basic<a class="headerlink" href="#basic" title="Permalink to this headline">¶</a></h3> +<p>Tests parsing, triple patterns, triple pattern removes, size, contextual removes</p> +<div class="section" id="source-graph"> +<h4>Source Graph<a class="headerlink" href="#source-graph" title="Permalink to this headline">¶</a></h4> +<div class="highlight-n3"><pre>@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . +@prefix : <http://test/> . +{:a :b :c; a :foo} => {:a :d :c} . +_:foo a rdfs:Class . +:a :d :c.</pre> +</div> +</div> +<div class="section" id="test-code"> +<h4>Test code<a class="headerlink" href="#test-code" title="Permalink to this headline">¶</a></h4> +<div class="highlight-python"><pre>implies = URIRef("http://www.w3.org/2000/10/swap/log#implies") +a = URIRef('http://test/a') +b = URIRef('http://test/b') +c = URIRef('http://test/c') +d = URIRef('http://test/d') +for s,p,o in g.triples((None,implies,None)): + formulaA = s + formulaB = o + + #contexts test + assert len(list(g.contexts()))==3 + + #contexts (with triple) test + assert len(list(g.contexts((a,d,c))))==2 + + #triples test cases + assert type(list(g.triples((None,RDF.type,RDFS.Class)))[0][0]) == BNode + assert len(list(g.triples((None,implies,None))))==1 + assert len(list(g.triples((None,RDF.type,None))))==3 + assert len(list(g.triples((None,RDF.type,None),formulaA)))==1 + assert len(list(g.triples((None,None,None),formulaA)))==2 + assert len(list(g.triples((None,None,None),formulaB)))==1 + assert len(list(g.triples((None,None,None))))==5 + assert len(list(g.triples((None,URIRef('http://test/d'),None),formulaB)))==1 + assert len(list(g.triples((None,URIRef('http://test/d'),None))))==1 + + #Remove test cases + g.remove((None,implies,None)) + assert len(list(g.triples((None,implies,None))))==0 + assert len(list(g.triples((None,None,None),formulaA)))==2 + assert len(list(g.triples((None,None,None),formulaB)))==1 + g.remove((None,b,None),formulaA) + assert len(list(g.triples((None,None,None),formulaA)))==1 + g.remove((None,RDF.type,None),formulaA) + assert len(list(g.triples((None,None,None),formulaA)))==0 + g.remove((None,RDF.type,RDFS.Class)) + + #remove_context tests + formulaBContext=Context(g,formulaB) + g.remove_context(formulaB) + assert len(list(g.triples((None,RDF.type,None))))==2 + assert len(g)==3 assert len(formulaBContext)==0 + g.remove((None,None,None)) + assert len(g)==0</pre> +</div> +</div> +</div> +<div class="section" id="formula-and-variables-test"> +<h3>Formula and Variables Test<a class="headerlink" href="#formula-and-variables-test" title="Permalink to this headline">¶</a></h3> +<div class="section" id="id11"> +<h4>Source Graph<a class="headerlink" href="#id11" title="Permalink to this headline">¶</a></h4> +<div class="highlight-n3"><pre>@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . +@prefix : <http://test/> . +{?x a rdfs:Class} => {?x a :Klass}.</pre> +</div> +</div> +<div class="section" id="id12"> +<h4>Test Code<a class="headerlink" href="#id12" title="Permalink to this headline">¶</a></h4> +<div class="highlight-python"><pre>implies = URIRef("http://www.w3.org/2000/10/swap/log#implies") +klass = URIRef('http://test/Klass') +for s,p,o in g.triples((None,implies,None)): + formulaA = s + formulaB = o + assert type(formulaA) == Formula + assert type(formulaB) == Formula + for s,p,o in g.triples((None,RDF.type,RDFS.Class)),formulaA): + assert type(s) == Variable + for s,p,o in g.triples((None,RDF.type,klass)),formulaB): + assert type(s) == Variable</pre> +</div> +</div> +</div> +<div class="section" id="transactional-tests"> +<h3>Transactional Tests<a class="headerlink" href="#transactional-tests" title="Permalink to this headline">¶</a></h3> +<p>To be instantiated.</p> +</div> +</div> +<div class="section" id="additional-terms-to-model"> +<h2>Additional Terms to Model<a class="headerlink" href="#additional-terms-to-model" title="Permalink to this headline">¶</a></h2> +<p>These are a list of additional kinds of RDF terms (all of which are special Literals)</p> +<blockquote> +<ul class="simple"> +<li>RegExLiteral - a REGEX string which can be used in any term slot in order to match by applying the Regular Expression to statements in the underlying graph.</li> +<li>Date (could provide some utility functions for date manipulation / serialization, etc..)</li> +<li>DateRange</li> +</ul> +</blockquote> +</div> +<div class="section" id="namespace-management-interfaces"> +<h2>Namespace Management Interfaces<a class="headerlink" href="#namespace-management-interfaces" title="Permalink to this headline">¶</a></h2> +<p>The following namespace management interfaces (defined in Graph) could be implemented in the RDF store. Currently, they exist as stub methods of <tt class="xref docutils literal"><span class="pre">Store</span></tt> and are defined in the store subclasses (e.g. <tt class="xref docutils literal"><span class="pre">IOMemory</span></tt>, <tt class="xref docutils literal"><span class="pre">AbstractSQLStore</span></tt>):</p> +<dl class="method"> +<dt id="rdflib.store.Store.bind"> +<!--[rdflib.store.Store.bind]--><tt class="descclassname">Store.</tt><tt class="descname">bind</tt><big>(</big><em>prefix</em>, <em>namespace</em><big>)</big><a class="headerlink" href="#rdflib.store.Store.bind" title="Permalink to this definition">¶</a></dt> +<dd></dd></dl> + +<dl class="method"> +<dt id="rdflib.store.Store.prefix"> +<!--[rdflib.store.Store.prefix]--><tt class="descclassname">Store.</tt><tt class="descname">prefix</tt><big>(</big><em>namespace</em><big>)</big><a class="headerlink" href="#rdflib.store.Store.prefix" title="Permalink to this definition">¶</a></dt> +<dd></dd></dl> + +<dl class="method"> +<dt id="rdflib.store.Store.namespace"> +<!--[rdflib.store.Store.namespace]--><tt class="descclassname">Store.</tt><tt class="descname">namespace</tt><big>(</big><em>prefix</em><big>)</big><a class="headerlink" href="#rdflib.store.Store.namespace" title="Permalink to this definition">¶</a></dt> +<dd></dd></dl> + +<dl class="method"> +<dt id="rdflib.store.Store.namespaces"> +<!--[rdflib.store.Store.namespaces]--><tt class="descclassname">Store.</tt><tt class="descname">namespaces</tt><big>(</big><big>)</big><a class="headerlink" href="#rdflib.store.Store.namespaces" title="Permalink to this definition">¶</a></dt> +<dd></dd></dl> + +</div> +<div class="section" id="open-issues"> +<h2>Open issues<a class="headerlink" href="#open-issues" title="Permalink to this headline">¶</a></h2> +<p>Does the Store interface need to have an identifier property or can we keep that at the Graph level?</p> +<p>The Store implementation needs a mechanism to distinguish between triples (quoted or asserted) in ConjunctiveGraphs (which are mutually exclusive universes in systems that make closed world assumptions - and queried separately). This is the separation that the store identifier provides. This is different from the name of a context within a ConjunctiveGraph (or the default context of a conjunctive graph). I tried to diagram the logical separation of ConjunctiveGraphs, SubGraphs and QuotedGraphs in this diagram</p> +<img alt="_images/ContextHierarchy.png" src="_images/ContextHierarchy.png" /> +<p>An identifier of <tt class="xref docutils literal"><span class="pre">None</span></tt> can be used to indicate the store (aka <cite>all contexts</cite>) in methods such as <tt class="xref docutils literal"><span class="pre">triples()</span></tt>, <tt class="xref docutils literal"><span class="pre">__len__()</span></tt>, etc. This works as long as we’re only dealing with one Conjunctive Graph at a time – which may not always be the case.</p> +<p>Is there any value in persisting terms that lie outside N3 (RegExLiteral,Date,etc..)?</p> +<p>Potentially, not sure yet.</p> +<p>Should a conjunctive query always return quads instead of triples? It would seem so, since knowing the context that produced a triple match is an essential aspect of query construction / optimization. Or if having the triples function yield/produce different length tuples is problematic, could an additional - and slightly redundant - interface be introduced?:</p> +<dl class="method"> +<dt id="rdflib.graph.ConjunctiveGraph.quads"> +<!--[rdflib.graph.ConjunctiveGraph.quads]--><tt class="descclassname">ConjunctiveGraph.</tt><tt class="descname">quads</tt><big>(</big><em>(s</em>, <em>p</em>, <em>o)</em><big>)</big><a class="headerlink" href="#rdflib.graph.ConjunctiveGraph.quads" title="Permalink to this definition">¶</a></dt> +<dd>Iterate over all the quads in the entire conjunctive graph</dd></dl> + +<p>Stores that weren’t context-aware could simply return <tt class="xref docutils literal"><span class="pre">None</span></tt> as the 4th item in the produced/yielded tuples or simply not support this interface.</p> +</div> +</div> + + + </div> + </div> + </div> + <div class="sphinxsidebar"> + <div class="sphinxsidebarwrapper"> + <h3><a href="index.html">Table Of Contents</a></h3> + <ul> +<li><a class="reference external" href="">A Universal RDF Store Interface</a><ul> +<li><a class="reference external" href="#terminology">Terminology</a></li> +<li><a class="reference external" href="#interpreting-syntax">Interpreting Syntax</a></li> +<li><a class="reference external" href="#formulae-and-variables-as-terms">Formulae and Variables as Terms</a></li> +<li><a class="reference external" href="#database-management">Database Management</a></li> +<li><a class="reference external" href="#triple-interfaces">Triple Interfaces</a></li> +<li><a class="reference external" href="#formula-context-interfaces">Formula / Context Interfaces</a></li> +<li><a class="reference external" href="#interface-test-cases">Interface Test Cases</a><ul> +<li><a class="reference external" href="#basic">Basic</a><ul> +<li><a class="reference external" href="#source-graph">Source Graph</a></li> +<li><a class="reference external" href="#test-code">Test code</a></li> +</ul> +</li> +<li><a class="reference external" href="#formula-and-variables-test">Formula and Variables Test</a><ul> +<li><a class="reference external" href="#id11">Source Graph</a></li> +<li><a class="reference external" href="#id12">Test Code</a></li> +</ul> +</li> +<li><a class="reference external" href="#transactional-tests">Transactional Tests</a></li> +</ul> +</li> +<li><a class="reference external" href="#additional-terms-to-model">Additional Terms to Model</a></li> +<li><a class="reference external" href="#namespace-management-interfaces">Namespace Management Interfaces</a></li> +<li><a class="reference external" href="#open-issues">Open issues</a></li> +</ul> +</li> +</ul> + + <h4>Previous topic</h4> + <p class="topless"><a href="gettingstarted.html" + title="previous chapter">Getting started with rdflib</a></p> + <h4>Next topic</h4> + <p class="topless"><a href="graphterms.html" + title="next chapter">RDF Graph Terms</a></p> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="_sources/univrdfstore.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" size="18" /> + <input type="submit" value="Go" /> + <input type="hidden" name="check_keywords" value="yes" /> + <input type="hidden" name="area" value="default" /> + </form> + <p 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" + accesskey="I">index</a></li> + <li class="right" > + <a href="modindex.html" title="Global Module Index" + accesskey="M">modules</a> |</li> + <li class="right" > + <a href="graphterms.html" title="RDF Graph Terms" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="gettingstarted.html" title="Getting started with rdflib" + accesskey="P">previous</a> |</li> + <li><a href="index.html">rdflib v2.5.0 documentation</a> »</li> + </ul> + </div> + <div class="footer"> + © Copyright 2009, Daniel Krech. + Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6. + </div> + </body> +</html>
\ No newline at end of file diff --git a/docs/_static/ContextHierarchy.png b/docs/_static/ContextHierarchy.png Binary files differnew file mode 100644 index 00000000..28b4977e --- /dev/null +++ b/docs/_static/ContextHierarchy.png diff --git a/docs/addons.rst b/docs/addons.rst new file mode 100644 index 00000000..1005e423 --- /dev/null +++ b/docs/addons.rst @@ -0,0 +1,364 @@ +.. _addons: Additions + +========= +Additions +========= + +TriXSerializer +============== + +John L. Clark jlc6 at po.cwru.edu + +Tue Aug 7 01:55:07 EDT 2007 + +.. note:: Devs, + + I've taken a first pass at implementing a simple TriX serializer. I + should have attached the new file (which goes in + `.../rdflib/syntax/serializers/TriXSerializer.py`) to this email, + along with a crazy little test script. The test script exercises + round tripping, but it turned out parsing was broken, so I fixed it; + the patch for that (and adding the new serializer to the plugin list) + should be attached as well. Finally, does anyone mind if I clean up + the TriX parser a bit? + + Take care, + + John L. Clark + + +TriXSerializer.py +----------------- + +.. code-block:: python + + from rdflib.syntax.serializers import Serializer + + from rdflib.URIRef import URIRef + from rdflib.Literal import Literal + from rdflib.BNode import BNode + + from rdflib.Graph import Graph, ConjunctiveGraph + + from Ft.Xml import MarkupWriter, XML_NAMESPACE + + TRIX_NS = u"http://www.w3.org/2004/03/trix/trix-1/" + + class TriXSerializer(Serializer): + def __init__(self, store): + super(TriXSerializer, self).__init__(store) + + def serialize(self, stream, base=None, encoding=None, **args): + self.writer = MarkupWriter(stream=stream, encoding=encoding, + indent="yes") + self.writer.startDocument() + self.writer.startElement(u"TriX", TRIX_NS) + + if isinstance(self.store, ConjunctiveGraph): + for subgraph in self.store.contexts(): + self._writeGraph(subgraph) + elif isinstance(self.store, Graph): + self._writeGraph(self.store) + else: + pass + + self.writer.endElement(u"TriX", TRIX_NS) + self.writer.endDocument() + + def _writeGraph(self, graph): + self.writer.startElement(u"graph", TRIX_NS) + if isinstance(graph.identifier, URIRef): + self.writer.simpleElement(u"uri", TRIX_NS, + content=unicode(graph.identifier)) + + for triple in graph.triples((None,None,None)): + self._writeTriple(triple) + self.writer.endElement(u"graph", TRIX_NS) + + def _writeTriple(self, triple): + self.writer.startElement(u"triple", TRIX_NS) + for component in triple: + if isinstance(component, URIRef): + self.writer.simpleElement(u"uri", TRIX_NS, + content=unicode(component)) + elif isinstance(component, BNode): + self.writer.simpleElement(u"id", TRIX_NS, + content=unicode(component)) + elif isinstance(component, Literal): + if component.datatype: + self.writer.simpleElement(u"typedLiteral", TRIX_NS, + content=unicode(component), + attributes={u"datatype": unicode(component.datatype)}) + elif component.language: + self.writer.simpleElement(u"plainLiteral", TRIX_NS, + content=unicode(component), + attributes={ + (u"xml:lang", XML_NAMESPACE): unicode(component.language)}) + else: + self.writer.simpleElement(u"plainLiteral", TRIX_NS, + content=unicode(component)) + self.writer.endElement(u"triple", TRIX_NS) + +trixserializer.diff +------------------- + +.. code-block:: text + + Index: rdflib/plugin.py + =================================================================== + --- rdflib/plugin.py (revision 1239) + +++ rdflib/plugin.py (working copy) + @@ -49,6 +49,9 @@ + register('pretty-xml', serializers.Serializer, + 'rdflib.syntax.serializers.PrettyXMLSerializer', 'PrettyXMLSerializer') + + +register('TriX', serializers.Serializer, + + 'rdflib.syntax.serializers.TriXSerializer', 'TriXSerializer') + + + register('nt', serializers.Serializer, + 'rdflib.syntax.serializers.NTSerializer', 'NTSerializer') + + Index: rdflib/syntax/parsers/TriXHandler.py + =================================================================== + --- rdflib/syntax/parsers/TriXHandler.py (revision 1239) + +++ rdflib/syntax/parsers/TriXHandler.py (working copy) + @@ -33,6 +33,7 @@ + """ + from rdflib import RDF, RDFS, Namespace + from rdflib import URIRef, BNode, Literal + +from rdflib.Namespace import Namespace + from rdflib.Graph import Graph + from rdflib.exceptions import ParserError, Error + from rdflib.syntax.xml_names import is_ncname + @@ -42,7 +43,7 @@ + + RDFNS = RDF.RDFNS + + -TRIXNS=Namespace.Namespace("http://www.w3.org/2004/03/trix/trix-1/") + +TRIXNS=u"http://www.w3.org/2004/03/trix/trix-1/" + + + class TriXHandler(handler.ContentHandler): + @@ -200,6 +201,7 @@ + self.error("This should never happen if the SAX parser ensures XML syntax correctness") + + if name[1]=="graph": + + self.graph = Graph(store = self.store.store) + self.state=1 + + if name[1]=="TriX": + +test_trixserializer.py +---------------------- + +.. code-block:: python + + from rdflib.Graph import ConjunctiveGraph + from rdflib import URIRef, Literal + from rdflib.Graph import Graph + + s1 = URIRef('store:1') + r1 = URIRef('resource:1') + r2 = URIRef('resource:2') + + label = URIRef('predicate:label') + + g1 = Graph(identifier = s1) + g1.add((r1, label, Literal("label 1", lang="en"))) + g1.add((r1, label, Literal("label 2"))) + + s2 = URIRef('store:2') + g2 = Graph(identifier = s2) + g2.add((r2, label, Literal("label 3"))) + + g = ConjunctiveGraph() + + for s,p,o in g1.triples((None, None, None)): + g.addN([(s,p,o,g1)]) + + for s,p,o in g2.triples((None, None, None)): + g.addN([(s,p,o,g2)]) + + r3 = URIRef('resource:3') + + g.add((r3, label, Literal(4))) + #g.addN([(r1, label, Literal("label 1"), s1), + # (r1, label, Literal("label 2"), s1), + # (r2, label, Literal("label 3"), s2)]) + + for c in g.contexts(): + pass + #s = Graph(g.store, identifier=c) + #print c, c.identifier.__class__, c.identifier, len(c) + + r = g.serialize(format='TriX') + print r + + g3 = ConjunctiveGraph() + from rdflib.StringInputSource import StringInputSource + g3.parse(StringInputSource(r, None), format='trix') + for c in g3.contexts(): + print c, c.identifier.__class__, c.identifier, len(c) + + +test output +----------- + +.. code-block:: xml + + <?xml version="1.0" encoding="UTF-8"?> + <TriX xmlns="http://www.w3.org/2004/03/trix/trix-1/"> + <graph> + <uri>store:2</uri> + <triple> + <uri>resource:2</uri> + <uri>predicate:label</uri> + <plainLiteral>label 3</plainLiteral> + </triple> + </graph> + <graph> + <uri>store:1</uri> + <triple> + <uri>resource:1</uri> + <uri>predicate:label</uri> + <plainLiteral>label 2</plainLiteral> + </triple> + <triple> + <uri>resource:1</uri> + <uri>predicate:label</uri> + <plainLiteral xml:lang="en">label 1</plainLiteral> + </triple> + </graph> + <graph> + <triple> + <uri>resource:3</uri> + <uri>predicate:label</uri> + <typedLiteral datatype="http://www.w3.org/2001/XMLSchema#integer">4</typedLiteral> + </triple> + </graph> + </TriX> + +.. code-block:: n3 + + [a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']]. + <class 'rdflib.BNode.BNode'> QeDIviuA11 1 + <store:2> a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']. + <class 'rdflib.URIRef.URIRef'> store:2 1 + <store:1> a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']. + <class 'rdflib.URIRef.URIRef'> store:1 2 + +SPARQL-XML Serializer +===================== + +.. code-block:: python + + # -*- coding: iso-8859-15 -*- + # (c) Mikael Högqvist, ZIB, AstroGrid-D + # This software is licensed under the software license specified at + # http://www.gac-grid.org/ + + # this is a work-around of the SPARQL XML-serialization in rdflib which does + # not work on all installation due to a bug in the python sax-parser + # We rely on ElementTree which is only available in Python 2.5 + + from cStringIO import StringIO + + try: + from xml.etree.cElementTree import Element, SubElement, ElementTree, ProcessingInstruction + import xml.etree.cElementTree as ET + except ImportError: + from cElementTree import Element, SubElement, ElementTree + import cElementTree as ET + + from rdflib import URIRef, BNode, Literal + + SPARQL_XML_NAMESPACE = u'http://www.w3.org/2005/sparql-results#' + XML_NAMESPACE = "http://www.w3.org/2001/XMLSchema#" + + name = lambda elem: u'{%s}%s' % (SPARQL_XML_NAMESPACE, elem) + xml_name = lambda elem: u'{%s}%s' % (XML_NAMESPACE, elem) + + def variables(results): + # don't include any variables which are not part of the + # result set + #res_vars = set(results.selectionF).intersection(set(results.allVariables)) + + + # this means select *, use all variables from the result-set + if len(results.selectionF) == 0: + res_vars = results.allVariables + else: + res_vars = [v for v in results.selectionF if v in results.allVariables] + + return res_vars + + def header(results, root): + head = SubElement(root, name(u'head')) + + res_vars = variables(results) + for var in res_vars: + v = SubElement(head, name(u'variable')) + # remove the ? + v.attrib[u'name'] = var[1:] + + + def binding(val, var, elem): + bindingElem = SubElement(elem, name(u'binding')) + bindingElem.attrib[u'name'] = var + + if isinstance(val,URIRef): + varElem = SubElement(bindingElem, name(u'uri')) + elif isinstance(val,BNode) : + varElem = SubElement(bindingElem, name(u'bnode')) + elif isinstance(val,Literal): + varElem = SubElement(bindingElem, name(u'literal')) + + if val.language != "" and val.language != None: + varElem.attrib[xml_name(u'lang')] = str(val.language) + elif val.datatype != "" and val.datatype != None: + varElem.attrib[name(u'datatype')] = str(val.datatype) + + varElem.text = str(val) + + def res_iter(results): + res_vars = variables(results) + + for row in results.selected: + if len(res_vars) == 1: + row = (row, ) + + yield zip(row, res_vars) + + def result_list(results, root): + resultsElem = SubElement(root, name(u'results')) + + ordered = results.orderBy + + if ordered == None: + ordered = False + + # removed according to the new working draft (2007-06-14) + # resultsElem.attrib[u'ordered'] = str(ordered) + # resultsElem.attrib[u'distinct'] = str(results.distinct) + + for row in res_iter(results): + resultElem = SubElement(resultsElem, name(u'result')) + # remove the ? from the variable name + [binding(val, var[1:], resultElem) for (val, var) in row] + + def serializeXML(results): + root = Element(name(u'sparql')) + + header(results, root) + result_list(results, root) + + out = StringIO() + tree = ElementTree(root) + + # xml declaration must be written by hand + # http://www.nabble.com/Writing-XML-files-with-ElementTree-t3433325.html + out.write('<?xml version="1.0" encoding="utf-8"?>') + out.write('<?xml-stylesheet type="text/xsl" href="/static/sparql-xml-to-html.xsl"?>') + tree.write(out, encoding='utf-8') + + return out.getvalue() diff --git a/docs/assorted_examples.rst b/docs/assorted_examples.rst new file mode 100644 index 00000000..344e7e11 --- /dev/null +++ b/docs/assorted_examples.rst @@ -0,0 +1,629 @@ +.. _assorted_examples: + +================= +Assorted examples +================= + +Conjunctive Graphs +================== + +.. code-block:: python + + from rdflib import Namespace, BNode, Literal, URIRef + from rdflib.Graph import Graph, ConjunctiveGraph + from rdflib.store.IOMemory import IOMemory + + ns = Namespace("http://love.com#") + + 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#") + + store = IOMemory() + + g = ConjunctiveGraph(store=store) + g.bind("love",ns) + + gmary = Graph(store=store, identifier=cmary) + + gmary.add((mary, ns['hasName'], Literal("Mary"))) + gmary.add((mary, ns['loves'], john)) + + gjohn = Graph(store=store, identifier=cjohn) + gjohn.add((john, ns['hasName'], Literal("John"))) + + #enumerate contexts + for c in g.contexts(): + print "-- %s " % c + + #separate graphs + print gjohn.serialize(format='n3') + print "===================" + print gmary.serialize(format='n3') + print "===================" + + #full graph + print g.serialize(format='n3') + + +Two-finger exercises +==================== + +.. code-block:: python + + import logging + + # Configure how we want rdflib logger to log messages + _logger = logging.getLogger("rdflib") + _logger.setLevel(logging.DEBUG) + _hdlr = logging.StreamHandler() + _hdlr.setFormatter(logging.Formatter('%(name)s %(levelname)s: %(message)s')) + _logger.addHandler(_hdlr) + + from rdflib.Graph import Graph + from rdflib import URIRef, Literal, BNode, Namespace + from rdflib import RDF + + store = Graph() + + # Bind a few prefix, namespace pairs. + store.bind("dc", "http://http://purl.org/dc/elements/1.1/") + store.bind("foaf", "http://xmlns.com/foaf/0.1/") + + # Create a namespace object for the Friend of a friend namespace. + FOAF = Namespace("http://xmlns.com/foaf/0.1/") + + # Create an identifier to use as the subject for Donna. + donna = BNode() + + # Add triples using store's add method. + store.add((donna, RDF.type, FOAF["Person"])) + store.add((donna, FOAF["nick"], Literal("donna", lang="foo"))) + store.add((donna, FOAF["name"], Literal("Donna Fales"))) + + # Iterate over triples in store and print them out. + print "--- printing raw triples ---" + for s, p, o in store: + print s, p, o + + # For each foaf:Person in the store print out its mbox property. + print "--- printing mboxes ---" + for person in store.subjects(RDF.type, FOAF["Person"]): + for mbox in store.objects(person, FOAF["mbox"]): + print mbox + + # Serialize the store as RDF/XML to the file foaf.rdf. + store.serialize("foaf.rdf", format="pretty-xml", max_depth=3) + + # Let's show off the serializers + + print "RDF Serializations:" + + # Serialize as XML + print "--- start: rdf-xml ---" + print store.serialize(format="pretty-xml") + print "--- end: rdf-xml ---\n" + + # Serialize as NTriples + print "--- start: ntriples ---" + print store.serialize(format="nt") + print "--- end: ntriples ---\n" + + + + +Update namespace +================ + +.. code-block:: python + + #OLD = "http://www.mindswap.org/2004/terrorOnt.owl#" + #OLD = "http://wang-desktop/TerrorOrgInstances#" + OLD = "http://localhost/" + NEW = "http://profilesinterror.mindswap.org/" + + redfoot.bind("terror", "http://counterterror.mindswap.org/2005/terrorism.owl#") + redfoot.bind("terror_old", "http://www.mindswap.org/2004/terrorOnt.owl#") + redfoot.bind("tech", "http://www.mindswap.org/~glapizco/technical.owl#") + redfoot.bind("wang-desk", "http://wang-desktop/TerrorOrgInstances#") + redfoot.bind("foaf", 'http://xmlns.com/foaf/0.1/') + redfoot.bind("dc", 'http://purl.org/dc/elements/1.1/') + + + REDFOOT = redfoot.namespace("http://redfoot.net/2005/redfoot#") + + for cid, _, source in redfoot.triples((None, REDFOOT.source, None)): + if source: + print "updating %s" % source + try: + context = redfoot.get_context(cid) + + for s, p, o in context: + context.remove((s, p, o)) + if isinstance(s, URIRef) and OLD in s: + s = URIRef(s.replace(OLD, NEW)) + if isinstance(p, URIRef) and OLD in p: + p = URIRef(p.replace(OLD, NEW)) + if isinstance(o, URIRef) and OLD in o: + o = URIRef(o.replace(OLD, NEW)) + context.add((s, p, o)) + + context.save(source, format="pretty-xml") + except Exception, e: + print e + + +SPARQL query +============ + +.. code-block:: python + + from rdflib import Literal, ConjunctiveGraph, Namespace, BNode, URIRef + + DC = Namespace(u"http://purl.org/dc/elements/1.1/";) + FOAF = Namespace(u"http://xmlns.com/foaf/0.1/";) + + graph = ConjunctiveGraph() + s = BNode() + graph.add((s, FOAF['givenName'], Literal('Alice'))) + b = BNode() + graph.add((b, FOAF['givenName'], Literal('Bob'))) + graph.add((b, DC['date'], Literal("2005-04-04T04:04:04Z"))) + + print graph.query("""PREFIX foaf: <http://xmlns.com/foaf/0.1/> + PREFIX dc: <http://purl.org/dc/elements/1.1/> + PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> + SELECT ?name + WHERE { ?x foaf:givenName ?name . + OPTIONAL { ?x dc:date ?date } . + FILTER ( bound(?date) ) }""").serialize('python') + + +Data reading exercise +===================== + +.. code-block:: python + + #!/usr/bin/env python + # -*- coding: utf-8 -*- + + """Demo script to show the different ways to read information + from an RDF file using rdflib, as found at http://rdflib.net/. + + The tree main methods are: + 1. Simple lookup in a list of triplets (SimpleLookup), + 2. SPARQL query, created with rdflib.sparql.* objects (CustomSparql), + 3. SPARQL query, created with bison (BisonSparql). + + The main function reads a file, xfn-example.rdf, and displays all resource + pairs with a symmetrical "xfn:met" relation (e.g. A met B and B met A) + Uses the rdfs:label of the resources to display the name. + + This demo file has been tested with the following versions of RDFlib: + rdflib 2.0.6 -- unsupported (since it has no "Graph" modules) + rdflib 2.1.3 -- methods 1, and 2 work fine + rdflib 2.1.4 -- methods 1, and 2 work fine + rdflib 2.2.3 -- methods 1, and 2 work fine + rdflib 2.3.0 -- methods 1, and 2 work fine + rdflib 2.3.1 -- methods 1, and 2 work fine + rdflib 2.3.2 -- methods 1, and 2 work fine + rdflib 2.3.3 -- methods 1, 2, and 3 work fine + rdflib 2.4.0 -- methods 1, 2, and 3 work fine (but function call for method 2 was changed) + """ + + __copyright__ = "rdflibdemo written by Freek Dijkstra, Universiteit van Amsterdam, april 2007, contributed to the public domain (feel free to attribute me, but it's not needed)." + + import os + import sys + import distutils.version + # semi-standard modules + try: + import rdflib + except ImportError: + raise ImportError("Module rdflib is not available. It can be downloaded from http://rdflib.net/\n") + if distutils.version.StrictVersion(rdflib.__version__) < "2.0.9": + raise ImportError("The installed version of rdflib, %s, is too old. 2.1 or higher is required" % rdflib.__version__) + from rdflib.Graph import Graph + from rdflib.sparql.sparqlGraph import SPARQLGraph + from rdflib.sparql.graphPattern import GraphPattern + if distutils.version.StrictVersion(rdflib.__version__) > "2.3.2": + from rdflib.sparql.bison import Parse # available in 2.3.3 and up + if distutils.version.StrictVersion(rdflib.__version__) > "2.3.9": + from rdflib.sparql import Query # available in 2.4.0 and up + + + + + def SimpleLookup(graph): + """ + Extracts information form a rdflib Graph object + using a simple list lookup. E.g.: + result = list(graph.subject_objects(self.xfn["met"])): + """ + assert(isinstance(graph, Graph)) + xfn = rdflib.Namespace("http://gmpg.org/xfn/1#") + rdf = rdflib.Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#") + rdfs = rdflib.Namespace("http://www.w3.org/2000/01/rdf-schema#") + meetings = [] + # Get a list of (subject, object) tuples in the graph with the xfn:met predicate + relations = list(graph.subject_objects(xfn["met"])) + for (person, peer) in relations: + if not (peer, person) in relations: + # person says he/she has met peer, but peer doesn't say he/she has met person. Skip. + continue + # since we're processing (person, peer), we can skip (peer, person) later + relations.remove((peer, person)) + personname = list(graph.objects(person, rdfs["label"])) + if len(personname) == 0: + continue # skip persons with no name + peername = list(graph.objects(peer, rdfs["label"])) + if len(peername) == 0: + continue # skip peers with no name + personname = list(graph.objects(person, rdfs["label"])) + # Add the name of the person and peer to list of people who've met. + meetings.append((personname[0], peername[0])) + + # Print the results + print "Simple Lookup (%d meetings found)" % len(meetings) + print 40*"-" + for (person, peer) in meetings: + print "%s and %s have met" % (person, peer) + print + + + def CustomSparql(graph): + """ + Extracts information form a rdflib Graph object + using a SPARQL query, put together using GraphPattern objects. E.g.: + select = ("?ifA","?ifB") + where = GraphPattern([("?ifA", xfn["met"], "?ifB")]) + result = graph.query(select,where) + See http://dev.w3.org/cvsweb/~checkout~/2004/PythonLib-IH/Doc/sparqlDesc.html for more information. + """ + assert(isinstance(graph, Graph)) + xfn = rdflib.Namespace("http://gmpg.org/xfn/1#") + rdf = rdflib.Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#") + rdfs = rdflib.Namespace("http://www.w3.org/2000/01/rdf-schema#") + select = ("?personname","?peername") + where = GraphPattern([ + ("?person", xfn["met"], "?peer"), + ("?peer", xfn["met"], "?person"), + ("?person", rdfs["label"], "?personname"), + ("?peer", rdfs["label"], "?peername"), + ]) + # Create a SPARQLGraph wrapper object out of the normal Graph + sparqlGrph = SPARQLGraph(graph) + # Make the query + if distutils.version.StrictVersion(rdflib.__version__) <= "2.3.9": + relations = sparqlGrph.query(select, where) + else: + # graph.query() function was changed in RDFlib 2.4.0 + bindings = { u"xfn": xfn, u"rdf": rdf, u"rdfs": rdfs } + relations = Query.query(sparqlGrph, select, where, initialBindings=bindings) + + for (person, peer) in relations: + # since we're processing (person, peer), we can skip (peer, person) later + relations.remove((peer, person)) + + # Print the results + print "Manual formatted SPARQL query (%d meetings found)" % len(relations) + print 40*"-" + for (person, peer) in relations: + print "%s and %s have met" % (person, peer) + print + + + def BisonSparql(graph): + """ + Extracts information form a rdflib Graph object + using a SPARQL query, parsed by the bison parser in RDFlib. + graphpattern = Parse('SELECT ?ifA ?ifB WHERE { ?ifA xfn:met ?ifB . ?ifB xfn:met ?ifA }') + result = graph.query(graphpattern, initNs=bindings) + """ + assert(isinstance(graph, Graph)) + if distutils.version.StrictVersion(rdflib.__version__) <= "2.3.2": + print "Skipping Bison SPARQL query (requires RDFlib 2.3.3 or higher; version %s detected)" % (rdflib.__version__) + print + return + xfn = rdflib.Namespace("http://gmpg.org/xfn/1#") + rdf = rdflib.Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#") + rdfs = rdflib.Namespace("http://www.w3.org/2000/01/rdf-schema#") + bindings = { u"xfn": xfn, u"rdf": rdf, u"rdfs": rdfs } + query = Parse('SELECT ?personname ?peername WHERE \ + { ?person xfn:met ?peer . ?peer xfn:met ?person . \ + ?person rdfs:label ?personname . ?peer rdfs:label ?peername }') + # Make the query, and serialize the result as python objects (as opposed to for example XML) + relations = graph.query(query, initNs=bindings).serialize('python') + for (person, peer) in relations: + # since we're processing (person, peer), we can skip (peer, person) later + relations.remove((peer, person)) + + # Print the results + print "Bison SPARQL query (%d meetings found)" % len(relations) + print 40*"-" + for (person, peer) in relations: + print "%s and %s have met" % (person, peer) + print + + def ReadFile(filename="xfn-example.rdf"): + """Read a RDF and returns the objects in a rdflib Graph object""" + graph = Graph() + print "Read RDF data from %s" % filename + print + graph.parse(filename) + return graph + + if __name__=="__main__": + print "RDFlib version %s detected" % rdflib.__version__ + print + graph = ReadFile() + SimpleLookup(graph) + CustomSparql(graph) + BisonSparql(graph) + +Example Foaf Smushing +===================== + +Filter a graph by normalizing all foaf persons into URIs based on their mbox_sha1sum. + +Suppose I got two FOAF documents each talking about the same person (according to mbox_sha1sum) but they each used a BNode for the subject. For this demo I've combined those two documents into one file: + +demo.n3 +------- + +.. code-block:: n3 + + @prefix foaf: <http://xmlns.com/foaf/0.1/> . + + # from one document + :p0 a foaf:Person; + foaf:mbox_sha1sum "65b983bb397fb71849da910996741752ace8369b"; + foaf:nick "mortenf"; + foaf:weblog <http://www.wasab.dk/morten/blog/archives/author/mortenf/> . + + # from another document + :p1 a foaf:Person; + foaf:mbox_sha1sum "65b983bb397fb71849da910996741752ace8369b"; + foaf:nick "mortenf"; + foaf:homepage <http://www.wasab.dk/morten/>; + foaf:interest <http://en.wikipedia.org/wiki/Atom_(standard)>, + +Now I'll use rdflib to transform all the incoming FOAF data to new data that lies about the subjects. It might be easier to do some queries on this resulting graph, although you wouldn't want to actually publish the result anywhere since it loses some information about FOAF people who really had a meaningful URI. + +fold_sha1.py +------------ + +.. code-block:: python + + """filter a graph by changing every subject with a foaf:mbox_sha1sum + into a new subject whose URI is based on the sha1sum. This new graph + might be easier to do some operations on. + """ + + from rdflib.Graph import Graph + from rdflib import Namespace + + FOAF = Namespace("http://xmlns.com/foaf/0.1/") + STABLE = Namespace("http://example.com/person/mbox_sha1sum/") + + g = Graph() + g.parse("demo.n3", format="n3") + + newURI = {} # old subject : stable uri + for s,p,o in g.triples((None, FOAF['mbox_sha1sum'], None)): + newURI[s] = STABLE[o] + + + out = Graph() + 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") + +Output +------ +note how all of the data has come together under one subject: + +.. code-block:: n3 + + @prefix _5: <http://example.com/person/mbox_sha1sum/65>. + @prefix foaf: <http://xmlns.com/foaf/0.1/>. + @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. + + _5:b983bb397fb71849da910996741752ace8369b a foaf:Person; + foaf:homepage <http://www.wasab.dk/morten/>; + foaf:interest <http://en.wikipedia.org/wiki/Atom_(standard)>; + foaf:mbox_sha1sum "65b983bb397fb71849da910996741752ace8369b"; + foaf:nick "mortenf"; + foaf:weblog <http://www.wasab.dk/morten/blog/archives/author/mortenf/>. + +An advantage of this approach over other methods for collapsing BNodes is that I can incrementally process new FOAF documents as they come in 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. + +Transitive traversal +==================== + +How to use the `transitive_objects` and `transitive_subjects` graph methods + +Formal definition +----------------- +The :meth:`transitive_objects` method finds all nodes such that there is a path from subject to one of those nodes using only the predicate property in the triples. The :meth:`transitive_subjects` method is similar; it finds all nodes such that there is a path from the node to the object using only the predicate property. + +Informal description, with an example +------------------------------------- +In brief, :meth:`transitive_objects` walks forward in a graph using a particular property, and :meth:`transitive_subjects` walks backward. A good example uses a property ``ex:parent``, the semantics of which are biological parentage. The :meth:`transitive_objects` method would get all the ancestors of a particular person (all nodes such that there is a parent path between the person and the object). The :meth:`transitive_subjects` method would get all the descendants of a particular person (all nodes such that there is a parent path between the node and the person). So, say that your URI is ``ex:person``. + +The following code would get all of your (known) ancestors, and then get all the (known) descendants of your maternal grandmother: + +.. code-block:: python + + 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') + + parent = URIRef('ex:parent') + + g = ConjunctiveGraph() + g.add((person, parent, dad)) + g.add((person, parent, mom)) + g.add((dad, parent, momOfDad)) + g.add((dad, parent, dadOfDad)) + g.add((mom, parent, momOfMom)) + g.add((mom, parent, dadOfMom)) + + print "Parents, forward from `ex:person`:" + for i in g.transitive_objects(person, parent): + print i + + print "Parents, *backward* from `ex:gm1`:" + for i in g.transitive_subjects(parent, momOfMom): + print i + +.. warning:: The :meth:`transitive_objects` method has the start node as the *first* argument, but the :meth:`transitive_subjects` method has the start node as the *second* argument. + +film.py +======= + +.. code-block:: python + + #!/usr/bin/env python + """ 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 + + -- + Usage: + film.py whoami "John Doe <john@doe.org>" + Initialize the store and set your name and email. + film.py whoami + Tell you who you are + film.py http://www.imdb.com/title/tt0105236/ + Review the movie "Reservoir Dogs" + """ + import datetime, os, sys, re, time, imdb + from rdflib import BNode, ConjunctiveGraph, URIRef, Literal, Namespace, RDF + + #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_-]+)+)>$') + + DC = Namespace('http://purl.org/dc/elements/1.1/') + FOAF = Namespace('http://xmlns.com/foaf/0.1/') + 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', 'http://purl.org/dc/elements/1.1/') + self.graph.bind('foaf', 'http://xmlns.com/foaf/0.1/') + self.graph.bind('imdb', 'http://www.csd.abdn.ac.uk/~ggrimnes/dev/imdb/IMDB#') + self.graph.bind('rev', 'http://purl.org/stuff/rev#') + + def save(self): + 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.save() + else: + 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'])))) + 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))) + print comment + if comment is not None: + 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 + + def help(): + print __doc__.split('--')[1] + + def main(argv=None): + if not argv: + argv = sys.argv + s = Store() + if argv[1] in ('help', '--help', 'h', '-h'): + help() + 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'): + 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'].encode('utf-8')) + for director in movie['director']: + print 'directed by: %s' % director['name'].encode('utf-8') + for writer in movie['writer']: + print 'writed 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(raw_input('Rating (on five): ')) + except ValueError: + rating = None + date = None + while not date: + try: + i = raw_input('Review date (YYYY-MM-DD): ') + date = datetime.datetime(*time.strptime(i, '%Y-%m-%d')[:6]) + except: + date = None + comment = raw_input('Comment: ') + s.new_review(movie, date, rating, comment) + else: + help() + + if __name__ == '__main__': + main() + diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 00000000..3963d220 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,198 @@ +# -*- coding: utf-8 -*- +# +# rdflib documentation build configuration file, created by +# sphinx-quickstart on Fri May 15 15:03:54 2009. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys, os + +# 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('.')) + +# -- 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'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'rdflib' +copyright = u'2009, Daniel Krech' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '2.5.0' +# The full version, including alpha/beta/rc tags. +release = '2.5.0' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of documents that shouldn't be included in the build. +#unused_docs = [] + +# List of directories, relative to source directory, that shouldn't be searched +# for source files. +exclude_trees = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#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 = 'default' + +# 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 = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# "<project> v<release> documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#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 + +# 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 + +# 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'] + +# 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' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_use_modindex = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#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 = '' + +# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = '' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'rdflibdoc' + + +# -- Options for LaTeX output -------------------------------------------------- + +# The paper size ('letter' or 'a4'). +#latex_paper_size = 'letter' + +# The font size ('10pt', '11pt' or '12pt'). +#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'Daniel Krech', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# Additional stuff for the LaTeX preamble. +#latex_preamble = '' + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_use_modindex = True + + +# Example configuration for intersphinx: refer to the Python standard library. +# intersphinx_mapping = {'http://docs.python.org/': None} diff --git a/docs/gettingstarted.rst b/docs/gettingstarted.rst new file mode 100644 index 00000000..ff89dcc6 --- /dev/null +++ b/docs/gettingstarted.rst @@ -0,0 +1,234 @@ +.. _gettingstarted: + +=========================== +Getting started with rdflib +=========================== + +Introduction to parsing RDF into rdflib graphs +---------------------------------------------- + +Reading an NT file +^^^^^^^^^^^^^^^^^^ + +RDF data has various syntaxes (``xml``, ``n3``, ``ntriples``, ``trix``, etc) that you might want to read. The simplest format is ``ntriples``. Create the file :file:`demo.nt` in the current directory with these two lines: + +.. code-block:: n3 + + <http://bigasterisk.com/foaf.rdf#drewp> \ + <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> \ + <http://xmlns.com/foaf/0.1/Person> . + <http://bigasterisk.com/foaf.rdf#drewp> \ + <http://example.com/says> \ + "Hello world" . + +In an interactive python interpreter, try this: + +.. code-block:: python + + >>> from rdflib.graph import Graph + >>> g = Graph() + >>> g.parse("demo.nt", format="nt") + <Graph identifier=HCbubHJy0 (<class 'rdflib.graph.Graph'>)> + >>> len(g) + 2 + >>> import pprint + >>> for stmt in g: + ... pprint.pprint(stmt) + ... + (rdflib.term.URIRef('http://bigasterisk.com/foaf.rdf#drewp'), + rdflib.term.URIRef('http://example.com/says'), + rdflib.term.Literal(u'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')) + +The final lines show how rdflib represents the two statements in the file. The statements themselves are just length-3 tuples; and the subjects, predicates, and objects are all rdflib types. + +Reading remote graphs +^^^^^^^^^^^^^^^^^^^^^ + +Reading graphs from the net is just as easy: + +.. code-block:: pycon + + >>> g.parse("http://bigasterisk.com/foaf.rdf") + >>> len(g) + 42 + +The format defaults to ``xml``, which is the common format for .rdf files you'll find on the net. + +See also + +.. automethod:: rdflib.graph.Graph.parse + +Other parsers supported by rdflib +--------------------------------- + +.. automodule:: rdflib.syntax.parsers + +.. automodule:: rdflib.syntax.parsers.n3p + +.. automodule:: rdflib.syntax.parsers.N3Parser + +.. autoclass:: rdflib.syntax.parsers.N3Parser.N3Parser + :members: + +.. automodule:: rdflib.syntax.parsers.NTParser + +.. autoclass:: rdflib.syntax.parsers.NTParser.NTParser + :members: + +.. automodule:: rdflib.syntax.parsers.ntriples + +.. autoclass:: rdflib.syntax.parsers.ntriples.NTriplesParser + :members: + +.. automodule:: rdflib.syntax.parsers.RDFXMLParser + +.. autoclass:: rdflib.syntax.parsers.RDFXMLParser.RDFXMLParser + :members: + +.. automodule:: rdflib.syntax.parsers.TriXParser + +.. autoclass:: rdflib.syntax.parsers.TriXParser.TriXParser + :members: + +.. .. automodule:: rdflib.syntax.parsers.RDFaParser +.. :members: +.. +.. .. autoclass:: rdflib.syntax.parsers.RDFaParser.RDFaParser +.. :members: +.. + +Introduction to using SPARQL to query an rdflib graph +----------------------------------------------------- + +Create an Rdflib Graph +^^^^^^^^^^^^^^^^^^^^^^ + +You might parse some files into a new graph (_`Introduction to parsing RDF into rdflib graphs`) or open an on-disk rdflib store. + +.. code-block:: python + + from rdflib.graph import Graph + g = Graph() + g.parse("http://bigasterisk.com/foaf.rdf") + g.parse("http://www.w3.org/People/Berners-Lee/card.rdf") + +LiveJournal produces FOAF data for their users, but they seem to use ``foaf:member_name`` for a person's full name. For this demo, I made ``foaf:name`` act as a synonym for ``foaf:member_name`` (a poor man's one-way ``owl:equivalentProperty``): + +.. code-block:: python + + from rdflib.namespace import Namespace + FOAF = Namespace("http://xmlns.com/foaf/0.1/") + g.parse("http://danbri.livejournal.com/data/foaf") + [g.add((s, FOAF['name'], n)) for s,_,n in g.triples((None, FOAF['member_name'], None))] + +Run a Query +^^^^^^^^^^^ + +.. code-block:: python + + for row in g.query( + """SELECT ?aname ?bname + WHERE { + ?a foaf:knows ?b . + ?a foaf:name ?aname . + ?b foaf:name ?bname . + }""", + initNs=dict(foaf=Namespace("http://xmlns.com/foaf/0.1/"))): + print "%s knows %s" % row + +The results are tuples of values in the same order as your SELECT arguments. + +.. code-block:: text + + Timothy Berners-Lee knows Edd Dumbill + Timothy Berners-Lee knows Jennifer Golbeck + Timothy Berners-Lee knows Nicholas Gibbins + Timothy Berners-Lee knows Nigel Shadbolt + Dan Brickley knows binzac + Timothy Berners-Lee knows Eric Miller + Drew Perttula knows David McClosky + Timothy Berners-Lee knows Dan Connolly + ... + +Namespaces +^^^^^^^^^^ +The :meth:`Graph.parse` :keyword:`initNs` argument is a dictionary of namespaces to be expanded in the query string. In a large program, it's common to use the same dict for every single query. You might even hack your graph instance so that the ``initNs`` arg is already filled in. + +If someone knows how to use the empty prefix (e.g. "?a :knows ?b"), please write about it here and in the :meth:`Graph.query` docs. + +*ewan klein provides the answer, use BASE to set a default namespace ...* + +.. code-block:: sparql + + BASE <http://xmlns.com/foaf/0.1/> + +Bindings +^^^^^^^^ + +Just like with SQL queries, it's common to run the same query many times with only a few terms changing. rdflib calls this ``initBindings``: + +.. code-block:: python + + FOAF = Namespace("http://xmlns.com/foaf/0.1/") + ns = dict(foaf=FOAF) + drew = URIRef('http://bigasterisk.com/foaf.rdf#drewp') + for row in g.query("""SELECT ?name + WHERE { ?p foaf:name ?name }""", + initNs=ns, initBindings={'?p' : drew}): + print row + +Output: + +.. code-block:: python + + (rdflib.Literal('Drew Perttula', language=None, datatype=None),) + +.. automethod:: rdflib.graph.Graph.query + +Store operations +---------------- + +Example code to create a MySQL triple store, add some triples, and serialize the resulting graph. + +.. code-block:: python + + import rdflib + from rdflib.graph import ConjunctiveGraph as Graph + from rdflib import plugin + from rdflib.store import Store, NO_STORE, VALID_STORE + from rdflib.namespace import Namespace + from rdflib.term import Literal + from rdflib.term import URIRef + + default_graph_uri = "http://rdflib.net/rdfstore" + configString = "host=localhost,user=username,password=password,db=rdfstore" + + # Get the mysql plugin. You may have to install the python mysql libraries + store = plugin.get('MySQL', Store)('rdfstore') + + # Open previously created store, or create it if it doesn't exist yet + rt = store.open(configString,create=False) + if rt == NO_STORE: + # There is no underlying MySQL infrastructure, create it + store.open(configString,create=True) + else: + assert rt == VALID_STORE,"There underlying store is corrupted" + + # There is a store, use it + graph = Graph(store, identifier = URIRef(default_graph_uri)) + + 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.add((rdflib['pic:1'], rdflib['name'], Literal('Jane & Bob'))) + graph.add((rdflib['pic:2'], rdflib['name'], Literal('Squirrel in Tree'))) + graph.commit() + + print "Triples in graph after add: ", len(graph) + + # display the graph in RDF/XML + print graph.serialize() diff --git a/docs/graph_merging.rst b/docs/graph_merging.rst new file mode 100644 index 00000000..51c40ff5 --- /dev/null +++ b/docs/graph_merging.rst @@ -0,0 +1,157 @@ +.. _graph_merging: Procedures to merge graphs + +============== +Merging graphs +============== + +Example 1 +--------- + +.. code-block:: python + + import logging + + _logger = logging.getLogger(redfoot_current) + + from rdflib.Graph import Graph + + f = file(args[0], "r") + + pairs = [] + for line in f: + try: + line = line.strip() + source, destination = line.split(" ") + except ValueError, e: + _logger.info("Could not split '%s'" % line) + continue + source, destination = URIRef(source).abstract(), URIRef(destination).abstract() + if destination.startswith(source): + _logger.info("Skipping %s->%s to avoid inf. loop" % (source, destination)) + else: + pairs.append((source, destination)) + + f.close() + + nothing_merged = True + + # merge contexts + for context in list(redfoot.contexts()): + for OLD, NEW in pairs: + if OLD in context.identifier: + if isinstance(context.identifier, URIRef): + identifier = URIRef(context.identifier.replace(OLD, NEW)) + elif isinstance(context.identifier, BNode): + identifier = BNode(context.identifier.replace(OLD, NEW)) + else: + _logger.warning( + "Unexpected identifier type. Skipping context '%s'" \ + % context.identifier) + continue + new_context = Graph(store=redfoot.store, + identifier=identifier, + namespace_manager=redfoot) + nothing_merged = False + else: + new_context = context + + for s, p, o in context: + ss, pp, oo = s, p, o + if isinstance(s, URIRef) and OLD in s: + ss = URIRef(s.replace(OLD, NEW)) + if isinstance(p, URIRef) and OLD in p: + pp = URIRef(p.replace(OLD, NEW)) + if isinstance(o, URIRef) and OLD in o: + oo = URIRef(o.replace(OLD, NEW)) + if (ss, pp, oo)!=(s, p, o) or context!=new_context: + nothing_merged = False + context.remove((s, p, o)) + new_context.add((ss, pp, oo)) + + if new_context!=context: + redfoot.remove_context(context.identifier) + + if nothing_merged: + _logger.warning("nothing merged.") + +Example 2 +--------- + +.. code-block:: python + + ''' + Tutorial 9 - demonstrate graph operations + + (not really quite graph operations since rdflib cannot merge models like + Jena, but this examples shows you can load two different RDF files and + rdflib will merge the two together into one model) + + Copyright (C) 2005 Sylvia Wong <sylvia at whileloop dot org> + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + ''' + + from rdflib.URIRef import URIRef + from rdflib.Literal import Literal + from rdflib.BNode import BNode + from rdflib.Namespace import Namespace + + # Import RDFLib's default TripleStore implementation. + from rdflib.TripleStore import TripleStore + + inputFileName1 = 'vc-db-3.rdf' + inputFileName2 = 'vc-db-4.rdf' + + store = TripleStore() + store.load(inputFileName1) + store.load(inputFileName2) + + print store.serialize() + +vc-db-3.rdf +^^^^^^^^^^^ + +.. code-block:: xml + + <rdf:RDF + xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' + xmlns:vCard='http://www.w3.org/2001/vcard-rdf/3.0#'> + + <rdf:Description rdf:about="http://somewhere/JohnSmith/"> + <vCard:FN>John Smith</vCard:FN> + <vCard:N rdf:parseType="Resource"> + <vCard:Family>Smith</vCard:Family> + <vCard:Given>John</vCard:Given> + </vCard:N> + </rdf:Description> + </rdf:RDF> + +vc-db-4.rdf +^^^^^^^^^^^ + +.. code-block:: xml + + <rdf:RDF + xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' + xmlns:vCard='http://www.w3.org/2001/vcard-rdf/3.0#'> + + <rdf:Description rdf:about="http://somewhere/JohnSmith/"> + <vCard:FN>John Smith</vCard:FN> + <vCard:EMAIL rdf:parseType="Resource"> + <rdf:type rdf:resource="http://www.w3.org/2001/vcard-rdf/3.0#internet"/> + <rdf:value>John@somewhere.com</rdf:value> + </vCard:EMAIL> + </rdf:Description> + </rdf:RDF> diff --git a/docs/graph_utilities.rst b/docs/graph_utilities.rst new file mode 100644 index 00000000..231cad21 --- /dev/null +++ b/docs/graph_utilities.rst @@ -0,0 +1,112 @@ +.. _graph_utilities: + +=============== +Graph utilities +=============== + + +Graphs as Iterators +------------------- + +RDFLib graphs also override :meth:`__iter__` in order to support iteration over the contained triples: + +.. code-block:: python + + for subject,predicate,obj_ in someGraph: + assert (subject,predicate,obj_) in someGraph, "Iterator / Container Protocols are Broken!!" + +Set Operations on RDFLib Graphs +------------------------------- + +:meth:`__iadd__` and :meth:`__isub__` are overridden to support adding and subtracting Graphs to/from each other (in place): + +* G1 += G1 +* G2 -= G2 + +Basic Triple Matching +--------------------- + +RDFLib graphs support basic triple pattern matching with a :meth:`triples` function. + +.. automethod:: rdflib.graph.Graph.triples + +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. + +Managing Triples +---------------- + +Adding Triples +^^^^^^^^^^^^^^ +Triples can be added in two ways: + +* They may be added with with the :meth:`parse` function. + + .. automethod:: rdflib.graph.Graph.parse + + The first argument can be a *source* of many kinds, but the most common is the serialization (in various formats: RDF/XML, Notation 3, NTriples of an RDF graph as a string. The :keyword:`format` parameter is one of ``n3``, ``xml``, or ``ntriples``. :keyword:`publicID` is the name of the graph into which the RDF serialization will be parsed. +* Triples can also be added with the :meth:`add` function: + + .. automethod:: rdflib.graph.Graph.add + +Removing Triples +^^^^^^^^^^^^^^^^ + +Similarly, triples can be removed by a call to :meth:`remove`: + +.. automethod:: rdflib.graph.Graph.remove + + +RDF Literal Support +------------------- + +RDFLib Literals essentially behave like unicode characters with an XML Schema datatype or language attribute. The class provides a mechanism to both convert Python literals (and their built-ins such as time/date/datetime) into equivalent RDF Literals and (conversely) convert Literals to their Python equivalent. There is some support of considering datatypes in comparing Literal instances, implemented as an override to :meth:`__eq__`. This mapping to and from Python literals is achieved with the following dictionaries: + +.. code-block:: python + + PythonToXSD = { + basestring : (None,None), + float : (None,XSD_NS+u'float'), + int : (None,XSD_NS+u'int'), + long : (None,XSD_NS+u'long'), + bool : (None,XSD_NS+u'boolean'), + date : (lambda i:i.isoformat(),XSD_NS+u'date'), + time : (lambda i:i.isoformat(),XSD_NS+u'time'), + datetime : (lambda i:i.isoformat(),XSD_NS+u'dateTime'), + } + +Maps Python instances to WXS datatyped Literals + +.. code-block:: python + + XSDToPython = { + XSD_NS+u'time' : (None,_strToTime), + XSD_NS+u'date' : (None,_strToDate), + XSD_NS+u'dateTime' : (None,_strToDateTime), + XSD_NS+u'string' : (None,None), + XSD_NS+u'normalizedString' : (None,None), + XSD_NS+u'token' : (None,None), + XSD_NS+u'language' : (None,None), + XSD_NS+u'boolean' : (None, lambda i:i.lower() in ['1','true']), + XSD_NS+u'decimal' : (float,None), + XSD_NS+u'integer' : (long ,None), + XSD_NS+u'nonPositiveInteger' : (int,None), + XSD_NS+u'long' : (long,None), + XSD_NS+u'nonNegativeInteger' : (int, None), + XSD_NS+u'negativeInteger' : (int, None), + XSD_NS+u'int' : (int, None), + XSD_NS+u'unsignedLong' : (long, None), + XSD_NS+u'positiveInteger' : (int, None), + XSD_NS+u'short' : (int, None), + XSD_NS+u'unsignedInt' : (long, None), + XSD_NS+u'byte' : (int, None), + XSD_NS+u'unsignedShort' : (int, None), + XSD_NS+u'unsignedByte' : (int, None), + XSD_NS+u'float' : (float, None), + XSD_NS+u'double' : (float, None), + XSD_NS+u'base64Binary' : (base64.decodestring, None), + XSD_NS+u'anyURI' : (None,None), + } + +Maps WXS datatyped Literals to Python. This mapping is used by the :meth:`toPython` method defined on all Literal instances. + + diff --git a/docs/graphs_bnodes.rst b/docs/graphs_bnodes.rst new file mode 100644 index 00000000..aa057336 --- /dev/null +++ b/docs/graphs_bnodes.rst @@ -0,0 +1,475 @@ +.. _graphs_bnodes: + +==================================== +Graphs, Named Graphs and Blank Nodes +==================================== + +Vin's question +============== + +Clarifying the query more precisely: + +.. code-block:: pycon + + >>> from rdflib.Graph import Graph, ConjunctiveGraph + >>> from rdflib import URIRef + +[1] + +.. code-block:: pycon + + >>> graph = Graph('MySQL', identifier = URIRef('http://www.example.com')) + >>> graph.identifier + rdflib.URIRef('http://www.example.com') + +[2] + +.. code-block:: pycon + + >>> graph1 = ConjunctiveGraph('MySQL', identifier = URIRef('http://www.example.com')) + >>> graph1.identifier + rdflib.BNode('VLjQILCh3') + +[3] + +.. code-block:: pycon + + >>> graph1 = ConjunctiveGraph('MySQL', identifier = URIRef('http://www.example.com')) + >>> graph1.identifier + rdflib.BNode('VLjQILCh4') + +In [1] when I mention the Graph identifier the return is a persistent +URIRef (i.e. it can be used out of the current model as well) which +gives me a unique name for the graph and now I am free to use it in +other model as well - may be it can be used for merging graphs. Where +as in [2] and [3] when I mention Graph identifier the return is a +BNode which changes values every time we invoke it (and hence BNodes +have local scope and are not good for using outside the model). My +query was simply to know why the Model "identifier" is giving BNode in +[2] comparing to a persistent URI in case [1]? In ConjunctiveGraph, +identifier is inherited from the Graph class. + +The discourse +============= + +This sparql-dev discussion airs some of the issues ... + +0016: Nuutti Kotivuori +---------------------- +http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0016.html + +This isn't exactly a SPARQL question, but it is very closely +related. I will first outline the question context. + +Assume an RDF statement store, which has a mechanism for tracking +statement origin (scope, context, graph, source whatever). Many of the +statements have a distinct origin, or source graph, they were imported +from. But there are also those which either seemingly have no origin, +or the origin is not known. The origin of these statements have to be +handled somehow. We'll come to the specific choices later on. + +This statement store offers a SPARQL query interface into it. The +facilities for querying named graphs in SPARQL would obviously be used +to query the different origins in the store. But there are two things +to decide. First, how should statements without an origin be accessed +in SPARQL? There are several choices on this, which I will outline +below. And related to the first one, second, what should the default +graph be for the queries if none is given explicitly. + +I will list a few possibilities and mention the problems and benefits +that seem to result from them as a basis for discussion. + + 1. Unknown origin is a distinct node, but separate from all uris, + blank nodes or literals. The default graph for the query is the + graph of the unknown origin nodes. + + - Separation of identifier spaces, no fear of any overlap. The + graph of statements with unknown origin is separate from any + named graph. + + - Since there is no way to represent the unknown origin in SPARQL + syntax, the default graph is the only way to access the nodes in + that graph. + + - The nodes in the unknown origin graph are not matched by any + graph query, since the name of the graph could not be returned + reasonably. That is: + + .. code-block:: sparql + + SELECT ?g ?s ?o ?p + WHERE { GRAPH ?g { ?s ?p ?o } } + + cannot return ?g for the unknown origin graph. + + 2. Unknown origin is a distinct node, as above. The default graph is + the RDF merge of all graphs in the store, including the statements + with an unknown origin. + + - The problems above. + + - In addition, there is no way to select nodes that explicitly + have an unknown origin. (Or is there? Could one match all the + statements for which there is no graph with the same statement? + In any case, this would be quite contorted.) + + 3. Unknown origin is represented by a distinct blank node; that is, + every statement has it's own blank node as the graph name, which + is not shared with any of the other statements. The default graph + is the RDF merge of all graphs in the store, including the + statements with an unknown origin. + + - This is probably closest to accurate modelling of the + situation. We know every statement has an origin, we just don't + know what it is - a situation commonly modelled with a blank + node. Also, we don't know which statements might share an + origin, so until we know better, we make them all distinct. + + - The origin of the statements is nicely queryable with SPARQL + queries and every statement has an origin, even if unknown. + + - Queries which specify several statements from a single graph + will not match the statements with unknown origins as it cannot + be confirmed that they would be from the same graph. + + - There is no way to match the origin of a single statement as + there is no way to match a certain blank node explicitly. The + current SPARQL treats it as an open variable(?). + + - There is no way to explicitly match statements that have an + unknown origin, since the origins are just distinct blank nodes. + + - Possibly hard to implement, because of the number of distinct + blank nodes. + + 4. Unknown origin is represented by a singleton blank node; that is, + every statement with an unknown origin shares one single blank + node as the graph name. The default graph is the RDF merge of all + graphs in the store. + + - Lumps all statements with an unknown origin under a single named + graph. Queries which match several statements from a single + graph will match statement sets from unknown origin as well. + + - The origin of the statements is nicely queryable with SPARQL + queries and every statement has an origin, even if unknown. + + - There is no way to explicitly match statements that have an + unknown origin, since the origin is a single blank node. If the + application provided a magic type for this blank node (_:x a + rdfx:UnknownOrigin), this could be matched with: + + .. code-block:: sparql + + SELECT ?s ?o ?p + WHERE { ?g a rdfx:UnknownOrigin . + GRAPH ?g { ?s ?o ?p } } + + But this again is quite contorted. (The same could be applied to + the third case as well, but the implementation of that would be + really tricky to be effecient.) + + 5. Unknown origin is represented by a singleton blank node as + above. The default graph is the singleton blank node of unknown + origin. + + - Mostly as above, but in the common case, explictly matching + statements that have an unknown origin would be easy in just + matching the statements from the default graph. + + 6. Unknown origin is represented by a well known URI that is shared + universally. The default graph is the RDF merge of all graphs in + the store. + + - Somewhat incorrectly asserts that the statements have a certain + origin, even though we don't know the origin. + + - The origin of the statements is nicely queryable with SPARQL. + + - Statements with an unknown origin can be easily explicitly + matched by comparing them against the well known URI. + + - Assigns a special meaning to an URI. + + - Hard to coordinate with a number of people implementing similar + solutions if not standardized. + +Some other variants of the above were omitted, since their problems +and benefits are easily reasoned. + +On irc, 'chimenzie' outlined the problem as such: + +17:35 chimezie:#swig => Hmm.. well, seems like what is missing is a good + definition of a 'name for nodes that don't have an explicit context' +17:36 chimezie:#swig => or rather 'a name for the context of nodes that aren't + assigned to a context explicitely' + +So, I'm out for some input on what might be the sanest route to +through this. + +TIA, +-- Naked + +0018: Richard Cyganiak +---------------------- + +http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0018.html + +Hi Nuutti, + +Without having thought through all the consequences ... + +Some of your options are not really possible with named graphs +because graphs need to be *named*, that is, the name *must* be a URI +and not a blank node. Blank nodes are always scoped to a single +graph, and using blank nodes as graph labels would make it impossible +to refer to a named graph from the outside world. This excludes #3 +and #4. + +In SPARQL, the default graph is structurally and syntactically +handled so differently from the other graphs that I wouldn't consider +using it for the same kind of data. That is, I tend to reserve the +default graph for metadata or the merge of all named graphs. This +excludes #1 and #5. + +#6 has the problem of re-using a single URI for many different things +-- the statements of unknown origin in Alice's store, *and* the +statements of unknown origin in Bob's store. While workable, this is +not an elegant solution. + +I would suggest that Alice and Bob each mint a new URI for the graph +containing the statements of unknown origin *in their own store*. Or +mint a new URI to hold each individual statement, or anything in +between. Since the owner of a URI gets to say what the meaning of the +URI is, they can declare that this chunk of URI space is reserved for +this purpose (assuming Alice and Bob each own a chunk of URI space). + +I wonder why you discounted this solution? + +I also question the existence of "statements without a known origin". +They surely didn't just pop up magically inside your triple store, +eh? I guess it's more like "statements whose origin I don't want to +model". + + +0020: Chimezie Ogbuji +--------------------- + +http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0020.html + +On Wed, 13 Sep 2006, Richard Cyganiak wrote: + +.. code-block:: text + + > Hi Nuutti, + > + > Without having thought through all the consequences ... + > + > Some of your options are not really possible with named graphs because graphs + > need to be *named*, that is, the name *must* be a URI and not a blank node. + +I don't agree. What's the source of this assertion? I think the core +issue here is that there is *no* concensus formalism for named graphs WRT RDF, yet SPARQL is dependent +on an RDF model that supports named graphs. If there is one, please +point me to it, because I ran across the same problem when constructing +programming APIs for named graphs. The only formalism I know of is Graham Kyle, John McCarthy's work [1]. + +.. code-block:: text + + > Blank nodes are always scoped to a single graph, and using blank nodes as + > graph labels would make it impossible to refer to a named graph from the + > outside world. This excludes #3 and #4. + +Well, Blank nodes used within a graph can't be referred to +directly but they can still be matched by SPARQL - doesn't make them any +less useful. The problem isn't the use of Blank nodes for graph names but +a the lack of a mechanism [2] to match the graph name(s) associated with a +node. Given how closely coupled SPARQL is with (admittedly informal) +named graph semantics, I would expect to be able to answer questions such as: + +"What are the graph names in which all the statements about <someIRI> are +asserted?" + +Assuming I could answer this question, then graph labels that are blank +nodes become as accessible as blank nodes asserted *within* a graph and it +becomes a question of what is the appropriate use for a bnode as a graph +label? + +If BNodes are used for existential assertions about nodes, why wouldn't +they be used as existential assertions about graphs? And if there is +some semantic consequence, it furthers the argument that the formalisms +for named graphs should be well articulated before they are tightly integrated into a query language. + +.. code-block:: text + + > I would suggest that Alice and Bob each mint a new URI for the graph + > containing the statements of unknown origin *in their own store*. Or mint a + > new URI to hold each individual statement, or anything in between. Since the + > owner of a URI gets to say what the meaning of the URI is, they can declare + > that this chunk of URI space is reserved for this purpose (assuming Alice and + > Bob each own a chunk of URI space). + > + > I wonder why you discounted this solution? + +I don't think it's an elegant solution when we already have the means +(within 'vanilla' RDF Model Theory) to express +existential assertions - which is exactly the scenario here. + +If a graph label is nothing but a name associated with a set of graphs, +why should it not behave the same as the name associated with a node +within a graph? + +.. code-block:: text + + > I also question the existence of "statements without a known origin". They + > surely didn't just pop up magically inside your triple store, eh? I guess + > it's more like "statements whose origin I don't want to model". + +How different is this from "nodes whose names I don't care to maintain / +model?" + +[1] http://ninebynine.org/RDFNotes/UsingContextsWithRDF.html#xtocid-6303976 + +[2] http://copia.ogbuji.net/blog/2006-07-14/querying-named-rdf-graph-aggregate + +0023: Nuutti Kotivuori +---------------------- + +http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0023.html + +Chimezie Ogbuji wrote: + +.. code-block:: text + + > I don't agree. What's the source of this assertion? I think the + > core issue here is that there is *no* concensus formalism for named + > graphs WRT RDF, yet SPARQL is dependent on an RDF model that + > supports named graphs. If there is one, please point me to it, + > because I ran across the same problem when constructing programming + > APIs for named graphs. The only formalism I know of is Graham Kyle, + > John McCarthy's work [1]. + +Well, one thing which would help me in this is a survey of the +approaches other people have taken when doing these things. + +I think I know the situation with Redland librdf, when I read the code +last, but I'm not sure if I'm correct. + +I think that in librdf, there are statements explicitly without a +context. In SPARQL queries, the default graph is the merge of all +statements in the store, with or without a context. Queries which +explicitly match the graph in a variable never match statements +without a context. And so there is no easy way to match all the +statements without a context only. + +I'd like to know atleast how rdflib and Jena (with whatever extensions +that this requires) solve this issue. + +-- Naked + +0027: Chimezie Ogbuji +--------------------- + +http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0027.html + +RDFLib has two API's: a Store API and a Graph API. Every Graph (there +are several kinds: QuotedGraphs, ConjunctiveGraphs, Named Graphs, +AggregateGraphs, ..) is associated with a Store instance and an +identifier. The identifiers are either a Blank Node or a URI. + +All the Store API's take a fourth parameter which is the containing Graph +(even the :meth:`__len__` method). So, theoretically the Store can choose to +persist RDF triples in a flat space (i.e., vanilla RDF model) and disregard the fourth parameter or use +the identifier of the containing graph to partition its persistence space +accordingly - it can even choose to partition formulae seperately (to +support N3 persistence) from the kind of Graph passed down to it (it will +receive QuotedGraph instances as the fourth parameter in this case). + +The :meth:`Store.triples` method returns a generator of (s,p,o), graphInst so each +Store implementation is expected to be able to associate each triple with +a containing graph (or None if the Store chooses to persist triples in a +flat space). + +The Graph API's do most of the leg work of named graph aggregation. +:class:`ConjunctiveGraph` is an (unamed) aggregation of all the named graphs within +the Store. It has a 'default' graph, whose name is associated with the +ConjunctiveGraph throughout its life. All methods work against this +default graph. Its constructor can take an identifier to use as the name +of this 'default' graph or it will assign a BNode. In practice (at least +how \*I\* use RDFLib), I instantiate a ConjunctiveGraph if I want to add +triples to the Store but don't care to mint a URI for the graph (the +scenario which triggered this thread). These triples can still be +addressed. + +:class:`ReadOnlyGraphAggregate` is a subset of the :class:`ConjunctiveGraph` where the names +of the graphs it provides an aggregate view for are passed on in the +constructor - this is how a SPARQL query with multiple FROM NAMED is +supported. + +:class:`QuotedGraphs` are meant to implement Notation 3 formulae. They are +associated with a required identifier that the N3 parser must provide in +order to maintain consistent formulae identification for scenarios such as +implication and such. + +The default dataset for SPARQL queries is equivalent to the Graph instance +on which the query is dispatched. If the :meth:`query` method is called on a +:class:`ConjunctiveGraph`, the default dataset is the entire Store, if it's a named +graph it's the named graph. + +This setup supports: + +- Flat space of triples +- Named Graph partitioning +- Notation 3 persistence + +0028: Nuutti Kotivuori +---------------------- + +http://lists.w3.org/Archives/Public/public-sparql-dev/2006JulSep/0028.html + +Chimezie Ogbuji wrote: + +.. code-block:: text + + > The Graph API's do most of the leg work of named graph + > aggregation. ConjunctiveGraph is an (unamed) aggregation of all the + > named graphs within the Store. It has a 'default' graph, whose name + > is associated with the ConjunctiveGraph throughout it's life. All + > methods work against this default graph. Its constructor can take an + > identifier to use as the name of this 'default' graph or it will + > assign a BNode. In practice (at least how *I* use RDFLib), I + > instanciate a ConjunctiveGraph if I want to add triples to the Store + > but don't care to mint a URI for the graph (the scenario which + > triggered this thread). These triples can still be addressed. + +Okay, in the context of this discussion, what RDFLib does is that +every time a ConjunctiveGraph is instantiated, it creates a new blank +node and uses that throughout the life of the ConjunctiveGraph +object. And the default graph is the merge of all graphs in the store. + +So triples without an origin will be associated with a blank node, +which is shared between added triples, but distinct between different +ConjunctiveGraph objects. This probably coincides rather nicely with +most usages of the API. Single "sessions" of manipulating nodes will +have the blank node origin shared. + +And the possible problems are mostly what was already mentioned +earlier about an approach like this. The blank node identities might +not coincide with the actual separateness of the sources graphs - +making a query which matches several statements out of a single graph +might not be too meaningful for these blank nodes. It is difficult to +query only nodes which have no specific origin. And since the graph +name is a blank node, there is no way to explicitly specify the graph +name to be specific blank node, as the SPARQL syntax doesn't allow +this. + +-- Naked + +References +---------- + +Two posts by Pat Hayes, recommended by Andy Seaborne. + +http://www.ihmc.us/users/phayes/RDFGraphSyntax.html + +http://lists.w3.org/Archives/Public/public-rdf-dawg/2006JulSep/0153.html diff --git a/docs/graphterms.rst b/docs/graphterms.rst new file mode 100644 index 00000000..dc3b0af8 --- /dev/null +++ b/docs/graphterms.rst @@ -0,0 +1,25 @@ +.. _graphterms: + +=============== +RDF Graph Terms +=============== + +The RDFLib classes listed below model RDF `terms`__ in a graph and inherit from a common `Identifier`_ class, which extends Python unicode. Instances of these are nodes in an RDF graph. + +.. _Seq: +.. autoclass:: rdflib.graph.Seq + :members: + +.. _QuotedGraph: +.. autoclass:: rdflib.graph.QuotedGraph + +.. _ReadOnlyGraphAggregate: +.. autoclass:: rdflib.graph.ReadOnlyGraphAggregate + +.. _Variable: +.. automodule:: rdflib.term +.. autoclass:: rdflib.term.Variable + + +.. __: univrdfstore.html#Terms +.. _Identifier: http://www.w3.org/2002/07/rdf-identifer-terminology/
\ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 00000000..b8d2a93b --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,52 @@ +.. rdflib documentation documentation master file, created by sphinx-quickstart on Wed May 14 06:45:33 2008. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +========== +rdflib 2.5 +========== + +Introduction +============ +RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information. The library contains an RDF/XML parser/serializer that conforms to the RDF/XML Syntax Specification (Revised) . The library also contains both in-memory and persistent Graph backends. It is being developed by a number of contributors and was created by Daniel Krech who continues to maintain it. + +RDFLib's use of various Python idioms makes them an appropriate way to introduce it to a Python programmer who hasn't used it before. + +RDFLib graphs redefine certain built-in Python methods in order to behave in a predictable way. RDFLib graphs emulate container types and are best thought of as a set of 3-item triples + +.. code-block:: text + + [ + (subject, predicate, object), + (subject1, predicate1, object1), + ... + (subjectN, predicateN, objectN) + ] + +RDFLib graphs are not sorted containers; they have ordinary set operations (e.g. :meth:`~rdflib.Graph.add` to add a triple) plus methods that search triples and return them in arbitrary order. + +Contents +======== +.. toctree:: + :maxdepth: 2 + + gettingstarted + univrdfstore + graphterms + namespace_utilities + graph_utilities + persistence + persisting_n3_terms + graph_merging + graphs_bnodes + assorted_examples + addons + Modules <modules/index> + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/docs/index.rst.txt b/docs/index.rst.txt new file mode 100644 index 00000000..1d6c56ab --- /dev/null +++ b/docs/index.rst.txt @@ -0,0 +1,20 @@ +.. rdflib documentation master file, created by + sphinx-quickstart on Fri May 15 15:03:54 2009. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to rdflib's documentation! +================================== + +Contents: + +.. toctree:: + :maxdepth: 2 + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/docs/modules/graphs/conjunctive_graph.rst b/docs/modules/graphs/conjunctive_graph.rst new file mode 100644 index 00000000..a0eefdb2 --- /dev/null +++ b/docs/modules/graphs/conjunctive_graph.rst @@ -0,0 +1,15 @@ +:mod:`rdflib.Graph.ConjunctiveGraph` -- ConjunctiveGraph class definition +========================================================================= + +================= +Conjunctive Graph +================= + +.. automodule:: rdflib.graph + + +Module Contents +--------------- + +.. autoclass:: rdflib.graph.ConjunctiveGraph + :members: diff --git a/docs/modules/graphs/graph.rst b/docs/modules/graphs/graph.rst new file mode 100644 index 00000000..962489bd --- /dev/null +++ b/docs/modules/graphs/graph.rst @@ -0,0 +1,12 @@ +:mod:`rdflib.Graph.Graph` -- Graph class definition +=================================================== + +===== +Graph +===== + +Module Contents +--------------- + +.. autoclass:: rdflib.graph.Graph + :members: diff --git a/docs/modules/graphs/index.rst b/docs/modules/graphs/index.rst new file mode 100644 index 00000000..b66a5a8e --- /dev/null +++ b/docs/modules/graphs/index.rst @@ -0,0 +1,22 @@ +.. _graphs: + +======= +Graphs +======= + +RDFLib defines the following kinds of Graphs: + +* 'Graph'(_''store''_,_''identifier''_) +* 'QuotedGraph'(_''store''_,_''identifier''_) +* 'ConjunctiveGraph'(_''store''_,_''default''_''identifier''_= ''None'') + +A Conjunctive Graph is the most relevant collection of graphs that are considered to be the boundary for closed world assumptions. This boundary is equivalent to that of the store instance (which is itself uniquely identified and distinct from other instances of :class:`Store` that signify other Conjunctive Graphs). It is equivalent to all the named graphs within it and associated with a ``_default_`` graph which is automatically assigned a :class:`BNode` for an identifier - if one isn't given. + +.. automodule:: rdflib.graph + +.. toctree:: + :maxdepth: 2 + + graph + conjunctive_graph + ../nodes/quoted_graph
\ No newline at end of file diff --git a/docs/modules/index.rst b/docs/modules/index.rst new file mode 100644 index 00000000..75eaec1c --- /dev/null +++ b/docs/modules/index.rst @@ -0,0 +1,15 @@ +.. _modules: + +======= +Modules +======= + +Contents: +========= + +.. toctree:: + :maxdepth: 3 + + nodes/index + graphs/index + others diff --git a/docs/modules/nodes/bnode.rst b/docs/modules/nodes/bnode.rst new file mode 100644 index 00000000..587f31a6 --- /dev/null +++ b/docs/modules/nodes/bnode.rst @@ -0,0 +1,10 @@ +:mod:`rdflib.term.BNode` -- RDF blank node functions +==================================================== + +.. automodule:: rdflib.term + +Module Contents +--------------- + +.. autoclass:: rdflib.term.BNode + :members: diff --git a/docs/modules/nodes/identifier.rst b/docs/modules/nodes/identifier.rst new file mode 100644 index 00000000..bbd0b108 --- /dev/null +++ b/docs/modules/nodes/identifier.rst @@ -0,0 +1,10 @@ +:mod:`rdflib.term.Identifier` -- Identifier class definition +============================================================ + +.. automodule:: rdflib.term + +Module Contents +--------------- + +.. autoclass:: rdflib.term.Identifier + :members: diff --git a/docs/modules/nodes/index.rst b/docs/modules/nodes/index.rst new file mode 100644 index 00000000..b9fa6a15 --- /dev/null +++ b/docs/modules/nodes/index.rst @@ -0,0 +1,22 @@ +.. _nodes: + +======= +Nodes +======= + +The RDFLib classes listed below model RDF `terms`__ in a graph and inherit from a common `Identifier`_ class, which extends Python unicode. Instances of these are nodes in an RDF graph. + +.. toctree:: + :maxdepth: 2 + + node + identifier + bnode + uriref + literal + variable + quoted_graph + + +.. __: univrdfstore.html#Terms +.. _Identifier: http://www.w3.org/2002/07/rdf-identifer-terminology/ diff --git a/docs/modules/nodes/literal.rst b/docs/modules/nodes/literal.rst new file mode 100644 index 00000000..ad408b9a --- /dev/null +++ b/docs/modules/nodes/literal.rst @@ -0,0 +1,10 @@ +:mod:`rdflib.term.Literal` -- Literal class definition +====================================================== + +.. automodule:: rdflib.term + +Module Contents +--------------- + +.. autoclass:: rdflib.term.Literal + :members: diff --git a/docs/modules/nodes/node.rst b/docs/modules/nodes/node.rst new file mode 100644 index 00000000..90fd2c5d --- /dev/null +++ b/docs/modules/nodes/node.rst @@ -0,0 +1,10 @@ +:mod:`rdflib.term.Node` -- Node class definition +================================================ + +.. automodule:: rdflib.term + +Module Contents +--------------- + +.. autoclass:: rdflib.term.Node + :members: diff --git a/docs/modules/nodes/quoted_graph.rst b/docs/modules/nodes/quoted_graph.rst new file mode 100644 index 00000000..0d202e23 --- /dev/null +++ b/docs/modules/nodes/quoted_graph.rst @@ -0,0 +1,13 @@ +:mod:`rdflib.graph.QuotedGraph` -- Quoted graphs +================================================ + +RDFLib graphs support an additional extension of RDF semantics for formulae. For the academically inclined, Graham Kyles `formal extension`__ is probably a good read. + +.. __: http://ninebynine.org/RDFNotes/UsingContextsWithRDF.html#xtocid-6303976 + +Formulae are represented formally by the :class:`rdflib.Graph.QuotedGraph` class and are disjoint from regular RDF graphs in that their statements are quoted. + +Module Contents +--------------- + +.. autoclass:: rdflib.graph.QuotedGraph diff --git a/docs/modules/nodes/uriref.rst b/docs/modules/nodes/uriref.rst new file mode 100644 index 00000000..672d2b54 --- /dev/null +++ b/docs/modules/nodes/uriref.rst @@ -0,0 +1,12 @@ +:mod:`rdflib.term.URIRef` -- URIRef class definition +==================================================== + +.. automodule:: rdflib.term + + + +Module Contents +--------------- + +.. autoclass:: rdflib.term.URIRef + :members: diff --git a/docs/modules/nodes/variable.rst b/docs/modules/nodes/variable.rst new file mode 100644 index 00000000..651c9a36 --- /dev/null +++ b/docs/modules/nodes/variable.rst @@ -0,0 +1,9 @@ +:mod:`rdflib.term.Variable` -- Variable class definition +======================================================== + +.. automodule:: rdflib.term + +Module Contents +--------------- + +.. autoclass:: rdflib.term.Variable diff --git a/docs/modules/others.rst b/docs/modules/others.rst new file mode 100644 index 00000000..2eb22584 --- /dev/null +++ b/docs/modules/others.rst @@ -0,0 +1,76 @@ +.. _others: Other modules + +============= +Other modules +============= + +Collection +---------- +.. automodule:: rdflib.collection + +.. autoclass:: rdflib.collection.Collection + :members: + +Journal +------- +.. automodule:: rdflib.journal + +.. autoclass:: rdflib.journal.JournalWriter + :members: + +.. autoclass:: rdflib.journal.JournalReader + :members: + +QueryResult +----------- +.. automodule:: rdflib.query.result +.. autoclass:: rdflib.query.result.QueryResult + :members: + +Statement +--------- +.. automodule:: rdflib.term +.. autoclass:: rdflib.term.Statement +.. automethod:: rdflib.term.Statement.__new__ +.. automethod:: rdflib.term.Statement.__reduce__ + +StringInputSource +----------------- +.. automodule:: rdflib.parser +.. autoclass:: rdflib.parser.StringInputSource + :members: + +TextIndex +--------- +.. automodule:: rdflib.textindex +.. autoclass:: rdflib.textindex.TextIndex + :members: + +TripleStore +----------- +.. automodule:: rdflib.TripleStore +.. autoclass:: rdflib.TripleStore.TripleStore + :members: + +URLInputSource +-------------- + +.. autoclass:: rdflib.parser.URLInputSource + :members: + +query +----- +.. automodule:: rdflib.query + +store +----- +.. automodule:: rdflib.store + +sparql +------ +.. automodule:: rdflib.sparql + +syntax +------ +.. automodule:: rdflib.syntax + diff --git a/docs/namespace_utilities.rst b/docs/namespace_utilities.rst new file mode 100644 index 00000000..3a21efcd --- /dev/null +++ b/docs/namespace_utilities.rst @@ -0,0 +1,24 @@ +.. _namespace_utilities: + +=================== +Namespace Utilities +=================== + +RDFLib provides mechanisms for managing Namespaces. In particular, there is a [http://svn.rdflib.net/trunk/rdflib/Namespace.py Namespace] class which takes (as its only argument) the Base URI of the namespace. Fully qualified URIs in the namespace can be constructed by attribute / dictionary access on Namespace instances: + +.. code-block:: pycon + + >>> from rdflib.namespace import Namespace + >>> fuxi = Namespace('http://metacognition.info/ontologies/FuXi.n3#') + >>> fuxi.ruleBase + u'http://metacognition.info/ontologies/FuXi.n3#ruleBase' + >>> fuxi['ruleBase'] + u'http://metacognition.info/ontologies/FuXi.n3#ruleBase' + +.. automodule:: rdflib.namespace + +Contents +-------- + +.. autoclass:: rdflib.namespace.Namespace + :members:
\ No newline at end of file diff --git a/docs/persistence.rst b/docs/persistence.rst new file mode 100644 index 00000000..76a4cb1e --- /dev/null +++ b/docs/persistence.rst @@ -0,0 +1,26 @@ +.. _persistence: + +=========== +Persistence +=========== + + +RDFLib provides an abstracted Store API for persistence of RDF and Notation 3. The :class:`Graph` class works with instances of this API (as the first argument to its constructor) for triple-based management of an RDF store including: garbage collection, transaction management, update, pattern matching, removal, length, and database management (:meth:`open` / :meth:`close` / :meth:`destroy`) . Additional persistence mechanisms can be supported by implementing this API for a different store. + +Currently supported databases: + +* MySQL +* SQLite +* Berkeley DB +* Zope Object Database +* Random access memory +* Redland RDF Application Framework + +Store instances can be created with the :meth:`plugin` function: + +.. code-block:: python + + from rdflib import plugin + from rdflib.store import Store + plugin.get('.. one of the supported Stores ..',Store)(identifier=.. id of conjunctive graph ..) + diff --git a/docs/persisting_n3_terms.rst b/docs/persisting_n3_terms.rst new file mode 100644 index 00000000..32638350 --- /dev/null +++ b/docs/persisting_n3_terms.rst @@ -0,0 +1,92 @@ +.. _persisting_n3_terms: + +=========================== +Persisting Notation 3 Terms +=========================== + +Using N3 Syntax for Persistence +------------------------------- +Blank Nodes, Literals, URI References, and Variables can be distinguished in persistence by relying on Notation 3 syntax convention. + +All URI References can be expanded and persisted as: + +.. code-block:: text + + <..URI..> + +All Literals can be expanded and persisted as: + +.. code-block:: text + + "..value.."@lang or "..value.."^^dtype_uri + +.. note:: ``@lang`` is a language tag and ``^^dtype_uri`` is the URI of a data type associated with the Literal + +Blank Nodes can be expanded and persisted as: + +.. code-block:: text + + _:Id + +.. note:: where Id is an identifier as determined by skolemization. Skolemization is a syntactic transformation routinely used in automatic inference systems in which existential variables are replaced by 'new' functions - function names not used elsewhere - applied to any enclosing universal variables. In RDF, Skolemization amounts to replacing every blank node in a graph by a 'new' name, i.e. a URI reference which is guaranteed to not occur anywhere else. In effect, it gives 'arbitrary' names to the anonymous entities whose existence was asserted by the use of blank nodes: the arbitrariness of the names ensures that nothing can be inferred that would not follow from the bare assertion of existence represented by the blank node. (Using a literal would not do. Literals are never 'new' in the required sense.) + +Variables can be persisted as they appear in their serialization ``(?varName)`` - since they only need be unique within their scope (the context of their associated statements) + +These syntactic conventions can facilitate term round-tripping. + +Variables by Scope +------------------ +Would an interface be needed in order to facilitate a quick way to aggregate all the variables in a scope (given by a formula identifier)? An interface such as: + +.. code-block:: python + + def variables(formula_identifier) + +The Need to Skolemize Formula Identifiers +----------------------------------------- +It would seem reasonable to assume that a formula-aware store would assign Blank Node identifiers as names of formulae that appear in a N3 serialization. So for instance, the following bit of N3: + +.. code-block:: n3 + + {?x a :N3Programmer} => {?x :has :Migrane} + +Could be interpreted as the assertion of the following statement: + +.. code-block:: n3 + + _:a log:implies _:b + +However, how are ``_:a`` and ``_:b`` distinguished from other Blank Nodes? A formula-aware store would be expected to persist the first set of statements as quoted statements in a formula named ``_:a`` and the second set as quoted statements in a formula named ``_:b``, but it would not be cost-effective for a serializer to have to query the store for all statements in a context named ``_:a`` in order to determine if ``_:a`` was associated with a formula (so that it could be serialized properly). + +Relying on ``log:Formula`` Membership +------------------------------------- + +The store could rely on explicit ``log:Formula`` membership (via ``rdf:type`` statements) to model the distinction of Blank Nodes associated with formulae. However, would these statements be expected from an N3 parser or known implicitly by the store? i.e., would all such Blank Nodes match the following pattern: + +.. code-block:: text + + ?formula rdf:type log:Formula + +Relying on an Explicit Interface +-------------------------------- +A formula-aware store could also support the persistence of this distinction by implementing a method that returns an iterator over all the formulae in the store: + +.. code-block:: python + + def formulae(triple=None) + +This function would return all the Blank Node identifiers assigned to formulae or just those that contain statements matching the given triple pattern and would be the way a serializer determines if a term refers to a formula (in order to properly serializer it). + +How much would such an interface reduce the need to model formulae terms as first class objects (perhaps to be returned by the :meth:`~rdflib.Graph.triple` function)? Would it be more useful for the :class:`~rdflib.Graph` (or the store itself) to return a Context object in place of a formula term (using the formulae interface to make this determination)? + +Conversely, would these interfaces (variables and formulae) be considered optimizations only since you have the distinction by the kinds of terms triples returns (which would be expanded to include variables and formulae)? + +Persisting Formula Identifiers +------------------------------ +This is the most straight forward way to maintain this distinction - without relying on extra interfaces. Formula identifiers could be persisted distinctly from other terms by using the following notation: + +.. code-block:: n3 + + {_:bnode} or {<.. URI ..>} + +This would facilitate their persistence round-trip - same as the other terms that rely on N3 syntax to distinguish between each other. diff --git a/docs/univrdfstore.rst b/docs/univrdfstore.rst new file mode 100644 index 00000000..7142ca57 --- /dev/null +++ b/docs/univrdfstore.rst @@ -0,0 +1,363 @@ +.. _univrdfstore: + +=============================== +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. + +.. _RDF Graph: http://www.w3.org/TR/rdf-concepts/#dfn-rdf-graph +.. _Notation 3: http://www.w3.org/2000/10/swap/Primer +.. _First Order Predicate Logic: http://en.wikipedia.org/wiki/First-order_predicate_logic + +Terminology +=========== + +.. topic:: **Context** + + A named, unordered set of statements (that could also be called a sub-graph). The :term:`named graph` `literature`__ and `ontology`__ are relevant to this concept. The term :term:`context` could be thought of as either the sub-graph itself or the relationship between an RDF triple and a sub-graph in which it is found (this latter is how the term context is used in the `Notation 3 Design Issues page`_). + + It is worth noting that the concept of logically grouping `triples`__ within an addressable 'set' or 'subgraph' is just barely beyond the scope of the RDF model. The RDF model defines a graph to be an arbitrary collection of triples and the semantics of these triples --- but doesn't give guidance on how to address such arbitrary collections in a consistent manner. Although a collection of triples can be thought of as a resource itself, the association between a triple and the collection (of which it is a part) is not covered. `Public RDF`_ is an example of an attempt to formally model this relationship - and includes one other unrelated extension: Articulated Text + +.. __: http://www.w3.org/2004/03/trix/ +.. __: http://metacognition.info/Triclops/?xslt=Triclops.xslt&query=type(list(rdfs:Class,owl:Class,rdf:Property))&queryType=Graph&remoteGraph=http://www.w3.org/2004/03/trix/rdfg-1/ +.. __: http://www.w3.org/TR/rdf-concepts/#section-triples +.. _Notation 3 Design Issues page: http://www.w3.org/DesignIssues/Notation3.html +.. _Public RDF: http://laurentszyster.be/blog/public-rdf/ + +.. topic:: **Conjunctive Graph** + + This refers to the 'top-level' Graph. It is the aggregation of all the contexts within it and is also the appropriate, absolute boundary for `closed world assumptions`__ / models. This distinction is the low-hanging fruit of RDF along the path to the semantic web and most of its value is in (corporate/enterprise) real-world problems: + + .. pull-quote:: + + There are at least two situations where the closed world assumption is used. The first is where it is assumed that a knowledge base contains all relevant facts. This is common in corporate databases. That is, the information it contains is assumed to be complete + + From a store perspective, closed world assumptions also provide the benefit of better query response times, due to the explicit closed world boundaries. Closed world boundaries can be made transparent by federated queries that assume each :class:`ConjunctiveGraph` is a section of a larger, unbounded universe. So a closed world assumption does not preclude you from an open world assumption. + + For the sake of persistence, Conjunctive Graphs must be distinguished by identifiers (which may not necessarily be RDF `identifiers`__ or may be an RDF identifier normalized - SHA1/MD5 perhaps - for database naming purposes) that could be referenced to indicate conjunctive queries (queries made across the entire conjunctive graph) or appear as nodes in asserted statements. In this latter case, such statements could be interpreted as being made about the entire 'known' universe. For example: + + .. code-block:: xml + + <urn:uuid:conjunctive-graph-foo> rdf:type :ConjunctiveGraph + <urn:uuid:conjunctive-graph-foo> rdf:type log:Truth + <urn:uuid:conjunctive-graph-foo> :persistedBy :MySQL + +.. __: http://cs.wwc.edu/~aabyan/Logic/CWA.html +.. __: http://www.w3.org/2002/07/rdf-identifer-terminology/ + +.. topic:: **Quoted Statement** + + A statement that isn't asserted but is referred to in some manner. Most often, this happens when we want to make a statement about another statement (or set of statements) without necessarily saying these quoted statements (are true). For example: + + .. code-block:: text + + Chimezie said "higher-order statements are complicated" + + Which can be written (in N3) as: + + .. code-block:: n3 + + :chimezie :said {:higherOrderStatements rdf:type :complicated} + +.. topic:: **Formula** + + A context whose statements are quoted or hypothetical. + + Context quoting can be thought of as very similar to `reification`__. The main difference is that quoted statements are not asserted or considered as statements of truth about the universe and can be referenced as a group: a hypothetical RDF Graph + +.. __: http://www.w3.org/TR/rdf-mt/#Reif + +.. topic:: **Universal Quantifiers / Variables** + + (relevant references): + + * OWL `Definition`__ of `SWRL`__. + * SWRL/RuleML `Variable`__ + +.. __: http://www.w3.org/Submission/SWRL/swrl.owl +.. __: http://www.w3.org/Submission/SWRL/ +.. __: http://www.w3.org/Submission/SWRL/#owls_Variable + +.. topic:: **Terms** + + Terms are the kinds of objects that can appear in a quoted/asserted triple. + + This includes those that are core to RDF: + + * Blank Nodes + * URI References + * Literals (which consist of a literal value, datatype and language tag) + + Those that extend the RDF model into N3: + + * Formulae + * Universal Quantifications (Variables) + + And those that are primarily for matching against 'Nodes' in the underlying Graph: + + * REGEX Expressions + * Date Ranges + * Numerical Ranges + +.. topic:: **Nodes** + + Nodes are a subset of the Terms that the underlying store actually persists. The set of such Terms depends on whether or not the store is formula-aware. Stores that aren't formula-aware would only persist those terms core to the RDF Model, and those that are formula-aware would be able to persist the N3 extensions as well. However, utility terms that only serve the purpose for matching nodes by term-patterns probably will only be terms and not nodes. + + The set of nodes of an RDF graph is the set of subjects and objects of triples in the graph. + +.. topic:: **Context-aware** + + An RDF store capable of storing statements within contexts is considered context-aware. Essentially, such a store is able to partition the RDF model it represents into individual, named, and addressable sub-graphs. + +.. topic:: **Formula-aware** + + An RDF store capable of distinguishing between statements that are asserted and statements that are quoted is considered formula-aware. + + Such a store is responsible for maintaining this separation and ensuring that queries against the entire model (the aggregation of all the contexts - specified by not limiting a 'query' to a specifically name context) do not include quoted statements. Also, it is responsible for distinguishing universal quantifiers (variables). + + .. note:: These 2 additional concepts (formulae and variables) must be thought of as core extensions and distinguishable from the other terms of a triple (for the sake of the persistence rountrip - at the very least). It's worth noting that the 'scope' of universal quantifiers (variables) and existential quantifiers (BNodes) is the formula (or context - to be specific) in which their statements reside. Beyond this, a Formula-aware store behaves the same as a Context-aware store. + +.. topic:: **Conjunctive Query** + + Any query that doesn't limit the store to search within a named context only. Such a query expects a context-aware store to search the entire asserted universe (the conjunctive graph). A formula-aware store is expected not to include quoted statements when matching such a query. + +.. topic:: **N3 Round Trip** + + This refers to the requirements on a formula-aware RDF store's persistence mechanism necessary for it to be properly populated by a N3 parser and rendered as syntax by a N3 serializer. + +.. topic:: **Transactional Store** + + An RDF store capable of providing transactional integrity to the RDF operations performed on it. + +Interpreting Syntax +=================== + +The following Notation 3 `document`__: + +.. code-block:: n3 + + {?x a :N3Programmer} => {?x :has [a :Migrane]} + +Could cause the following statements to be asserted in the store: + +.. code-block:: n3 + + _:a log:implies _:b + +This statement would be asserted in the partition associated with quoted statements (in a formula named ``_:a``) + +.. code-block:: n3 + + ?x rdf:type :N3Programmer + +Finally, these statements would be asserted in the same partition (in a formula named _:b) + +.. code-block:: n3 + + ?x :has _:c + + _:c rdf:type :Migrane + +.. __: http://metacognition.info/Triclops/?xslt=Triclops.xslt&query=log:N3Document&queryType=Triple&remoteGraph=http://www.w3.org/2000/10/swap/log# + +Formulae and Variables as Terms +=============================== +Formulae and variables are distinguishable from URI references, Literals, and BNodes by the following syntax: + +.. code-block:: text + + { .. } - Formula ?x - Variable + +They must also be distinguishable in persistence to ensure they can be round-tripped. + +.. note:: There are a number of other issues regarding the `persisting of N3 terms <persisting_n3_terms.html>`_. + +Database Management +=================== + +An RDF store should provide standard interfaces for the management of database connections. Such interfaces are standard to most database management systems (Oracle, MySQL, Berkeley DB, Postgres, etc..) + +The following methods are defined to provide this capability (see below for description of the :term:`configuration` string): + +.. automethod:: rdflib.store.Store.open + +.. automethod:: rdflib.store.Store.close + +.. automethod:: rdflib.store.Store.destroy + +The *configuration* string is understood by the store implementation and represents all the parameters needed to locate an individual instance of a store. This could be similar to an ODBC string or in fact be an ODBC string, if the connection protocol to the underlying database is ODBC. The :meth:`open` function needs to fail intelligently in order to clearly express that a store (identified by the given configuration string) already exists or that there is no store (at the location specified by the configuration string) depending on the value of :keyword:`create`. + +Triple Interfaces +================= +An RDF store could provide a standard set of interfaces for the manipulation, management, and/or retrieval of its contained triples (asserted or quoted): + +.. automethod:: rdflib.store.Store.add + +.. automethod:: rdflib.store.Store.remove + +.. automethod:: rdflib.store.Store.triples + + .. note:: The :meth:`triples` method can be thought of as the primary mechanism for producing triples with nodes that match the corresponding terms in the *(s, p, o)* term pattern provided. The term pattern ``(None, None, None)`` matches all nodes. + +.. automethod:: rdflib.store.Store.__len__ + + +Formula / Context Interfaces +============================ + +These interfaces work on contexts and formulae (for stores that are formula-aware) interchangeably. + +.. automethod:: rdflib.graph.ConjunctiveGraph.contexts + +.. automethod:: rdflib.graph.ConjunctiveGraph.remove_context + +Interface Test Cases +==================== + +Basic +------------------------- + +Tests parsing, triple patterns, triple pattern removes, size, contextual removes + +Source Graph +^^^^^^^^^^^^^ + +.. code-block:: n3 + + @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + @prefix : <http://test/> . + {:a :b :c; a :foo} => {:a :d :c} . + _:foo a rdfs:Class . + :a :d :c. + +Test code +^^^^^^^^^ + +.. code-block:: python + + implies = URIRef("http://www.w3.org/2000/10/swap/log#implies") + a = URIRef('http://test/a') + b = URIRef('http://test/b') + c = URIRef('http://test/c') + d = URIRef('http://test/d') + for s,p,o in g.triples((None,implies,None)): + formulaA = s + formulaB = o + + #contexts test + assert len(list(g.contexts()))==3 + + #contexts (with triple) test + assert len(list(g.contexts((a,d,c))))==2 + + #triples test cases + assert type(list(g.triples((None,RDF.type,RDFS.Class)))[0][0]) == BNode + assert len(list(g.triples((None,implies,None))))==1 + assert len(list(g.triples((None,RDF.type,None))))==3 + assert len(list(g.triples((None,RDF.type,None),formulaA)))==1 + assert len(list(g.triples((None,None,None),formulaA)))==2 + assert len(list(g.triples((None,None,None),formulaB)))==1 + assert len(list(g.triples((None,None,None))))==5 + assert len(list(g.triples((None,URIRef('http://test/d'),None),formulaB)))==1 + assert len(list(g.triples((None,URIRef('http://test/d'),None))))==1 + + #Remove test cases + g.remove((None,implies,None)) + assert len(list(g.triples((None,implies,None))))==0 + assert len(list(g.triples((None,None,None),formulaA)))==2 + assert len(list(g.triples((None,None,None),formulaB)))==1 + g.remove((None,b,None),formulaA) + assert len(list(g.triples((None,None,None),formulaA)))==1 + g.remove((None,RDF.type,None),formulaA) + assert len(list(g.triples((None,None,None),formulaA)))==0 + g.remove((None,RDF.type,RDFS.Class)) + + #remove_context tests + formulaBContext=Context(g,formulaB) + g.remove_context(formulaB) + assert len(list(g.triples((None,RDF.type,None))))==2 + assert len(g)==3 assert len(formulaBContext)==0 + g.remove((None,None,None)) + assert len(g)==0 + + +Formula and Variables Test +-------------------------- + +Source Graph +^^^^^^^^^^^^ + +.. code-block:: n3 + + @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . + @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + @prefix : <http://test/> . + {?x a rdfs:Class} => {?x a :Klass}. + +Test Code +^^^^^^^^^ + +.. code-block:: python + + implies = URIRef("http://www.w3.org/2000/10/swap/log#implies") + klass = URIRef('http://test/Klass') + for s,p,o in g.triples((None,implies,None)): + formulaA = s + formulaB = o + assert type(formulaA) == Formula + assert type(formulaB) == Formula + for s,p,o in g.triples((None,RDF.type,RDFS.Class)),formulaA): + assert type(s) == Variable + for s,p,o in g.triples((None,RDF.type,klass)),formulaB): + assert type(s) == Variable + +Transactional Tests +------------------- + +To be instantiated. + +Additional Terms to Model +========================= +These are a list of additional kinds of RDF terms (all of which are special Literals) + + * RegExLiteral - a REGEX string which can be used in any term slot in order to match by applying the Regular Expression to statements in the underlying graph. + * Date (could provide some utility functions for date manipulation / serialization, etc..) + * DateRange + +Namespace Management Interfaces +=============================== + +The following namespace management interfaces (defined in Graph) could be implemented in the RDF store. Currently, they exist as stub methods of :class:`~rdflib.store.Store` and are defined in the store subclasses (e.g. :class:`~rdflib.store.IOMemory`, :class:`~rdflib.store.AbstractSQLStore`): + +.. automethod:: rdflib.store.Store.bind + +.. automethod:: rdflib.store.Store.prefix + +.. automethod:: rdflib.store.Store.namespace + +.. automethod:: rdflib.store.Store.namespaces + +Open issues +=========== +Does the Store interface need to have an identifier property or can we keep that at the Graph level? + +The Store implementation needs a mechanism to distinguish between triples (quoted or asserted) in ConjunctiveGraphs (which are mutually exclusive universes in systems that make closed world assumptions - and queried separately). This is the separation that the store identifier provides. This is different from the name of a context within a ConjunctiveGraph (or the default context of a conjunctive graph). I tried to diagram the logical separation of ConjunctiveGraphs, SubGraphs and QuotedGraphs in this diagram + +.. image:: _static/ContextHierarchy.png + +An identifier of ``None`` can be used to indicate the store (aka `all contexts`) in methods such as :meth:`triples`, :meth:`__len__`, etc. This works as long as we're only dealing with one Conjunctive Graph at a time -- which may not always be the case. + +Is there any value in persisting terms that lie outside N3 (RegExLiteral,Date,etc..)? + +Potentially, not sure yet. + +Should a conjunctive query always return quads instead of triples? It would seem so, since knowing the context that produced a triple match is an essential aspect of query construction / optimization. Or if having the triples function yield/produce different length tuples is problematic, could an additional - and slightly redundant - interface be introduced?: + +.. automethod:: rdflib.graph.ConjunctiveGraph.quads + +Stores that weren't context-aware could simply return ``None`` as the 4th item in the produced/yielded tuples or simply not support this interface. + |
