摩西工具包中几个预处理脚本的包装。
mosestokenizer的Python项目详细描述
这个包为来自 摩西工具包,即normalize-punctuation.perl,tokenizer.perl, detokenizer.perl和split-sentences.perl。
示例用法
所有提供的类都可从包mosestokenizer中导入。
>>> from mosestokenizer import *
所有类都有一个构造函数,它接受两个字母的语言代码作为 参数('en'、'fr'、'de'等)和结果对象 是可以调用的。
创建时,这些包装器对象将作为 背景进程。当不再需要对象时,应调用 .close()方法关闭后台进程并释放系统资源。
这些对象还支持上下文管理器接口。 因此,如果在with块中使用,则调用.close()方法 当块退出时自动进行。
以下两个MosesTokenizer用法是等价的:
>>> # here we will call .close() explicitly at the end: >>> tokenize = MosesTokenizer('en') >>> tokenize('Hello World!') ['Hello', 'World', '!'] >>> tokenize.close()>>> # here we take advantage of the context manager interface: >>> with MosesTokenizer('en') as tokenize: >>> tokenize('Hello World!') ... ['Hello', 'World', '!']
如上所示,MosesTokenizer可调用对象接受一个字符串并返回 令牌(字符串)列表。
相反,MosesDetokenizer接受一个令牌列表并返回一个字符串:
>>> with MosesDetokenizer('en') as detokenize: >>> detokenize(['Hello', 'World', '!']) ... 'Hello World!'
MosesSentenceSplitter做的比名字上说的还要多。除了分裂 句子,它也会打开文本,也就是说,它会试图猜测一个句子 是否继续下一行。它需要一个行(字符串)列表 返回句子(字符串)列表:
>>> with MosesSentenceSplitter('en') as splitsents: >>> splitsents([ ... 'Mr. Smith is away. Do you want to', ... 'leave a message?' ... ]) ... ['Mr. Smith is away.', 'Do you want to leave a message?']
MosesPunctuationNormalizer对象将字符串作为参数并返回 字符串:
>>> with MosesPunctuationNormalizer('en') as normalize: >>> normalize('«Hello World» — she said…') ... '"Hello World" - she said...'
许可证
版权所有?2016-2017,Luís Gomes<;luismsgomes@gmail.com>;。
这个库是免费软件;您可以重新分发它和/或 根据GNU小公众条款修改 自由软件基金会发布的许可证;或者 许可证的2.1版,或(由您选择)任何更高版本。
这个图书馆的发行是希望它能有用, 但没有任何保证;甚至没有 适销性或适合某一特定目的的适销性。看GNU 更详细的信息,请参阅较低的通用公共许可证。
你应该收到一份GNU的副本 与此库一起使用许可证;如果没有,请写入免费软件 马萨诸塞州波士顿富兰克林街51号5楼基金会公司 02110-1301美国