简体   繁体   English

情绪分析,极性得分 output 重复几次而不是出现一次

[英]Sentiment Analysis, polarity score output repeating several times instead of appearing once

I have an issue with my polarity score.我的极性分数有问题。 When I'm extracting the sentiment from a sentence, it prints the sentiment 14 times instead of just once.当我从一个句子中提取情绪时,它会打印 14 次而不是一次。

I'm having trouble deducting the source of the issue.我无法推断问题的根源。 Can any of you help me?你们中的任何人都可以帮助我吗?

My coding looks like the following:我的编码如下所示:

  text_data='Du er ikke rar'
pos=0
neg=0
neu=0

for text in text_data:
  analysis=SV.sentida(text_data)

  if analysis > 0:
    print('positiv')
    print("--"*20)
    pos=pos+1
  elif analysis == 0:
    print('neutral')
    print("--"*20)
    neu=neu+1
  else:
    print('negativ')
    print("--"*20)
    neg=neg+1

print(text_data)
print("--"*10)

OUTPUT: OUTPUT:

negativ
----------------------------------------
negativ
----------------------------------------
negativ
----------------------------------------
negativ
----------------------------------------
negativ
----------------------------------------
negativ
----------------------------------------
negativ
----------------------------------------
negativ
----------------------------------------
negativ
----------------------------------------
negativ
----------------------------------------
negativ
----------------------------------------
negativ
----------------------------------------
negativ
----------------------------------------
negativ
----------------------------------------
Du er ikke rar
--------------------

This for text in text_data: makes you iterate over every letter in your string: D,u, ,e,r, ,i,k,k,e...for text in text_data:使您遍历字符串中的每个字母: D,u, ,e,r, ,i,k,k,e...

That is why you have so many outputs.这就是为什么你有这么多输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM