我怎样才能获得模块" remote_tag"在Python?

时间:2015-03-17 13:39:41

标签: python nltk text-mining

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()

1 个答案:

答案 0 :(得分:0)

通过以下五行代码创建我们自己的 remote_tag.py 模块,该代码来自 Python文本处理与NLTK 2.0 Cookbook 的第204页,并放在与我们导入它的程序。

    import cPickle as pickle

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

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