膜拜斗大的熊猫:
点击打开链接
import numpy as np
import tensorflow as tf
import random
import pickle
from collections import Counter
import nltk
from nltk.tokenize import word_tokenize
#将一句话拆分为多个单词
from nltk.stem import WordNetLemmatizer
#将单词都还原成一般形式
pos_file = 'pos.txt'
neg_file = 'neg.txt'
#创建词汇表
def create_lexicon(pos_file,neg_file):
lex=[]
#读取文件
def process_file(f):
with open(pos_file,'r') as f:
lex=[]
lines=f.readlines()
for line in lines:
words=word_tokenize(line.lower())
lex+=words
return lex
lex+=process_file(pos_file)
lex+=process_file(neg_file)
lemmatizer=WordNetLemmatizer()
lex=[lemmatizer