python - 处理列表中的字符串(Python 情绪分析)
问题描述
我喜欢对酒店评论做一个小的情绪分析。
示例(stop_word_filter:
['即使','虽然','图片','显示','干净','房间','实际','房间','退出','脏','寿命','还','检查','15','时钟','房间','未','准备好','时间']
我发现这是关于“旅馆房间”和“干净”的。我现在想将关闭的“否定”词连接到应该是“脏”的“干净”。我整合了一个负面词列表。我挂在执行...
代码:
bullets = [] #output
distances = []
bad_word_locations = []
rubrik_word_location = [] #category_word
#if there is a category word in the review
if len(rubrik_uR_list) == 1:
#get the index of that one
rubrik_word_location = stop_words_filter.index(rubrik_uR_list[0])
#go throu all negative words and if one of them in my sentence get the index of that word
for w in negativ_words_list:
if w in stop_words_filter:
bad_word_locations.append(stop_words_filter.index(w))
#NOW ITS GETTING CRUCIAL
#if we found one
if len(bad_word_locations) > 0:
#I need to some how catch now the closest word, my code is not doing this
distances.append(abs(rubrik_word_location-bad_word_locations[0]))
bullets.append(stop_words_filter[min(distances)])
#if I got more categories in one review I need to remind that somehow...
blacklist.append(stop_words_filter[min(distances)])
我在编程方面很差,我明白了。我将真诚地感谢您的帮助。
提前致谢, 尼克拉斯
解决方案
我只能自己弄清楚。
def getBulletPoint(pos_filter,stop_words_filter, rubrik_uR_list):
index_of_category_word = 0
distance = 0
count = 0
#Finde alle negaive Wörter
for w in negativ_words_list:
if w in stop_words_filter:
bad_words.append(w)
#finde die Indexe der negativen Wörter
for w in bad_words:
word_index.append(stop_words_filter.index(w))
if len(rubrik_uR_list) > 0 and len(bad_words) > 0 : #Wenn wir überhaupt ein Rubrikwort haben
#-------------Loop-------------------
for w in rubrik_uR_list:
saved_distance = 1000
# bullets.append(rubrik_list[count])
# bullets.append(rubrik_uR_list[count])
index_of_category_word = stop_words_filter.index(rubrik_uR_list[count])
for i in word_index:
distance = abs(i-index_of_category_word)
if distance < saved_distance:
current_bullet = (stop_words_filter[i])
saved_distance = distance
bullets.append(current_bullet)
count = count + 1
最好的问候, 尼克拉斯
推荐阅读
- entity-framework - 使用 ASP.NET Core 3.1 和 Entity Framework 进行初始迁移时,出现错误“实体类型 'X' 需要定义主键”
- django-admin - 在 django 管理站点中更改模型类名称
- jquery - jQuery ajax 响应时间
- xamarin - 仅使用 WSDL 文件在 Xamarin 表单中使用 SOAP Web 服务
- tensorflow - TensorFlow 适用于 Slurm 交互式会话,但不适用于 Slurm 作业
- oracle - wso2 身份服务器错误 ORA-12839: 修改后无法并行修改对象
- kubernetes - Nginx 入口控制器重写目标注释和规则以向 url 添加尾部斜杠
- reactjs - 2020 年的 React Redux Typescript 令人困惑
- oauth-2.0 - redirect_uri_mismatch 无缘无故
- flutter - 我如何使用颤振创建和维护会话