示例#1
0
    def test_find_leaf_branch(self):
        """
        Given a list of leaf nodes, find the appropriate node from the given jsonld

        """

        jsonld_graph = {
            "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by": {
                "@id":
                "http://*****:*****@type":
                "http://www.cidoc-crm.org/cidoc-crm/E82_Actor_Appellation",
                "http://www.w3.org/1999/02/22-rdf-syntax-ns#value": "Will",
            }
        }

        graphtree = self.unique_graph.get_tree()
        for child in graphtree["children"]:
            if child["node"].name == "Name":
                node = child
        reader = JsonLdReader()
        branch = reader.findBranch(
            node["children"],
            "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by",
            jsonld_graph[
                "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by"],
        )
        self.assertEqual(str(branch["node"].pk),
                         "839b0e4c-95e6-11e8-aada-14109fd34195")
示例#2
0
    def test_find_branch_from_jsonld_2(self):
        """
        The same test as above except that we now add an additional node to the supplied json which now will match a branch in the graph
        The graph is partially unique (the children of the root are not unique)

        """

        ambiguous_jsonld_graph = {
            "@id":
            "http://*****:*****@type": [
                "http://www.cidoc-crm.org/cidoc-crm/E82_Actor_Appellation",
                "http://*****:*****@id":
                "http://*****:*****@type":
                "http://www.cidoc-crm.org/cidoc-crm/E41_Appellation",
                "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by": {
                    "@id":
                    "http://*****:*****@type":
                    "http://www.cidoc-crm.org/cidoc-crm/E82_Actor_Appellation",
                    "http://www.w3.org/1999/02/22-rdf-syntax-ns#value": "Will",
                },
                "http://www.cidoc-crm.org/cidoc-crm/P1i_identifies": {
                    "@id":
                    "http://*****:*****@type":
                    "http://www.cidoc-crm.org/cidoc-crm/E41_Appellation",
                    "http://www.w3.org/1999/02/22-rdf-syntax-ns#value":
                    "Smith",
                },
            }],
        }

        graphtree = self.ambiguous_graph.get_tree()
        reader = JsonLdReader()
        branch = reader.findBranch(
            graphtree["children"],
            "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by",
            ambiguous_jsonld_graph[
                "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by"],
        )
        self.assertEqual(str(branch["node"].pk),
                         "3f40c4c0-9693-11e8-8a0f-14109fd34195")
示例#3
0
    def test_find_unique_branch_from_jsonld(self):
        """
        Test that we can find the correct branch in the graph that matches the supplied json-ld
        The graph is partially unique (the children of the root are not unique)

        """

        jsonld_graph = {
            "@id":
            "http://*****:*****@type": [
                "http://*****:*****@id":
                "http://*****:*****@type": "http://www.cidoc-crm.org/cidoc-crm/E41_Appellation",
                "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by": {
                    "@id":
                    "http://*****:*****@type":
                    "http://www.cidoc-crm.org/cidoc-crm/E82_Actor_Appellation",
                    "http://www.w3.org/1999/02/22-rdf-syntax-ns#value": "Will",
                },
                "http://www.cidoc-crm.org/cidoc-crm/P1i_identifies": {
                    "@id":
                    "http://*****:*****@type":
                    "http://www.cidoc-crm.org/cidoc-crm/E41_Appellation",
                    "http://www.w3.org/1999/02/22-rdf-syntax-ns#value":
                    "Smith",
                },
            },
        }
        graphtree = self.unique_graph.get_tree()
        reader = JsonLdReader()
        branch = reader.findBranch(
            graphtree["children"],
            "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by",
            jsonld_graph[
                "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by"],
        )
        self.assertEqual(str(branch["node"].pk),
                         "3e1e65dc-95e6-11e8-9de9-14109fd34195")
