noobProgrammer
noobProgrammer

Reputation: 37

Get tense of verb java

I am using simpleNLG to find the actual tense of a verb. But i cannot seem to be doing it right, instead of giving the tense of the verb it converts it to present tense :/

public class TenseWas
{
    public static void main(String[] args)
    {
        String word = "ate";
        Lexicon lexicon=Lexicon.getDefaultLexicon();
        NLGFactory nlgFactory=new NLGFactory(lexicon);
        Realiser realiser=new Realiser(lexicon);
        SPhraseSpec p=nlgFactory.createClause();
        p.setVerb(word);
        if(p.getVerb().getFeature(Feature.TENSE) == (Tense.PAST))
        {
            System.out.println("past");
        }
        if(p.getVerb().getFeature(Feature.TENSE) == (Tense.FUTURE))
        {
            System.out.println("future");
        }
        if(p.getVerb().getFeature(Feature.TENSE) == (Tense.PRESENT))
        {
            System.out.println("Present");
        }
        String output=realiser.realiseSentence(p);
        System.out.println(output);
    }
}

This is what appears in the console:

Eats.

Upvotes: 2

Views: 1171

Answers (2)

macmania314
macmania314

Reputation: 457

answering this for future programmers.

As @Bohemian pointed out, simplenlg isn't used to classify the verb tense of a verb, it's a realization engine, being used to convert an abstract representation of 'sentence' to an actual sentence.

If you look at the lexicon xml 'database' library that simplenlg uses, it comprises the annotated version of verbs and nouns, etc. It's in https://github.com/simplenlg/simplenlg/blob/master/src/main/resources/default-lexicon.xml. FYI, you can use other lexicon xml databases.

<word>
    <base>sleep</base>
    <category>verb</category>
    <id>E0056246</id>
    <present3s>sleeps</present3s>
    <intransitive/>
    <past>slept</past>
    <pastParticiple>slept</pastParticiple>
    <presentParticiple>sleeping</presentParticiple>
    <transitive/>
</word>

So to answer your question, you shouldn't use simplenlg to get a tense of a verb but use other NLP/'smarter' libraries to do 'verb' or word classification such as the Parts of Speech Tagger in CoreNLP or OpenNLP, here's information on them, OpenNLP vs Stanford CoreNLP

Upvotes: 1

Bohemian
Bohemian

Reputation: 425073

Calling getFeature() doesn't tell you what tense the verb you set was, it echoes back the tense of the clause as set by you for rendering the clause. You use it like this:

p.setSubject("Foo");
p.setVerb("eat");
p.setObject("bar");
p.setFeature(Feature.TENSE, Tense.PAST); 
String output = realiser.realiseSentence(p);
System.out.println(output); // "Foo ate bar"

Upvotes: 1

Related Questions