/** * check if this record has a standard (regular) inflection * * @param record * @param simplenlg * syntactic category * @return true if standard (regular) inflection */ private bool standardInflections(LexRecord record, LexicalCategory category) { List <string> variants = null; switch (category.GetLexicalCategory()) { case LexicalCategory.LexicalCategoryEnum.NOUN: variants = record.GetCatEntry().GetNounEntry().GetVariants(); break; case LexicalCategory.LexicalCategoryEnum.ADJECTIVE: variants = record.GetCatEntry().GetAdjEntry().GetVariants(); break; case LexicalCategory.LexicalCategoryEnum.ADVERB: variants = record.GetCatEntry().GetAdvEntry().GetVariants(); break; case LexicalCategory.LexicalCategoryEnum.MODAL: variants = record.GetCatEntry().GetModalEntry().GetVariant(); break; case LexicalCategory.LexicalCategoryEnum.VERB: if (record.GetCatEntry().GetVerbEntry() != null) // aux verbs (eg be) won't have verb entries { variants = record.GetCatEntry().GetVerbEntry().GetVariants(); } break; } return(variants != null && variants.Contains("reg")); }
/** * get matching keys from an index map * * @param indexKey * @param category * @param indexMap * @return */ private IList <WordElement> getWordsFromIndex(string indexKey, LexicalCategory category, IDictionary <string, IList <WordElement> > indexMap) { IList <WordElement> result = new List <WordElement>(); // case 1: unknown, return empty list if (!indexMap.ContainsKey(indexKey)) { return(result); } // case 2: category is ANY, return everything if (category.GetLexicalCategory() == LexicalCategory.LexicalCategoryEnum.ANY) { foreach (WordElement word in indexMap[indexKey]) { result.Add(new WordElement(word)); } return(result); } else { // case 3: other category, search for match foreach (WordElement word in indexMap[indexKey]) { if (word.Category == category) { result.Add(new WordElement(word)); } } } return(result); }
/** * return list of WordElement from LexAccessApiResult * * @param category * - desired category (eg, NOUN) (this filters list) * @param lexResult * - the LexAccessApiResult * @return list of WordElement */ private IList <WordElement> getWordsFromLexResult(LexicalCategory category, LexAccessApiResult lexResult) { List <LexRecord> recordList = lexResult.GetJavaObjs(); // set up array of words to return IList <WordElement> wordElements = new List <WordElement>(); // iterate through result records, adding to words as appropriate foreach (LexRecord record in recordList) { if (category.GetLexicalCategory() == LexicalCategory.LexicalCategoryEnum.ANY || category == getSimplenlgCategory(record)) { wordElements.Add(makeWord(record)); } } return(wordElements); }
/** * make a WordElement from a lexical record. Currently just specifies basic * params and inflections Should do more in the future! * * @param record * @return */ private WordElement makeWord(LexRecord record) // LexRecord { // get basic data String baseForm = record.GetBase(); LexicalCategory category = record.GetSimpleNLGCategory(record); String id = record.GetEui(); // create word class WordElement wordElement = new WordElement(baseForm, category, id); // now add type information switch (category.GetLexicalCategory()) { case LexicalCategory.LexicalCategoryEnum.ADJECTIVE: addAdjectiveInfo(wordElement, record.GetCatEntry().GetAdjEntry()); break; case LexicalCategory.LexicalCategoryEnum.ADVERB: addAdverbInfo(wordElement, record.GetCatEntry().GetAdvEntry()); break; case LexicalCategory.LexicalCategoryEnum.NOUN: addNounInfo(wordElement, record.GetCatEntry().GetNounEntry()); break; case LexicalCategory.LexicalCategoryEnum.VERB: addVerbInfo(wordElement, record.GetCatEntry().GetVerbEntry()); break; // ignore closed class words } Inflection?defaultInfl = wordElement.getDefaultInflectionalVariant(); // now add inflected forms // if (keepStandardInflections || !standardInflections(record, // category)) { foreach (InflVar inflection in record.GetInflVarsAndAgreements().GetInflValues()) { String simplenlgInflection = getSimplenlgInflection(inflection .GetInflection()); if (simplenlgInflection != null) { String inflectedForm = inflection.GetVar(); Inflection?inflType = Inflection.REGULAR.getInflCode(inflection.GetType()); // store all inflectional variants, except for regular ones // unless explicitly set if (inflType != null && !(Inflection.REGULAR == inflType && !keepStandardInflections)) { wordElement.addInflectionalVariant((Inflection)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) && !keepStandardInflections))) { wordElement.setFeature(simplenlgInflection, inflectedForm); } // wordElement // .setFeature(simplenlgInflection, inflection.GetVar()); } } // } // add acronym info addAcronymInfo(wordElement, record); // now add spelling variants addSpellingVariants(wordElement, record); return(wordElement); }