Esempio n. 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#')))))
Esempio n. 2
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)))
     )
Esempio n. 3
0
    def testGraphNavigationByTriples(self):
        with stdout_replaced():
            gc = GraphComponent(rdfSources=[])
        g = gc.makeGraph(lxmlNode=parseXml(RDF_XML_NAVIGATION))

        result = list(g.triples(subject='uri:nav', predicate=namespaces.dcterms+'publisher'))
        self.assertEquals(1, len(result))
        self.assertEquals(
            ('uri:nav', namespaces.dcterms+'publisher'),
            result[0][:2])
        bnode = result[0][2]
        self.assertTrue(isinstance(bnode, BNode))

        result = list(g.triples(subject=bnode.value))
        self.assertEquals(
            [(bnode.value, namespaces.rdfs+'label', Literal('Pub'))],
            result)