如何在python中检测连续键入的twitter表情符号

如何在python中检测连续键入的twitter表情符号,python,twitter,nltk,Python,Twitter,Nltk,我正在windows和NLTK包中使用python 2.7 我想检测tweet中的twitter表情符号(emoticon)。此代码能够检测特定的表情符号,前提是表情符号不会立即与另一个表情符号连用 from nltk.tokenize import TweetTokenizer, word_tokenize def negationDetection(tweet): words = word_tokenize(tweet) print words emoticonList

我正在windows和NLTK包中使用python 2.7

我想检测tweet中的twitter表情符号(emoticon)。此代码能够检测特定的表情符号,前提是表情符号不会立即与另一个表情符号连用

from nltk.tokenize import TweetTokenizer,  word_tokenize
def negationDetection(tweet):
   words = word_tokenize(tweet)
   print words
   emoticonList = ['❤']
   i=0
   for word in words:
      if word in emoticonList:
          print "detected"
      i+=1
a = "Congratulations to my cousin James Daniel Brown for graduating from Texas Tech University ❤ go red raiders"
b = negationDetection(a)
检测到结果>>>


但是如果tweet是
a=“祝贺我的表弟詹姆斯·丹尼尔·布朗从德克萨斯理工大学毕业❤ 这是我找到的解决方案

def否定检测(tweet):
表情列表=['❤']
对于表情列表中的i:
如果tweet.find(i)=-1:
持续
其他:
打印“找到”,i

a=“幸好我没有在其他地方申请……美国大学2020❤️也许您应该切换
for
循环:
for word in emoticonList:if word in words
。尝试过但不起作用不熟悉NLTK,但将
word\u标记化
解析
❤作为一个标记。“\xe2\x9d\xa4\xf0\x9f\x8e\x89\xe2\x9d\xa4\xf0\x9f\x8e\x89\xe2\x9d\xa4”您对行中任何地方的表情符号感兴趣还是只对完全由表情符号组成的单词感兴趣?