Given an English sentence, I am looking for a programmatic way to tell whether the sentence is written in passive voice.
Currently, I just check if there is a was
or were
inside the sentence. If yes, then the function will say that the sentence is in passive voice (I do no not know even if this is true). Is there a better approach?
I just want to make a simple detector for passive voice, I do not care much for accuracy and efficiency. Here what I ended up with:
// http://english.stackexchange.com/questions/472/how-can-i-reliably-and-accurately-identify-the-passive-voice-in-writing-or-speec // forms of be, have and get int auxilary_verb(char* str) { if(strstr(str, "be ") || strstr(str, "been ") || strstr(str, "being ") || strstr(str, "have ") || strstr(str, "had ") || strstr(str, "was ") || strstr(str, "were ") || strstr(str, "wasn") || strstr(str, "weren") || strstr(str, "got ") || strstr(str, "get ") || strstr(str, "getting ")) { return 1; } else { return 0; } } // past participles of the verbs here http://web2.uvcs.uvic.ca/elc/sample/beginner/gs/gs_10.htm int past_participle_transitive_verb(char* str) { if(strstr(str, "brought ") || strstr(str, "cost ") || strstr(str, "given ") || strstr(str, "lent ") || strstr(str, "offered ") || strstr(str, "passed ") || strstr(str, "played ") || strstr(str, "read ") || strstr(str, "sent ") || strstr(str, "sung ") || strstr(str, "sent ") || strstr(str, "taught ") || strstr(str, "written ") || strstr(str, "bought ") || strstr(str, "get done ") || strstr(str, "left ") || strstr(str, "made ") || strstr(str, "owed ") || strstr(str, "paid ") || strstr(str, "promised ") || strstr(str, "refused ") || strstr(str, "shown ") || strstr(str, "taken ") || strstr(str, "told ") ) { return 1; } else { return 0; } } // Once a week, the house is cleaned by Tom. <- passive // By the end of the week, I'll be gone. <- not passive, but ok. int contains_by(char* str) { return (strstr(str, "by ") != NULL); } // how to find No direct object -> I don't know. // The subject of the verb phrase is the entity undergoing an action or having its state changed -> I don't know. int passive_voice(char* str) { // relax conditions, by applying || isntead of && if(auxilary_verb(str) || past_participle_transitive_verb(str) || contains_by(str)) { return 1; } else { return 0; } }
Asked By : gsamaras
Answered By : vzn
detecting passive voice is an AI application also used/ implemented in grammar checker/ correction software with proprietary algorithms. there is a complexity/ accuracy tradeoff. simpler algorithms can be useful and better accuracy requires more sophisticated algorithms. here are two papers on the subject including a masters thesis (60p). final link is an open source implementation of passive voice checking used in OpenOffice.
Learning to Identify Reduced Passive Verb Phrases with a Shallow Parser Igo, Riloff AAAI-2008
IDENTIFYING REDUCED PASSIVE VOICE CONSTRUCTIONS IN SHALLOW PARSING ENVIRONMENTS / Igo
open source grammar checker for open office including passive voice checking
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/35951
0 comments:
Post a Comment
Let us know your responses and feedback