Example #1
0
 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"
Example #2
0
    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"
Example #3
0
 def test_transform_graph(self):
     known_iri = 'http://publications.europa.eu/resources/authority/celex/md_CODE'
     s = self.g.V().has('iri', known_iri).outE().inV().tree().next()
     result = rdf2g.expand_tree(self.g, s)
     assert result, "Nothing returned"
     assert result[0][
         "@label"] == 'celexd:md_CODE', "Unexpected label %s" % result[0][
             "@label"]
     assert result[0]["rdf:type"]["@label"] == "skos:Concept", "Unexpected rdf:type label %s" % \
                                                               result[0]["rdf:type"][
                                                                   "@label"]
     assert result[0]["skos:inScheme"]["@label"] == "lamd:DocumentProperty", "Unexpected label %s" % \
                                                                             result[0]["skos:inScheme"]["@label"]
     assert result[0]["skos:inScheme"]["skos:prefLabel"] == "Document metadata", "Unexpected label %s" % \
                                                                                 result[0]["skos:inScheme"][
                                                                                     "skos:prefLabel"]
Example #4
0
    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]"
Example #5
0
 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