patternMinor
Detect if a sentence is in passive voice
Viewed 0 times
sentencepassivedetectvoice
Problem
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
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. I don't know.
// The
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. I don't know.
// The
Solution
I recommend you look at methods in the NLP literature for parsing a sentence and identifying its structure, classifying the tense of the sentence and the words present in it, and identifying the subject and object of the sentence. That should help you build a more accurate classifier. If you extract suitable features, given the parse tree, and then apply a suitable machine learning algorithm, you might get a more effective classifier.
Context
StackExchange Computer Science Q#35951, answer score: 7
Revisions (0)
No revisions yet.