示例#4
0
    def test_cant_find_branch_from_ambiguous_jsonld(self):
        """
        Test that we raise the appropriate error when we can't find the correct branch in the graph given that the supplied
        json-ld could match more than one branch
        The graph is partially unique (the children of the root are not unique)

        """

        ambiguous_jsonld_graph = {
            "@id":
            "http://*****:*****@type": [
                "http://www.cidoc-crm.org/cidoc-crm/E82_Actor_Appellation",
                "http://*****:*****@id":
                "http://*****:*****@type":
                "http://www.cidoc-crm.org/cidoc-crm/E41_Appellation",
                "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by": {
                    "@id":
                    "http://*****:*****@type":
                    "http://www.cidoc-crm.org/cidoc-crm/E82_Actor_Appellation",
                    "http://www.w3.org/1999/02/22-rdf-syntax-ns#value":
                    "Will - Ambiguous",
                },
            }],
        }

        graphtree = self.ambiguous_graph.get_tree()
        reader = JsonLdReader()
        with self.assertRaises(reader.AmbiguousGraphException) as cm:
            branch = reader.findBranch(
                graphtree["children"],
                "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by",
                ambiguous_jsonld_graph[
                    "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by"],
            )
示例#5
0
    def test_find_other_unique_branch_from_jsonld(self):
        """
        Test that we can find the correct branch in the graph that matches the supplied json-ld
        The graph is partially unique (the children of the root are not unique)

        """

        jsonld_graph = {
            "@id":
            "http://*****:*****@type": [
                "http://www.cidoc-crm.org/cidoc-crm/E82_Actor_Appellation",
                "http://*****:*****@id":
                "http://*****:*****@type":
                "http://www.cidoc-crm.org/cidoc-crm/E41_Appellation",
                "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by": {
                    "@id":
                    "http://*****:*****@type":
                    "http://www.ics.forth.gr/isl/CRMdig/D21_Person_Name",
                    "http://www.w3.org/1999/02/22-rdf-syntax-ns#value":
                    "The Shadow",
                },
            }],
        }

        graphtree = self.unique_graph.get_tree()
        reader = JsonLdReader()
        branch = reader.findBranch(
            graphtree["children"],
            "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by",
            jsonld_graph[
                "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by"],
        )
        self.assertEqual(str(branch["node"].pk),
                         "91679e1e-95e6-11e8-a166-14109fd34195")
示例#6
0
    def test_cant_find_branch_from_jsonld(self):
        """
        Test that we raise the appropriate error when we can't find the correct branch in the graph that matches the supplied json-ld
        The graph is partially unique (the children of the root are not unique)

        """

        incorrect_jsonld_graph = {
            "@id":
            "http://*****:*****@type": [
                "http://www.cidoc-crm.org/cidoc-crm/E82_Actor_Appellation",
                "http://*****:*****@id":
                "http://*****:*****@type":
                "http://www.cidoc-crm.org/cidoc-crm/E41_Appellation",
                "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by": {
                    "@id":
                    "http://*****:*****@type":
                    "---THIS TYPE IS INCORRECT AND SHOULN'T MATCH---",
                    "http://www.w3.org/1999/02/22-rdf-syntax-ns#value":
                    "The Shadow",
                },
            }],
        }

        graphtree = self.unique_graph.get_tree()
        reader = JsonLdReader()
        with self.assertRaises(reader.DataDoesNotMatchGraphException) as cm:
            branch = reader.findBranch(
                graphtree["children"],
                "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by",
                incorrect_jsonld_graph[
                    "http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by"],
            )
