MCPcopy Create free account
hub / github.com/Open-Quant/openquant / detect_repeated_margin_lines

Function detect_repeated_margin_lines

scripts/afml_semantic_index.py:107–124  ·  view source on GitHub ↗
(pages: list[dict[str, Any]])

Source from the content-addressed store, hash-verified

105
106
107def detect_repeated_margin_lines(pages: list[dict[str, Any]]) -> set[str]:
108 top_counter: Counter[str] = Counter()
109 bottom_counter: Counter[str] = Counter()
110
111 for p in pages:
112 lines = [normalize_line(ln) for ln in p["raw_text"].splitlines() if ln.strip()]
113 if not lines:
114 continue
115
116 top_lines = [ln for ln in lines[:3] if not is_probably_boilerplate(ln)]
117 bottom_lines = [ln for ln in lines[-3:] if not is_probably_boilerplate(ln)]
118 top_counter.update(top_lines)
119 bottom_counter.update(bottom_lines)
120
121 threshold = max(3, math.ceil(len(pages) * 0.08))
122 repeated = {line for line, c in top_counter.items() if c >= threshold}
123 repeated |= {line for line, c in bottom_counter.items() if c >= threshold}
124 return repeated
125
126
127def clean_pages(pages: list[dict[str, Any]], repeated_margin_lines: set[str]) -> list[dict[str, Any]]:

Callers 1

build_indexFunction · 0.85

Calls 4

normalize_lineFunction · 0.85
is_probably_boilerplateFunction · 0.85
maxFunction · 0.85
updateMethod · 0.80

Tested by

no test coverage detected