Example #1
0
    def testSubclassNameAppearsInRepr(self):
        class MyURIRef(URIRef):
            pass

        x = MyURIRef('http://example.com/')
        self.assertEqual(repr(x),
                         uformat("MyURIRef(%(u)s'http://example.com/')"))
Example #2
0
uformat("""
This parser will read in an JSON-LD formatted document and create an RDF
Graph. See:

    http://json-ld.org/

Example usage::

    >>> from rdflib import Graph, URIRef, Literal
    >>> test_json = '''
    ... {
    ...     "@context": {
    ...         "dc": "http://purl.org/dc/terms/",
    ...         "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    ...         "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
    ...     },
    ...     "@id": "http://example.org/about",
    ...     "dc:title": {
    ...         "@language": "en",
    ...         "@literal": "Someone's Homepage"
    ...     }
    ... }
    ... '''
    >>> g = Graph().parse(data=test_json, format='json-ld')
    >>> list(g) == [(URIRef('http://example.org/about'),
    ...     URIRef('http://purl.org/dc/terms/title'),
    ...     Literal(%(u)s"Someone's Homepage", lang=%(u)s'en'))]
    True

"""
        )
Example #3
0
    def testSubclassNameAppearsInRepr(self):
        class MyLiteral(Literal):
            pass

        x = MyLiteral(u"foo")
        self.assertEqual(repr(x), uformat("MyLiteral(%(u)s'foo')"))
Example #4
0
 def testOmitsMissingDatatype(self):
     self.assertEqual(repr(Literal("foo", lang='en')),
                      uformat("rdflib.term.Literal(%(u)s'foo', lang='en')"))
Example #5
0
 def testOmitsMissingLang(self):
     self.assertEqual(
         repr(Literal("foo", datatype=URIRef('http://example.com/'))),
         uformat(
             "rdflib.term.Literal(%(u)s'foo', datatype=rdflib.term.URIRef(%(u)s'http://example.com/'))"
         ))
Example #6
0
 def testSubclassNameAppearsInRepr(self):
     class MyLiteral(Literal):
         pass
     x = MyLiteral(u"foo")
     self.assertEqual(repr(x), uformat("MyLiteral(%(u)s'foo')"))
Example #7
0
 def testOmitsMissingDatatypeAndLang(self):
     self.assertEqual(repr(Literal("foo")),
                      uformat("rdflib.term.Literal(%(u)s'foo')"))
Example #8
0
 def testOmitsMissingLang(self):
     self.assertEqual(
         repr(Literal("foo", datatype=URIRef('http://example.com/'))),
         uformat("rdflib.term.Literal(%(u)s'foo', datatype=rdflib.term.URIRef(%(u)s'http://example.com/'))"))
Example #9
0
 def testOmitsMissingDatatype(self):
     self.assertEqual(repr(Literal("foo", lang='en')),
                      uformat("rdflib.term.Literal(%(u)s'foo', lang='en')"))
Example #10
0
 def testOmitsMissingDatatypeAndLang(self):
     self.assertEqual(repr(Literal("foo")),
                      uformat("rdflib.term.Literal(%(u)s'foo')"))
Example #11
0
 def testSubclassNameAppearsInRepr(self):
     class MyURIRef(URIRef):
         pass
     x = MyURIRef('http://example.com/')
     self.assertEqual(repr(x), uformat("MyURIRef(%(u)s'http://example.com/')"))
Example #12
0
from rdflib.py3compat import format_doctest_out as uformat
uformat("""
This parser will read in an JSON-LD formatted document and create an RDF
Graph. See:

    http://json-ld.org/

Example usage::

    >>> from rdflib import Graph, URIRef, Literal
    >>> test_json = '''
    ... {
    ...     "@context": {
    ...         "dc": "http://purl.org/dc/terms/",
    ...         "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    ...         "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
    ...     },
    ...     "@id": "http://example.org/about",
    ...     "dc:title": {
    ...         "@language": "en",
    ...         "@literal": "Someone's Homepage"
    ...     }
    ... }
    ... '''
    >>> g = Graph().parse(data=test_json, format='json-ld')
    >>> list(g) == [(URIRef('http://example.org/about'),
    ...     URIRef('http://purl.org/dc/terms/title'),
    ...     Literal(%(u)s"Someone's Homepage", lang=%(u)s'en'))]
    True

""")
# NOTE: This code reads the entire JSON object into memory before parsing, but