1717
1818from rocrate_validator .models import Severity
1919from tests .ro_crates import ValidROC
20- from tests .shared import do_entity_test
20+ from tests .shared import do_entity_test , SPARQL_PREFIXES
2121
2222# set up logging
2323logger = logging .getLogger (__name__ )
@@ -27,18 +27,10 @@ def test_5src_root_data_entity_no_source_organization():
2727 """\
2828 Test a Five Safes Crate where the Root Data Entity it does not reference a sourceOrganization.
2929 """
30- def remove_source_org (graph ):
31- SCHEMA = rdflib .Namespace ("http://schema.org/" )
32- target_subject = rdflib .URIRef ("./" )
33- target_predicate = SCHEMA .sourceOrganization
34- target_object = None
35-
36- for s , p , o in graph .triples ((target_subject , target_predicate , target_object )):
37- print (f"Removing: { s } , { p } , { o } " )
38-
39- graph .remove ((target_subject , target_predicate , target_object ))
40-
41- return graph
30+ sparql = SPARQL_PREFIXES + """DELETE WHERE {
31+ <./> schema:sourceOrganization ?object
32+ }
33+ """
4234
4335 do_entity_test (
4436 rocrate_path = ValidROC ().five_safes_crate_result ,
@@ -50,28 +42,25 @@ def remove_source_org(graph):
5042 SHOULD link to a Contextual Entity in the RO-Crate Metadata File with a name."""
5143 ],
5244 profile_identifier = "five-safes-crate" ,
53- rocrate_entity_mod_function = remove_source_org ,
45+ rocrate_entity_mod_sparql = sparql ,
5446 )
5547
5648
5749def test_5src_root_data_entity_source_organization_not_entity ():
5850 """\
5951 Test a Five Safes Crate where the Root Data Entity it does not reference a sourceOrganization.
6052 """
61- def replace_source_org (graph ):
62- SCHEMA = rdflib .Namespace ("http://schema.org/" )
63- target_subject = rdflib .URIRef ("./" )
64- target_predicate = SCHEMA .sourceOrganization
65- original_object = None
66- new_object = rdflib .Literal ('Investigation of cancer (TRE72 project 81)' )
67-
68- for s , p , o in graph .triples ((target_subject , target_predicate , original_object )):
69- print (f"Replacing: { s } , { p } , { o } " )
70-
71- graph .remove ((target_subject , target_predicate , original_object ))
72- graph .add ((target_subject , target_predicate , new_object ))
53+ sparql = SPARQL_PREFIXES + """DELETE {
54+ <./> schema:sourceOrganization ?o
55+ }
56+ INSERT {
57+ <./> schema:sourceOrganization "Investigation of cancer (TRE72 project 81)"
58+ }
59+ WHERE {
60+ <./> schema:sourceOrganization ?o
61+ }
7362
74- return graph
63+ """
7564
7665 do_entity_test (
7766 rocrate_path = ValidROC ().five_safes_crate_result ,
@@ -83,5 +72,5 @@ def replace_source_org(graph):
8372 SHOULD link to a Contextual Entity in the RO-Crate Metadata File with a name."""
8473 ],
8574 profile_identifier = "five-safes-crate" ,
86- rocrate_entity_mod_function = replace_source_org ,
75+ rocrate_entity_mod_sparql = sparql ,
8776 )
0 commit comments