如何在Python中获取模块“remote\u tag”?

2024-05-14 12:57:18 发布

您现在位置:Python中文网/ 问答频道 /正文

Python Text Processing with NLTK 2.0 Cookbook的第203页中有一个导入模块remote_tag的示例。但我没有找到任何网站可以下载该模块。如何在Python中获取模块remote_tag?你知道吗

>>> import execnet, remote_tag, nltk.tag, nltk.data
>>> from nltk.corpus import treebank
>>> import cPickle as pickle
>>> tagger = pickle.dumps(nltk.data.load(nltk.tag._POS_TAGGER))
>>> gw = execnet.makegateway()
>>> channel = gw.remote_exec(remote_tag)
>>> channel.send(tagger)
>>> channel.send(treebank.sents()[0])
>>> tagged_sentence = channel.receive()
>>> tagged_sentence == treebank.tagged_sents()[0]
True
>>> gw.exit()

Tags: 模块importsenddataremotetagchannelpickle
1条回答
网友
1楼 · 发布于 2024-05-14 12:57:18

创建我们自己的远程_标签.py模块,按照Python文本处理的第204页的五行代码,使用NLTK 2.0 Cookbook将其放入与我们导入的程序相同的目录中。你知道吗

    import cPickle as pickle

    if __name__ == '__channelexec__':
       tagger = pickle.loads(channel.receive())

       for sentence in channel:
         channel.send(tagger.tag(sentence))

相关问题 更多 >

    热门问题