Skip to main content

Apply juman++ to batch inputs in parallel

Project description

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.

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

jumanpp-batch-0.1.2.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

jumanpp_batch-0.1.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file jumanpp-batch-0.1.2.tar.gz.

File metadata

  • Download URL: jumanpp-batch-0.1.2.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for jumanpp-batch-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bafd34d7491acaffc9e7bdda1c951035547557e897797044597f423e18e17573
MD5 4f87a501e24947d6fa9aa9d22cb8b8a3
BLAKE2b-256 0fb78c2b4f1e5e953d8cfa30bd4d8ea95d6361c89464af7bf514e5990936ae41

See more details on using hashes here.

File details

Details for the file jumanpp_batch-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: jumanpp_batch-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for jumanpp_batch-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0e4b08994cdb721ffa4a5ead49e103c6aa0c74c61e3c0ecde0b457f7a7769dfd
MD5 ca691f22d532402fee6a8ab82bd37dd3
BLAKE2b-256 8e2acc3fc10dd6d621d4498ce3bd6a3bd38d75d78acc739a939dff3811c8a9b8

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