Package simplenlg.phrasespec

Examples of simplenlg.phrasespec.SPhraseSpec


    WordElement eth = (WordElement) factory.createWord("etherise",
        LexicalCategory.VERB);
    Assert.assertEquals("etherize", eth.getDefaultSpellingVariant());
    eth.setDefaultSpellingVariant("etherise");
    Assert.assertEquals("etherise", eth.getDefaultSpellingVariant());
    SPhraseSpec s = this.factory.createClause(this.factory
        .createNounPhrase("the", "doctor"), eth, this.factory.createNounPhrase("the patient"));
    Assert.assertEquals("the doctor etherises the patient", this.realiser.realise(s).getRealisation());
  }
View Full Code Here


   * @return a <code>SPhraseSpec</code> representing this phrase.
   */
  public SPhraseSpec createClause(Object subject, Object verb,
      Object directObject) {

    SPhraseSpec phraseElement = new SPhraseSpec(this);

    if (verb != null) {
      // AG: fix here: check if "verb" is a VPPhraseSpec or a Verb
      if (verb instanceof PhraseElement) {
        phraseElement.setVerbPhrase((PhraseElement) verb);
      } else {
        phraseElement.setVerb(verb);
      }
    }

    if (subject != null)
      phraseElement.setSubject(subject);

    if (directObject != null) {
      phraseElement.setObject(directObject);
    }

    return phraseElement;
  }
View Full Code Here

    s.setFeature(Feature.TENSE, Tense.PAST);
    return s;
  }

  private NLGElement disagreePhrase(String name){  // used by testRafael
    SPhraseSpec s = phraseFactory.createClause();
    s.setSubject(phraseFactory.createNounPhrase(name));
    s.setVerbPhrase(phraseFactory.createVerbPhrase("disagree with"));
    s.setObject("it");
    s.setFeature(Feature.TENSE, Tense.PAST);
    return s;
  }
View Full Code Here

  public void testWikipedia() {
    // test code fragments in wikipedia
    // realisation
    NPPhraseSpec subject = phraseFactory.createNounPhrase("the", "woman");
    subject.setPlural(true);
    SPhraseSpec sentence = phraseFactory.createClause(subject, "smoke");
    sentence.setFeature(Feature.NEGATED, true);
    Assert.assertEquals("The women do not smoke.", realiser.realiseSentence(sentence));

    // aggregation
    SPhraseSpec s1 = phraseFactory.createClause("the man", "be", "hungry");
    SPhraseSpec s2 = phraseFactory.createClause("the man", "buy", "an apple");
    NLGElement result = new ClauseCoordinationRule().apply(s1, s2);
    Assert.assertEquals("The man is hungry and buys an apple.", realiser.realiseSentence(result));

  }
View Full Code Here

  }
 
  @Test
  public void testLean() {
    // A Lean's test
    SPhraseSpec sentence = phraseFactory.createClause();
    sentence.setVerb("be");
    sentence.setObject("a ball");
    sentence.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
    Assert.assertEquals("What is a ball?", realiser.realiseSentence(sentence));
   
    sentence = phraseFactory.createClause();
    sentence.setVerb("be");
    NPPhraseSpec object = phraseFactory.createNounPhrase("example");
    object.setPlural(true);
    object.addModifier("of jobs");
    sentence.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_SUBJECT);
    sentence.setObject(object);
    Assert.assertEquals("What are examples of jobs?", realiser.realiseSentence(sentence));
   
    SPhraseSpec p = phraseFactory.createClause();
        NPPhraseSpec sub1 = phraseFactory.createNounPhrase("Mary");
          
        sub1.setFeature(LexicalFeature.GENDER, Gender.FEMININE);
        sub1.setFeature(Feature.PRONOMINAL, true);
        sub1.setFeature(Feature.PERSON, Person.FIRST);
        p.setSubject(sub1);
        p.setVerb("chase");
        p.setObject("the monkey");


        String output2 = realiser.realiseSentence(p); // Realiser created earlier.
        Assert.assertEquals("I chase the monkey.", output2);
View Full Code Here

  /**
   * Subject WH Questions with modals
   */
  @Test
  public void testModalWHSubjectQuestion() {
    SPhraseSpec p = this.phraseFactory.createClause(this.dog, "upset",
        this.man);
    p.setFeature(Feature.TENSE, Tense.PAST);
    Assert.assertEquals("the dog upset the man", this.realiser.realise(p)
        .getRealisation());

    // first without modal
    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
    Assert.assertEquals("who upset the man", this.realiser.realise(p)
        .getRealisation());

    p.setFeature(Feature.INTERROGATIVE_TYPE,
            InterrogativeType.WHAT_SUBJECT);
    Assert.assertEquals("what upset the man", this.realiser.realise(p)
        .getRealisation());

    // now with modal auxiliary
    p.setFeature(Feature.MODAL, "may");

    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
    Assert.assertEquals("who may have upset the man", this.realiser
        .realise(p).getRealisation());

    p.setFeature(Feature.TENSE, Tense.FUTURE);
    Assert.assertEquals("who may upset the man", this.realiser.realise(p)
        .getRealisation());

    p.setFeature(Feature.TENSE, Tense.PAST);
    p
        .setFeature(Feature.INTERROGATIVE_TYPE,
            InterrogativeType.WHAT_SUBJECT);
    Assert.assertEquals("what may have upset the man", this.realiser
        .realise(p).getRealisation());

    p.setFeature(Feature.TENSE, Tense.FUTURE);
    Assert.assertEquals("what may upset the man", this.realiser.realise(p)
        .getRealisation());
  }
