Skip to content

Commit d1ee55a

Browse files
authored
Merge pull request #216 from simleo/fix_indirect_data_entities
Fix indirect data entities
2 parents c1f6798 + 5645db3 commit d1ee55a

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

rocrate/rocrate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ def __add_parts(self, parts, entities, source):
176176
else:
177177
instance = cls(self, source / id_, id_, properties=entity)
178178
self.add(instance)
179-
self.__add_parts(as_list(entity.get("hasPart", [])), entities, source)
179+
if instance.type == "Dataset":
180+
self.__add_parts(as_list(entity.get("hasPart", [])), entities, source)
180181

181182
def __read_contextual_entities(self, entities):
182183
type_map = {_.__name__: _ for _ in subclasses(ContextEntity)}

test/test_read.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,9 @@ def test_indirect_data_entity(tmpdir):
537537
d2_e = crate.dereference("d1/d2")
538538
assert d2_e
539539
assert d2_e in crate.data_entities
540+
f1_e = crate.dereference("d1/d2/f1")
541+
assert f1_e
542+
assert f1_e in crate.data_entities
540543

541544

542545
@pytest.mark.filterwarnings("ignore")
@@ -597,3 +600,62 @@ def test_from_dict(tmpdir):
597600
crate.write(out_path)
598601
with pytest.raises(ValueError):
599602
ROCrate(metadata, init=True)
603+
604+
605+
def test_no_data_entity_link_from_file():
606+
metadata = {
607+
"@context": "https://w3id.org/ro/crate/1.1/context",
608+
"@graph": [
609+
{
610+
"@id": "ro-crate-metadata.json",
611+
"@type": "CreativeWork",
612+
"about": {"@id": "./"},
613+
"conformsTo": {"@id": "https://w3id.org/ro/crate/1.1"}
614+
},
615+
{
616+
"@id": "./",
617+
"@type": "Dataset",
618+
"hasPart": [
619+
{"@id": "d1"},
620+
{"@id": "packed.cwl"}
621+
]
622+
},
623+
{
624+
"@id": "d1",
625+
"@type": "Dataset"
626+
},
627+
{
628+
"@id": "packed.cwl",
629+
"@type": [
630+
"File",
631+
"SoftwareSourceCode",
632+
"ComputationalWorkflow"
633+
],
634+
"hasPart": [
635+
{"@id": "packed.cwl#do_this.cwl"},
636+
{"@id": "packed.cwl#do_that.cwl"}
637+
]
638+
},
639+
{
640+
"@id": "packed.cwl#do_this.cwl",
641+
"@type": "SoftwareApplication",
642+
},
643+
{
644+
"@id": "packed.cwl#do_that.cwl",
645+
"@type": "SoftwareApplication",
646+
}
647+
]
648+
}
649+
crate = ROCrate(metadata)
650+
d1 = crate.dereference("d1")
651+
assert d1
652+
assert d1 in crate.data_entities
653+
assert d1 not in crate.contextual_entities
654+
wf = crate.dereference("packed.cwl")
655+
assert wf
656+
assert wf in crate.data_entities
657+
assert wf not in crate.contextual_entities
658+
t1 = crate.dereference("packed.cwl#do_this.cwl")
659+
assert t1
660+
assert t1 not in crate.data_entities
661+
assert t1 in crate.contextual_entities

0 commit comments

Comments
 (0)