nlp
日语句子分析:GiNZA 切分 → 规则引擎对齐 → 标准 tokens / chunks。
这是一套对照权威金标不断迭代的黑盒规则引擎,不是自动机器学习。主回归集为 standard。
概念
| 路径 | 含义 |
|---|---|
data/<数据集>/ |
权威数据(sentence-*.json,含 text + tokens + chunks) |
data/standard/ |
标准集(全量回归必须全绿) |
data/hits/ |
年度ヒット话题 |
data/tokyo-rail/ |
东京线路 / 机场联络线新闻 |
rules/ |
人读规则;实现必须对齐 |
src/nlp/align.py |
规则引擎 |
src/nlp/analyzer.py |
对外 API:analyze() |
已舍弃:截图 OCR、分列的 gold/+corpus/、入库的引擎输出。
安装
本地开发:
uv sync --group dev
从 PyPI(发行名 memshare-nlp,import nlp 不变):
pip install memshare-nlp
# 或
uv add memshare-nlp
需要 Python ≥ 3.10(推荐 3.12)。
发布到 PyPI
- 在 PyPI Trusted Publishers 为项目
memshare-nlp添加 GitHub publisher:选本仓库、workflowpublish.yml、environmentpypi。 - 在 GitHub 仓库 Settings → Environments 建
pypi(可开保护规则)。 - 打标签发布:
git tag v0.1.0 && git push origin v0.1.0(会先跑测试再上传)。 - 只想构建不上传:Actions → Publish → Run workflow,保持
dry_run。
作为包使用
from nlp import analyze
result = analyze("こんにちは、Miraaです。")
for t in result["tokens"]:
print(t["text"], t["tokenType"])
for c in result["chunks"]:
print(c["chunkType"], c["text"], c["tokenIndices"])
CLI:
uv run nlp
uv run nlp こんにちは、世界。
HTTP 服务
uv run nlp-serve
curl -s http://127.0.0.1:8000/analyze \
-H 'Content-Type: application/json' \
-d '{"text":"こんにちは、Miraaです。"}' | jq .
GET /healthPOST /analyze→{ text, model, tokens, chunks }
回归与评测
# standard 金标 + 正反例 + API
uv run pytest
# 按词/块部分匹配计分,输出通过率(默认不因未满分失败)
uv run nlp-eval
uv run nlp-eval standard hits tokyo-rail
uv run nlp-eval hits --strict # 综合未到 100% 则退出码 1
计分:词按 (text, tokenType)、块按 (chunkType, text) 逐位对拍;命中数 / max(金标长, 引擎长)。综合 = 全部词块命中 / 全部词块槽位。整句全对另计。
数据集:standard(主回归)、hits(年度ヒット话题)、tokyo-rail(东京线路新闻)。
对照视图(HTML)
uv run nlp-eval standard hits tokyo-rail --dump
node web/render.mjs
打开 views/index.html。说明见 web/README.md。色表:web/colors.json。
改规则前请读 AGENT.md 与 rules/chunking.md。
输出 schema
{
"text": "こんにちは、Miraaです。",
"model": "ja_ginza",
"tokens": [{"text": "こんにちは", "tokenType": "-"}],
"chunks": [{"chunkType": "FRAME", "text": "こんにちは、", "tokenIndices": [0, 1]}]
}
tokenType:名詞動詞形容詞助詞接续助动词-chunkType:PREDFRAMEPHRASE-
Metadata
Release files for memshare-nlp 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| memshare_nlp-0.1.0.tar.gz | 16.3 kB | With provenance | Details for memshare_nlp-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| memshare_nlp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for memshare_nlp-0.1.0-py3-none-any.whl |
Total release size: 34.6 kB
Security for memshare-nlp 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.