def test_get_n_levels_down(self): known_label = "lamd:md_DTN" node = rdf2g.get_node(self.g, known_label) tree = rdf2g.generate_traversal_tree(self.g, node, max_depth=2) exp_tree = rdf2g.expand_tree(self.g, tree) assert exp_tree[0]["@label"] == "lamd:md_DTN", "Not the expected node: " + known_label assert exp_tree[0]["rdf:type"]["@label"] == "skos:Concept", "Not a concept"
def test_generate_tree(self): known_label = "celexd:md_DTN" node = rdf2g.get_node(self.g, known_label) tree = rdf2g.generate_traversal_tree(self.g, node, max_depth=1) assert tree, "Nothing returned" assert tree["@value"], "Unexpected tree structure" assert tree["@value"][0]["value"], "Unexpected tree structure" assert 4 > len(tree["@value"][0]["value"] ["@value"]) > 2, "Unexpected tree structure" assert tree["@value"][0]["value"]["@value"][1][ "value"], "Unexpected tree structure"
def test_expand_tree_1(self): known_label = "celexd:md_DTN" node = rdf2g.get_node(self.g, known_label) tree = rdf2g.generate_traversal_tree(self.g, node, max_depth=1) exp_tree = rdf2g.expand_tree(self.g, tree) pprint(exp_tree) assert exp_tree, "Nothing returned" assert "@id" in exp_tree[0] and "@label" in exp_tree[ 0], "Unexpected tree structure" assert exp_tree[0][ "@label"] == known_label, "Unexpected tree structure" assert exp_tree[0]["rdf:type"][ "@label"] == "skos:Concept", "Unexpected tree structure"
def test_expand_tree_multi_value(self): skos_concept_iri = rdflib.URIRef( "http://publications.europa.eu/resources/authority/lam/res_h9ci2wPXrcUXBh9JkkHzUY" ) skos_concept_label = "lamd:res_h9ci2wPXrcUXBh9JkkHzUY" node = rdf2g.get_node(self.g, skos_concept_label) # pprint(str(node)) tree = rdf2g.generate_traversal_tree(self.g, node, max_depth=2) # pprint(tree) exp_tree = rdf2g.expand_tree(self.g, tree)[0] # pprint(exp_tree) assert isinstance(exp_tree["skos:member"], list), "Expecting multiple members" assert "rdf:type" in exp_tree["skos:member"][ 0], "Expecting an rdf:type [0]" assert "rdf:type" in exp_tree["skos:member"][ 1], "Expecting an rdf:type [1]" assert "rdf:type" in exp_tree["skos:member"][ 2], "Expecting an rdf:type [2]"
def test_operations(self): known_label = "http://sample.igsn.org/soilarchive/bqs2dj2u6s73o70jcpr0" node = rdf2g.get_node(self.g, known_label) tree = rdf2g.generate_traversal_tree(self.g, node, max_depth=1) print(tree)
def __generate_tree(self, for_nodes, content_key, default_max_depth=3): css_trees = [rdf2g.generate_traversal_tree(self.g, root_=cs, max_depth=default_max_depth) for cs in for_nodes] css_exp_tees = [rdf2g.expand_tree(self.g, cs_tree) for cs_tree in css_trees] # flatten the dicts css_exp_tees = [i[0] if len(i) == 1 else i for i in css_exp_tees] self.content[content_key] = css_exp_tees