我的DataFrame中有专栏,现在我的要求是:
请找到我使用的下面的示例代码。
1.试着对数据进行词干化和归一化处理,但不准确;2.甚至使用了空间化和归一化处理,结果也是一样的。
产出看上去要好一些,但在刺激的同时,其他的词也在起作用。
m='dog ran out of Dogs and Dog ran out of cat and dog''s adidas'
try:
def stem(tokens):
x=[]
stemmer = SnowballStemmer(language='english')
for token in tokens:
x.append(stemmer.stem(token))
return x
except:
print('problem at stemming')
s12=' '.join(stem(m.split()))
#####Then written code for duplicate removal
try:
def unique_list(list1):
marker = set()
result = [not marker.add(x.casefold()) and x for x in list1 if x.casefold() not in marker]
return result
except:
print("Problem in removing duplicates")
s5=' '.join(unique_list(s12.split()))实际情况:“狗用完了狗,狗用完了猫和狗的阿迪达”,实际结果是:“狗用完了狗,狗用完了猫和狗阿迪达。”
所以,在实际的结果中,它也是修饰阿迪达斯,这是字符串中的最后一个词。它正在变成“阿迪达”而不是阿迪达斯
预期结果:“狗用完了狗,狗也用完了猫和阿迪达斯”
需要你的想法或帮助来解决这个问题。
发布于 2019-06-03 06:36:11
from nltk import WordNetLemmatizer
lemm = WordNetLemmatizer()
sent = 'dog ran out of Dogs and Dog ran out of cat and dog''s adidas'
word_token = [y.lower() for y in sent.split()]
print(' '.join([lemm.lemmatize(word,'n') for word in word_token]))
#o/p
'dog ran out of dog and dog ran out of cat and dog adidas'https://stackoverflow.com/questions/56357016
复制相似问题