NLTK. Find if the offer is in the form of a survey

I am trying to determine if a sentence is a question or an expression. Besides finding a question mark at the end of a sentence, is there any other way to detect this? I process messages on Twitter and people don’t necessarily follow good practices like question marks on Twitter.

Link to other libraries also with me if nltk now works.

+4
source share
2 answers

One easy way to do this is to parse the sentence and find the tag assigned to it. For example, parsing the phrase "Is there a way to do this?" with parser Stanford 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)))))) (. ?))) 

where SQ means "yes / no inverted question or the main sentence of the 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))))) (. ?))) 

where SBARQ means "A direct question entered by a wh-word or wh-phrase." It is very simple to call an external parser from Python and process its output, for example, check this Python interface for Stanford NLP tools.

+11
source

You can check the likely keywords and compare the list of questions with the queries you want to check.

 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 
0
source

Source: https://habr.com/ru/post/1493647/


All Articles