-
Notifications
You must be signed in to change notification settings - Fork 1.2k
增加新命令及部分功能优化 #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yangda611
wants to merge
6
commits into
lingfengQAQ:master
Choose a base branch
from
yangda611:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
增加新命令及部分功能优化 #88
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1991bbe
Add `orchestrate` batch orchestrator and `entity-clean` utility, wire…
codex 954ef23
docs: add targeted auto-fix workflow for bad chapters and continuity
codex 9e2dee8
feat(orchestrate): add one-click autofix mode for bad chapters
codex 2bb35a5
Merge pull request #1 from yangda611/work
yangda611 d3f3c07
Merge branch 'lingfengQAQ:master' into master
yangda611 900e94f
Merge branch 'lingfengQAQ:master' into master
yangda611 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #!/usr/bin/env python3 | ||
| # -*- coding: utf-8 -*- | ||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import re | ||
| import sqlite3 | ||
| from pathlib import Path | ||
|
|
||
| from data_modules.config import DataModulesConfig | ||
|
|
||
| ASCII_SNAKE = re.compile(r"^[a-z0-9]+(?:_[a-z0-9]+){1,}$") | ||
|
|
||
|
|
||
| def _looks_dirty(entity_id: str, canonical_name: str) -> bool: | ||
| eid = (entity_id or "").strip().lower() | ||
| name = (canonical_name or "").strip().lower() | ||
| return bool(ASCII_SNAKE.match(eid) or ASCII_SNAKE.match(name)) | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser(description="Cleanup dirty entities (snake_case pinyin/english)") | ||
| parser.add_argument("--project-root", required=True) | ||
| parser.add_argument("--format", choices=["json", "text"], default="json") | ||
| parser.add_argument("--mark-invalid", action="store_true", help="write invalid_facts rows for dirty entities") | ||
| parser.add_argument("--chapter", type=int, default=None) | ||
| args = parser.parse_args() | ||
|
|
||
| config = DataModulesConfig.from_project_root(Path(args.project_root)) | ||
| db_path = Path(config.index_db) | ||
| rows = [] | ||
| with sqlite3.connect(str(db_path)) as conn: | ||
| cur = conn.cursor() | ||
| cur.execute("SELECT id, type, canonical_name FROM entities") | ||
| all_rows = cur.fetchall() | ||
| for entity_id, entity_type, canonical_name in all_rows: | ||
| if _looks_dirty(str(entity_id), str(canonical_name or "")): | ||
| rows.append({"id": entity_id, "type": entity_type, "canonical_name": canonical_name}) | ||
|
|
||
| marked = 0 | ||
| if args.mark_invalid and rows: | ||
| cur.execute( | ||
| """ | ||
| CREATE TABLE IF NOT EXISTS invalid_facts ( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| source_type TEXT NOT NULL, | ||
| source_id TEXT NOT NULL, | ||
| reason TEXT NOT NULL, | ||
| marked_by TEXT, | ||
| chapter INTEGER, | ||
| status TEXT DEFAULT 'pending', | ||
| marked_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
| resolved_at TIMESTAMP | ||
| ) | ||
| """ | ||
| ) | ||
| for item in rows: | ||
| cur.execute( | ||
| "INSERT INTO invalid_facts (source_type, source_id, reason, marked_by, chapter, status) VALUES (?, ?, ?, ?, ?, 'pending')", | ||
| ("entity", item["id"], "dirty_ascii_snake_entity", "entity_cleanup", args.chapter), | ||
| ) | ||
| marked += 1 | ||
| conn.commit() | ||
|
|
||
| payload = {"dirty_entities": rows, "count": len(rows), "marked_invalid": marked} | ||
| if args.format == "json": | ||
| print(json.dumps(payload, ensure_ascii=False, indent=2)) | ||
| else: | ||
| print(f"dirty_entities={len(rows)} marked_invalid={marked}") | ||
| for item in rows: | ||
| print(f"- {item['id']} ({item['canonical_name']})") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On initialized projects,
invalid_factsis already created byindex_managerwithchapter_discoveredandconfirmed_at, notchapter/resolved_at; becauseCREATE TABLE IF NOT EXISTSleaves that table unchanged,entity-clean --mark-invalidfails withno column named chapteras soon as it finds a dirty entity. The insert should use the existing schema (or the sharedmark_invalid_facthelper) so the advertised cleanup command works on real project databases.Useful? React with 👍 / 👎.