Search code examples
javaeclipsenlg

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.


Solution

  • 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"