0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

言語処理100本ノック(2020): 33

Posted at
"""
33. 「AのB」Permalink
2つの名詞が「の」で連結されている名詞句を抽出せよ

[[{'surface': '', 'base': '*', 'pos': 'BOS/EOS', 'pos1': '*'},
  {'surface': '', 'base': '', 'pos': '名詞', 'pos1': ''},
  {'surface': '', 'base': '*', 'pos': 'BOS/EOS', 'pos1': '*'}],
 [{'surface': '', 'base': '*', 'pos': 'BOS/EOS', 'pos1': '*'},
  {'surface': '吾輩', 'base': '吾輩', 'pos': '名詞', 'pos1': '代名詞'},
  {'surface': '', 'base': '', 'pos': '助詞', 'pos1': '係助詞'},
  {'surface': '', 'base': '', 'pos': '名詞', 'pos1': '一般'},
  {'surface': '', 'base': '', 'pos': '助動詞', 'pos1': '*'},
  {'surface': 'ある', 'base': 'ある', 'pos': '助動詞', 'pos1': '*'},
  {'surface': '', 'base': '', 'pos': '記号', 'pos1': '句点'},
  {'surface': '', 'base': '*', 'pos': 'BOS/EOS', 'pos1': '*'}],
"""
import itertools
from typing import List

import utils


def get_none_phase(sentence: List[dict]) -> List[str]:
    result = []
    for i, word in enumerate(sentence):
        if (
            word["surface"] == ""
            and sentence[i - 1]["pos"] == "名詞"
            and sentence[i + 1]["pos"] == "名詞"
        ):
            result.append(sentence[i - 1]["surface"] + "" + sentence[i + 1]["surface"])
    return result


data = utils.read_json("30_neko_mecab.json")
none_phases = [get_none_phase(sentence) for sentence in data]
# In [75]: none_phases[:10]
# Out[75]: [[], [], [], [], [], [], [], [], [], ['彼の掌']]
flat = list(itertools.chain(*none_phases))
# ['彼の掌', '掌の上', '書生の顔', 'はずの顔', '顔の真中']

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?