Package simplenlg.framework

Examples of simplenlg.framework.DocumentElement


  /**
   * Tests for lists and embedded lists
   */
  public void testListItems() {
    DocumentElement list = this.phraseFactory.createList();
    list.addComponent(this.phraseFactory.createListItem(p1));
    list.addComponent(this.phraseFactory.createListItem(p2));
    list.addComponent(this.phraseFactory.createListItem(this.phraseFactory
        .createCoordinatedPhrase(p1, p2)));
    String realisation = this.realiser.realise(list).getRealisation();
    Assert.assertEquals(
        "* you are happy\n* I am sad\n* you are happy and I am sad\n",
        realisation);
View Full Code Here


    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
View Full Code Here

 
    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

  public String realiseSentence(NLGElement element) {
    NLGElement realised = null;
    if (element instanceof DocumentElement)
      realised = realise(element);
    else {
      DocumentElement sentence = new DocumentElement(DocumentCategory.SENTENCE, null);
      sentence.addComponent(element);
      realised = realise(sentence);
    }
   
    if (realised == null)
      return null;
View Full Code Here

   *            the wrapper DocumentElement object
   * @return the document element
   */
  public DocumentElement UnwrapDocumentElement(
      simplenlg.xmlrealiser.wrapper.XmlDocumentElement wt) {
    DocumentElement t = factory.createDocument();

    if (wt.getCat() != null) {
      t.setCategory(Enum.valueOf(DocumentCategory.class, wt.getCat()
          .toString()));
    }
    if (wt.getTitle() != null) {
      t.setTitle(wt.getTitle());
    }

    for (simplenlg.xmlrealiser.wrapper.XmlNLGElement wp : wt.getChild()) {
      NLGElement p = UnwrapNLGElement(wp);
      t.addComponent(p);
    }

    return t;
  }
View Full Code Here

      try {
        if (lexicon == null) {
          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);
View Full Code Here

    this.s1
        .setFeature(Feature.INTERROGATIVE_TYPE,
            InterrogativeType.YES_NO);

    NLGFactory docFactory = new NLGFactory(this.lexicon);
    DocumentElement sent = docFactory.createSentence(this.s1);
    Assert.assertEquals("Does the woman kiss the man?", this.realiser //$NON-NLS-1$
        .realise(sent).getRealisation());

    // simple past
    // sentence: "the woman kissed the man"
View Full Code Here

    qs2.setVerb("are");
    qs2.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
    qs2.setFeature(Feature.PASSIVE, false);
    qs2.setFeature(Feature.INTERROGATIVE_TYPE,InterrogativeType.HOW_MANY);
    qs2.setObject("in a 2.50 g sample of pure Gold");
    DocumentElement sentence = this.phraseFactory.createSentence(qs2);
    Assert.assertEquals("How many moles of Gold are in a 2.50 g sample of pure Gold?", this.realiser.realise(sentence).getRealisation());
  }
View Full Code Here

TOP

Related Classes of simplenlg.framework.DocumentElement

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.