Package simplenlg.framework

Examples of simplenlg.framework.WordElement$InflectionSet


        .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


      addPostModifier((String)modifier);
      return;
    }
   
    // extract WordElement if modifier is a single word
    WordElement modifierWord = null;
    if (modifierElement != null && modifierElement instanceof WordElement)
      modifierWord = (WordElement) modifierElement;
    else if (modifierElement != null && modifierElement instanceof InflectedWordElement)
      modifierWord = ((InflectedWordElement) modifierElement).getBaseWord();
   
    if (modifierWord != null && modifierWord.getCategory() == LexicalCategory.ADVERB) {
      addPreModifier(modifierWord);
      return;
    }
   
    // default case
View Full Code Here

        String baseForm = ((InflectedWordElement) element)
            .getBaseForm();
        ElementCategory category = element.getCategory();

        if (this.lexicon != null && baseForm != null) {
          WordElement word = ((InflectedWordElement) element)
              .getBaseWord();

          if (word == null) {
            if (category instanceof LexicalCategory) {
              word = this.lexicon.lookupWord(baseForm,
View Full Code Here

   * @param category
   *            - category of word
   * @return WordElement entry for specified info
   */
  protected WordElement createWord(String baseForm, LexicalCategory category) {
    return new WordElement(baseForm, category); // return default
    // WordElement of this
    // baseForm, category
  }
View Full Code Here

   * @param baseForm
   *            - base form of word
   * @return WordElement entry for specified info
   */
  protected WordElement createWord(String baseForm) {
    return new WordElement(baseForm); // return default WordElement of this
    // baseForm
  }
View Full Code Here

    String baseForm = record.GetBase();   
    LexicalCategory category = getSimplenlgCategory(record);
    String id = record.GetEui();

    // create word class
    WordElement wordElement = new WordElement(baseForm, category, id);

    // now add type information
    switch (category) {
    case ADJECTIVE:
      addAdjectiveInfo(wordElement, record.GetCatEntry().GetAdjEntry());
      break;
    case ADVERB:
      addAdverbInfo(wordElement, record.GetCatEntry().GetAdvEntry());
      break;
    case NOUN:
      addNounInfo(wordElement, record.GetCatEntry().GetNounEntry());
      break;
    case VERB:
      addVerbInfo(wordElement, record.GetCatEntry().GetVerbEntry());
      break;
    // ignore closed class words
    }

    Inflection defaultInfl = (Inflection) wordElement
        .getDefaultInflectionalVariant();

    // now add inflected forms
    // if (keepStandardInflections || !standardInflections(record,
    // category)) {
    for (InflVar inflection : record.GetInflVarsAndAgreements()
        .GetInflValues()) {
      String simplenlgInflection = getSimplenlgInflection(inflection
          .GetInflection());

      if (simplenlgInflection != null) {
        String inflectedForm = inflection.GetVar();
        Inflection inflType = Inflection.getInflCode(inflection
            .GetType());

        // store all inflectional variants, except for regular ones
        // unless explicitly set
        if (inflType != null
            && !(Inflection.REGULAR.equals(inflType) && !this.keepStandardInflections)) {
          wordElement.addInflectionalVariant(inflType,
              simplenlgInflection, inflectedForm);
        }

        // if the infl variant is the default, also set this feature on
        // the word
        if (defaultInfl == null
            || (defaultInfl.equals(inflType) && !(Inflection.REGULAR
                .equals(inflType) && !this.keepStandardInflections))) {
          wordElement.setFeature(simplenlgInflection, inflectedForm);
        }

        // wordElement
        // .setFeature(simplenlgInflection, inflection.GetVar());
      }
View Full Code Here

        if (fullForm.contains("|")) {
          // get the acronym id
          String acronymID = fullForm.substring(
              fullForm.indexOf("|") + 1, fullForm.length());
          // create the full form element
          WordElement fullFormWE = this.getWordByID(acronymID);

          if (fullForm != null) {
            // add as full form of this acronym
            acronymOf.add(fullFormWE);
View Full Code Here

          // p.setSpecifier(UnwrapWordElement(wp.getSpec()));
          simplenlg.xmlrealiser.wrapper.XmlNLGElement spec = wp
              .getSpec();

          if (spec instanceof simplenlg.xmlrealiser.wrapper.XmlWordElement) {
            WordElement specifier = (WordElement) UnwrapWordElement((simplenlg.xmlrealiser.wrapper.XmlWordElement) spec);

            if (specifier != null) {
              p.setSpecifier(specifier);
            }
View Full Code Here

          && ((InflectedWordElement) word).getBaseWord()
              .getBaseForm().isEmpty()) {
        word = null; // cch TESTING

      } else if (word instanceof WordElement) {
        WordElement we = (WordElement) word;

        // Inflection
        if (wordElement.getVar() != null) {
          Inflection defaultInflection = Enum.valueOf(
              Inflection.class, wordElement.getVar().toString());
          we.setDefaultInflectionalVariant(defaultInflection);
        }

        // Spelling variant may have been given as base form in xml.
        // If so, use that variant.
        if (!baseForm.matches(we.getBaseForm())) {
          we.setDefaultSpellingVariant(baseForm);
        }
      }
    }

    return word;
View Full Code Here

  /**
   * check that spelling variants are properly set
   */
  @Test
  public void testSpellingVariants() {
    WordElement asd = lexicon.getWord("Adams-Stokes disease");
    List<String> spellVars = asd
        .getFeatureAsStringList(LexicalFeature.SPELL_VARS);
    Assert.assertTrue(spellVars.contains("Adams Stokes disease"));
    Assert.assertTrue(spellVars.contains("Adam-Stokes disease"));
    Assert.assertEquals(2, spellVars.size());
    Assert.assertEquals(asd.getBaseForm(), asd
        .getFeatureAsString(LexicalFeature.DEFAULT_SPELL));

    // default spell variant is baseform
    Assert.assertEquals("Adams-Stokes disease", asd
        .getDefaultSpellingVariant());

    // default spell variant changes
    asd.setDefaultSpellingVariant("Adams Stokes disease");
    Assert.assertEquals("Adams Stokes disease", asd
        .getDefaultSpellingVariant());
  }
View Full Code Here

TOP

Related Classes of simplenlg.framework.WordElement$InflectionSet

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.