|
1 | | -"""Instantiating Graphs with default store (IOMemory) and default identifier |
| 1 | +from __future__ import generators |
| 2 | +from rdflib.py3compat import format_doctest_out |
| 3 | +__doc__ = format_doctest_out("""\ |
| 4 | +Instantiating Graphs with default store (IOMemory) and default identifier |
2 | 5 | (a BNode): |
3 | 6 |
|
4 | 7 | >>> g = Graph() |
|
24 | 27 |
|
25 | 28 | >>> g = Graph('IOMemory', URIRef("http://rdflib.net")) |
26 | 29 | >>> g.identifier |
27 | | - rdflib.term.URIRef(u'http://rdflib.net') |
| 30 | + rdflib.term.URIRef(%(u)s'http://rdflib.net') |
28 | 31 | >>> str(g) |
29 | 32 | "<http://rdflib.net> a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory']." |
30 | 33 |
|
|
43 | 46 | >>> print(len(g)) |
44 | 47 | 0 |
45 | 48 | >>> g.add((statementId, RDF.type, RDF.Statement)) |
46 | | - >>> g.add((statementId, RDF.subject, URIRef(u'http://rdflib.net/store/ConjunctiveGraph'))) |
| 49 | + >>> g.add((statementId, RDF.subject, URIRef(%(u)s'http://rdflib.net/store/ConjunctiveGraph'))) |
47 | 50 | >>> g.add((statementId, RDF.predicate, RDFS.label)) |
48 | 51 | >>> g.add((statementId, RDF.object, Literal("Conjunctive Graph"))) |
49 | 52 | >>> print(len(g)) |
|
77 | 80 | >>> stmt2 = BNode() |
78 | 81 | >>> stmt3 = BNode() |
79 | 82 | >>> g1.add((stmt1, RDF.type, RDF.Statement)) |
80 | | - >>> g1.add((stmt1, RDF.subject, URIRef(u'http://rdflib.net/store/ConjunctiveGraph'))) |
| 83 | + >>> g1.add((stmt1, RDF.subject, URIRef(%(u)s'http://rdflib.net/store/ConjunctiveGraph'))) |
81 | 84 | >>> g1.add((stmt1, RDF.predicate, RDFS.label)) |
82 | 85 | >>> g1.add((stmt1, RDF.object, Literal("Conjunctive Graph"))) |
83 | 86 | >>> g2.add((stmt2, RDF.type, RDF.Statement)) |
84 | | - >>> g2.add((stmt2, RDF.subject, URIRef(u'http://rdflib.net/store/ConjunctiveGraph'))) |
| 87 | + >>> g2.add((stmt2, RDF.subject, URIRef(%(u)s'http://rdflib.net/store/ConjunctiveGraph'))) |
85 | 88 | >>> g2.add((stmt2, RDF.predicate, RDF.type)) |
86 | 89 | >>> g2.add((stmt2, RDF.object, RDFS.Class)) |
87 | 90 | >>> g3.add((stmt3, RDF.type, RDF.Statement)) |
88 | | - >>> g3.add((stmt3, RDF.subject, URIRef(u'http://rdflib.net/store/ConjunctiveGraph'))) |
| 91 | + >>> g3.add((stmt3, RDF.subject, URIRef(%(u)s'http://rdflib.net/store/ConjunctiveGraph'))) |
89 | 92 | >>> g3.add((stmt3, RDF.predicate, RDFS.comment)) |
90 | 93 | >>> g3.add((stmt3, RDF.object, Literal("The top-level aggregate graph - The sum of all named graphs within a Store"))) |
91 | 94 | >>> len(list(ConjunctiveGraph(store).subjects(RDF.type, RDF.Statement))) |
|
105 | 108 | >>> len(uniqueGraphNames) |
106 | 109 | 2 |
107 | 110 | |
108 | | -Parsing N3 from StringIO |
| 111 | +Parsing N3 from a string |
109 | 112 |
|
110 | | - >>> from StringIO import StringIO |
111 | 113 | >>> g2 = Graph() |
112 | 114 | >>> src = ''' |
113 | 115 | ... @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . |
|
117 | 119 | ... rdf:predicate rdfs:label; |
118 | 120 | ... rdf:object "Conjunctive Graph" ] . |
119 | 121 | ... ''' |
120 | | - >>> g2 = g2.parse(StringIO(src), format='n3') |
| 122 | + >>> g2 = g2.parse(data=src, format='n3') |
121 | 123 | >>> print(len(g2)) |
122 | 124 | 4 |
123 | 125 |
|
124 | 126 | Using Namespace class: |
125 | 127 |
|
126 | 128 | >>> RDFLib = Namespace('http://rdflib.net') |
127 | 129 | >>> RDFLib.ConjunctiveGraph |
128 | | - rdflib.term.URIRef(u'http://rdflib.netConjunctiveGraph') |
| 130 | + rdflib.term.URIRef(%(u)s'http://rdflib.netConjunctiveGraph') |
129 | 131 | >>> RDFLib['Graph'] |
130 | | - rdflib.term.URIRef(u'http://rdflib.netGraph') |
131 | | -
|
132 | | -""" |
| 132 | + rdflib.term.URIRef(%(u)s'http://rdflib.netGraph') |
133 | 133 |
|
134 | | -from __future__ import generators |
| 134 | +""") |
135 | 135 |
|
136 | 136 | import logging |
137 | 137 | _logger = logging.getLogger(__name__) |
@@ -588,29 +588,29 @@ def preferredLabel(self, subject, lang=None, default=[], |
588 | 588 | skos:prefLabel or rdfs:label. |
589 | 589 | |
590 | 590 | >>> g = ConjunctiveGraph() |
591 | | - >>> u = URIRef(u'http://example.com/foo') |
| 591 | + >>> u = URIRef(%(u)s'http://example.com/foo') |
592 | 592 | >>> g.add([u, RDFS.label, Literal('foo')]) |
593 | 593 | >>> g.add([u, RDFS.label, Literal('bar')]) |
594 | 594 | >>> sorted(g.preferredLabel(u)) #doctest: +NORMALIZE_WHITESPACE |
595 | | - [(rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'), |
| 595 | + [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2000/01/rdf-schema#label'), |
596 | 596 | rdflib.term.Literal(%(u)s'bar')), |
597 | | - (rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'), |
| 597 | + (rdflib.term.URIRef(%(u)s'http://www.w3.org/2000/01/rdf-schema#label'), |
598 | 598 | rdflib.term.Literal(%(u)s'foo'))] |
599 | 599 | >>> g.add([u, SKOS.prefLabel, Literal('bla')]) |
600 | 600 | >>> g.preferredLabel(u) #doctest: +NORMALIZE_WHITESPACE |
601 | | - [(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'), |
| 601 | + [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'), |
602 | 602 | rdflib.term.Literal(%(u)s'bla'))] |
603 | 603 | >>> g.add([u, SKOS.prefLabel, Literal('blubb', lang='en')]) |
604 | 604 | >>> sorted(g.preferredLabel(u)) #doctest: +NORMALIZE_WHITESPACE |
605 | | - [(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'), |
| 605 | + [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'), |
606 | 606 | rdflib.term.Literal(%(u)s'blubb', lang='en')), |
607 | | - (rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'), |
| 607 | + (rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'), |
608 | 608 | rdflib.term.Literal(%(u)s'bla'))] |
609 | 609 | >>> g.preferredLabel(u, lang='') #doctest: +NORMALIZE_WHITESPACE |
610 | | - [(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'), |
| 610 | + [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'), |
611 | 611 | rdflib.term.Literal(%(u)s'bla'))] |
612 | 612 | >>> g.preferredLabel(u, lang='en') #doctest: +NORMALIZE_WHITESPACE |
613 | | - [(rdflib.term.URIRef(u'http://www.w3.org/2004/02/skos/core#prefLabel'), |
| 613 | + [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2004/02/skos/core#prefLabel'), |
614 | 614 | rdflib.term.Literal(%(u)s'blubb', lang='en'))] |
615 | 615 | """ |
616 | 616 |
|
|
0 commit comments