Skip to content

Commit 798b109

Browse files
committed
fixed problem with prov:Agent metadata for freesurfer, ants, fsl segmentations in corr datasets which only have segmentations and no other project-level metadata
1 parent 06e78ba commit 798b109

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

src/nidm/experiment/Utils.py

+36-9
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,12 @@ def read_nidm(nidmDoc):
471471
# print(query2)
472472
qres2 = rdf_graph_parse.query(query2)
473473

474+
# check qres2 length and if zero then skip all this converting from prov to rdf and back to add
475+
# data element isAbout definitions that are identified with a url and not a qualified name as required by prov
476+
# but not rdf in general
477+
if len(qres2) == 0:
478+
continue
479+
474480
# Step 1: Convert `project.graph` (ProvDocument) to an RDFLib Graph
475481
rdf_graph = Graph()
476482
rdf_graph.parse(
@@ -583,11 +589,25 @@ def add_metadata_for_subject(rdf_graph, subject_uri, namespaces, nidm_obj):
583589
# so we check explicitly here
584590
if obj_nm == str(Constants.PROV):
585591
nidm_obj.add_attributes(
586-
{predicate: QualifiedName(Constants.PROV[obj_term])}
592+
{
593+
predicate: pm.QualifiedName(
594+
namespace=pm.Namespace(
595+
uri=Constants.PROV, prefix="prov"
596+
),
597+
localpart=str(obj_term),
598+
)
599+
}
587600
)
588601
elif obj_nm == str(Constants.NIDM):
589602
nidm_obj.add_attributes(
590-
{predicate: QualifiedName(Constants.NIDM[obj_term])}
603+
{
604+
predicate: pm.QualifiedName(
605+
namespace=pm.Namespace(
606+
uri=Constants.NIDM, prefix="prov"
607+
),
608+
localpart=str(obj_term),
609+
)
610+
}
591611
)
592612
else:
593613
found_uri = find_in_namespaces(
@@ -596,20 +616,27 @@ def add_metadata_for_subject(rdf_graph, subject_uri, namespaces, nidm_obj):
596616
# if obj_nm is not in namespaces then it must just be part of some URI in the triple
597617
# so just add it as a prov.Identifier
598618
if not found_uri:
599-
nidm_obj.add_attributes({predicate: Identifier(objects)})
619+
nidm_obj.add_attributes({predicate: URIRef(objects)})
600620
# else add as explicit prov.QualifiedName because it's easier to read
601621
else:
602622
nidm_obj.add_attributes(
603623
{predicate: pm.QualifiedName(found_uri, obj_term)}
604624
)
605625
except Exception:
606-
nidm_obj.add_attributes(
607-
{
608-
predicate: pm.QualifiedName(
609-
namespace=Namespace(str(objects)), localpart=""
610-
)
611-
}
626+
# here we likely have a uri without a localpart so we'll search and see if we have a namespace for
627+
# it.
628+
found_uri = find_in_namespaces(
629+
search_uri=URIRef(str(objects)), namespaces=namespaces
612630
)
631+
632+
# if objects is not in namespaces just add as a generic url
633+
if not found_uri:
634+
nidm_obj.add_attributes({predicate: URIRef(objects)})
635+
# else add as explicit prov.QualifiedName because it's easier to read
636+
else:
637+
nidm_obj.add_attributes(
638+
{predicate: pm.QualifiedName(found_uri, "")}
639+
)
613640
else:
614641
# check if this is a qname and if so expand it
615642
# added to handle when a value is a qname. this should expand it....

0 commit comments

Comments
 (0)