Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pipeline/src/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ def _resolve_links(self, node_lookup):
if isinstance(value, Link):
resolved_value = node_lookup[value.identifier]
setattr(self, property.name, resolved_value)
elif hasattr(value, "_resolve_links"):
value._resolve_links(node_lookup)
elif isinstance(value, (tuple, list)):
resolved_values = []
for item in value:
if isinstance(item, Link):
resolved_values.append(node_lookup[item.identifier])
else:
resolved_values.append(item)
if hasattr(item, "_resolve_links"):
item._resolve_links(node_lookup)
setattr(self, property.name, resolved_values)


class LinkedMetadata(Node):
Expand Down
28 changes: 28 additions & 0 deletions pipeline/tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,31 @@ def test_issue0008():
"givenName": "A",
}
assert actual == expected


def test_issue0026():
# https://github.com/openMetadataInitiative/openMINDS_Python/issues/26
# When reading a JSON-LD file, the attributes of LinkedMetadata nodes
# inside EmbeddedMetadata nodes are not set properly

uni1 = omcore.Organization(full_name="University of This Place", id="_:uthisp")
person = omcore.Person(
given_name="A",
family_name="Professor",
affiliation = [omcore.Affiliation(member_of=uni1)],
id="_:ap"
)

c = Collection(person)

# uni1 was not added explicitly, but should nevertheless be included in the JSON-LD export

output_paths = c.save("issue0026.jsonld", individual_files=False, include_empty_properties=False)

new_collection = Collection()
new_collection.load(*output_paths)
os.remove("issue0026.jsonld")

person_again = [item for item in new_collection if isinstance(item, omcore.Person)][0]
assert len(person_again.affiliation) == 1
assert person_again.affiliation[0].member_of.full_name == "University of This Place"