2013-07-26 21 views
4

我試圖檢測句子是一個問題還是一個陳述。除了在句子結尾處尋找問號外,還有另一種方法來檢測這個問題嗎?我正在處理Twitter帖子,並且人們不一定要遵循Twitter上的問號等良好做法。NLTK。查找一個句子是否處於提問形式

如果nltk現在可以工作,引用其他庫也可以。

+7

這是一個[開放研究領域](http://www.aclweb.org/anthology-new/C/C10/C10-1130.pdf)。您可以嘗試實施該文件。 – verbsintransit

回答

10

一個簡單的方法是解析一個句子並查找分配給它的標籤。例如,解析句子「有沒有辦法做到這一點?」與斯坦福解析器將返回:

(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-短語以下」。又如:

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

其中SBARQ表示「由疑問詞或一個wh-短語引入直接的問題」。從Python調用外部解析器並處理其輸出非常簡單,例如,檢查this Python interface到斯坦福大學的NLP工具。

0

您可以檢查可能的關鍵字問題,並將樣品問題列表與您要檢查的輸入進行比較。

Sample_Questions = ["what is the weather like","where are we today","why did you do that","where is the dog","when are we going to leave","why do you hate me","what is the Answer to question 8", 
        "what is a dinosour","what do i do in an hour","why do we have to leave at 6.00", "When is the apointment","where did you go","why did you do that","how did he win","why won’t you help me", 
        "when did he find you","how do you get it","who does all the shipping","where do you buy stuff","why don’t you just find it in the target","why don't you buy stuff at target","where did you say it was", 
        "when did he grab the phone","what happened at seven am","did you take my phone","do you like me","do you know what happened yesterday","did it break when it dropped","does it hurt everyday", 
        "does the car break down often","can you drive me home","where did you find me" 
        "can it fly from here to target","could you find it for me"] 


def Question_Sentence_Match(): 
       for Ran_Question in Sample_Questions: 
        Question_Matcher = SequenceMatcher(None, Ran_Question, what_person_said_l).ratio() 
        if Question_Matcher > 0.5: 
         print (Question_Matcher) 
         print ("Similar to Question: "+Ran_Question) 
         print ("likely a Question") 
         return True 
相關問題