Examples of NLGFactory


Examples of simplenlg.framework.NLGFactory

   * test section 10 code
   */
  @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 )
View Full Code Here

Examples of simplenlg.framework.NLGFactory

   */
  @SuppressWarnings({ "deprecation" })
  @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 ) ;
   
View Full Code Here

Examples of simplenlg.framework.NLGFactory

   * test section 13 code
   */
  @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 ) ;
View Full Code Here

Examples of simplenlg.framework.NLGFactory

   * test section 14 code
   */
  @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

Examples of simplenlg.framework.NLGFactory

  private static NLGElement createNot(PhraseElement phrase,
      Stack<NLGElement> vgComponents, NLGElement frontVG, boolean hasModal) {
    NLGElement newFront = frontVG;

    if (phrase.getFeatureAsBoolean(Feature.NEGATED).booleanValue()) {
      NLGFactory factory = phrase.getFactory();

      if (!vgComponents.empty() || frontVG != null && isCopular(frontVG)) {
        vgComponents.push(new InflectedWordElement(
            "not", LexicalCategory.ADVERB)); //$NON-NLS-1$
      } else {
        if (frontVG != null && !hasModal) {
          frontVG.setFeature(Feature.NEGATED, true);
          vgComponents.push(frontVG);
        }

        vgComponents.push(new InflectedWordElement(
            "not", LexicalCategory.ADVERB)); //$NON-NLS-1$

        if (factory != null) {
          newFront = factory.createInflectedWord("do",
              LexicalCategory.VERB);

        } else {
          newFront = new InflectedWordElement(
              "do", LexicalCategory.VERB); //$NON-NLS-1$
View Full Code Here

Examples of simplenlg.framework.NLGFactory

   * {@inheritDoc}
   */
  @Override
  public void initialise() {
    this._rules = new ArrayList<AggregationRule>();
    this._factory = new NLGFactory();
  }
View Full Code Here

Examples of simplenlg.framework.NLGFactory

   *
   * @param lexicon
   *            the lexicon to use
   */
  public UnWrapper(Lexicon lexicon) {
    factory = new NLGFactory(lexicon);
  }
View Full Code Here

Examples of simplenlg.framework.NLGFactory

  /**
   * Creates a new instance of AggregationRule
   */
  public AggregationRule() {
    this.factory = new NLGFactory();
  }
View Full Code Here

Examples of simplenlg.framework.NLGFactory

  /*
   * * 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

Examples of simplenlg.framework.NLGFactory

   *            the <code>PhraseElement</code> representation of the clause.
   * @return the <code>NLGElement</code> representing the realised clause.
   */
  static NLGElement realise(SyntaxProcessor parent, PhraseElement phrase) {
    ListElement realisedElement = null;
    NLGFactory phraseFactory = phrase.getFactory();
    NLGElement splitVerb = null;
    boolean interrogObj = false;

    if (phrase != null) {
      realisedElement = new ListElement();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.