Skip to main content

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

  1. 在 PyPI Trusted Publishers 为项目 memshare-nlp 添加 GitHub publisher:选本仓库、workflow publish.yml、environment pypi。
  2. 在 GitHub 仓库 Settings → Environments 建 pypi(可开保护规则)。
  3. 打标签发布:git tag v0.1.0 && git push origin v0.1.0(会先跑测试再上传)。
  4. 只想构建不上传: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 /health
  • POST /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:PRED FRAME PHRASE -

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)

Source distribution for memshare-nlp 0.1.0
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)

Table of built distributions (wheels) for memshare-nlp 0.1.0
File Interpreter ABI Platform Actions
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

Release files / memshare_nlp-0.1.0.tar.gz

Download URL memshare_nlp-0.1.0.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
81314d66d1de9448241630e68cee778f0528056913240adde66973b1ccca850c
BLAKE2b-256 checksum
How to use checksums
be7aa6524e696abe8fdc66c286611be13bb0800dfb98821e8e11996a799f1eab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / memshare_nlp-0.1.0-py3-none-any.whl

Download URL memshare_nlp-0.1.0-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
94ba71acbf7c2bef25c8e00995491509b60b0e0c63232d9a2f543a01d81280fd
BLAKE2b-256 checksum
How to use checksums
85a35f4e8103fae774481b408d077454372f43ab70093327e3a79a1b15ec32e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

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.

Select from 2 files

Attestation for memshare_nlp-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page