Examples of NLGFactory


Examples of simplenlg.framework.NLGFactory

    // below is a simple complete example of using simplenlg V4
    // afterwards is an example of using simplenlg just for morphology
   
    // set up
    Lexicon lexicon = new XMLLexicon();                          // default simplenlg lexicon
    NLGFactory nlgFactory = new NLGFactory(lexicon);             // factory based on lexicon

    // create sentences
    //   "John did not go to the bigger park. He played football there."
    NPPhraseSpec thePark = nlgFactory.createNounPhrase("the", "park");   // create an NP
    AdjPhraseSpec bigp = nlgFactory.createAdjectivePhrase("big");        // create AdjP
    bigp.setFeature(Feature.IS_COMPARATIVE, true);                       // use comparative form ("bigger")
    thePark.addModifier(bigp);                                        // add adj as modifier in NP
    // above relies on default placement rules.  You can force placement as a premodifier
    // (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
        .createSentence(johnGoToThePark);

    // below creates a sentence DocumentElement by concatenating strings
    StringElement hePlayed = new StringElement("he played");       
    StringElement there = new StringElement("there");
    WordElement football = new WordElement("football");

    DocumentElement sentence2 = nlgFactory.createSentence();
    sentence2.addComponent(hePlayed);
    sentence2.addComponent(football);
    sentence2.addComponent(there);

    // now create a paragraph which contains these sentences
    DocumentElement paragraph = nlgFactory.createParagraph();
    paragraph.addComponent(sentence);
    paragraph.addComponent(sentence2);

    // create a realiser.  Note that a lexicon is specified, this should be
    // the same one used by the NLGFactory
    Realiser realiser = new Realiser(lexicon);
    //realiser.setDebugMode(true);     // uncomment this to print out debug info during realisation
    NLGElement realised = realiser.realise(paragraph);

    System.out.println(realised.getRealisation());

    // end of main example
   
    // second example - using simplenlg just for morphology
    // below is clumsy as direct access to morphology isn't properly supported in V4.2
    // hopefully will be better supported in later versions
 
    // get word element for "child"
    WordElement word = (WordElement) nlgFactory.createWord("child", LexicalCategory.NOUN);
    // create InflectedWordElement from word element
    InflectedWordElement inflectedWord = new InflectedWordElement(word);
    // set the inflected word to plural
    inflectedWord.setPlural(true);
    // realise the inflected word
View Full Code Here

Examples of simplenlg.framework.NLGFactory

  @Before
  protected void setUp() {
    //this.lexicon = new NIHDBLexicon("A:\\corpora\\LEX\\lexAccess2011\\data\\HSqlDb\\lexAccess2011.data"); // NIH lexicon
    //lexicon = new XMLLexicon("E:\\NIHDB\\default-lexicon.xml");    // default XML lexicon
    lexicon = new XMLLexicon()// built in lexicon
    this.phraseFactory = new NLGFactory(this.lexicon);
    this.realiser = new Realiser(this.lexicon);
   
    this.man = this.phraseFactory.createNounPhrase("the", "man"); //$NON-NLS-1$ //$NON-NLS-2$
    this.woman = this.phraseFactory.createNounPhrase("the", "woman")//$NON-NLS-1$//$NON-NLS-2$
    this.dog = this.phraseFactory.createNounPhrase("the", "dog"); //$NON-NLS-1$ //$NON-NLS-2$
View Full Code Here

Examples of simplenlg.framework.NLGFactory

   * test section 3 code
   */
  @Test
  public void testSection3() {
    Lexicon lexicon = Lexicon.getDefaultLexicon();                         // default simplenlg lexicon
    NLGFactory nlgFactory = new NLGFactory(lexicon);             // factory based on lexicon

    NLGElement s1 = nlgFactory.createSentence("my dog is happy");
   
    Realiser r = new Realiser(lexicon);
   
    String output = r.realiseSentence(s1);
   
View Full Code Here

Examples of simplenlg.framework.NLGFactory

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

Examples of simplenlg.framework.NLGFactory

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

Examples of simplenlg.framework.NLGFactory

   * test ability to use variant words
   */
  @Test
  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

Examples of simplenlg.framework.NLGFactory

   * test section 5 to match simplenlg tutorial version 4's code
   */
  @Test
    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 ) ;
View Full Code Here

Examples of simplenlg.framework.NLGFactory

   * test section 6 to match simplenlg tutorial version 4' code
   */
  @Test
  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 ) ;
View Full Code Here

Examples of simplenlg.framework.NLGFactory

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

Examples of simplenlg.framework.NLGFactory

   * test section 8 code
   */
  @Test
    public void testSection8( ) {
      Lexicon lexicon = Lexicon.getDefaultLexicon( ) ;      // default simplenlg lexicon
      NLGFactory nlgFactory = new NLGFactory( lexicon ) // factory based on lexicon
      Realiser realiser = new Realiser( lexicon ) ;
     
      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 ) ;
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.