INNER CODE UNIT · Python

expand

kangarooking/cangjie-skill · scripts/build_index.py:25

    def expand(m: re.Match) -> str:
        s = m.group(0)
        if len(s) == 1:
            return s
        return " ".join(s[i : i + 2] for i in range(len(s) - 1))

    return CJK_RE.sub(expand, text)


def build(chunks_path: Path, db_path: Path) -> int:
    chunks = [json.loads(line) for line in chunks_path.read_text(encoding="utf-8").splitlines() if line.strip()]
    db_path.parent.mkdir(parents=True, exist_ok=True)
    db_path.unlink(missing_ok=True)
    con = sqlite3.connect(db_path)
    con.execute("CREATE TABLE chunks (seq INTEGER PRIMARY KEY, chunk_id TEXT, heading_path TEXT, text TEXT, keywords TEXT)")
    con.execute("CREATE VIRTUAL TABLE chunks_fts USING fts5(chunk_id, heading_path, body, keywords)")
    for seq, c in enumerate(chunks):
        hp = " / ".join(c["heading_path"])

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…