Package simplenlg.framework

Examples of simplenlg.framework.WordElement


  /**
   * Test spelling/orthographic variants with different inflections
   */
  public void testSpellingVariantWithInflection() {
    WordElement word = lexicon.getWord("formalization");
    List<String> spellVars = word
        .getFeatureAsStringList(LexicalFeature.SPELL_VARS);
    Assert.assertTrue(spellVars.contains("formalisation"));
    Assert.assertEquals(Inflection.REGULAR, word
        .getDefaultInflectionalVariant());

    // create with default spelling
    NPPhraseSpec np = factory.createNounPhrase("the", word);
    np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
    Assert.assertEquals("the formalizations", this.realiser.realise(np)
        .getRealisation());

    // reset spell var
    word.setDefaultSpellingVariant("formalisation");
    Assert.assertEquals("the formalisations", this.realiser.realise(np)
        .getRealisation());
  }
View Full Code Here


  /**
   * Test the inflectional variants for a verb.
   */
  public void testVerbInflectionalVariants() {
    WordElement word = lexicon.getWord("lie", LexicalCategory.VERB);
    Assert.assertEquals(Inflection.REGULAR, word
        .getDefaultInflectionalVariant());

    // default past is "lied"
    InflectedWordElement infl = new InflectedWordElement(word);
    infl.setFeature(Feature.TENSE, Tense.PAST);
    String past = realiser.realise(infl).getRealisation();
    Assert.assertEquals("lied", past);

    // switch to irregular
    word.setDefaultInflectionalVariant(Inflection.IRREGULAR);
    infl = new InflectedWordElement(word);
    infl.setFeature(Feature.TENSE, Tense.PAST);
    past = realiser.realise(infl).getRealisation();
    Assert.assertEquals("lay", past);

    // switch back to regular
    word.setDefaultInflectionalVariant(Inflection.REGULAR);
    Assert.assertEquals(null, word.getFeature(LexicalFeature.PAST));
    infl = new InflectedWordElement(word);
    infl.setFeature(Feature.TENSE, Tense.PAST);
    past = realiser.realise(infl).getRealisation();
    Assert.assertEquals("lied", past);
  }
View Full Code Here

  /**
   * Test inflectional variants for nouns
   */
  public void testNounInflectionalVariants() {
    WordElement word = lexicon.getWord("sanctum", LexicalCategory.NOUN);
    Assert.assertEquals(Inflection.REGULAR, word
        .getDefaultInflectionalVariant());

    // reg plural shouldn't be stored
    Assert.assertEquals(null, word.getFeature(LexicalFeature.PLURAL));
    InflectedWordElement infl = new InflectedWordElement(word);
    infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
    String plur = realiser.realise(infl).getRealisation();
    Assert.assertEquals("sanctums", plur);

    // switch to glreg
    word.setDefaultInflectionalVariant(Inflection.GRECO_LATIN_REGULAR);
    infl = new InflectedWordElement(word);
    infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
    plur = realiser.realise(infl).getRealisation();
    Assert.assertEquals("sancta", plur);

    // and back to reg
    word.setDefaultInflectionalVariant(Inflection.REGULAR);
    infl = new InflectedWordElement(word);
    infl.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
    plur = realiser.realise(infl).getRealisation();
    Assert.assertEquals("sanctums", plur);
  }
