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#')))))
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'))), )
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))) )
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()))