View Full Code Here

  /**
   * Subject WH Questions with modals
   */
  @Test
  public void testModalWHObjectQuestion() {
    SPhraseSpec p = this.phraseFactory.createClause(this.dog, "upset",
        this.man);
    p.setFeature(Feature.TENSE, Tense.PAST);
    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);

    Assert.assertEquals("who did the dog upset", this.realiser.realise(p)
        .getRealisation());

    p.setFeature(Feature.MODAL, "may");
    Assert.assertEquals("who may the dog have upset", this.realiser
        .realise(p).getRealisation());

    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
    Assert.assertEquals("what may the dog have upset", this.realiser
        .realise(p).getRealisation());

    p.setFeature(Feature.TENSE, Tense.FUTURE);
    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
    Assert.assertEquals("who may the dog upset", this.realiser.realise(p)
        .getRealisation());

    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
    Assert.assertEquals("what may the dog upset", this.realiser.realise(p)
        .getRealisation());
  }
View Full Code Here

  /**
   * Questions with tenses requiring auxiliaries + subject WH
   */
  @Test
  public void testAuxWHSubjectQuestion() {
    SPhraseSpec p = this.phraseFactory.createClause(this.dog, "upset",
        this.man);
    p.setFeature(Feature.TENSE, Tense.PRESENT);
    p.setFeature(Feature.PERFECT, true);
    Assert.assertEquals("the dog has upset the man", this.realiser.realise(
        p).getRealisation());

    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_SUBJECT);
    Assert.assertEquals("who has upset the man", this.realiser.realise(p)
        .getRealisation());

    p
        .setFeature(Feature.INTERROGATIVE_TYPE,
            InterrogativeType.WHAT_SUBJECT);
    Assert.assertEquals("what has upset the man", this.realiser.realise(p)
        .getRealisation());
  }
View Full Code Here

  /**
   * Questions with tenses requiring auxiliaries + subject WH
   */
  @Test
  public void testAuxWHObjectQuestion() {
    SPhraseSpec p = this.phraseFactory.createClause(this.dog, "upset",
        this.man);

    // first without any aux
    p.setFeature(Feature.TENSE, Tense.PAST);
    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
    Assert.assertEquals("what did the dog upset", this.realiser.realise(p)
        .getRealisation());

    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
    Assert.assertEquals("who did the dog upset", this.realiser.realise(p)
        .getRealisation());

    p.setFeature(Feature.TENSE, Tense.PRESENT);
    p.setFeature(Feature.PERFECT, true);

    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
    Assert.assertEquals("who has the dog upset", this.realiser.realise(p)
        .getRealisation());

    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
    Assert.assertEquals("what has the dog upset", this.realiser.realise(p)
        .getRealisation());

    p.setFeature(Feature.TENSE, Tense.FUTURE);
    p.setFeature(Feature.PERFECT, true);

    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHO_OBJECT);
    Assert.assertEquals("who will the dog have upset", this.realiser
        .realise(p).getRealisation());

    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
    Assert.assertEquals("what will the dog have upset", this.realiser
        .realise(p).getRealisation());

  }
View Full Code Here

  /**
   * Test for questions with "be"
   */
  @Test
  public void testBeQuestions() {
    SPhraseSpec p = this.phraseFactory.createClause(this.phraseFactory
        .createNounPhrase("a", "ball"), this.phraseFactory.createWord(
        "be", LexicalCategory.VERB), this.phraseFactory
        .createNounPhrase("a", "toy"));

    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHAT_OBJECT);
    Assert.assertEquals("what is a ball", this.realiser.realise(p)
        .getRealisation());

    p.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.YES_NO);
    Assert.assertEquals("is a ball a toy", this.realiser.realise(p)
        .getRealisation());

    p
        .setFeature(Feature.INTERROGATIVE_TYPE,
            InterrogativeType.WHAT_SUBJECT);
    Assert.assertEquals("what is a toy", this.realiser.realise(p)
        .getRealisation());

    SPhraseSpec p2 = this.phraseFactory.createClause("Mary", "be",
        "beautiful");
    p2.setFeature(Feature.INTERROGATIVE_TYPE, InterrogativeType.WHY);
    Assert.assertEquals("why is Mary beautiful", this.realiser.realise(p2)
        .getRealisation());

    p2
        .setFeature(Feature.INTERROGATIVE_TYPE,
            InterrogativeType.WHO_SUBJECT);
    Assert.assertEquals("who is beautiful", this.realiser.realise(p2)
        .getRealisation());
  }
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.