Package simplenlg.phrasespec

Examples of simplenlg.phrasespec.SPhraseSpec


    public void testSection5A( ) {
      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( "the monkey" ) ;
     
      String output = realiser.realiseSentence( p ) ;
      Assert.assertEquals( "Mary chases the monkey.", output ) ;
     } // testSection5A
View Full Code Here


  public void testSection6A( ) {
    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( "the monkey" ) ;
 
    p.setFeature( Feature.TENSE, Tense.PAST ) ;
    String output = realiser.realiseSentence( p ) ;
    Assert.assertEquals( "Mary chased the monkey.", output ) ;

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

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

    p = nlgFactory.createClause( ) ;
    p.setSubject( "Mary" ) ;
    p.setVerb( "chase" ) ;
    p.setObject( "the monkey" ) ;

    p.setFeature( Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO ) ;
    output = realiser.realiseSentence( p ) ;
    Assert.assertEquals( "Does Mary chase the monkey?", 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 ) ;
  } // textSection6A
View Full Code Here

    public void testSection7( ) {
      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( "the monkey" ) ;
      p.addComplement( "very quickly" ) ;
      p.addComplement( "despite her exhaustion" ) ;
     
      String output = realiser.realiseSentence( p ) ;
      Assert.assertEquals( "Mary chases the monkey very quickly despite her exhaustion.", output ) ;
     } // testSection7
View Full Code Here

      NPPhraseSpec subject = nlgFactory.createNounPhrase( "Mary" ) ;
      NPPhraseSpec object = nlgFactory.createNounPhrase( "the monkey" ) ;
      VPPhraseSpec verb = nlgFactory.createVerbPhrase( "chase" ) ; ;
      subject.addModifier( "fast" ) ;
     
      SPhraseSpec p = nlgFactory.createClause( ) ;
      p.setSubject( subject ) ;
      p.setVerb( verb ) ;
      p.setObject( object ) ;
     
      String outputA = realiser.realiseSentence( p ) ;
      Assert.assertEquals( "Fast Mary chases the monkey.", outputA ) ;
     
      verb.addModifier( "quickly" ) ;
View Full Code Here

      // next line is not correct ~ should be nlgFactory.createCoordinatedPhrase ~ may be corrected in the API
      CoordinatedPhraseElement subj = nlgFactory.createCoordinatedPhrase( subject1, subject2 ) ;
     
      VPPhraseSpec verb = nlgFactory.createVerbPhrase( "chase" ) ; ;

      SPhraseSpec p = nlgFactory.createClause( ) ;
      p.setSubject( subj ) ;
      p.setVerb( verb ) ;
      p.setObject( "the monkey" ) ;
     
      String outputA = realiser.realiseSentence( p ) ;
      Assert.assertEquals( "Mary and your giraffe chase the monkey.", outputA ) ;
     
      NPPhraseSpec object1 = nlgFactory.createNounPhrase( "the monkey" ) ;
      NPPhraseSpec object2 = nlgFactory.createNounPhrase( "George" ) ;
     
      // next line is not correct ~ should be nlgFactory.createCoordinatedPhrase ~ may be corrected in the API
      CoordinatedPhraseElement obj = nlgFactory.createCoordinatedPhrase( object1, object2 ) ;
      obj.addCoordinate( "Martha" ) ;
      p.setObject( obj ) ;
     
      String outputB = realiser.realiseSentence( p ) ;
      Assert.assertEquals( "Mary and your giraffe chase the monkey, George and Martha.", outputB )

      obj.setFeature( Feature.CONJUNCTION, "or" ) ;
View Full Code Here

    Lexicon lexicon = Lexicon.getDefaultLexicon( ) ;     // default simplenlg lexicon
    NLGFactory nlgFactory = new NLGFactory( lexicon ) // factory based on lexicon

    Realiser realiser = new Realiser( lexicon ) ;
   
    SPhraseSpec pA = nlgFactory.createClause( "Mary", "chase", "the monkey" ) ;
    pA.addComplement( "in the park" ) ;
   
    String outputA = realiser.realiseSentence( pA ) ;   
    Assert.assertEquals( "Mary chases the monkey in the park.", outputA ) ;
   
    // alternative build paradigm
    NPPhraseSpec place = nlgFactory.createNounPhrase( "park" ) ;
    SPhraseSpec pB = nlgFactory.createClause( "Mary", "chase", "the monkey" ) ;
   
    // next line is depreciated ~ may be corrected in the API
    place.setDeterminer( "the" ) ;
    PPPhraseSpec pp = nlgFactory.createPrepositionPhrase( ) ;
    pp.addComplement( place ) ;
    pp.setPreposition( "in" ) ;
   
    pB.addComplement( pp ) ;
   
    String outputB = realiser.realiseSentence( pB ) ;   
    Assert.assertEquals( "Mary chases the monkey in park.", outputB ) // NB missing the determiner "the" !! 
   
    place.addPreModifier( "leafy" ) ;
