Created
January 5, 2021 12:12
-
-
Save hirocarma/64ba16ec270cf29fc9055385039a07c4 to your computer and use it in GitHub Desktop.
Frequency analysis of text files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import MeCab | |
| import sys | |
| import re | |
| import collections | |
| cmd, infile = sys.argv | |
| with open(infile) as f: | |
| text = f.read() | |
| f.close() | |
| m = MeCab.Tagger ('-Ochasen') | |
| node = m.parseToNode(text) | |
| words=[] | |
| while node: | |
| hinshi = node.feature.split(",")[0] | |
| if hinshi in ["名詞"]: | |
| origin = node.feature.split(",")[6] | |
| words.append(origin) | |
| node = node.next | |
| c = collections.Counter(words) | |
| print(c.most_common(40)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment