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.

Janomeで固有名詞の登場順を得る。

Posted at
text="長い文章"
zyogaiList=["名詞,代名詞","名詞,非自立","名詞,数"]#除外
cf = [UnicodeNormalizeCharFilter()]#前処理フィルタ
    tf = [CompoundNounFilter(),POSKeepFilter(["品詞"]),POSStopFilter(zyogaiList),TokenCountFilter(att='base_form')] #後処理フィルタ準備 att="base_form"で品詞活用をまとめて基本形のみにする
    a = Analyzer(char_filters =cf,token_filters=tf)#解析器生成
    results = a.analyze(text)#解析
    print(syurui,"登場順")
    s =sorted(results, key=lambda x:x[1],reverse=True)#結果並べ替え
    for i,wc in enumerate(s):
      if i >= 50:break
      print((i +1),':',wc)

こういうやつで


POSKeepFilter(["品詞"]

の品詞を"名詞"とか"動詞"とかにすることで、その品詞に該当する登場順が出力できることは本にもwebにも載っている。
でも固有名詞pを出したいときどうすれば良いのかが見つからなかったので、備忘録として残した。

結論
名詞,固有名詞
とすればいい!

つまり

POSKeepFilter(["名詞,固有名詞"])

こういうことであり、

最初に提示したコードなら


text="長い文章"
zyogaiList=["名詞,代名詞","名詞,非自立","名詞,数"]#除外
cf = [UnicodeNormalizeCharFilter()]#前処理フィルタ
    tf = [CompoundNounFilter(),POSKeepFilter(["名詞,固有名詞"]),POSStopFilter(zyogaiList),TokenCountFilter(att='base_form')] #後処理フィルタ準備 att="base_form"で品詞活用をまとめて基本形のみにする
    a = Analyzer(char_filters =cf,token_filters=tf)#解析器生成
    results = a.analyze(text)#解析
    print(syurui,"登場順")
    s =sorted(results, key=lambda x:x[1],reverse=True)#結果並べ替え
    for i,wc in enumerate(s):
      if i >= 50:break
      print((i +1),':',wc)

こうすると実現できる。

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?