View Full Code Here

    Lexicon lexicon = Lexicon.getDefaultLexicon( ) ;     // default simplenlg lexicon
    NLGFactory nlgFactory = new NLGFactory( lexicon ) // factory based on lexicon

    Realiser realiser = new Realiser( lexicon ) ;
 
    SPhraseSpec s1 = nlgFactory.createClause( "my cat",   "like", "fish"  ) ;
    SPhraseSpec s2 = nlgFactory.createClause( "my dog""like""big bones" ) ;
    SPhraseSpec s3 = nlgFactory.createClause( "my horse", "like", "grass" ) ;   
   
    CoordinatedPhraseElement c = nlgFactory.createCoordinatedPhrase( ) ;
    c.addCoordinate( s1 ) ;
    c.addCoordinate( s2 ) ; // gives the wrong result ~ should be 'bones' but get 'bone' !
    c.addCoordinate( s3 ) ;
   
    String outputA = realiser.realiseSentence( c ) ;
    Assert.assertEquals( "My cat likes fish, my dog likes big bones and my horse likes grass.", outputA ) ;
   
    SPhraseSpec p = nlgFactory.createClause( "I", "be""happy" ) ;
    SPhraseSpec q = nlgFactory.createClause( "I", "eat", "fish" ) ;
    q.setFeature( Feature.COMPLEMENTISER, "because" ) ;
    q.setFeature( Feature.TENSE, Tense.PAST ) ;
    p.addComplement( q ) ;
   
    String outputB = realiser.realiseSentence( p ) ;
    Assert.assertEquals( "I am happy because I ate fish.", outputB ) ;
  } // testSection13
View Full Code Here

    Lexicon lexicon = Lexicon.getDefaultLexicon( ) ;     // default simplenlg lexicon
    NLGFactory nlgFactory = new NLGFactory( lexicon ) // factory based on lexicon

    Realiser realiser = new Realiser( lexicon ) ;
 
    SPhraseSpec p1 = nlgFactory.createClause( "Mary", "chase", "the monkey" ) ;
    SPhraseSpec p2 = nlgFactory.createClause( "The monkey", "fight back" ) ;
    SPhraseSpec p3 = nlgFactory.createClause( "Mary", "be", "nervous" ) ;
   
    DocumentElement s1 = nlgFactory.createSentence( p1 ) ;
    DocumentElement s2 = nlgFactory.createSentence( p2 ) ;
    DocumentElement s3 = nlgFactory.createSentence( p3 ) ;
   
