June 2023
Intermediate to advanced
316 pages
4h 31m
Japanese
1 #!/usr/bin/env python 2 import sys, string 3 4 # [単語,頻度]の大域的リスト 5 word_freqs = [] 6 # ストップワードのリスト 7 with open('../stop_words.txt') as f: 8 stop_words = f.read().split(',') 9 stop_words.extend(list(string.ascii_lowercase)) 10 11 # ファイル内の行単位で繰り返し 12 for line in open(sys.argv[1]): 13 start_char = None 14 i = 0 15 for c in line: 16 if start_char is None: 17 if c.isalnum(): 18 # 単語の始まり 19 start_char = i 20 else: 21 if not c.isalnum(): 22 # 単語の終わり。見つけた単語の処理を行う 23 found = False 24 word = line[start_char:i].lower() 25 # ストップワードに該当しない単語を処理する 26 if word not in stop_words: ...