示例#7
0
    def test_cant_find_branch_from_complex_ambigious_jsonld(self):
        """
        The same test as above except that we now supply a jsonld structure that matches more then one branch in the graph (it's ambiguous)

        """

        complex_jsonld_graph = {
            "@id":
            "http://*****:*****@type": [
                "http://www.cidoc-crm.org/cidoc-crm/E12_Production",
                "http://*****:*****@id":
                "http://*****:*****@type":
                "http://www.cidoc-crm.org/cidoc-crm/E17_Type_Assignment",
                "http://www.cidoc-crm.org/cidoc-crm/P42_assigned": [
                    {
                        "@id":
                        "http://*****:*****@type":
                        "http://www.cidoc-crm.org/cidoc-crm/E55_Type",
                        "http://www.w3.org/1999/02/22-rdf-syntax-ns#value":
                        "174e9486-0663-4c9d-ab78-c7e441720c26",
                    },
                    {
                        "@id":
                        "http://*****:*****@type": "http://www.cidoc-crm.org/cidoc-crm/E55_Type",
                        "http://www.w3.org/1999/02/22-rdf-syntax-ns#value":
                        "None",
                    },
                ],
                "http://www.cidoc-crm.org/cidoc-crm/P4_has_time-span": {
                    "@id":
                    "http://*****:*****@type":
                    "http://www.cidoc-crm.org/cidoc-crm/E52_Time-Span",
                    "http://www.cidoc-crm.org/cidoc-crm/P78_is_identified_by":
                    [
                        {
                            "@id":
                            "http://*****:*****@type":
                            "http://www.cidoc-crm.org/cidoc-crm/E49_Time_Appellation",
                            "http://www.w3.org/1999/02/22-rdf-syntax-ns#value":
                            "2018-08-06",
                        },
                        {
                            "@id":
                            "http://*****:*****@type":
                            "http://www.cidoc-crm.org/cidoc-crm/E49_Time_Appellation",
                            "http://www.w3.org/1999/02/22-rdf-syntax-ns#value":
                            "2018-09-20",
                        },
                    ],
                },
            }],
        }

        graphtree = self.phase_type_assignment_graph.get_tree()
        reader = JsonLdReader()
        with self.assertRaises(reader.AmbiguousGraphException) as cm:
            branch = reader.findBranch(
                graphtree["children"],
                "http://www.cidoc-crm.org/cidoc-crm/P41i_was_classified_by",
                complex_jsonld_graph[
                    "http://www.cidoc-crm.org/cidoc-crm/P41i_was_classified_by"],
            )
示例#8
0
    def test_find_branch_from_complex_jsonld(self):
        """
        Given a more complicated json structure find the branch in the graph

        """

        complex_jsonld_graph = {
            "@id":
            "http://*****:*****@type": [
                "http://www.cidoc-crm.org/cidoc-crm/E12_Production",
                "http://*****:*****@id":
                "http://*****:*****@type":
                "http://www.cidoc-crm.org/cidoc-crm/E17_Type_Assignment",
                "http://www.cidoc-crm.org/cidoc-crm/P42_assigned": {
                    "@id":
                    "http://*****:*****@type": "http://www.cidoc-crm.org/cidoc-crm/E55_Type",
                    "http://www.w3.org/1999/02/22-rdf-syntax-ns#value": "None",
                },
                "http://www.cidoc-crm.org/cidoc-crm/P2_has_type": {
                    "@id":
                    "http://*****:*****@type":
                    "http://www.cidoc-crm.org/cidoc-crm/E55_Type",
                    "http://www.w3.org/1999/02/22-rdf-syntax-ns#value":
                    "51cbfba6-34ee-4fbd-8b6e-10ef73fd4083",
                },
                "http://www.cidoc-crm.org/cidoc-crm/P4_has_time-span": {
                    "@id":
                    "http://*****:*****@type":
                    "http://www.cidoc-crm.org/cidoc-crm/E52_Time-Span",
                    "http://www.cidoc-crm.org/cidoc-crm/P78_is_identified_by":
                    [
                        {
                            "@id":
                            "http://*****:*****@type":
                            "http://www.cidoc-crm.org/cidoc-crm/E49_Time_Appellation",
                            "http://www.w3.org/1999/02/22-rdf-syntax-ns#value":
                            "2018-08-05",
                        },
                        {
                            "@id":
                            "http://*****:*****@type":
                            "http://www.cidoc-crm.org/cidoc-crm/E49_Time_Appellation",
                            "http://www.w3.org/1999/02/22-rdf-syntax-ns#value":
                            "2018-08-06",
                        },
                    ],
                },
            }],
        }

        graphtree = self.phase_type_assignment_graph.get_tree()
        reader = JsonLdReader()
        branch = reader.findBranch(
            graphtree["children"],
            "http://www.cidoc-crm.org/cidoc-crm/P41i_was_classified_by",
            complex_jsonld_graph[
                "http://www.cidoc-crm.org/cidoc-crm/P41i_was_classified_by"],
        )
        self.assertEqual(str(branch["node"].pk),
                         "049fc0c9-fa36-11e6-9e3e-026d961c88e6")