View Full Code Here

  /**
   * Check that spelling variants are preserved during realisation of NPs
   */
  @Test
  public void testSpellingVariantsInNP() {
    WordElement asd = lexicon.getWord("Adams-Stokes disease");
    Assert.assertEquals("Adams-Stokes disease", asd
        .getDefaultSpellingVariant());
    NPPhraseSpec np = this.factory.createNounPhrase(asd);
    np.setSpecifier(lexicon.getWord("the"));
    Assert.assertEquals("the Adams-Stokes disease", this.realiser.realise(
        np).getRealisation());

    // change spelling var
    asd.setDefaultSpellingVariant("Adams Stokes disease");
    Assert.assertEquals("Adams Stokes disease", asd
        .getDefaultSpellingVariant());
    Assert.assertEquals("the Adams Stokes disease", this.realiser.realise(
        np).getRealisation());

    np.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
View Full Code Here

        NodeList wordNodes = lexRoot.getChildNodes();
        for (int i = 0; i < wordNodes.getLength(); i++) {
          Node wordNode = wordNodes.item(i);
          // ignore things that aren't elements
          if (wordNode.getNodeType() == Node.ELEMENT_NODE) {
            WordElement word = convertNodeToWord(wordNode);
            if (word != null) {
              words.add(word);
              IndexWord(word);
            }
          }
View Full Code Here

   * add special cases to lexicon
   *
   */
  private void addSpecialCases() {
    // add variants of "be"
    WordElement be = getWord("be", LexicalCategory.VERB);
    if (be != null) {
      updateIndex(be, "is", indexByVariant);
      updateIndex(be, "am", indexByVariant);
      updateIndex(be, "are", indexByVariant);
      updateIndex(be, "was", indexByVariant);
View Full Code Here

  /**
   * Check that spelling variants are preserved during realisation of VPs
   */
  @Test
  public void testSpellingVariantsInVP() {
    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

    // System.out.println("Error in loading XML lexicon: Word with no base");
    // return null;
    // }

    // create word
    WordElement word = new WordElement();
    List<Inflection> inflections = new ArrayList<Inflection>();

    // now copy features
    NodeList nodes = wordNode.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
      Node featureNode = nodes.item(i);

      if (featureNode.getNodeType() == Node.ELEMENT_NODE) {
        String feature = featureNode.getNodeName().trim();
        String value = featureNode.getTextContent();

        if (value != null)
          value = value.trim();

        if (feature == null) {
          System.out.println("Error in XML lexicon node for "
              + word.toString());
          break;
        }

        if (feature.equalsIgnoreCase(XML_BASE)) {
          word.setBaseForm(value);
        } else if (feature.equalsIgnoreCase(XML_CATEGORY))
          word.setCategory(LexicalCategory.valueOf(value
              .toUpperCase()));
        else if (feature.equalsIgnoreCase(XML_ID))
          word.setId(value);

        else if (value == null || value.equals("")) {
          // if this is an infl code, add it to inflections
          Inflection infl = Inflection.getInflCode(feature);

          if (infl != null) {
            inflections.add(infl);
          } else {
            // otherwise assume it's a boolean feature
            word.setFeature(feature, true);
          }
        } else
          word.setFeature(feature, value);
      }

    }

    // if no infl specified, assume regular
    if (inflections.isEmpty()) {
      inflections.add(Inflection.REGULAR);
    }

    // default inflection code is "reg" if we have it, else random pick form
    // infl codes available
    Inflection defaultInfl = inflections.contains(Inflection.REGULAR) ? Inflection.REGULAR
        : inflections.get(0);   
   
    word.setFeature(LexicalFeature.DEFAULT_INFL, defaultInfl);
    word.setDefaultInflectionalVariant(defaultInfl);
   
    for(Inflection infl: inflections) {
      word.addInflectionalVariant(infl);
    }

    // done, return word
    return word;
  }
View Full Code Here

    SharedLexiconTests.doBasicTests(lexicon);
  }

  @Test
  public void testAcronyms() {
    WordElement uk = lexicon.getWord("UK");
    WordElement unitedKingdom = lexicon.getWord("United Kingdom");
    List<NLGElement> fullForms = uk
        .getFeatureAsElementList(LexicalFeature.ACRONYM_OF);

    // "uk" is an acronym of 3 full forms
    Assert.assertEquals(3, fullForms.size());
View Full Code Here

  public void testStandardInflections() {
    // test keepStandardInflection flag
    boolean keepInflectionsFlag = lexicon.isKeepStandardInflections();

    lexicon.setKeepStandardInflections(true);
    WordElement dog = lexicon.getWord("dog", LexicalCategory.NOUN);
    Assert.assertEquals("dogs", dog
        .getFeatureAsString(LexicalFeature.PLURAL));

    lexicon.setKeepStandardInflections(false);
    WordElement cat = lexicon.getWord("cat", LexicalCategory.NOUN);
    Assert
        .assertEquals(null, cat
            .getFeatureAsString(LexicalFeature.PLURAL));

    // restore flag to original state
    lexicon.setKeepStandardInflections(keepInflectionsFlag);
  }
View Full Code Here

TOP

Related Classes of simplenlg.framework.WordElement

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.