Detect if a sentence is in passive voice 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. &lt;- passive
// By the end of the week, I'll be gone. &lt;- not passive, but ok.
int contains_by(char* str) {
    return (strstr(str, "by ") != NULL);
}

// how to find No direct object -&gt; I don't know.
// The subject of the verb phrase is the entity undergoing an action or having its state changed -&gt; I don't know.

int passive_voice(char* str) {
    // relax conditions, by applying || isntead of &amp;&amp;
    if(auxilary_verb(str) || past_participle_transitive_verb(str) || contains_by(str)) {
        return 1;
    } else {
        return 0;
    }
}
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.