Skip to main content

jumanpp-batch

Apply JUMAN++ to batch input in parallel

Build Status PyPI Status

This python package facilitates the usage of juman++ software by providing the functionalities to apply the command (1) to batch input (2) and in parallel.

Requirement

  • Python 2.7+, 3.4+
  • JUMAN++ 1.0.2, 2.0.0

Installation

JUMAN++

Refer to the official document for the details (Manual).

Requirements:

  • GCC 4.9+
  • Boost 1.57+
  • (Optional) gperftool

On ubuntu, these can be installed by:

sudo apt-get install build-essential libboost-all-dev google-perftools

As of this writing, JUMAN++ v1.0.2 can be installed by the following command:

wget http://lotus.kuee.kyoto-u.ac.jp/nl-resource/jumanpp/jumanpp-1.02.tar.xz
tar xJvf jumanpp-1.02.tar.xz
cd jumanpp-1.02 && ./configure && make && sudo make install && ../

Check:

echo "すもももももももものうち" | jumanpp
#すもも すもも すもも 名詞 6 普通名詞 1 * 0 * 0 "代表表記:酸桃/すもも 自動獲得:EN_Wiktionary"
#@ すもも すもも すもも 名詞 6 普通名詞 1 * 0 * 0 "自動獲得:テキスト"
#も も も 助詞 9 副助詞 2 * 0 * 0 NIL
#もも もも もも 名詞 6 普通名詞 1 * 0 * 0 "代表表記:股/もも カテゴリ:動物-部位"
#@ もも もも もも 名詞 6 普通名詞 1 * 0 * 0 "代表表記:桃/もも 漢字読み:訓 カテゴリ:植物;人工物-食べ物 ドメイン:料理・食事"
#も も も 助詞 9 副助詞 2 * 0 * 0 NIL
#もも もも もも 名詞 6 普通名詞 1 * 0 * 0 "代表表記:股/もも カテゴリ:動物-部位"
#@ もも もも もも 名詞 6 普通名詞 1 * 0 * 0 "代表表記:桃/もも 漢字読み:訓 カテゴリ:植物;人工物-食べ物 ドメイン:料理・食事"
#の の の 助詞 9 接続助詞 3 * 0 * 0 NIL
#うち うち うち 名詞 6 副詞的名詞 9 * 0 * 0 "代表表記:うち/うち"
#EOS

jumanpp-batch library

The library can be downloaded from the PyPI repository.

pip install jumanpp-batch

Or install the development version from GitHub.

git clone https://github.com/kota7/jumanpp-batch.git
pip install -U ./jumanpp-batch

Usage

Execute JUMAN++ jobs

from jumanpp_batch import jumanpp_batch, parse_outfiles
texts = ["すもももももももものうち", "隣の客はよく柿食う客だ", "犬も歩けば棒に当たる",
         "伊香保温泉日本の名湯", "海賊王に俺はなる!"]
outfiles = jumanpp_batch(texts, num_procs=3) 
print(outfiles)
#['jumanpp-result_1.txt', 'jumanpp-result_2.txt', 'jumanpp-result_3.txt']

The results are saved in files.

!cat {outfiles[0]}
#すもも すもも すもも 名詞 6 普通名詞 1 * 0 * 0 "代表表記:酸桃/すもも 自動獲得:EN_Wiktionary"
#@ すもも すもも すもも 名詞 6 普通名詞 1 * 0 * 0 "自動獲得:テキスト"
#も も も 助詞 9 副助詞 2 * 0 * 0 NIL
#もも もも もも 名詞 6 普通名詞 1 * 0 * 0 "代表表記:股/もも カテゴリ:動物-部位"
#@ もも もも もも 名詞 6 普通名詞 1 * 0 * 0 "代表表記:桃/もも 漢字読み:訓 カテゴリ:植物;人工物-食べ物 ドメイン:料理・食事"
#も も も 助詞 9 副助詞 2 * 0 * 0 NIL
#もも もも もも 名詞 6 普通名詞 1 * 0 * 0 "代表表記:股/もも カテゴリ:動物-部位"
#@ もも もも もも 名詞 6 普通名詞 1 * 0 * 0 "代表表記:桃/もも 漢字読み:訓 カテゴリ:植物;人工物-食べ物 ドメイン:料理・食事"
#の の の 助詞 9 接続助詞 3 * 0 * 0 NIL
#うち うち うち 名詞 6 副詞的名詞 9 * 0 * 0 "代表表記:うち/うち"
#EOS
#隣 となり 隣 名詞 6 普通名詞 1 * 0 * 0 "代表表記:隣り/となり カテゴリ:場所-その他"
#の の の 助詞 9 接続助詞 3 * 0 * 0 NIL
#...

