Exemplo n.º 1
0
    def test_get_node(self):
        skos_concept_iri = rdflib.URIRef(
            "http://www.w3.org/2004/02/skos/core#Concept")
        skos_concept_label = "skos:Concept"
        skos_concept_id = self.g.V().hasLabel(
            skos_concept_label).toList()[0].id
        skos_concept_node = self.g.V().hasLabel(skos_concept_label).toList()[0]
        # known_iri_str = "http://publications.europa.eu/resources/authority/celex/md_OJ_ID"

        n = rdf2g.get_node(self.g, skos_concept_iri)
        assert isinstance(n, Vertex), "The node is not found; 1"
        assert rdf2g.get_node_properties(
            self.g, n)["@label"] == skos_concept_label, "Wrong label"
        n = rdf2g.get_node(self.g, skos_concept_label)
        assert isinstance(n, Vertex), "The node is not found; 2"
        assert rdf2g.get_node_properties(
            self.g, n)["@label"] == skos_concept_label, "Wrong label"
        n = rdf2g.get_node(self.g, skos_concept_id)
        assert isinstance(n, Vertex), "The node is not found; 3"
        assert rdf2g.get_node_properties(
            self.g, n)["@label"] == skos_concept_label, "Wrong label"
        n = rdf2g.get_node(self.g, skos_concept_node)
        assert isinstance(n, Vertex), "The node is not found; 4"
        assert rdf2g.get_node_properties(
            self.g, n)["@label"] == skos_concept_label, "Wrong label"
Exemplo n.º 2
0
    def test_get_node_1(self):
        skos_concept_iri = rdflib.URIRef(
            "http://publications.europa.eu/resources/authority/lam/res_h9ci2wPXrcUXBh9JkkHzUY"
        )
        skos_concept_label = "lamd:res_h9ci2wPXrcUXBh9JkkHzUY"
        pprint(self.g.V().hasLabel(skos_concept_label).toList())

        skos_concept_id = self.g.V().hasLabel(
            skos_concept_label).toList()[0].id
        skos_concept_node = self.g.V().hasLabel(skos_concept_label).toList()[0]

        n = rdf2g.get_node(self.g, skos_concept_iri)
        assert isinstance(n, Vertex), "The node is not found; 1"
        assert rdf2g.get_node_properties(
            self.g, n)["@label"] == skos_concept_label, "Wrong label"
        n = rdf2g.get_node(self.g, skos_concept_label)
        assert isinstance(n, Vertex), "The node is not found; 2"
        assert rdf2g.get_node_properties(
            self.g, n)["@label"] == skos_concept_label, "Wrong label"
        n = rdf2g.get_node(self.g, skos_concept_id)
        assert isinstance(n, Vertex), "The node is not found; 3"
        assert rdf2g.get_node_properties(
            self.g, n)["@label"] == skos_concept_label, "Wrong label"
        n = rdf2g.get_node(self.g, skos_concept_node)
        assert isinstance(n, Vertex), "The node is not found; 4"
        assert rdf2g.get_node_properties(
            self.g, n)["@label"] == skos_concept_label, "Wrong label"
Exemplo n.º 3
0
    def test_add_edge(self):
        known_iri_str1 = "http://publications.europa.eu/resources/authority/celex/md_OJ_ID"
        known_iri_str2 = "http://www.w3.org/2004/02/skos/core#Concept"
        known_iri_str3 = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
        known_iri_str4 = "http://www.w3.org/1999/02/22-rdf-syntax-ns#super-type"

        v1 = rdf2g.get_node(self.g, known_iri_str1)
        v2 = rdf2g.get_node(self.g, known_iri_str2)
        rdf2g.link_nodes(self.g, v1, v2, rdflib.URIRef(known_iri_str3),
                         self.rdf_graph)
        rdf2g.link_nodes(self.g, v1, v2, rdflib.URIRef(known_iri_str4),
                         self.rdf_graph)
Exemplo n.º 4
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"
Exemplo n.º 5
0
 def __get_top_collections(self, collection_qname="skos:Collection"):
     """
         get nodes that are collections and have no incoming skos:member relations
     :return:
     """
     type_id = rdf2g.get_node(self.g, collection_qname)
     collections = self.g.V().match(__.as_("a").out("rdf:type").hasId(type_id.id),
                                    __.not_(__.as_("a").in_("skos:member"))).select("a").toList()
     return collections
Exemplo n.º 6
0
    def test_load_properties(self):
        self.rdf_graph_props = rdflib.Graph()
        self.rdf_graph_props.parse(str(LAM_PROPERTY_EXAMPLE), format="ttl")
        logging.info('%s triples loaded into RDF graph' % str(len(self.rdf_graph_props)))

        rdf2g.clear_graph(self.g)
        known_label = "lamd:md_DTN"
        assert rdf2g.load_rdf2g(self.g, self.rdf_graph_props), "Could not load the graph"
        assert rdf2g.get_node(self.g, known_label), "Could not find the node " + known_label
Exemplo n.º 7
0
    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"
Exemplo n.º 8
0
    def test_add_property(self):
        known_iri_str = "http://publications.europa.eu/resources/authority/celex/md_OJ_ID"
        n = rdf2g.get_node(self.g, known_iri_str)

        rdf2g.add_property(self.g, n, "property", "value", self.rdf_graph)
        props = rdf2g.get_node_properties(self.g, n)
        assert 'property' in props, "Expecting 'property' key among the node properties "

        rdf2g.add_property(self.g, n, rdflib.URIRef(known_iri_str),
                           "super value", self.rdf_graph)
        props = rdf2g.get_node_properties(self.g, n)
        assert 'celexd:md_OJ_ID' in props, "Expecting 'celexd:md_OJ_ID' key among the node properties "
Exemplo n.º 9
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"
Exemplo n.º 10
0
    def test_get_top_collections(self):
        """
            This test works with Version LAM_metadata_05_ECO of the source file
        :return:
        """
        known_label = "skos:Collection"
        type_id = rdf2g.get_node(self.g, known_label)
        # 17 expoected
        collections = self.g.V().as_("node").where(__.out("rdf:type").hasId(type_id.id)).select("node").dedup().toList()
        assert len(collections) > 10, "Did not retrieve the expected  17 collections"
        collections = self.g.V().match(__.as_("a").out("rdf:type").hasId(type_id.id),
                                       __.as_("a").in_("skos:member")).select("a").properties(
            "skos:prefLabel").toList()
        assert len(collections) > 5, "Did not retrieve the expected 9 collections"

        collections = self.g.V().match(__.as_("a").out("rdf:type").hasId(type_id.id),
                                       __.not_(__.as_("a").in_("skos:member"))).select("a").toList()
        assert len(collections) > 5, "Did not retrieve the expected 8 collections"
Exemplo n.º 11
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]"
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
 def test_get_node_properties(self):
     known_iri_str = "http://publications.europa.eu/resources/authority/celex/md_OJ_ID"
     n = rdf2g.get_node(self.g, known_iri_str)
     props = rdf2g.get_node_properties(self.g, n)
     assert 'iri' in props, "Expecting 'iri' key among the node properties "