Python 是否可以将NLTK一致性功能用于表情符号?

Python 是否可以将NLTK一致性功能用于表情符号?,python,nltk,Python,Nltk,我已经成功地将NLTK中的concordance()方法与通过古腾堡语料库读入的我自己的文本文件一起使用: bom = open('sentences-with-emoji.txt') from nltk.text import Text bom = Text(nltk.corpus.gutenberg.words('/my-own-text-file.txt')) bom.concordance('messiah') 我之所以说“通过”,是因为concorda

我已经成功地将NLTK中的
concordance()
方法与通过古腾堡语料库读入的我自己的文本文件一起使用:

    bom = open('sentences-with-emoji.txt')
    from nltk.text import Text
    bom = Text(nltk.corpus.gutenberg.words('/my-own-text-file.txt'))
    bom.concordance('messiah')
我之所以说“通过”,是因为
concordance()
方法只通过指定的语料库(即古腾堡语料库)读取单词。古腾堡语料库中没有表情符号。因此,当我尝试使用包含表情符号的不同文件时,如下所示:

bom=open('句子-with-emoji.txt')
从nltk.text导入文本
bom=文本(nltk.corpus.gutenberg.words('/带有表情符号的句子).txt'))

bom.concordance('
nltk.text
要求您传递标记列表。此外,您不必创建新的语料库或通过
gutenberg.words
进行额外的往返。加载原始文本文件并对其进行标记就足够了

#raw=open('句-with-emoji.txt')。read()

raw='word,这样我就可以复制您上面所做的,但是,当我尝试访问文件中的表情符号时,我得到的
没有匹配项
。如何从文件(而不是变量)中获得表情符号的一致性?@matt_07734您能用加载文件的方式更新问题吗?@matt_07734您必须先标记原始文本字符串。然后将此标记列表传递给text()构造函数。您的响应按发布的方式工作。我使用了错误的文本文件…我犯了愚蠢的错误。不过,谢谢您的回答!