MCPcopy Create free account
hub / github.com/917Dhj/DeepPaperNote / caption_items

Function caption_items

scripts/plan_figure_table_decisions.py:47–85  ·  view source on GitHub ↗
(source_manifest: dict[str, Any])

Source from the content-addressed store, hash-verified

45
46
47def caption_items(source_manifest: dict[str, Any]) -> list[dict[str, Any]]:
48 captions = (
49 source_manifest.get("captions", {})
50 if isinstance(source_manifest.get("captions"), dict)
51 else {}
52 )
53 grouped: dict[str, dict[str, Any]] = {}
54 scores: dict[str, int] = {}
55 order: list[str] = []
56 for kind, key in (("figure", "figures"), ("table", "tables")):
57 for item in captions.get(key, []) or []:
58 if not isinstance(item, dict):
59 continue
60 label = normalize_whitespace(str(item.get("id", "")))
61 caption = normalize_whitespace(str(item.get("caption", "")))
62 if not label and not caption:
63 continue
64 page = item.get("page") or item.get("page_number") or 0
65 group_key = caption_label_key(label)
66 if not group_key:
67 continue
68 candidate = {
69 "kind": kind,
70 "label": label,
71 "caption": caption,
72 "page": page,
73 "pages": item.get("pages") or ([page] if page else []),
74 "section_id": item.get("section_id", ""),
75 }
76 score = caption_preference_score(label, caption)
77 if group_key not in grouped:
78 grouped[group_key] = candidate
79 scores[group_key] = score
80 order.append(group_key)
81 continue
82 if score > scores[group_key]:
83 grouped[group_key] = candidate
84 scores[group_key] = score
85 return [grouped[key] for key in order]
86
87
88def planned_items(figures_wrapper: dict[str, Any]) -> dict[str, dict[str, Any]]:

Callers 1

build_decisionsFunction · 0.85

Calls 3

normalize_whitespaceFunction · 0.90
caption_label_keyFunction · 0.90
caption_preference_scoreFunction · 0.90

Tested by

no test coverage detected