NLTK.判断一个句子是否是疑问句 [英] NLTK. Find if a sentence is in a questioning form

查看:29
本文介绍了NLTK.判断一个句子是否是疑问句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检测一个句子是一个问题还是一个陈述.除了寻找句尾的问号之外,还有其他方法可以检测到这一点吗?我正在处理 Twitter 帖子,人们不一定遵循 Twitter 上的问号等良好做法.

I am trying to detect if a sentence is a question or a statement. Apart from looking for a question mark at the end of the sentence, is there another way to detect this? I am processing Twitter posts and people are not necessarily following good practises like question marks on Twitter.

如果 nltk 现在可以使用,我也可以参考其他库.

Reference to other libraries is also ok with me if nltk does now work.

推荐答案

一种简单的方法是解析一个句子并查找分配给它的标签.例如,解析句子有没有办法做到这一点?"与斯坦福解析器将返回:

One simple way to do this is to parse a sentence and look for the tag assigned to it. For example, parsing the sentence "Is there any way to do this?" with Stanford parser will return:

(ROOT
  (SQ (VBZ Is)
    (NP (EX there))
    (NP
      (NP (DT any) (JJ other) (NN way))
      (S
        (VP (TO to)
          (VP (VB do)
            (NP (DT this))))))
    (. ?)))

其中 SQ 表示倒置是/否问题,或 wh 问题的主句,遵循 SBARQ 中的 wh 短语".另一个例子:

where SQ denotes "Inverted yes/no question, or main clause of a wh-question, following the wh-phrase in SBARQ". Another example:

(ROOT
  (SBARQ
    (WHNP (WP What))
    (SQ (VBZ is)
      (NP
        (NP (DT the) (NN capital))
        (PP (IN of)
          (NP (NNP Scotland)))))
    (. ?)))

其中 SBARQ 表示由 wh 词或 wh 短语引入的直接问题".从 Python 调用外部解析器并处理其输出非常简单,例如检查 this Python interface 到斯坦福 NLP 工具.

where SBARQ denotes "Direct question introduced by a wh-word or a wh-phrase". It's pretty straightforward to call an external parser from Python and process its output, for example check this Python interface to Stanford NLP tools.

这篇关于NLTK.判断一个句子是否是疑问句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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