Skip to main content

Japanese text normalizer for mecab-neologd

Project description

downloads pyversion latest version license

neologdn is a Japanese text normalizer for mecab-neologd.

The normalization is based on the neologd’s rules: https://github.com/neologd/mecab-ipadic-neologd/wiki/Regexp.ja

Contributions are welcome!

NOTE: Installing this module requires C++11 compiler.

Installation

$ pip install neologdn

Usage

import neologdn
neologdn.normalize("ハンカクカナ")
# => 'ハンカクカナ'
neologdn.normalize("全角記号!?@#")
# => '全角記号!?@#'
neologdn.normalize("全角記号例外「・」")
# => '全角記号例外「・」'
neologdn.normalize("長音短縮ウェーーーーイ")
# => '長音短縮ウェーイ'
neologdn.normalize("チルダ削除ウェ~∼∾〜〰~イ")
# => 'チルダ削除ウェイ'
neologdn.normalize("いろんなハイフン˗֊‐‑‒–⁃⁻₋−")
# => 'いろんなハイフン-'
neologdn.normalize("   PRML  副 読 本   ")
# => 'PRML副読本'
neologdn.normalize(" Natural Language Processing ")
# => 'Natural Language Processing'
neologdn.normalize("かわいいいいいいいいい", repeat=6)
# => 'かわいいいいいい'
neologdn.normalize("無駄無駄無駄無駄ァ", repeat=1)
# => '無駄ァ'
neologdn.normalize("1995〜2001年", tilde="normalize")
# => '1995~2001年'
neologdn.normalize("1995~2001年", tilde="normalize_zenkaku")
# => '1995〜2001年'
neologdn.normalize("1995〜2001年", tilde="ignore")  # Don't convert tilde
# => '1995〜2001年'
neologdn.normalize("1995〜2001年", tilde="remove")
# => '19952001年'
neologdn.normalize("1995〜2001年")  # Default parameter
# => '19952001年'

Benchmark

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

%timeit normalize(normalize_neologd.normalize_neologd)
# => 9.55 s ± 29.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)


import neologdn
%timeit normalize(neologdn.normalize)
# => 6.66 s ± 35.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

neologdn is about x1.43 faster than sample code.

details are described as the below notebook: https://github.com/ikegami-yukino/neologdn/blob/master/benchmark/benchmark.ipynb

License

Apache Software License.

Contribution

Contributions are welcome! See: https://github.com/ikegami-yukino/neologdn/blob/master/.github/CONTRIBUTING.md

Cited by

Book

山本 和英. テキスト処理の要素技術. 近代科学者. P.41. 2021.

Blog

CHANGES

0.5.3 (2024-05-03)

  • Support Python 3.12

0.5.2 (2023-08-03)

  • Support Python 3.10 and 3.11 (Many thanks @polm)

0.5.1 (2021-05-02)

  • Improve performance of shorten_repeat function (Many thanks @yskn67)

  • Add tilde option to normalize function

0.4 (2018-12-06)

  • Add shorten_repeat function, which shortening contiguous substring. For example: neologdn.normalize(“無駄無駄無駄無駄ァ”, repeat=1) -> 無駄ァ

0.3.2 (2018-05-17)

  • Add option for suppression removal of spaces between Japanese characters

0.2.2 (2018-03-10)

  • Fix bug (daku-ten & handaku-ten)

  • Support mac osx 10.13 (Many thanks @r9y9)

0.2.1 (2017-01-23)

  • Fix bug (Check if a previous character of daku-ten character is in maps) (Many thanks @unnonouno)

0.2 (2016-04-12)

  • Add lengthened expression (repeating character) threshold

0.1.2 (2016-03-29)

  • Fix installation bug

0.1.1.1 (2016-03-19)

  • Support Windows

  • Explicitly specify to -std=c++11 in build (Many thanks @id774)

0.1.1 (2015-10-10)

Initial release.

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

neologdn-0.5.3.tar.gz (144.6 kB view details)

Uploaded Source

File details

Details for the file neologdn-0.5.3.tar.gz.

File metadata

  • Download URL: neologdn-0.5.3.tar.gz
  • Upload date:
  • Size: 144.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for neologdn-0.5.3.tar.gz
Algorithm Hash digest
SHA256 f3f31878f7e0576f3b5a4f28f90cc5dccfc8880e616a0481332d478fe75160a5
MD5 4cb62a73bc02307314f592dc96f68403
BLAKE2b-256 fa3c266f9e4ec59d6d73e17f8434a43acd2575822e1c71fd40bbbe22a630d229

See more details on using hashes here.

Supported by

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