Skip to content

Commit 8ebfe21

Browse files
committed
Check inlined or inlined_as_list slots only if range is class in schema
1 parent 1aae031 commit 8ebfe21

File tree

3 files changed

+90
-14
lines changed

3 files changed

+90
-14
lines changed

linkml_runtime/utils/schemaview.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,22 +1317,22 @@ def is_inlined(self, slot: SlotDefinition, imports=True) -> bool:
13171317
:param imports:
13181318
:return:
13191319
"""
1320-
if slot.inlined:
1321-
return True
1322-
elif slot.inlined_as_list:
1323-
return True
1324-
else:
1325-
range = slot.range
1326-
if range in self.all_classes():
1327-
id_slot = self.get_identifier_slot(range, imports=imports)
1328-
if id_slot is None:
1329-
# must be inlined as has no identifier
1330-
return True
1331-
else:
1332-
# not explicitly declared inline and has an identifier: assume is ref, not inlined
1333-
return False
1320+
range = slot.range
1321+
if range in self.all_classes():
1322+
if slot.inlined:
1323+
return True
1324+
elif slot.inlined_as_list:
1325+
return True
1326+
1327+
id_slot = self.get_identifier_slot(range, imports=imports)
1328+
if id_slot is None:
1329+
# must be inlined as has no identifier
1330+
return True
13341331
else:
1332+
# not explicitly declared inline and has an identifier: assume is ref, not inlined
13351333
return False
1334+
else:
1335+
return False
13361336

13371337
def slot_applicable_range_elements(self, slot: SlotDefinition) -> List[ClassDefinitionName]:
13381338
"""
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
id: http://example.org/schemaview_is_inlined
2+
name: schemaview_is_inlined
3+
description: This schema defines various slots that exercise the SchemaView.is_inlined() method
4+
prefixes:
5+
linkml: https://w3id.org/linkml/
6+
imports:
7+
- linkml:types
8+
default_range: string
9+
10+
classes:
11+
ThingWithId:
12+
slots:
13+
- id
14+
- value
15+
ThingWithoutId:
16+
slots:
17+
- value
18+
19+
slots:
20+
id:
21+
identifier: true
22+
value:
23+
24+
a_thing_with_id:
25+
range: ThingWithId
26+
27+
inlined_thing_with_id:
28+
range: ThingWithId
29+
inlined: true
30+
31+
inlined_as_list_thing_with_id:
32+
range: ThingWithId
33+
inlined_as_list: true
34+
35+
a_thing_without_id:
36+
range: ThingWithoutId
37+
38+
inlined_thing_without_id:
39+
range: ThingWithoutId
40+
inlined: true
41+
42+
inlined_as_list_thing_without_id:
43+
range: ThingWithoutId
44+
inlined_as_list: true
45+
46+
an_integer:
47+
range: integer
48+
49+
# Pathological cases
50+
inlined_integer:
51+
range: integer
52+
inlined: true
53+
54+
inlined_as_list_integer:
55+
range: integer
56+
inlined_as_list: true

tests/test_utils/test_schemaview.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,26 @@ def test_mergeimports(self):
706706
prefixes_list
707707
)
708708

709+
def test_is_inlined(self):
710+
schema_path = os.path.join(INPUT_DIR, "schemaview_is_inlined.yaml")
711+
sv = SchemaView(schema_path)
712+
cases = [
713+
# slot name, expected is_inline
714+
("a_thing_with_id", False),
715+
("inlined_thing_with_id", True),
716+
("inlined_as_list_thing_with_id", True),
717+
("a_thing_without_id", True),
718+
("inlined_thing_without_id", True),
719+
("inlined_as_list_thing_without_id", True),
720+
("an_integer", False),
721+
("inlined_integer", False),
722+
("inlined_as_list_integer", False)
723+
]
724+
for slot_name, expected_result in cases:
725+
with self.subTest(slot_name=slot_name):
726+
slot = sv.get_slot(slot_name)
727+
actual_result = sv.is_inlined(slot)
728+
self.assertEqual(actual_result, expected_result)
709729

710730
if __name__ == '__main__':
711731
unittest.main()

0 commit comments

Comments
 (0)