Ejemplo n.º 1
0
 def testEmptyPropertyAttribs(self):
     RDFParser(sink=self.sink).parse(XML(INPUT_RDF))
     relationBnode = self.sink.objects(subject=uri, curie="dcterms:relation")[0]
     self.assertEquals(
         [Literal("JPM")],
         list(self.sink.objects(subject=relationBnode.value, predicate=namespaces.curieToUri("dcterms:title"))),
     )
     self.assertEquals(
         [Uri(namespaces.curieToUri("foaf:Person"))],
         list(self.sink.objects(subject=relationBnode.value, curie="rdf:type")),
     )
Ejemplo n.º 2
0
 def testLiteralWithCommentAndPI(self):
     RDFParser(sink=self.sink).parse(XML(INPUT_RDF))
     self.assertEquals(
         sorted([Literal("1970"), Literal("1970-01-01")], key=lambda l: (l.value, l.lang)),
         sorted(
             [o for s, p, o in self.sink.triples(subject=uri, predicate=namespaces.curieToUri("dcterms:date"))],
             key=lambda l: (l.value, l.lang),
         ),
     )
Ejemplo n.º 3
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'))),
        )
Ejemplo n.º 4
0
    def testBlankNodesAndLiterals(self):
        BNode.nextGenId = 0
        RDFParser(sink=self.sink).parse(XML(INPUT_RDF))
        self.assertEquals([BNode("_:id0")], list(self.sink.objects(subject=uri, curie="dcterms:creator")))
        self.assertEquals(
            [Uri("http://dbpedia.org/ontology/Person")], list(self.sink.objects(subject="_:id0", curie="rdf:type"))
        )

        contributor = self.sink.objects(subject=uri, predicate=namespaces.curieToUri("dcterms:contributor"))[0]
        self.assertEquals(
            [Literal("Anonymous", lang="en")], list(self.sink.objects(subject=contributor.value, curie="rdfs:label"))
        )

        self.assertTrue(
            Literal("An illustrated history of Black Americans", lang="en")
            in set(self.sink.objects(subject=uri, curie="dcterms:title"))
        )