NLTK的语义解析 [英] Semantic parsing with NLTK

查看:328
本文介绍了NLTK的语义解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用NLTK进行语音导航命令的语义解析,例如 去旧金山",给我指示123大街的路线"等信息

I am trying to use NLTK for semantic parsing of spoken navigation commands such as "go to San Francisco", "give me directions to 123 Main Street", etc.

这可以通过一个非常简单的CFG语法来完成,例如

This could be done with a fairly simple CFG grammar such as

S -> COMMAND LOCATION
COMMAND -> "go to" | "give me directions to" | ...
LOCATION -> CITY | STREET | ...

问题在于这涉及非原子(超过一个字长)字面量,例如"go to"(转到),NLTK似乎没有为之准备(如果我错了,请纠正我).解析任务具有标记的先决条件,所有标记器似乎总是标记单个单词.因此,我的选择似乎是:

The problem is that this involves non-atomic (more than one word-long) literals such as "go to", which NLTK doesn't seem to be set up for (correct me if I am wrong). The parsing task has tagging as a prerequisite, and all taggers seem to always tag individual words. So, my options seem to be:

a)定义一个自定义标记器,该标记器可以将非语法标记分配给单词序列,而不是单个单词(例如,转到":命令"). b)使用功能来增强语法,例如:

a) Define a custom tagger that can assign non-syntactic tags to word sequences rather than individual words (e.g., "go to" : "COMMAND"). b) Use features to augment the grammar, e.g., something like:

COMMAND -> VB[sem='go'] P[sem='to'] | ...

c)使用分块器提取诸如COMMAND之类的子结构,然后将解析器应用于结果. NLTK是否允许分块器->解析器级联?

c) Use a chunker to extract sub-structures like COMMAND, then apply a parser to the result. Does NLTK allow chunker->parser cascading?

其中一些选项似乎令人费解(黑客攻击).有什么好办法吗?

Some of these options seem convoluted (hacks). Is there a good way?

推荐答案

似乎您要识别命令.

答案已针对此问题进行了探讨,并包含与您的选项(a)类似的解决方案,但自此以来有所不同它可以让标记器完成大部分工作. (b)确实似乎有点骇人听闻...但是您正在创建一个漂亮的自定义应用程序,因此它可以工作!我会做(c)的另一种方法-根据(a)中的CFG进行解析然后进行分块.

This answer has looked into that and contains a solution similar to your option (a), but a bit different since it lets the tagger do most of the work. (b) indeed seems a bit hacky... but you're creating a pretty custom application, so it could work! I would do (c) the other way around - parsing and then chunking based on the CFG in (a).

总的来说,正如另一个答案所解释的那样,似乎还不是一个完美的方法.

Overall, however, as the other answer explains, there doesn't seem to be a perfect way to do this just yet.

您可能还希望查看 pattern.en .他们的

You might also want to look at pattern.en. Their

mood()函数尝试将已解析的句子识别为指示性,命令性,条件性或虚拟性

mood() function tries to identify a parsed Sentence as indicative, imperative, conditional or subjunctive

这篇关于NLTK的语义解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