예제 #1
0
 def testTriples(self):
     with stdout_replaced():
         g = GraphComponent(rdfSources=[])
     g = g.makeGraph(parseXml(RDF_XML))
     self.assertEquals([('uri:uri', namespaces.dcterms + 'title', Literal('The title'))], list(g.triples(subject='uri:uri', predicate=namespaces.dcterms + 'title')))
     self.assertEquals([('uri:uri', namespaces.dcterms + 'title', Literal('The title'))], list(g.triples(subject=None, predicate=namespaces.dcterms + 'title', object=Literal('The title'))))
     self.assertEquals([('uri:uri', namespaces.rdf + 'type', Uri('type:type#'))], list(g.triples(object=Uri('type:type#'))))
     self.assertEquals(1, len(list(g.triples(object=Uri('type:type#')))))
     self.assertEquals(1, len(list(g.triples(subject='uri:uri', predicate=namespaces.rdf+'type', object=Uri('type:type#')))))
예제 #2
0
    def testTriplesUsingRealOntology(self):
        subdir = join(self.tempdir, 'subdir')
        makedirs(subdir)
        copy(join(rdfDir, 'nl_property_labels.rdf'), subdir)
        with stdout_replaced():
            g = GraphComponent(rdfSources=[self.tempdir])

        self.assertTrue(10 < len(list(g.triples())), list(g.triples()))
        self.assertEquals([
                (namespaces.curieToUri('dcterms:title'),
                 namespaces.curieToUri('rdfs:label'),
                 Literal('Titel', lang='nl')
                )
            ],
            list(g.triples(
                subject=namespaces.curieToUri('dcterms:title'),
                predicate=namespaces.curieToUri('rdfs:label'))),
        )
예제 #3
0
 def testMakeGraph(self):
     with stdout_replaced():
         g = GraphComponent(rdfSources=[])
     g = g.makeGraph(parseXml(RDF_XML))
     self.assertEquals(set([
             ('uri:uri', namespaces.dcterms + 'title', Literal('The title')),
             ('uri:uri', namespaces.rdf + 'type', Uri('type:type#'))
         ]),
         set(list(g.triples(None, None, None)))
     )
예제 #4
0
    def testInitializeGraphComponentFromRdfObjects(self):
        class A(object):
            @property
            def context(self):
                return 'uri:context'

            def asRdfXml(self):
                yield '''\
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
    <rdf:Description rdf:about="uri:someUri">
        <rdfs:label xml:lang="nl">Some resource</rdfs:label>
    </rdf:Description>
</rdf:RDF>'''

        with stdout_replaced():
            gc = GraphComponent(rdfSources=[A()])
        self.assertEquals([("uri:someUri", curieToUri("rdfs:label"), Literal("Some resource", lang="nl"))], list(gc.triples()))