Skip to main content

sentence segmenter for japanese text

Project description

ja_sentence_segmenter

Test PyPI Python Versions

日本語のテキストに対して、ルールベースによる文区切り(sentence segmentation)を行います。

Getting Started

Prerequisites

  • Python 3.9+

Installing

pip install ja_sentence_segmenter

Usage

import functools

from ja_sentence_segmenter.common.pipeline import make_pipeline
from ja_sentence_segmenter.concatenate.simple_concatenator import concatenate_matching
from ja_sentence_segmenter.normalize.neologd_normalizer import normalize
from ja_sentence_segmenter.split.simple_splitter import split_newline, split_punctuation

split_punc2 = functools.partial(split_punctuation, punctuations=r"。!?")
concat_tail_no = functools.partial(concatenate_matching, former_matching_rule=r"^(?P<result>.+)(の)$", remove_former_matched=False)
segmenter = make_pipeline(normalize, split_newline, concat_tail_no, split_punc2)

# Golden Rule: Simple period to end sentence #001 (from https://github.com/diasks2/pragmatic_segmenter/blob/master/spec/pragmatic_segmenter/languages/japanese_spec.rb#L6)
text1 = "これはペンです。それはマーカーです。"
print(list(segmenter(text1)))
> ["これはペンです。", "それはマーカーです。"]

Development

This project uses uv for dependency management.

git clone https://github.com/wwwcojp/ja_sentence_segmenter.git
cd ja_sentence_segmenter
uv sync

uv run poe lint       # lint and format check (ruff)
uv run poe typecheck  # type check (mypy)
uv run poe test       # run tests (pytest)
uv run tox            # run tests on all supported Python versions

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Contributing

TODO

License

MIT

Acknowledgments

テキストの正規化処理

テキスト正規化のコードは、mecab-ipadic-NEologdの以下のWIKIを参考に一部修正を加えています。

サンプルコードの提供者であるhideaki-t氏とoverlast氏に感謝します。

https://github.com/neologd/mecab-ipadic-neologd/wiki/Regexp.ja#python-written-by-hideaki-t--overlast

文区切り(sentence segmentation)のルール

文区切りのルールとして、Pragmatic Segmenterの日本語ルールを参考にしました。

https://github.com/diasks2/pragmatic_segmenter#golden-rules-japanese

また、以下のテストコード中で用いられているテストデータを、本PJのテストコードで利用しました。

https://github.com/diasks2/pragmatic_segmenter/blob/master/spec/pragmatic_segmenter/languages/japanese_spec.rb

作者のKevin S. Dias氏とコントリビュータの方々に感謝します。

Thanks to Kevin S. Dias and contributors.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ja_sentence_segmenter-0.1.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ja_sentence_segmenter-0.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file ja_sentence_segmenter-0.1.0.tar.gz.

File metadata

  • Download URL: ja_sentence_segmenter-0.1.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ja_sentence_segmenter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 23cbdaf637ed66bdbf3ba6bb9859703332b2ebeed67f673713047bc89fac48f2
MD5 7e876f6fe68c070db062e9cb4abf7700
BLAKE2b-256 6f942d0e099acc617b08fc120df96582d2e6d4ee224074d872267e993fadbeb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for ja_sentence_segmenter-0.1.0.tar.gz:

Publisher: release.yml on wwwcojp/ja_sentence_segmenter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ja_sentence_segmenter-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ja_sentence_segmenter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8945f776fb39db7fffff1dedfae329cca0be7d8e1ec859a181a8275af15f06e
MD5 5497f9bc458d5ab35b3cb7250e8560cf
BLAKE2b-256 520140e0a4a9f405604d4cd2cd396dec998cba762b94501c45368e1ba0c73fbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for ja_sentence_segmenter-0.1.0-py3-none-any.whl:

Publisher: release.yml on wwwcojp/ja_sentence_segmenter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page