"""
35.Häufigkeit des Auftretens von Wörtern
Suchen Sie die Wörter, die im Satz erscheinen, und ihre Häufigkeit des Auftretens, und ordnen Sie sie in absteigender Reihenfolge der Häufigkeit des Auftretens an.
[[{'surface': '', 'base': '*', 'pos': 'BOS/EOS', 'pos1': '*'},
{'surface': 'einer', 'base': 'einer', 'pos': 'Substantiv', 'pos1': 'Nummer'},
{'surface': '', 'base': '*', 'pos': 'BOS/EOS', 'pos1': '*'}],
[{'surface': '', 'base': '*', 'pos': 'BOS/EOS', 'pos1': '*'},
{'surface': 'ich', 'base': 'ich', 'pos': 'Substantiv', 'pos1': '代Substantiv'},
{'surface': 'Ist', 'base': 'Ist', 'pos': 'Partikel', 'pos1': '係Partikel'},
{'surface': 'Katze', 'base': 'Katze', 'pos': 'Substantiv', 'pos1': 'Allgemeines'},
{'surface': 'damit', 'base': 'Ist', 'pos': 'Hilfsverb', 'pos1': '*'},
{'surface': 'Gibt es', 'base': 'Gibt es', 'pos': 'Hilfsverb', 'pos1': '*'},
{'surface': '。', 'base': '。', 'pos': 'Symbol', 'pos1': 'Phrase'},
{'surface': '', 'base': '*', 'pos': 'BOS/EOS', 'pos1': '*'}],
"""
from collections import Counter
from typing import List
import utils
def get_tf(sentence_list: List[List[dict]]) -> dict:
words = [word["surface"] for sent in sentence_list for word in sent[1:-1]]
c = Counter(words)
return c.most_common()
data = utils.read_json("30_neko_mecab.json")
result = get_tf(data)
# [('von', 9194),
# ('。', 7486),
# ('Hand', 6868),
# ('、', 6772),
# ('Ist', 6420),
# ('Zu', 6243),
# ('Zu', 6071),
# ('Wann', 5508),
# ('Aber', 5337),
# ('Ta', 3988)]
Recommended Posts