/** * This method performs the morphology for adjectives. * * @param element * the <code>InflectedWordElement</code>. * @param baseWord * the <code>WordElement</code> as created from the lexicon * entry. * @return a <code>StringElement</code> representing the word after * inflection. */ public static NLGElement doAdjectiveMorphology(InflectedWordElement element, WordElement baseWord) { string realised = null; object patternValue = element.getFeature(LexicalFeature.DEFAULT_INFL); // base form from baseWord if it exists, otherwise from element string baseForm = getBaseForm(element, baseWord); if (element.getFeatureAsBoolean(Feature.IS_COMPARATIVE)) { realised = element.getFeatureAsString(LexicalFeature.COMPARATIVE); if (ReferenceEquals(realised, null) && baseWord != null) { realised = baseWord.getFeatureAsString(LexicalFeature.COMPARATIVE); } if (ReferenceEquals(realised, null)) { if (Inflection.REGULAR_DOUBLE.Equals(patternValue)) { realised = buildDoubleCompAdjective(baseForm); } else { realised = buildRegularComparative(baseForm); } } } else if (element.getFeatureAsBoolean(Feature.IS_SUPERLATIVE)) { realised = element.getFeatureAsString(LexicalFeature.SUPERLATIVE); if (ReferenceEquals(realised, null) && baseWord != null) { realised = baseWord.getFeatureAsString(LexicalFeature.SUPERLATIVE); } if (ReferenceEquals(realised, null)) { if (Inflection.REGULAR_DOUBLE.Equals(patternValue)) { realised = buildDoubleSuperAdjective(baseForm); } else { realised = buildRegularSuperlative(baseForm); } } } else { realised = baseForm; } StringElement realisedElement = new StringElement(realised); realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, element.getFeature(InternalFeature.DISCOURSE_FUNCTION)); return(realisedElement); }
/** * quick-and-dirty routine for computing morph forms Should be replaced by * something better! * * @param word * @param feature * @param string * @return */ private string getVariant(WordElement word, string feature, string suffix) { if (word.hasFeature(feature)) { return(word.getFeatureAsString(feature)); } else { return(getForm(word.BaseForm, suffix)); } }
public virtual void standardInflectionsTest() { bool keepInflectionsFlag = lexicon.KeepStandardInflections; lexicon.KeepStandardInflections = true; WordElement dog = lexicon.getWord("dog", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)); Assert.AreEqual("dogs", dog.getFeatureAsString(LexicalFeature.PLURAL)); lexicon.KeepStandardInflections = false; WordElement cat = lexicon.getWord("cat", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)); Assert.AreEqual(null, cat.getFeatureAsString(LexicalFeature.PLURAL)); lexicon.KeepStandardInflections = keepInflectionsFlag; }
public virtual void spellingVariantsTest() { WordElement asd = lexicon.getWord("Adams-Stokes disease"); IList <string> spellVars = asd.getFeatureAsStringList(LexicalFeature.SPELL_VARS); Assert.IsTrue(spellVars.Contains("Adams Stokes disease")); Assert.IsTrue(spellVars.Contains("Adam-Stokes disease")); Assert.AreEqual(2, spellVars.Count); Assert.AreEqual(asd.BaseForm, asd.getFeatureAsString(LexicalFeature.DEFAULT_SPELL)); // default spell variant is baseform Assert.AreEqual("Adams-Stokes disease", asd.DefaultSpellingVariant); // default spell variant changes asd.DefaultSpellingVariant = "Adams Stokes disease"; Assert.AreEqual("Adams Stokes disease", asd.DefaultSpellingVariant); }
public virtual void multipleSpecificsTests() { // try to get word which is only in NIH lexicon WordElement UK = lexicon.getWord("UK"); Assert.AreEqual(true, UK.getFeatureAsString(LexicalFeature.ACRONYM_OF).Contains("United Kingdom")); // test alwaysSearchAll flag bool alwaysSearchAll = lexicon.AlwaysSearchAll; // tree as noun exists in both, but as verb only in NIH lexicon.AlwaysSearchAll = true; Assert.AreEqual(3, lexicon.getWords("tree").Count); // 3 = once in XML plus twice in NIH lexicon.AlwaysSearchAll = false; Assert.AreEqual(1, lexicon.getWords("tree").Count); // restore flag to original state lexicon.AlwaysSearchAll = alwaysSearchAll; }
public virtual void doBasicTests(Lexicon lexicon) { // test getWords. Should be 2 "can" (of any cat), 1 noun tree, 0 adj // trees Assert.AreEqual(3, lexicon.getWords("can").Count); Assert.AreEqual(1, lexicon.getWords("can", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)).Count); Assert.AreEqual(0, lexicon.getWords("can", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADJECTIVE)).Count); // below test removed as standard morph variants no longer recorded in // lexicon // WordElement early = lexicon.getWord("early", // LexicalCategory.ADJECTIVE); // Assert.assertEquals("earlier", // early.getFeatureAsString(Feature.COMPARATIVE)); // test getWord. Comparative of ADJ "good" is "better", superlative is // "best", this is a qualitative and predicative adjective WordElement good = lexicon.getWord("good", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADJECTIVE)); Assert.AreEqual("better", good.getFeatureAsString(LexicalFeature.COMPARATIVE)); Assert.AreEqual("best", good.getFeatureAsString(LexicalFeature.SUPERLATIVE)); Assert.AreEqual(true, good.getFeatureAsBoolean(LexicalFeature.QUALITATIVE)); Assert.AreEqual(true, good.getFeatureAsBoolean(LexicalFeature.PREDICATIVE)); Assert.AreEqual(false, good.getFeatureAsBoolean(LexicalFeature.COLOUR)); Assert.AreEqual(false, good.getFeatureAsBoolean(LexicalFeature.CLASSIFYING)); // test getWord. There is only one "woman", and its plural is "women". // It is not an acronym, not proper, and countable WordElement woman = lexicon.getWord("woman"); Assert.AreEqual("women", woman.getFeatureAsString(LexicalFeature.PLURAL)); Assert.AreEqual(null, woman.getFeatureAsString(LexicalFeature.ACRONYM_OF)); Assert.AreEqual(false, woman.getFeatureAsBoolean(LexicalFeature.PROPER)); Assert.IsFalse(woman.hasInflectionalVariant(Inflection.UNCOUNT)); // NB: This fails if the lexicon is XMLLexicon. No idea why. // Assert.assertEquals("irreg", // woman.getFeatureAsString(LexicalFeature.DEFAULT_INFL)); // test getWord. Noun "sand" is non-count WordElement sand = lexicon.getWord("sand", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.NOUN)); Assert.AreEqual(true, sand.hasInflectionalVariant(Inflection.UNCOUNT)); Assert.AreEqual(Inflection.UNCOUNT, sand.getDefaultInflectionalVariant()); // test hasWord Assert.AreEqual(true, lexicon.hasWord("tree")); // "tree" exists Assert.AreEqual(false, lexicon.hasWord("tree", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADVERB))); // but not as an adverb // test getWordByID; quickly, also check that this is a verb_modifier WordElement quickly = lexicon.getWordByID("E0051632"); Assert.AreEqual("quickly", quickly.BaseForm); Assert.AreEqual(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.ADVERB), quickly.Category); Assert.AreEqual(true, quickly.getFeatureAsBoolean(LexicalFeature.VERB_MODIFIER)); Assert.AreEqual(false, quickly.getFeatureAsBoolean(LexicalFeature.SENTENCE_MODIFIER)); Assert.AreEqual(false, quickly.getFeatureAsBoolean(LexicalFeature.INTENSIFIER)); // test getWordFromVariant, verb type (tran or intran, not ditran) WordElement eat = lexicon.getWordFromVariant("eating"); Assert.AreEqual("eat", eat.BaseForm); Assert.AreEqual(new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB), eat.Category); Assert.AreEqual(true, eat.getFeatureAsBoolean(LexicalFeature.INTRANSITIVE)); Assert.AreEqual(true, eat.getFeatureAsBoolean(LexicalFeature.TRANSITIVE)); Assert.AreEqual(false, eat.getFeatureAsBoolean(LexicalFeature.DITRANSITIVE)); Assert.AreEqual("been", lexicon.getWordFromVariant("is", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)) .getFeatureAsString(LexicalFeature.PAST_PARTICIPLE)); // test BE is handled OK // test modal WordElement can = lexicon.getWord("can", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.MODAL)); Assert.AreEqual("could", can.getFeatureAsString(LexicalFeature.PAST)); // test non-existent word Assert.AreEqual(0, lexicon.getWords("akjmchsgk").Count); // test lookup word method Assert.AreEqual( lexicon.lookupWord("say", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)).BaseForm, "say"); Assert.AreEqual( lexicon.lookupWord("said", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)).BaseForm, "say"); Assert.AreEqual( lexicon.lookupWord("E0054448", new LexicalCategory(LexicalCategory.LexicalCategoryEnum.VERB)).BaseForm, "say"); }
/** * This method performs the morphology for nouns. * * @param element * the <code>InflectedWordElement</code>. * @param baseWord * the <code>WordElement</code> as created from the lexicon * entry. * @return a <code>StringElement</code> representing the word after * inflection. */ protected internal static StringElement doNounMorphology(InflectedWordElement element, WordElement baseWord) { StringBuilder realised = new StringBuilder(); // base form from baseWord if it exists, otherwise from element string baseForm = getBaseForm(element, baseWord); if (element.Plural && !element.getFeatureAsBoolean(LexicalFeature.PROPER)) { string pluralForm = null; // AG changed: now check if default infl is uncount // if (element.getFeatureAsBoolean(LexicalFeature.NON_COUNT) // .booleanValue()) { // pluralForm = baseForm; object elementDefaultInfl = element.getFeature(LexicalFeature.DEFAULT_INFL); if (elementDefaultInfl != null && Inflection.UNCOUNT.Equals(elementDefaultInfl)) { pluralForm = baseForm; } else { pluralForm = element.getFeatureAsString(LexicalFeature.PLURAL); } if (ReferenceEquals(pluralForm, null) && baseWord != null) { // AG changed: now check if default infl is uncount // if (baseWord.getFeatureAsBoolean(LexicalFeature.NON_COUNT) // .booleanValue()) { // pluralForm = baseForm; string baseDefaultInfl = baseWord.getFeatureAsString(LexicalFeature.DEFAULT_INFL); if (!ReferenceEquals(baseDefaultInfl, null) && baseDefaultInfl.Equals("uncount")) { pluralForm = baseForm; } else { pluralForm = baseWord.getFeatureAsString(LexicalFeature.PLURAL); } } if (ReferenceEquals(pluralForm, null)) { object pattern = element.getFeature(LexicalFeature.DEFAULT_INFL); if (Inflection.GRECO_LATIN_REGULAR.Equals(pattern)) { pluralForm = buildGrecoLatinPluralNoun(baseForm); } else { pluralForm = buildRegularPluralNoun(baseForm); } } realised.Append(pluralForm); } else { realised.Append(baseForm); } checkPossessive(element, realised); StringElement realisedElement = new StringElement(realised.ToString(), element.Capitalized); // adapted by GJdV realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, element.getFeature(InternalFeature.DISCOURSE_FUNCTION)); return(realisedElement); }
/** * This method performs the morphology for verbs. * * @param element * the <code>InflectedWordElement</code>. * @param baseWord * the <code>WordElement</code> as created from the lexicon * entry. * @return a <code>StringElement</code> representing the word after * inflection. */ protected internal static NLGElement doVerbMorphology(InflectedWordElement element, WordElement baseWord) { string realised = null; object numberValue = element.getFeature(Feature.NUMBER); object personValue = element.getFeature(Feature.PERSON); object tense = element.getFeature(Feature.TENSE); Tense? tenseValue; // AG: change to avoid deprecated getTense // if tense value is Tense, cast it, else default to present if (tense is Tense) { tenseValue = (Tense?)tense; } else { tenseValue = Tense.PRESENT; } object formValue = element.getFeature(Feature.FORM); object patternValue = element.getFeature(LexicalFeature.DEFAULT_INFL); // base form from baseWord if it exists, otherwise from element string baseForm = getBaseForm(element, baseWord); if (element.getFeatureAsBoolean(Feature.NEGATED) || Form.BARE_INFINITIVE.Equals(formValue)) { realised = baseForm; } else if (Form.PRESENT_PARTICIPLE.Equals(formValue)) { realised = element.getFeatureAsString(LexicalFeature.PRESENT_PARTICIPLE); if (ReferenceEquals(realised, null) && baseWord != null) { realised = baseWord.getFeatureAsString(LexicalFeature.PRESENT_PARTICIPLE); } if (ReferenceEquals(realised, null)) { if (Inflection.REGULAR_DOUBLE.Equals(patternValue)) { realised = buildDoublePresPartVerb(baseForm); } else { realised = buildRegularPresPartVerb(baseForm); } } } else if (Tense.PAST.Equals(tenseValue) || Form.PAST_PARTICIPLE.Equals(formValue)) { if (Form.PAST_PARTICIPLE.Equals(formValue)) { realised = element.getFeatureAsString(LexicalFeature.PAST_PARTICIPLE); if (ReferenceEquals(realised, null) && baseWord != null) { realised = baseWord.getFeatureAsString(LexicalFeature.PAST_PARTICIPLE); } if (ReferenceEquals(realised, null)) { if ("be".Equals(baseForm, StringComparison.OrdinalIgnoreCase)) { //$NON-NLS-1$ realised = "been"; //$NON-NLS-1$ } else if (Inflection.REGULAR_DOUBLE.Equals(patternValue)) { realised = buildDoublePastVerb(baseForm); } else { realised = buildRegularPastVerb(baseForm, numberValue, personValue); } } } else { realised = element.getFeatureAsString(LexicalFeature.PAST); if (ReferenceEquals(realised, null) && baseWord != null) { realised = baseWord.getFeatureAsString(LexicalFeature.PAST); } if (ReferenceEquals(realised, null)) { if (Inflection.REGULAR_DOUBLE.Equals(patternValue)) { realised = buildDoublePastVerb(baseForm); } else { realised = buildRegularPastVerb(baseForm, numberValue, personValue); } } } } else if ((numberValue == null || NumberAgreement.SINGULAR.Equals(numberValue)) && (personValue == null || Person.THIRD.Equals(personValue)) && (tenseValue == null || Tense.PRESENT.Equals(tenseValue))) { realised = element.getFeatureAsString(LexicalFeature.PRESENT3S); if (ReferenceEquals(realised, null) && baseWord != null && !"be".Equals(baseForm, StringComparison.OrdinalIgnoreCase)) { //$NON-NLS-1$ realised = baseWord.getFeatureAsString(LexicalFeature.PRESENT3S); } if (ReferenceEquals(realised, null)) { realised = buildPresent3SVerb(baseForm); } } else { if ("be".Equals(baseForm, StringComparison.OrdinalIgnoreCase)) { //$NON-NLS-1$ if (Person.FIRST.Equals(personValue) && (NumberAgreement.SINGULAR.Equals(numberValue) || numberValue == null)) { realised = "am"; //$NON-NLS-1$ } else { realised = "are"; //$NON-NLS-1$ } } else { realised = baseForm; } } StringElement realisedElement = new StringElement(realised); realisedElement.setFeature(InternalFeature.DISCOURSE_FUNCTION, element.getFeature(InternalFeature.DISCOURSE_FUNCTION)); return(realisedElement); }