@@ -471,6 +471,12 @@ def read_nidm(nidmDoc):
471
471
# print(query2)
472
472
qres2 = rdf_graph_parse .query (query2 )
473
473
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
+
474
480
# Step 1: Convert `project.graph` (ProvDocument) to an RDFLib Graph
475
481
rdf_graph = Graph ()
476
482
rdf_graph .parse (
@@ -583,11 +589,25 @@ def add_metadata_for_subject(rdf_graph, subject_uri, namespaces, nidm_obj):
583
589
# so we check explicitly here
584
590
if obj_nm == str (Constants .PROV ):
585
591
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
+ }
587
600
)
588
601
elif obj_nm == str (Constants .NIDM ):
589
602
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
+ }
591
611
)
592
612
else :
593
613
found_uri = find_in_namespaces (
@@ -596,20 +616,27 @@ def add_metadata_for_subject(rdf_graph, subject_uri, namespaces, nidm_obj):
596
616
# if obj_nm is not in namespaces then it must just be part of some URI in the triple
597
617
# so just add it as a prov.Identifier
598
618
if not found_uri :
599
- nidm_obj .add_attributes ({predicate : Identifier (objects )})
619
+ nidm_obj .add_attributes ({predicate : URIRef (objects )})
600
620
# else add as explicit prov.QualifiedName because it's easier to read
601
621
else :
602
622
nidm_obj .add_attributes (
603
623
{predicate : pm .QualifiedName (found_uri , obj_term )}
604
624
)
605
625
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
612
630
)
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
+ )
613
640
else :
614
641
# check if this is a qname and if so expand it
615
642
# added to handle when a value is a qname. this should expand it....
0 commit comments