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

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

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

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("***")
#['すもも (すもも)', 'もも (もも)', 'もも (もも)', 'うち (うち)']
#***
#['隣 (となり)', '客 (きゃく)', '柿 (かき)', '食う (くう)', '客 (きゃく)']
#***
#['犬 (いぬ)', '歩く (あるけば)', '棒 (ぼう)', '当たる (あたる)']
#***
#['伊香保 (伊香保)', '温泉 (おんせん)', '日本 (にっぽん)', '湯 (ゆ)']
#***
#['海賊 (かいぞく)', '王 (おう)', '俺 (おれ)', 'なる (なる)']
#***

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.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

jumanpp_batch-0.1.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jumanpp-batch-0.1.1.tar.gz
  • Upload date:
  • Size: 8.5 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.1.tar.gz
Algorithm Hash digest
SHA256 77e08c53c6fe68009f527bd2ce36f75e497378d2d36bf70fecc30d08754ed1d0
MD5 c063af6d6591dac6e8096233d5ddcb16
BLAKE2b-256 2392f07ff4b00823e59dc50c190dc72ad827a518fa5bf186acdc42753241acaa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jumanpp_batch-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1a0d59190e86caf90b125178e85fba7feaac79966d9fc92055c0f0ea550dade
MD5 4684739970685027fc3d8851a090820f
BLAKE2b-256 1484d967923babc5f10dab0ed5d6986f6cd2d0229278f35639670fad2ffa4056

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