def test_node_data(test_graph): predicates_to_collapse = [ rdflib.URIRef("www.testing.com/has"), rdflib.URIRef("www.testing.com/goes"), ] collapsed_netx = collapse_predicates( test_graph, predicates_to_collapse=predicates_to_collapse, namespaces={}) # test that the node data is indeed collapsed by trying out each key and their expected values. first_pred = list( collapsed_netx.nodes[rdflib.URIRef("www.testing.com/Luke")].keys())[0] second_pred = list( collapsed_netx.nodes[rdflib.URIRef("www.testing.com/Luke")].keys())[1] assert collapsed_netx.nodes[rdflib.URIRef("www.testing.com/Luke")][ second_pred] == rdflib.term.Literal("one brother") assert collapsed_netx.nodes[rdflib.URIRef( "www.testing.com/Luke")][first_pred] == CustomURIRef( uri=rdflib.URIRef("www.testing.com/EmiratesStadium"), namespaces={})
def test_node_data(test_graph): predicates_to_collapse = [ rdflib.URIRef("www.testing.com/has"), rdflib.URIRef("www.testing.com/goes"), ] collapsed_netx = collapse_predicates( test_graph, predicates_to_collapse=predicates_to_collapse, namespaces={"ts": "www.testing.com/"}, ) # test that the node data is indeed collapsed by trying out each key and their expected values. first_pred = "ts:has" second_pred = "ts:goes" subject = rdflib.URIRef("www.testing.com/Luke") assert len(collapsed_netx.nodes[subject][first_pred]) == 2 assert collapsed_netx.nodes[subject][second_pred] == CustomURIRef( uri=rdflib.URIRef("www.testing.com/EmiratesStadium"), namespaces={"ts": "www.testing.com/"}, ) assert "one brother" in collapsed_netx.nodes[subject][first_pred] assert "one mother" in collapsed_netx.nodes[subject][first_pred]
def test5(self): custom = CustomURIRef(uri=URIRef("www.example.org/1"), namespaces=self.namespaces) normal = URIRef("www.example.org/2") self.assertNotEqual(custom, normal)
def test4(self): custom = str( CustomURIRef(uri=URIRef("www.example.org/1"), namespaces=self.graph.namespace_manager)) normal = "ex:1" self.assertEqual(custom, normal)
def test3(self): # now do similar stuff but with a NamespaceManager object instead... custom = CustomURIRef(uri=URIRef("www.example.org/1"), namespaces=self.graph.namespace_manager) normal = URIRef("www.example.org/1") self.assertEqual(custom, normal)