2013-07-26 1 views
4

문장이 질문인지 진술인지 알아 내려고합니다. 문장의 끝에서 물음표를 찾는 것 외에도 이것을 감지 할 수있는 또 다른 방법이 있습니까? 나는 트위터 게시물을 처리 중이며 사람들은 반드시 트위터의 물음표와 같은 우수 사례를 따르지 않습니다.NLTK 문장이 질문 형식인지 확인하십시오.

nltk이 작동하면 다른 라이브러리에 대한 참조 또한 나에게 좋습니다.

+7

[연구의 공개 영역] (http://www.aclweb.org/anthology-new/C/C10/C10-1130.pdf)입니다. 이 논문을 구현해보십시오. – verbsintransit

답변

10

한 가지 간단한 방법은 문장을 구문 분석하고 그것에 할당 된 태그를 찾는 것입니다. 예를 들어 문장을 파싱하면 "이 방법이 있습니까?" 스탠포드 파서 반환합니다 SQ는 "SBARQ에서 어 문구 다음 거꾸로 예/아니오 질문, 또는 ㅁ - 질문의 주요 조항"을 의미하지

(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)))))) 
    (. ?))) 

. 다른 예 :

(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 도구에 확인하는 것은 매우 간단합니다.

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 
관련 문제