Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle non-array hasPart entries #163

Merged
merged 1 commit into from
Sep 22, 2023
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
4 changes: 2 additions & 2 deletions rocrate/rocrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def __read_data_entities(self, entities, source, gen_preview):

root_entity = entities.pop(root_id)
assert root_id == root_entity.pop('@id')
parts = root_entity.pop('hasPart', [])
parts = as_list(root_entity.pop('hasPart', []))
self.add(RootDataset(self, root_id, properties=root_entity))
preview_entity = entities.pop(Preview.BASENAME, None)
if preview_entity and not gen_preview:
Expand All @@ -167,7 +167,7 @@ def __add_parts(self, parts, entities, source):
else:
instance = cls(self, source / id_, id_, properties=entity)
self.add(instance)
self.__add_parts(entity.get("hasPart", []), entities, source)
self.__add_parts(as_list(entity.get("hasPart", [])), entities, source)

def __read_contextual_entities(self, entities):
type_map = {_.__name__: _ for _ in subclasses(ContextEntity)}
Expand Down
6 changes: 3 additions & 3 deletions test/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,17 @@ def test_indirect_data_entity(tmpdir):
{
"@id": "./",
"@type": "Dataset",
"hasPart": [{"@id": "d1"}]
"hasPart": {"@id": "d1"}
},
{
"@id": "d1",
"@type": "Dataset",
"hasPart": [{"@id": "d1/d2"}]
"hasPart": {"@id": "d1/d2"}
},
{
"@id": "d1/d2",
"@type": "Dataset",
"hasPart": [{"@id": "d1/d2/f1"}]
"hasPart": {"@id": "d1/d2/f1"}
},
{
"@id": "d1/d2/f1",
Expand Down
Loading