gpt4 book ai didi

python - 使用 TreeTagger 进行标记时必须使用 *unicode* 字符串作为标记文本吗?

转载 作者:行者123 更新时间:2023-11-30 22:57:22 24 4
gpt4 key购买 nike

来自TreeTagger's website我创建了一个目录并下载了指定的文件。然后treetaggerwrapper ,因此从 documentation我尝试测试并尝试如何标记一些文本,如下所示:

In [40]:

import treetaggerwrapper

tagger = treetaggerwrapper.TreeTagger(TAGLANG='en')

tags = tagger.TagText("This is a very short text to tag.")

print tags

然后我收到以下警告:

WARNING:TreeTagger:Abbreviation file not found: english-abbreviations
WARNING:TreeTagger:Processing without abbreviations file.
ERROR:TreeTagger:Must use *unicode* string as text to tag, not <type 'str'>.

---------------------------------------------------------------------------
TreeTaggerError Traceback (most recent call last)
<ipython-input-40-37b912126580> in <module>()
1 import treetaggerwrapper
2 tagger = treetaggerwrapper.TreeTagger(TAGLANG='en')
----> 3 tags = tagger.TagText("This is a very short text to tag.")
4 print tags

/usr/local/lib/python2.7/site-packages/treetaggerwrapper.pyc in TagText(self, text, numlines, tagonly, prepronly, tagblanks, notagurl, notagemail, notagip, notagdns, encoding, errors)
1236 return self.tag_text(text, numlines=numlines, tagonly=tagonly,
1237 prepronly=prepronly, tagblanks=tagblanks, notagurl=notagurl,
-> 1238 notagemail=notagemail, notagip=notagip, notagdns=notagdns)
1239
1240 # --------------------------------------------------------------------------

/usr/local/lib/python2.7/site-packages/treetaggerwrapper.pyc in tag_text(self, text, numlines, tagonly, prepronly, tagblanks, notagurl, notagemail, notagip, notagdns, nosgmlsplit)
1302 # Raise exception now, with an explicit message.
1303 logger.error("Must use *unicode* string as text to tag, not %s.", type(text))
-> 1304 raise TreeTaggerError("Must use *unicode* string as text to tag.")
1305
1306 if isinstance(text, six.text_type):

TreeTaggerError: Must use *unicode* string as text to tag.

哪里可以下载英语和西类牙语的缩写文件?以及如何正确安装treetaggerwrapper?

最佳答案

该方法仅接受 unicode 字符串,在字符串中添加 u 使其成为 unicode 字符串:

tags = tagger.TagText(u"This is a very short text to tag.")

“这是要标记的非常短的文本。”str 类型,一旦添加 u 它就是 unicode:

In [12]: type("This is a very short text to tag.")
Out[12]: str

In [13]: type(u"This is a very short text to tag.")
Out[13]: unicode

如果您从其他来源获取 str,则需要解码:

In [15]: s = "This is a very short text to tag."

In [16]: type(s)
Out[16]: str

In [17]: type(s.decode("utf-8"))
Out[17]: unicode

可以下载标记脚本here

关于python - 使用 TreeTagger 进行标记时必须使用 *unicode* 字符串作为标记文本吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36680144/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com