Package simplenlg.realiser.english

Examples of simplenlg.realiser.english.Realiser


   */
  @Test
    public void testSection10( ) {
      Lexicon lexicon = Lexicon.getDefaultLexicon( ) ;      // default simplenlg lexicon
      NLGFactory nlgFactory = new NLGFactory( lexicon ) // factory based on lexicon
      Realiser realiser = new Realiser( lexicon ) ;
     
      NPPhraseSpec subject1 = nlgFactory.createNounPhrase( "Mary" ) ;
      NPPhraseSpec subject2 = nlgFactory.createNounPhrase( "your", "giraffe" ) ;
     
      // 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" ) ;
     
      String outputC = realiser.realiseSentence( p ) ;
      Assert.assertEquals( "Mary and your giraffe chase the monkey, George or Martha.", outputC )
  } // testSection10
View Full Code Here


  @Test
  public void testSection11( ) {
    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" ) ;
   
    String outputC = realiser.realiseSentence( pB ) ;   
    Assert.assertEquals( "Mary chases the monkey in leafy park.", outputC ) // NB missing the determiner "the" !! 
   } // testSection11
View Full Code Here

  @Test
  public void testSection13( ) {
    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

  @Test
  public void testSection14( ) {
    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 ) ;
   
    DocumentElement par1 = nlgFactory.createParagraph( Arrays.asList( s1, s2, s3 ) ) ;
   
    String output14a = realiser.realise( par1 ).getRealisation() ;
    Assert.assertEquals( "Mary chases the monkey. The monkey fights back. Mary is nervous.\n\n", output14a ) ;
    //   actual output ~  Mary chases the monkey. The monkey fights back. Mary is nervous.
    // So what exactly is JUnit not happy about?
    DocumentElement section = nlgFactory.createSection( "The Trials and Tribulation of Mary and the Monkey" ) ;
        section.addComponent( par1 ) ;
        String output14b = realiser.realise( section ).getRealisation() ;
        Assert.assertEquals( "The Trials and Tribulation of Mary and the Monkey\nMary chases the monkey. The monkey fights back. Mary is nervous.\n\n", output14b ) ;
  } // testSection14
View Full Code Here

   * * Sets up the accessor and runs it -- takes ca. 26 sec
   */
  public void setUp() {
    this.lexicon = new NIHDBLexicon(DB_FILENAME);
    this.factory = new NLGFactory(lexicon);
    this.realiser = new Realiser(this.lexicon);
  }
View Full Code Here

          lexicon = Lexicon.getDefaultLexicon();
        }
        UnWrapper w = new UnWrapper(lexicon);
        DocumentElement t = w.UnwrapDocumentElement(wt);
        if (t != null) {
          Realiser r = new Realiser(lexicon);
          r.initialise();

          NLGElement tr = r.realise(t);

          output = tr.getRealisation();
        }

      } catch (Exception e) {
View Full Code Here

TOP

Related Classes of simplenlg.realiser.english.Realiser

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.