Package simplenlg.phrasespec

Examples of simplenlg.phrasespec.SPhraseSpec


  /**
   * Slightly more complex tests for forms.
   */
  public void testForm2() {
    // set s4 as subject of a new sentence
    SPhraseSpec temp = this.phraseFactory.createClause(this.s4, "be", //$NON-NLS-1$
        "recommended"); //$NON-NLS-1$

    Assert.assertEquals(
        "however tomorrow Jane and Andrew's picking up the " + //$NON-NLS-1$
            "balls in the shop is recommended", //$NON-NLS-1$
        this.realiser.realise(temp).getRealisation());

    // compose this with a new sentence
    // ER - switched direct and indirect object in sentence
    SPhraseSpec temp2 = this.phraseFactory.createClause("I", "tell", temp); //$NON-NLS-1$ //$NON-NLS-2$
    temp2.setFeature(Feature.TENSE, Tense.FUTURE);

    PhraseElement indirectObject = this.phraseFactory
        .createNounPhrase("John"); //$NON-NLS-1$

    temp2.setIndirectObject(indirectObject);

    Assert.assertEquals("I will tell John that however tomorrow Jane and " + //$NON-NLS-1$
        "Andrew's picking up the balls in the shop is " + //$NON-NLS-1$
        "recommended", //$NON-NLS-1$
        this.realiser.realise(temp2).getRealisation());

    // turn s4 to imperative and put it in indirect object position

    this.s4 = this.phraseFactory.createClause();
    this.s4.setFeature(Feature.CUE_PHRASE, "however"); //$NON-NLS-1$
    this.s4.addFrontModifier("tomorrow"); //$NON-NLS-1$

    CoordinatedPhraseElement subject = new CoordinatedPhraseElement(
        this.phraseFactory.createNounPhrase("Jane"), this.phraseFactory //$NON-NLS-1$
            .createNounPhrase("Andrew")); //$NON-NLS-1$

    this.s4.setSubject(subject);

    PhraseElement pick = this.phraseFactory.createVerbPhrase("pick up"); //$NON-NLS-1$
    this.s4.setVerbPhrase(pick);
    this.s4.setObject("the balls"); //$NON-NLS-1$
    this.s4.addPostModifier("in the shop"); //$NON-NLS-1$
    this.s4.setFeature(Feature.TENSE, Tense.FUTURE);
    this.s4.setFeature(Feature.FORM, Form.IMPERATIVE);

    temp2 = this.phraseFactory.createClause("I", "tell", this.s4); //$NON-NLS-1$ //$NON-NLS-2$
    indirectObject = this.phraseFactory.createNounPhrase("John"); //$NON-NLS-1$
    temp2.setIndirectObject(indirectObject);
    temp2.setFeature(Feature.TENSE, Tense.FUTURE);

    Assert.assertEquals("I will tell John however to pick up the balls " //$NON-NLS-1$
        + "in the shop tomorrow", this.realiser.realise(temp2) //$NON-NLS-1$
        .getRealisation());
  }
