Negima
Negima is a Python package to extract phrases in Japanese text by using the part-of-speeches based rules you defined.
Negimaは日本語の文章の中から定義した品詞のルールにあてはまるフレーズを抽出するPythonパッケージです。
Installing
Install and update using pip:
$ pip install -U negima
Install using setup.py:
$ python setup.py install
Dependencies
A Simple Example
sample.py
from negima import MorphemeMerger
mm = MorphemeMerger()
# csv
mm.set_rule_from_csv('rules/1_noun.csv')
# tsv
# mm.set_rule_from_csv('rules/1_noun.tsv', sep='\t')
# # excel
# mm.set_rule_from_excel('rules/rules.xlsx', sheet_name='1_noun')
words, _ = mm.get_rule_pattern('今日はいい天気')
print(words)
$ python sample.py
['今日', '天気']
Rule
You can define rules in a csv, tsv or excel format.
A rule file requires following 9 columns.
Define one of part-of-speeches each row.
*ルールはcsv, tsv, excelファイルの形式で定義することができるます。
ルールには以下の9種のカラムが必要になります。また、1行には1形態素の品詞の情報を定義します。
*
- id
- A rule starts with non-empty id column.
idが空でなければ、ルールのスタートを示す - id has to be unique.
idはユニークである必要がある - Rules are applied in ascendings order of id (ids are compared as UTF-8 strings, not as byte arrays).
ex: id:000_XXX has priority over id:999_ZZZ
idは文字列としてsortされて小さい順にそのルールの優先度が定義される
例: id:000_XXXのルールはid:999_ZZZのルールよりも優先度が高い
- A rule starts with non-empty id column.
- min
- Minimum repeat number. 0 means that morpheme is optional.
形態素の最小繰り返し回数。0に設定するとそのパーツはあってもなくても良い - default=1
- Minimum repeat number. 0 means that morpheme is optional.
- max
- Maximum repeat number
形態素の最大繰り返し回数 - default=1
- Maximum repeat number
- pos0, pos1, pos2, pos3, pos4, pos5
- Part of speeches of morphemes parsed by mecab.
mecabでparseされた形態素の品詞や活用の名前- pos0: 表層 (ex: 名詞)
- pos1: 品詞1 (ex: 副詞可能)
- pos2: 品詞2
- pos3: 品詞3
- pos4: 活用1
- pos5: 活用2
- To represent OR condition, concatenate part-of-speeches with
|as a separator.
|で品詞を接続することでOR条件の定義が可能である
- Part of speeches of morphemes parsed by mecab.
You can add arbitrary columns to your rule file. other columns are just ignored.
An example is available at rule/3_independent_phrase.csv, which has a row example that describes an example sentence for the rule.
上記以外にも任意の列の追加が可能です。
rule/3_independent_phrase.csvではexampleという列を追加し、ルールにあてはまるサンプルを記述しています。
Simple rule (csv)
A rule to extract compound noun. このようなルールを定義することで、複合名詞を抽出できます
| id | min | max | pos0 | pos1 | pos2 | pos3 | pos4 | pos5 |
|---|---|---|---|---|---|---|---|---|
| 1 | 0 | 2 | 接頭詞 | |||||
| 1 | 4 | 名詞 | 一般|サ変接続|数 | |||||
| 0 | 2 | 名詞 | 接尾 |
Caution Don't insert empty row between rules.
注意 ルール同士の間に空行をはさまないようにすること
Rule samples
rule/1_noun.csv
Extract nouns.
名詞の抽出
約5000人が国立競技場に駆けつけた->5000人国立競技場場所がわかりにくいのでたどり着けなかった->場所
rule/2_nouns.csv
Extract compound nouns.
複合名詞の抽出
約5000人が国立競技場に駆けつけた->約5000人国立競技場場所がわかりにくいのでたどり着けなかった->場所
rule/3_independent_phrase.csv
Extract a little complex phrase.
形容詞や否定の「ない」を含んだ少し複雑なルールのフェーズの抽出
新人研修のレベルは高い->新人研修レベルは高いあのサイトはホテルの比較がしやすくないので好きではない->サイトホテル比較がしやすくない好きではない
Metadata
Release files for negima 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| negima-0.1.3.tar.gz | 6.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| negima-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.1 kB
Release files / negima-0.1.3.tar.gz
| Download URL | negima-0.1.3.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
70d13d89c63cde2d978349debaba69f1b2baac96f3c2d9e9600ed1fe15a2c350
|
|
BLAKE2b-256 checksum How to use checksums |
dde2920889fc985905e54c0dc5a4f51f87f71b743398714a126fcca70cc653a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.4.7
|
Release files / negima-0.1.3-py3-none-any.whl
| Download URL | negima-0.1.3-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
51a226b88ab0038dae9679de3c5dd1aee02f7c0de3955357187aecc9e60aa0dd
|
|
BLAKE2b-256 checksum How to use checksums |
c96e8a416d9cb6c3f479404e3d48a0d32a326de09745550658ba0989aac8acfb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.4.7
|