File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,18 @@ def _resolve_links(self, node_lookup):
152152 if isinstance (value , Link ):
153153 resolved_value = node_lookup [value .identifier ]
154154 setattr (self , property .name , resolved_value )
155+ elif hasattr (value , "_resolve_links" ):
156+ value ._resolve_links (node_lookup )
157+ elif isinstance (value , (tuple , list )):
158+ resolved_values = []
159+ for item in value :
160+ if isinstance (item , Link ):
161+ resolved_values .append (node_lookup [item .identifier ])
162+ else :
163+ resolved_values .append (item )
164+ if hasattr (item , "_resolve_links" ):
165+ item ._resolve_links (node_lookup )
166+ setattr (self , property .name , resolved_values )
155167
156168
157169class LinkedMetadata (Node ):
Original file line number Diff line number Diff line change @@ -186,3 +186,31 @@ def test_issue0008():
186186 "givenName" : "A" ,
187187 }
188188 assert actual == expected
189+
190+
191+ def test_issue0026 ():
192+ # https://github.com/openMetadataInitiative/openMINDS_Python/issues/26
193+ # When reading a JSON-LD file, the attributes of LinkedMetadata nodes
194+ # inside EmbeddedMetadata nodes are not set properly
195+
196+ uni1 = omcore .Organization (full_name = "University of This Place" , id = "_:uthisp" )
197+ person = omcore .Person (
198+ given_name = "A" ,
199+ family_name = "Professor" ,
200+ affiliation = [omcore .Affiliation (member_of = uni1 )],
201+ id = "_:ap"
202+ )
203+
204+ c = Collection (person )
205+
206+ # uni1 was not added explicitly, but should nevertheless be included in the JSON-LD export
207+
208+ output_paths = c .save ("issue0026.jsonld" , individual_files = False , include_empty_properties = False )
209+
210+ new_collection = Collection ()
211+ new_collection .load (* output_paths )
212+ os .remove ("issue0026.jsonld" )
213+
214+ person_again = [item for item in new_collection if isinstance (item , omcore .Person )][0 ]
215+ assert len (person_again .affiliation ) == 1
216+ assert person_again .affiliation [0 ].member_of .full_name == "University of This Place"
You can’t perform that action at this time.
0 commit comments