View Full Code Here


   */
  @Test
  public void testGerundsubject() {

    // the man's giving the woman John's flower upset Peter
    SPhraseSpec _s4 = this.phraseFactory.createClause();
    _s4.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset")); //$NON-NLS-1$
    _s4.setFeature(Feature.TENSE, Tense.PAST);
    _s4.setObject(this.phraseFactory.createNounPhrase("Peter")); //$NON-NLS-1$
    this.s3.setFeature(Feature.PERFECT, true);

    // set the sentence as subject of another: makes it a gerund
    _s4.setSubject(this.s3);

    // suppress the genitive realisation of the NP subject in gerund
    // sentences
    this.s3.setFeature(Feature.SUPPRESS_GENITIVE_IN_GERUND, true);

View Full Code Here

   */
  @Test
  public void testComplexSentence1() {
    setUp();
    // the man's giving the woman John's flower upset Peter
    SPhraseSpec complexS = this.phraseFactory.createClause();
    complexS.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset")); //$NON-NLS-1$
    complexS.setFeature(Feature.TENSE, Tense.PAST);
    complexS.setObject(this.phraseFactory.createNounPhrase("Peter")); //$NON-NLS-1$
    this.s3.setFeature(Feature.PERFECT, true);
    complexS.setSubject(this.s3);

    // check the realisation: subject should be genitive
    Assert.assertEquals(
        "the man's having given the woman John's flower upset Peter", //$NON-NLS-1$
        this.realiser.realise(complexS).getRealisation());

    setUp();
    // coordinate sentences in subject position
    SPhraseSpec s5 = this.phraseFactory.createClause();
    s5.setSubject(this.phraseFactory.createNounPhrase("some", "person")); //$NON-NLS-1$ //$NON-NLS-2$
    s5.setVerbPhrase(this.phraseFactory.createVerbPhrase("stroke")); //$NON-NLS-1$
    s5.setObject(this.phraseFactory.createNounPhrase("the", "cat")); //$NON-NLS-1$ //$NON-NLS-2$

    CoordinatedPhraseElement coord = new CoordinatedPhraseElement(this.s3,
        s5);
    complexS = this.phraseFactory.createClause();
    complexS.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset")); //$NON-NLS-1$
    complexS.setFeature(Feature.TENSE, Tense.PAST);
    complexS.setObject(this.phraseFactory.createNounPhrase("Peter")); //$NON-NLS-1$
    complexS.setSubject(coord);
    this.s3.setFeature(Feature.PERFECT, true);

    Assert.assertEquals("the man's having given the woman John's flower " //$NON-NLS-1$
        + "and some person's stroking the cat upset Peter", //$NON-NLS-1$
        this.realiser.realise(complexS).getRealisation());

    setUp();
    // now subordinate the complex sentence
    // coord.setClauseStatus(SPhraseSpec.ClauseType.MAIN);
    SPhraseSpec s6 = this.phraseFactory.createClause();
    s6.setVerbPhrase(this.phraseFactory.createVerbPhrase("tell")); //$NON-NLS-1$
    s6.setFeature(Feature.TENSE, Tense.PAST);
    s6.setSubject(this.phraseFactory.createNounPhrase("the", "boy")); //$NON-NLS-1$ //$NON-NLS-2$
    // ER - switched indirect and direct object
    PhraseElement indirect = this.phraseFactory.createNounPhrase("every", //$NON-NLS-1$
        "girl"); //$NON-NLS-1$
    s6.setIndirectObject(indirect);
    complexS = this.phraseFactory.createClause();
    complexS.setVerbPhrase(this.phraseFactory.createVerbPhrase("upset")); //$NON-NLS-1$
    complexS.setFeature(Feature.TENSE, Tense.PAST);
    complexS.setObject(this.phraseFactory.createNounPhrase("Peter")); //$NON-NLS-1$
    s6.setObject(complexS);
    coord = new CoordinatedPhraseElement(this.s3, s5);
    complexS.setSubject(coord);
    this.s3.setFeature(Feature.PERFECT, true);
    Assert.assertEquals(
        "the boy told every girl that the man's having given the woman " //$NON-NLS-1$
View Full Code Here

   * Tests passive.
   */
  @Test
  public void testPassive() {
    // passive with just complement
    SPhraseSpec _s1 = this.phraseFactory.createClause(null,
        "intubate", this.phraseFactory.createNounPhrase("the", "baby")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    _s1.setFeature(Feature.PASSIVE, true);

    Assert.assertEquals("the baby is intubated", this.realiser //$NON-NLS-1$
        .realise(_s1).getRealisation());

    // passive with subject and complement
    _s1 = this.phraseFactory.createClause(null,
        "intubate", this.phraseFactory.createNounPhrase("the", "baby")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    _s1.setSubject(this.phraseFactory.createNounPhrase("the nurse")); //$NON-NLS-1$
    _s1.setFeature(Feature.PASSIVE, true);
    Assert.assertEquals("the baby is intubated by the nurse", //$NON-NLS-1$
        this.realiser.realise(_s1).getRealisation());

    // passive with subject and indirect object
    SPhraseSpec _s2 = this.phraseFactory.createClause(null, "give", //$NON-NLS-1$
        this.phraseFactory.createNounPhrase("the", "baby")); //$NON-NLS-1$ //$NON-NLS-2$

    PhraseElement morphine = this.phraseFactory
        .createNounPhrase("50ug of morphine"); //$NON-NLS-1$
    _s2.setIndirectObject(morphine);
    _s2.setFeature(Feature.PASSIVE, true);
    Assert.assertEquals("the baby is given 50ug of morphine", //$NON-NLS-1$
        this.realiser.realise(_s2).getRealisation());

    // passive with subject, complement and indirect object
    _s2 = this.phraseFactory.createClause(this.phraseFactory
        .createNounPhrase("the", "nurse"), "give", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        this.phraseFactory.createNounPhrase("the", "baby")); //$NON-NLS-1$ //$NON-NLS-2$

    morphine = this.phraseFactory.createNounPhrase("50ug of morphine"); //$NON-NLS-1$
    _s2.setIndirectObject(morphine);
    _s2.setFeature(Feature.PASSIVE, true);
    Assert.assertEquals("the baby is given 50ug of morphine by the nurse", //$NON-NLS-1$
        this.realiser.realise(_s2).getRealisation());

    // test agreement in passive
    PhraseElement _s3 = this.phraseFactory.createClause(
View Full Code Here

    coord.addPostModifier(this.behindTheCurtain);
    Assert.assertEquals("slowly got up and fell down behind the curtain",
        this.realiser.realise(coord).getRealisation());

    // put within the context of a sentence
    SPhraseSpec s = this.phraseFactory.createClause("Jake", coord);
    s.setFeature(Feature.TENSE, Tense.PAST);
    Assert.assertEquals(
        "Jake slowly got up and fell down behind the curtain",
        this.realiser.realise(s).getRealisation());

    // add premod to the sentence
    s.addPreModifier(this.lexicon
        .getWord("however", LexicalCategory.ADVERB));
    Assert.assertEquals(
        "Jake however slowly got up and fell down behind the curtain",
        this.realiser.realise(s).getRealisation());

    // add postmod to the sentence
    s.addPostModifier(this.inTheRoom);
    Assert
        .assertEquals(
            "Jake however slowly got up and fell down behind the curtain in the room",
            this.realiser.realise(s).getRealisation());
  }
View Full Code Here

    // (before head) by using addPreModifier
    PPPhraseSpec toThePark = nlgFactory.createPrepositionPhrase("to");    // create a PP
    toThePark.setObject(thePark);                                     // set PP object
    // could also just say nlgFactory.createPrepositionPhrase("to", the Park);

    SPhraseSpec johnGoToThePark = nlgFactory.createClause("John",      // create sentence
        "go", toThePark);

    johnGoToThePark.setFeature(Feature.TENSE,Tense.PAST);              // set tense
    johnGoToThePark.setFeature(Feature.NEGATED, true);                 // set negated
   
    // note that constituents (such as subject and object) are set with setXXX methods
    // while features are set with setFeature

    DocumentElement sentence = nlgFactory              // create a sentence DocumentElement from SPhraseSpec
View Full Code Here

  /**
   * Tests for WH questions with be in past tense
   */
  @Test
  public void testBeQuestionsPast() {
    SPhraseSpec p = this.phraseFactory.createClause(this.phraseFactory
        .createNounPhrase("a", "ball"), this.phraseFactory.createWord(
        "be", LexicalCategory.VERB), this.phraseFactory
        .createNounPhrase("a", "toy"));
    p.setFeature(Feature.TENSE, Tense.PAST);

    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
    Assert.assertEquals("what was a ball", this.realiser.realise(p)
        .getRealisation());

    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
    Assert.assertEquals("was a ball a toy", this.realiser.realise(p)
        .getRealisation());

    p
        .setFeature(Feature.INTERROGATIVE_TYPE,
            InterrogativeType.WHAT_SUBJECT);
    Assert.assertEquals("what was a toy", this.realiser.realise(p)
        .getRealisation());

    SPhraseSpec p2 = this.phraseFactory.createClause("Mary", "be",
        "beautiful");
    p2.setFeature(Feature.TENSE, Tense.PAST);
    p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
    Assert.assertEquals("why was Mary beautiful", this.realiser.realise(p2)
        .getRealisation());

    p2
        .setFeature(Feature.INTERROGATIVE_TYPE,
            InterrogativeType.WHO_SUBJECT);
    Assert.assertEquals("who was beautiful", this.realiser.realise(p2)
        .getRealisation());
  }
View Full Code Here

  public void testSection5() {
    Lexicon lexicon = Lexicon.getDefaultLexicon();                         // default simplenlg lexicon
    NLGFactory nlgFactory = new NLGFactory(lexicon);             // factory based on lexicon
    Realiser realiser = new Realiser(lexicon);
   
    SPhraseSpec p = nlgFactory.createClause();
    p.setSubject("my dog");
    p.setVerb("chase");
    p.setObject("George");
   
    String output = realiser.realiseSentence(p);
    Assert.assertEquals("My dog chases George.", output);
   }
View Full Code Here

  public void testSection6() {
    Lexicon lexicon = Lexicon.getDefaultLexicon();                         // default simplenlg lexicon
    NLGFactory nlgFactory = new NLGFactory(lexicon);             // factory based on lexicon
    Realiser realiser = new Realiser(lexicon);
   
    SPhraseSpec p = nlgFactory.createClause();
    p.setSubject("Mary");
    p.setVerb("chase");
    p.setObject("George");
   
    p.setFeature(Feature.TENSE, Tense.PAST);
    String output = realiser.realiseSentence(p);
    Assert.assertEquals("Mary chased George.", output);

    p.setFeature(Feature.TENSE, Tense.FUTURE);
    output = realiser.realiseSentence(p);
    Assert.assertEquals("Mary will chase George.", output);

    p.setFeature(Feature.NEGATED, true);
    output = realiser.realiseSentence(p);
    Assert.assertEquals("Mary will not chase George.", output);

    p = nlgFactory.createClause();
    p.setSubject("Mary");
    p.setVerb("chase");
    p.setObject("George");
    p.setFeature(Feature.INTERROGATIVE_TYPE,
        InterrogativeType.YES_NO);
    output = realiser.realiseSentence(p);
    Assert.assertEquals("Does Mary chase George?", output);

    p.setSubject("Mary");
    p.setVerb("chase");
    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
    output = realiser.realiseSentence(p);
    Assert.assertEquals("Who does Mary chase?", output);

    p = nlgFactory.createClause();
    p.setSubject("the dog");
    p.setVerb("wake up");
    output = realiser.realiseSentence(p);
    Assert.assertEquals("The dog wakes up.", output);

   }
View Full Code Here

  public void testVariants() {
    Lexicon lexicon = Lexicon.getDefaultLexicon();                         // default simplenlg lexicon
    NLGFactory nlgFactory = new NLGFactory(lexicon);             // factory based on lexicon
    Realiser realiser = new Realiser(lexicon);
   
    SPhraseSpec p = nlgFactory.createClause();
    p.setSubject("my dog");
    p.setVerb("is")// variant of be
    p.setObject("George");
   
    String output = realiser.realiseSentence(p);
    Assert.assertEquals("My dog is George.", output);
   
    p = nlgFactory.createClause();
    p.setSubject("my dog");
    p.setVerb("chases")// variant of chase
    p.setObject("George");
   
    output = realiser.realiseSentence(p);
    Assert.assertEquals("My dog chases George.", output);
   

        p = nlgFactory.createClause();
    p.setSubject(nlgFactory.createNounPhrase("the", "dogs"));   // variant of "dog"
    p.setVerb("is")// variant of be
    p.setObject("happy")// variant of happy
    output = realiser.realiseSentence(p);
    Assert.assertEquals("The dog is happy.", output);
   
    p = nlgFactory.createClause();
    p.setSubject(nlgFactory.createNounPhrase("the", "children"));   // variant of "child"
    p.setVerb("is")// variant of be
    p.setObject("happy")// variant of happy
    output = realiser.realiseSentence(p);
    Assert.assertEquals("The child is happy.", output);

    // following functionality is enabled
    p = nlgFactory.createClause();
    p.setSubject(nlgFactory.createNounPhrase("the", "dogs"));   // variant of "dog"
    p.setVerb("is")// variant of be
    p.setObject("happy")// variant of happy
    output = realiser.realiseSentence(p);
    Assert.assertEquals("The dog is happy.", output); //corrected automatically   
  }
View Full Code Here

TOP

Related Classes of simplenlg.phrasespec.SPhraseSpec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.