diff --git a/openpecha/serializers/serialize.py b/openpecha/serializers/serialize.py index d4ef275f..d96becc7 100644 --- a/openpecha/serializers/serialize.py +++ b/openpecha/serializers/serialize.py @@ -210,12 +210,13 @@ def apply_index(self): for ann_id, topic in self.index_layer["annotations"].items(): topic_ann = defaultdict(str) sub_topics = topic["parts"] - for i, sub_topic in enumerate(sub_topics): - if sub_topic: - vol_id = f"v{sub_topic['span']['vol']:03}" - sub_topic["type"] = AnnType.sub_topic - if sub_topic["work_id"] != sub_topics[i - 1]["work_id"]: - self.apply_annotation(vol_id, sub_topic) + for sub_topic_uuid, sub_topic in sub_topics.items(): + sub_topic_ann = defaultdict(str) + vol_id = f"v{sub_topic['span'][0]['vol']:03}" + sub_topic_ann["type"] = AnnType.sub_topic + sub_topic_ann["work_id"] = sub_topic["work_id"] + sub_topic_ann["span"] = sub_topic['span'][0] + self.apply_annotation(vol_id, sub_topic_ann) if topic["span"]: vol_id = f"v{topic['span'][0]['vol']:03}" topic_ann["type"] = AnnType.topic diff --git a/tests/data/serialize/hfml/opf/P000003.opf/index.yml b/tests/data/serialize/hfml/opf/P000003.opf/index.yml index d294868a..271b83c8 100644 --- a/tests/data/serialize/hfml/opf/P000003.opf/index.yml +++ b/tests/data/serialize/hfml/opf/P000003.opf/index.yml @@ -3,7 +3,7 @@ annotation_type: index revision: '00001' annotations: 12590fb37da14c32ba0785f7f68c6f5e: - parts: [] + parts: {} span: - vol: 1 start: 0 @@ -13,7 +13,7 @@ annotations: end: 218 work_id: D1118 ac26bb9b4a034a0fa959ecc6af68fa0e: - parts: [] + parts: {} span: - vol: 2 start: 218