View Full Code Here

   * that John was walking"
   */
  @Test
  public void testClausalComp() {
    this.phraseFactory.setLexicon(this.lexicon);
    SPhraseSpec s = this.phraseFactory.createClause();

    s.setSubject(this.phraseFactory
        .createNounPhrase("John")); //$NON-NLS-1$

    // Create a sentence first
    CoordinatedPhraseElement maryAndSusan = new CoordinatedPhraseElement(
        this.phraseFactory.createNounPhrase("Mary"), //$NON-NLS-1$
        this.phraseFactory.createNounPhrase("Susan")); //$NON-NLS-1$

    this.kiss.clearComplements();
    s.setVerbPhrase(this.kiss);
    s.setObject(maryAndSusan);
    s.setFeature(Feature.PROGRESSIVE, true);
    s.setFeature(Feature.TENSE,Tense.PAST);
    s.addPostModifier(this.inTheRoom);
    Assert.assertEquals("John was kissing Mary and Susan in the room", //$NON-NLS-1$
        this.realiser.realise(s).getRealisation());

    // make the main VP past
    this.say.setFeature(Feature.TENSE,Tense.PAST);
    Assert.assertEquals("said", this.realiser.realise(this.say) //$NON-NLS-1$
        .getRealisation());

    // now add the sentence as complement of "say". Should make the sentence
    // subordinate
    // note that sentential punctuation is suppressed
    this.say.addComplement(s);
    Assert.assertEquals(
        "said that John was kissing Mary and Susan in the room", //$NON-NLS-1$
        this.realiser.realise(this.say).getRealisation());

    // add a postModifier to the main VP
    // yields [says [that John was kissing Mary and Susan in the room]
    // [behind the curtain]]
    this.say.addPostModifier(this.behindTheCurtain);
    Assert
        .assertEquals(
            "said that John was kissing Mary and Susan in the room behind the curtain", //$NON-NLS-1$
            this.realiser.realise(this.say).getRealisation());

    // create a new sentential complement
    PhraseElement s2 = this.phraseFactory.createClause(this.phraseFactory
        .createNounPhrase("all"), //$NON-NLS-1$
        "be", //$NON-NLS-1$
        this.phraseFactory.createAdjectivePhrase("fine")); //$NON-NLS-1$

    s2.setFeature(Feature.TENSE,Tense.FUTURE);
    Assert.assertEquals("all will be fine", this.realiser.realise(s2) //$NON-NLS-1$
        .getRealisation());

    // add the new complement to the VP
    // yields [said [that John was kissing Mary and Susan in the room and
    // all will be fine] [behind the curtain]]
    CoordinatedPhraseElement s3 = new CoordinatedPhraseElement(s, s2);
    this.say.clearComplements();
    this.say.addComplement(s3);

    // first with outer complementiser suppressed
    s3.setFeature(Feature.SUPRESSED_COMPLEMENTISER, true);
    Assert.assertEquals(
        "said that John was kissing Mary and Susan in the room " //$NON-NLS-1$
            + "and all will be fine behind the curtain", //$NON-NLS-1$
        this.realiser.realise(this.say).getRealisation());

    setUp();
    s = this.phraseFactory.createClause();

    s.setSubject(this.phraseFactory
        .createNounPhrase("John")); //$NON-NLS-1$

    // Create a sentence first
    maryAndSusan = new CoordinatedPhraseElement(
        this.phraseFactory.createNounPhrase("Mary"), //$NON-NLS-1$
        this.phraseFactory.createNounPhrase("Susan")); //$NON-NLS-1$

    s.setVerbPhrase(this.kiss);
    s.setObject(maryAndSusan);
    s.setFeature(Feature.PROGRESSIVE, true);
    s.setFeature(Feature.TENSE,Tense.PAST);
    s.addPostModifier(this.inTheRoom);
    s2 = this.phraseFactory.createClause(this.phraseFactory
        .createNounPhrase("all"), //$NON-NLS-1$
        "be", //$NON-NLS-1$
        this.phraseFactory.createAdjectivePhrase("fine")); //$NON-NLS-1$

View Full Code Here

    }

    // Sentence
    else if (wps instanceof simplenlg.xmlrealiser.wrapper.XmlSPhraseSpec) {
      simplenlg.xmlrealiser.wrapper.XmlSPhraseSpec wp = (simplenlg.xmlrealiser.wrapper.XmlSPhraseSpec) wps;
      SPhraseSpec sp = factory.createClause();
      NLGElement vp = null;

      ArrayList<NLGElement> subjects = new ArrayList<NLGElement>();
      for (simplenlg.xmlrealiser.wrapper.XmlNLGElement p : wp.getSubj()) {
        NLGElement p1 = UnwrapNLGElement(p);
        checkFunction(simplenlg.features.DiscourseFunction.SUBJECT, p1);
        subjects.add(p1);
      }

      if (subjects.size() > 0) {
        sp.setFeature(InternalFeature.SUBJECTS, subjects);
      }

      if (wp.getVp() != null) {
        vp = UnwrapNLGElement(wp.getVp());
        sp.setVerbPhrase(vp);
      }

      if (wp.getCuePhrase() != null) {
        NLGElement cue = UnwrapNLGElement(wp.getCuePhrase());
        cue.setFeature(InternalFeature.DISCOURSE_FUNCTION,
            DiscourseFunction.CUE_PHRASE);
        sp.setFeature(Feature.CUE_PHRASE, cue);
      }

      if (wp.getCOMPLEMENTISER() != null) {
        sp.setFeature(Feature.COMPLEMENTISER, wp.getCOMPLEMENTISER());
      }

      setSFeatures(wp, sp, vp);

      // Common phrase components.
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.