diff --git a/src/dsp_tools/analyse_xml_data/construct_and_analyze_graph.py b/src/dsp_tools/analyse_xml_data/construct_and_analyze_graph.py index 11cbcacae..46214d36c 100644 --- a/src/dsp_tools/analyse_xml_data/construct_and_analyze_graph.py +++ b/src/dsp_tools/analyse_xml_data/construct_and_analyze_graph.py @@ -28,7 +28,7 @@ def create_info_from_xml_for_graph( resptr_links = [] xml_links = [] all_resource_ids = [] - for resource in root.iter(tag="{https://dasch.swiss/schema}resource"): + for resource in root.iter(tag="resource"): resptr, xml = _create_info_from_xml_for_graph_from_one_resource(resource) all_resource_ids.append(resource.attrib["id"]) resptr_links.extend(resptr) @@ -43,9 +43,9 @@ def _create_info_from_xml_for_graph_from_one_resource( xml_links: list[XMLLink] = [] for prop in resource.getchildren(): match prop.tag: - case "{https://dasch.swiss/schema}resptr-prop": + case "resptr-prop": resptr_links.extend(_create_resptr_link_objects(resource.attrib["id"], prop)) - case "{https://dasch.swiss/schema}text-prop": + case "text-prop": xml_links.extend(_create_text_link_objects(resource.attrib["id"], prop)) return resptr_links, xml_links diff --git a/test/unittests/test_analyse_xml_data/test_construct_and_analyze_graph.py b/test/unittests/test_analyse_xml_data/test_construct_and_analyze_graph.py index e3645dada..9bacc701b 100644 --- a/test/unittests/test_analyse_xml_data/test_construct_and_analyze_graph.py +++ b/test/unittests/test_analyse_xml_data/test_construct_and_analyze_graph.py @@ -40,6 +40,7 @@ def test_create_info_from_xml_for_graph_from_one_resource() -> None: """ ) + remove_namespace(test_ele) res_resptr_links, res_xml_links = _create_info_from_xml_for_graph_from_one_resource(test_ele) res_B_19 = [obj.target_id for obj in res_resptr_links] assert "res_B_19" in res_B_19 @@ -64,6 +65,7 @@ def test_create_info_from_xml_for_graph_from_one_resource_one() -> None: """ ) + remove_namespace(test_ele) res_resptr, res_xml = _create_info_from_xml_for_graph_from_one_resource(test_ele) assert res_resptr[0].target_id == "res_B_11" assert isinstance(res_resptr[0], ResptrLink) @@ -75,6 +77,7 @@ def test_create_info_from_xml_for_graph_from_one_resource_no_links() -> None: test_ele = etree.fromstring( '' ) + remove_namespace(test_ele) res_resptr, res_xml = _create_info_from_xml_for_graph_from_one_resource(test_ele) assert (res_resptr, res_xml) == ([], []) @@ -95,6 +98,7 @@ def test_text_only_create_info_from_xml_for_graph_from_one_resource() -> None: """ ) + remove_namespace(test_ele) res_resptr, res_xml = _create_info_from_xml_for_graph_from_one_resource(test_ele) assert not res_resptr res_xml_ids = [x.target_ids for x in res_xml] @@ -109,6 +113,7 @@ def test_extract_id_one_text_with_one_id() -> None: """ ) + remove_namespace(test_ele) res = _extract_ids_from_one_text_value(test_ele) assert res == {"res_A_11"} @@ -118,6 +123,7 @@ def test_extract_id_one_text_with_iri() -> None: 'res_A_11' ) + remove_namespace(test_ele) res = _extract_ids_from_one_text_value(test_ele) assert res == set() @@ -132,6 +138,7 @@ def test_extract_id_one_text_with_several_id() -> None: """ ) + remove_namespace(test_ele) res = _extract_ids_from_one_text_value(test_ele) assert res == {"res_A_11", "res_B_11"} @@ -143,6 +150,7 @@ def test_extract_ids_from_text_prop_with_several_text_links() -> None: 'href="IRI:res_A_18:IRI">res_A_18res_B_18' ) + remove_namespace(test_ele) res = _create_text_link_objects("res_C_18", test_ele) res_ids = [x.target_ids for x in res] assert unordered(res_ids) == [{"res_A_18"}, {"res_B_18"}] @@ -157,6 +165,7 @@ def test_create_class_instance_resptr_link_one_link() -> None: """ ) + remove_namespace(test_ele) res = _create_resptr_link_objects("res_A_15", test_ele) assert res[0].target_id == "res_C_15" @@ -172,6 +181,7 @@ def test_create_class_instance_resptr_link_several() -> None: """ ) + remove_namespace(test_ele) res = _create_resptr_link_objects("res_D_13", test_ele) assert all(isinstance(x, ResptrLink) for x in res) assert res[0].target_id == "res_A_13" @@ -192,15 +202,16 @@ def test_create_info_from_xml_for_graph_check_UUID_in_root() -> None: b'href="IRI:res_C_11:IRI">res_C_11end text.' ) + remove_namespace(root) res_resptr_li, res_xml_li, res_all_ids = create_info_from_xml_for_graph(root) res_resptr = res_resptr_li[0] assert isinstance(res_resptr, ResptrLink) res_xml = res_xml_li[0] assert isinstance(res_xml, XMLLink) assert unordered(res_all_ids) == ["res_A_11", "res_B_11", "res_C_11"] - xml_res_resptr = root.find(".//{https://dasch.swiss/schema}resptr") + xml_res_resptr = root.find(".//resptr") assert xml_res_resptr.attrib["stashUUID"] == res_resptr.link_uuid # type: ignore[union-attr] - xml_res_text = root.find(".//{https://dasch.swiss/schema}text") + xml_res_text = root.find(".//text") assert xml_res_text.attrib["stashUUID"] == res_xml.link_uuid # type: ignore[union-attr] @@ -558,5 +569,11 @@ def test_generate_upload_order_two_circles() -> None: assert not list(graph.nodes()) +def remove_namespace(tag: etree._Element) -> None: + """Remove namespace URI from the element's name, including all its children.""" + for elem in tag.iter(): + elem.tag = etree.QName(elem).localname + + if __name__ == "__main__": pytest.main([__file__])