我正在尝试创建一个类似英语的小语言来指定任务.基本思想是将一个陈述分成这些动词应该适用的动词和名词短语.我正在使用nltk,但没有得到我希望的结果,例如:
>>> nltk.pos_tag(nltk.word_tokenize("select the files and copy to harddrive'"))
[('select', 'NN'), ('the', 'DT'), ('files', 'NNS'), ('and', 'CC'), ('copy', 'VB'), ('to', 'TO'), ("harddrive'", 'NNP')]
>>> nltk.pos_tag(nltk.word_tokenize("move the files to harddrive'"))
[('move', 'NN'), ('the', 'DT'), ('files', 'NNS'), ('to', 'TO'), ("harddrive'", 'NNP')]
>>> nltk.pos_tag(nltk.word_tokenize("copy the files to harddrive'"))
[('copy', 'NN'), ('the', 'DT'), ('files', 'NNS'), ('to', 'TO'), ("harddrive'", 'NNP')]
Run Code Online (Sandbox Code Playgroud)
在每种情况下,它都没有意识到第一个单词(选择,移动和复制)是作为动词.我知道我可以创建自定义标注器和语法来解决这一点,但在同一时间,我不愿去重新发明轮子,当很多东西是我的联赛.我特别希望能够处理非英语语言的解决方案.
所以无论如何,我的问题之一是:这种语法有更好的标记吗?有没有办法可以比现有的标记更加频繁地使用动词形式?有没有办法训练标记器?有更好的方法吗?
有这个:
text = word_tokenize("The quick brown fox jumps over the lazy dog")
Run Code Online (Sandbox Code Playgroud)
并运行:
nltk.pos_tag(text)
Run Code Online (Sandbox Code Playgroud)
我明白了:
[('The', 'DT'), ('quick', 'NN'), ('brown', 'NN'), ('fox', 'NN'), ('jumps', 'NNS'), ('over', 'IN'), ('the', 'DT'), ('lazy', 'NN'), ('dog', 'NN')]
Run Code Online (Sandbox Code Playgroud)
这是不正确的.quick brown lazy句子中的标签应为:
('quick', 'JJ'), ('brown', 'JJ') , ('lazy', 'JJ')
Run Code Online (Sandbox Code Playgroud)