June 2023
Intermediate to advanced
316 pages
4h 31m
Japanese
1 #!/usr/bin/env python 2 import sys, re, operator, string 3 4 # lambdaにできない補助関数 5 # 6 def extract_words(obj, path_to_file): 7 with open(path_to_file) as f: 8 obj['data'] = f.read() 9 pattern = re.compile(r'[\W_]+') 10 data_str = ''.join(pattern.sub(' ', obj['data']).lower()) 11 obj['data'] = data_str.split() 12 13 def load_stop_words(obj): 14 with open('../stop_words.txt') as f: 15 obj['stop_words'] = f.read().split(',') 16 # 1文字を単語として追加 17 obj['stop_words'].extend(list(string.ascii_lowercase))
Read now
Unlock full access