-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtokenizing.py
36 lines (27 loc) · 939 Bytes
/
tokenizing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
import logging
from collections import Counter
from kiwipiepy import Kiwi
from typing import List
class Tokenizer:
def __init__(self):
self.tokenizer = Kiwi()
def tokenize(self, content_list: List[str]) -> Counter:
"""
tokenize for list of contents
:param content_list: list of contents
:return: list of tokens
"""
token_list = []
for content in content_list:
token_list.extend([
token.form for token in self.tokenizer.tokenize(content) if token.tag == 'NNG'
])
return Counter(token_list)
if __name__ == "__main__":
tokenizer = Tokenizer()
logging.info("[INFO] Count for tokens")
content_list = [content.rstrip('\n') for content in sys.stdin]
token_counter = tokenizer.tokenize(content_list)
for token, count in token_counter.most_common():
print(token, count, sep="\t")