NLTK.查找句子是否为疑问形式 [英] NLTK. Find if a sentence is in a questioning form

查看:58
本文介绍了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表示在SBARQ中的用语短语之后,反转了是/否问题或wh-quest的主要子句".另一个例子:

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表示直接由疑问词或短语引起的问题".从Python调用外部解析器并处理其输出非常简单,例如,检查此Python接口斯坦福大学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天全站免登陆