Parse the output files into tokens

for id_, tokens in parse_outfiles(outfiles):
    print(tokens)
    print("***")
#[JumanppToken(surface='すもも', reading='すもも', headword='すもも', pos='名詞', pos_id='6', pos2='普通名詞', pos2_id='1', infltype='*', infltype_id='0', inflform='*', inflform_id='0', info='代表表記:酸桃/すもも 自動獲得:EN_Wiktionary', is_alternative=False), JumanppToken(surface='も', reading='も', headword='も', pos='助詞', pos_id='9', pos2='副助詞', pos2_id='2', infltype='*', infltype_id='0', inflform='*', inflform_id='0', info='NIL', is_alternative=False), JumanppToken(surface='もも', reading='もも', headword='もも', pos='名詞', pos_id='6', pos2='普通名詞', pos2_id='1', infltype='*', infltype_id='0', inflform='*', inflform_id='0', info='代表表記:股/もも カテゴリ:動物-部位', is_alternative=False), JumanppToken(surface='も', reading='も', headword='も', pos='助詞', pos_id='9', pos2='副助詞', pos2_id='2', infltype='*', infltype_id='0', inflform='*', inflform_id='0', info='NIL', is_alternative=False), JumanppToken(surface='もも', reading='もも', headword='もも', pos='名詞', pos_id='6', pos2='普通名詞', pos2_id='1', infltype='*', infltype_id='0', inflform='*', inflform_id='0', info='代表表記:股/もも カテゴリ:動物-部位', is_alternative=False), JumanppToken(surface='の', reading='の', headword='の', pos='助詞', pos_id='9', pos2='接続助詞', pos2_id='3', infltype='*', infltype_id='0', inflform='*', inflform_id='0', info='NIL', is_alternative=False), JumanppToken(surface='うち', reading='うち', headword='うち', pos='名詞', pos_id='6', pos2='副詞的名詞', pos2_id='9', infltype='*', infltype_id='0', inflform='*', inflform_id='0', info='代表表記:うち/うち', is_alternative=False)]
#***
#[JumanppToken(surface='隣', reading='となり', headword='隣', pos='名詞', pos_id='6', pos2='普通名詞', pos2_id='1', infltype='*', infltype_id='0', inflform='*', inflform_id='0', info='代表表記:隣り/となり カテゴリ:場所-その他', is_alternative=False), JumanppToken(surface='の', reading='の', 

Apply formatter and filter to the tokens

for id_, tokens in parse_outfiles(outfiles,
                                  format_func=lambda x: "{} ({})".format(x.headword, x.reading),
                                  pos_filter=("名詞", "動詞")):
    print(tokens)
    print("***")
#['すもも (すもも)', 'もも (もも)', 'もも (もも)', 'うち (うち)']
#***
#['隣 (となり)', '客 (きゃく)', '柿 (かき)', '食う (くう)', '客 (きゃく)']
#***
#['犬 (いぬ)', '歩く (あるけば)', '棒 (ぼう)', '当たる (あたる)']
#***
#['伊香保 (伊香保)', '温泉 (おんせん)', '日本 (にっぽん)', '湯 (ゆ)']
#***
#['海賊 (かいぞく)', '王 (おう)', '俺 (おれ)', 'なる (なる)']
#***

More examples

Please also refer to usage notebook for the detailed description of the library.

Release files for jumanpp-batch 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jumanpp-batch 0.1.2
File Size Uploaded
jumanpp-batch-0.1.2.tar.gz 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jumanpp-batch 0.1.2
File Interpreter ABI Platform
jumanpp_batch-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size:16.7 kB

Release files / jumanpp-batch-0.1.2.tar.gz

Download URL jumanpp-batch-0.1.2.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
bafd34d7491acaffc9e7bdda1c951035547557e897797044597f423e18e17573
BLAKE2b-256 checksum
How to use checksums
0fb78c2b4f1e5e953d8cfa30bd4d8ea95d6361c89464af7bf514e5990936ae41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/0.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200325 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.2

Release files / jumanpp_batch-0.1.2-py3-none-any.whl

Download URL jumanpp_batch-0.1.2-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e4b08994cdb721ffa4a5ead49e103c6aa0c74c61e3c0ecde0b457f7a7769dfd
BLAKE2b-256 checksum
How to use checksums
8e2acc3fc10dd6d621d4498ce3bd6a3bd38d75d78acc739a939dff3811c8a9b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/0.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200325 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

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