
6.6
単語の種類を考慮する
137
登場する場合でも、その平均をとることにします。たとえば、上の例のfantasizeの場合、
PosScore
は0.1875、
NegScore
は0.0625になります。
次に示す
load_sent_word_net()
という関数は、ここで説明したこと全てを行い、結果として
ディクショナリを返します。このディクショナリに使われるキーは「品詞の種類/ 単語」の形式をとりま
す。たとえば、「n/implant」のようになります。また、ディクショナリがとる値は、ポジティブスコアと
ネガティブスコアです。
import csv, collections
def load_sent_word_net():
sent_scores = collections.defaultdict(list)
with open(os.path.join(DATA_DIR,
SentiW
ordNet_3.0.0_20130122.txt"), "r") as csvfile:
reader = csv.reader(csvfile, delimiter='\t', quotechar='"')
for line in reader:
if line[0].startswith("#"):
continue
if len(line)==1:
continue
POS,ID,PosScore,NegScore,SynsetTerms,Gloss = line
if len(POS)==0 or ...