private IDictata GetExistingMeaning(string word, LexicalType wordType = LexicalType.Noun) { List <string> allContext = new List <string>(); //Get all local nouns allContext.AddRange(_currentPlace.GetContents <IInanimate>().SelectMany(thing => thing.Keywords)); allContext.AddRange(_currentPlace.GetContents <IMobile>().SelectMany(thing => thing.Keywords)); allContext.AddRange(_currentPlace.Keywords); allContext.AddRange(_actor.Keywords); IDictata existingMeaning = null; //It's a thing we can see if (allContext.Contains(word)) { existingMeaning = new Dictata() { Name = word, WordType = LexicalType.ProperNoun }; } else { //TODO: We need to discriminate based on lexical type as well, we could have multiple of the same word with different types if (_currentDictionary.Any(dict => dict.Name.Equals(word, StringComparison.InvariantCultureIgnoreCase))) { existingMeaning = _currentDictionary.FirstOrDefault(dict => dict.Name.Equals(word, StringComparison.InvariantCultureIgnoreCase))?.GetForm(wordType); } } return(existingMeaning); }
/// <summary> /// Try to add a modifier to a lexica /// </summary> /// <param name="modifier">the lexica that is the modifier</param> /// <returns>Whether or not it succeeded</returns> public ILexica TryModify(LexicalType type, GrammaticalType role, string phrase, bool passthru = false) { ILexica modifier = new Lexica(type, role, phrase, Context); modifier = TryModify(modifier); return(passthru ? this : modifier); }
private void ParsePhrase(IEnumerable <ILexica> lexes, ILanguage language) { if (language?.PhraseRules != null && language.PhraseRules.Count() > 0) { foreach (DictataPhraseRule phraseRule in language.PhraseRules) { int validCount = 0; foreach (IGrouping <LexicalType, ILexica> lexGroup in lexes.GroupBy(lex => lex.Type)) { short minCount = phraseRule.Elements.FirstOrDefault(rule => rule.WordType == lexGroup.Key)?.MinimumNumber ?? 0; if (minCount == -1 || (minCount == 0 && lexGroup.Count() == 0) || (minCount > 0 && lexGroup.Count() >= minCount)) { validCount++; } } //Prepositional position phrase if (validCount == Enum.GetNames(typeof(LexicalType)).Count()) { LexicalType primaryType = phraseRule.Elements.FirstOrDefault(ruleLex => ruleLex.Primary)?.WordType ?? LexicalType.Preposition; IDictata primaryWord = lexes.FirstOrDefault(lex => lex.Type == primaryType)?.GetDictata(); if (primaryWord == null) { primaryWord = lexes.FirstOrDefault().GetDictata(); } DictataPhrase newPhrase = new DictataPhrase() { Elegance = (int)Math.Truncate((primaryWord.Elegance + 1) * 1.2), Quality = (int)Math.Truncate((primaryWord.Quality + 1) * 1.2), Severity = (int)Math.Truncate((primaryWord.Severity + 1) * 1.2), Antonyms = primaryWord.Antonyms, PhraseAntonyms = primaryWord.PhraseAntonyms, Synonyms = primaryWord.Synonyms, PhraseSynonyms = primaryWord.PhraseSynonyms, Feminine = primaryWord.Feminine, Language = primaryWord.Language, Perspective = primaryWord.Perspective, Positional = primaryWord.Positional, Semantics = primaryWord.Semantics, Tense = primaryWord.Tense, Words = new HashSet <IDictata>(lexes.Select(lex => lex.GetDictata())) }; if (!CheckForExistingPhrase(newPhrase)) { newPhrase.SystemSave(); } } } } }
public Lexica(LexicalType type, GrammaticalType role, string phrase, IEntity origin, IEntity observer) { Type = type; Phrase = phrase; Role = role; Modifiers = new HashSet <ILexica>(); LexicalProcessor.VerifyLexeme(this); Context = BuildContext(origin, observer); }
public Lexica(LexicalType type, GrammaticalType role, string phrase, LexicalContext context) { Type = type; Phrase = phrase; Role = role; Modifiers = new HashSet <ILexica>(); LexicalProcessor.VerifyLexeme(this); Context = context.Clone(); }
public Lexica(LexicalType type, GrammaticalType role, string phrase, LexicalContext context) { Type = type; Phrase = phrase; Role = role; Modifiers = new HashSet <ILexica>(); Context = context.Clone(); GetDictata(); }
public Lexica(LexicalType type, GrammaticalType role, string phrase, IEntity origin, IEntity observer) { Type = type; Phrase = phrase; Role = role; Modifiers = new HashSet <ILexica>(); Context = BuildContext(origin, observer); GetDictata(); }
public static IDictata GetWord(LexicalContext context, LexicalType type) { if (context.Language == null) { IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); context.Language = globalConfig.BaseLanguage; } IEnumerable <IDictata> possibleWords = ConfigDataCache.GetAll <IDictata>().Where(dict => dict.Language == context.Language && dict.WordType == type && dict.GetLexeme().SuitableForUse); return(possibleWords.OrderByDescending(word => GetSynonymRanking(word, context)).FirstOrDefault()); }
/// <summary> /// Get a word form by criteria /// </summary> /// <param name="word">the text name of the word</param> /// <param name="form">the lexical type</param> /// <param name="semantics">the semantic meaning</param> /// <param name="bestFit">should we grab best fit for meaning or be more exacting</param> /// <returns>the word, or nothing</returns> public IDictata GetForm(LexicalType form, string[] semantics, bool bestFit = true) { IDictata returnValue = null; if (bestFit || semantics.Count() == 0) { returnValue = WordForms.Where(wordForm => wordForm.WordType == form) .OrderByDescending(wordForm => semantics.Sum(sem => wordForm.Semantics.Contains(sem) ? 1 : 0)) .FirstOrDefault(); } else { var expectedMinimumSemanticSimilarity = semantics.Count() / 2; returnValue = WordForms.FirstOrDefault(wordForm => wordForm.WordType == form && semantics.Sum(sem => wordForm.Semantics.Contains(sem) ? 1 : 0) >= expectedMinimumSemanticSimilarity); } return(returnValue); }
public static PartOfSpeech MapLexicalTypes(LexicalType pos) { switch (pos) { case LexicalType.Adjective: return(PartOfSpeech.Adjective); case LexicalType.Adverb: return(PartOfSpeech.Adverb); case LexicalType.Noun: return(PartOfSpeech.Noun); case LexicalType.Verb: return(PartOfSpeech.Verb); } return(PartOfSpeech.None); }
/// <summary> /// Create or modify a lexeme within this language /// </summary> /// <param name="word">the word we're making</param> /// <returns></returns> public ILexeme CreateOrModifyLexeme(string word, LexicalType form, string[] semantics) { word = word.ToLower(); Regex rgx = new Regex("[^a-z -]"); word = rgx.Replace(word, ""); if (string.IsNullOrWhiteSpace(word) || word.All(ch => ch == '-') || word.IsNumeric()) { return(null); } ILexeme lex = ConfigDataCache.Get <ILexeme>(string.Format("{0}_{1}_{2}", ConfigDataType.Dictionary, Name, word)); if (lex == null) { lex = new Lexeme() { Name = word, Language = this }; lex.SystemSave(); lex.PersistToCache(); } if (form != LexicalType.None && lex.GetForm(form, semantics, false) == null) { var newDict = new Dictata() { Name = word, WordType = form, Language = this, Semantics = new HashSet <string>(semantics) }; lex.AddNewForm(newDict); } return(lex); }
/// <summary> /// Create or modify a lexeme with no word form basis, gets tricky with best fit scenarios /// </summary> /// <param name="word">just the text of the word</param> /// <returns>A lexeme</returns> public static ILexeme CreateOrModifyLexeme(ILanguage language, string word, ref List <string> processedWords) { word = word.ToLower(); Regex rgx = new Regex("[^a-z -]"); word = rgx.Replace(word, ""); if (string.IsNullOrWhiteSpace(word) || word.All(ch => ch == '-')) { return(null); } ILexeme newLex = ConfigDataCache.Get <ILexeme>(string.Format("{0}_{1}", language.Name, word)); if (newLex == null) { newLex = language.CreateOrModifyLexeme(word, LexicalType.None, new string[0]); } if (newLex.IsSynMapped || processedWords.Any(wrd => wrd.Equals(word))) { if (!processedWords.Any(wrd => wrd.Equals(word))) { processedWords.Add(word); } return(newLex); } processedWords.Add(word); bool exists = true; SearchSet searchSet = null; List <Search> results = new List <Search>(); WordNet.OverviewFor(word, string.Empty, ref exists, ref searchSet, results); //We in theory have every single word form for this word now if (exists && results != null) { LexicalType[] invalidTypes = new LexicalType[] { LexicalType.Article, LexicalType.Conjunction, LexicalType.ProperNoun, LexicalType.Pronoun, LexicalType.None }; foreach (SynonymSet synSet in results.SelectMany(result => result.senses)) { //grab semantics somehow List <string> semantics = new List <string>(); var indexSplit = synSet.defn.IndexOf(';'); string definition = synSet.defn.Substring(0, indexSplit < 0 ? synSet.defn.Length - 1 : indexSplit).Trim(); string[] defWords = definition.Split(' '); foreach (string defWord in defWords) { var currentWord = defWord.ToLower(); currentWord = rgx.Replace(currentWord, ""); if (currentWord.Equals(word) || string.IsNullOrWhiteSpace(word) || word.All(ch => ch == '-') || word.IsNumeric()) { continue; } var defLex = language.CreateOrModifyLexeme(currentWord, LexicalType.None, new string[0]); if (defLex != null && !defLex.ContainedTypes().Any(typ => invalidTypes.Contains(typ))) { semantics.Add(currentWord); } } var type = MapLexicalTypes(synSet.pos.Flag); newLex = language.CreateOrModifyLexeme(word, type, semantics.ToArray()); var newDict = newLex.GetForm(type, semantics.ToArray(), false); ///wsns indicates hypo/hypernymity so int baseWeight = synSet.words[Math.Max(0, synSet.whichword - 1)].wnsns; newDict.Severity = baseWeight; newDict.Elegance = Math.Max(0, newDict.Name.SyllableCount() * 3); newDict.Quality = synSet.words.Count(); foreach (Lexeme synWord in synSet.words) { ///wsns indicates hypo/hypernymity so int mySeverity = synWord.wnsns; int myElegance = Math.Max(0, synWord.word.SyllableCount() * 3); int myQuality = synWord.semcor?.semcor ?? 0; //Don't bother if this word is already the same word we started with if (synWord.word.Equals(newDict.Name, StringComparison.InvariantCultureIgnoreCase)) { continue; } //it's a phrase if (synWord.word.Contains("_")) { string[] words = synWord.word.Split('_'); //foreach (string phraseWord in words) //{ // //make the phrase? maybe later //} } else { var newWord = synWord.word.ToLower(); newWord = rgx.Replace(newWord, ""); if (newWord.Equals(word) || string.IsNullOrWhiteSpace(newWord) || newWord.All(ch => ch == '-') || newWord.IsNumeric()) { continue; } newDict.MakeRelatedWord(language, synWord.word, true); } } } } newLex.IsSynMapped = true; newLex.SystemSave(); newLex.PersistToCache(); return(newLex); }
/// <summary> /// Get a wordform by grouping id /// </summary> /// <param name="wordType">the lexical type of the word</param> /// <param name="formGroup">the form grouping id</param> /// <returns>the word</returns> public IDictata GetForm(LexicalType wordType, short formGroup = -1) { return(WordForms.FirstOrDefault(form => form.WordType == wordType && (formGroup < 0 || form.FormGroup == formGroup))); }
public JsonResult <string[]> GetDictata(string languageCode, LexicalType wordType, string term) { IEnumerable <IDictata> words = ConfigDataCache.GetAll <IDictata>().Where(dict => dict.WordType == wordType && dict.Name.Contains(term) && dict.Language.GoogleLanguageCode.Equals(languageCode)); return(Json(words.Select(word => word.Name).ToArray())); }
/// <summary> /// Create or modify a lexeme with no word form basis, gets tricky with best fit scenarios /// </summary> /// <param name="word">just the text of the word</param> /// <returns>A lexeme</returns> public static ILexeme CreateOrModifyLexeme(ILanguage language, string word, LexicalType wordType, ref List <string> processedWords) { word = word.ToLower(); Regex rgx = new Regex("[^a-z -]"); if (rgx.IsMatch(word)) { return(null); } ILexeme newLex = ConfigDataCache.Get <ILexeme>(string.Format("{0}_{1}_{2}", ConfigDataType.Dictionary, language.Name, word)); if (newLex == null) { newLex = language.CreateOrModifyLexeme(word, wordType, new string[0]); } if ((newLex.IsSynMapped && newLex.MirriamIndexed) || processedWords.Any(wrd => wrd.Equals(word))) { if (!processedWords.Any(wrd => wrd.Equals(word))) { processedWords.Add(word); } } else { LexicalType[] invalidTypes = new LexicalType[] { LexicalType.Article, LexicalType.Conjunction, LexicalType.ProperNoun, LexicalType.Pronoun, LexicalType.None }; processedWords.Add(word); //This is wordnet processing, wordnet doesnt have any of the above and will return weird results if we let it if (!invalidTypes.Contains(wordType)) { var synSets = WordNetHarness.GetSynSets(word, new PartOfSpeech[] { PartOfSpeech.Adjective, PartOfSpeech.Adverb, PartOfSpeech.Noun, PartOfSpeech.Verb }); //We in theory have every single word form for this word now if (synSets != null) { SemanticContext[] invalidContexts = new SemanticContext[] { SemanticContext.Group, SemanticContext.Event, SemanticContext.Location, SemanticContext.Competition, SemanticContext.Person , SemanticContext.Plant, SemanticContext.Animal, SemanticContext.Time, SemanticContext.Artifact }; foreach (SynSet synSet in synSets) { if (synSet.PartOfSpeech == PartOfSpeech.None) { continue; } var synContext = TranslateContext(synSet.LexicographerFileName); if (invalidContexts.Contains(synContext)) { continue; } var newDict = newLex.GetForm(MapLexicalTypes(synSet.PartOfSpeech), -1); if (newDict == null) { newLex = language.CreateOrModifyLexeme(word, MapLexicalTypes(synSet.PartOfSpeech), new string[0]); newDict = newLex.GetForm(MapLexicalTypes(synSet.PartOfSpeech), -1); newDict.Context = TranslateContext(synSet.LexicographerFileName); } //We're going to use the definition from here if (!string.IsNullOrWhiteSpace(synSet.Gloss)) { newDict.Definition = synSet.Gloss; } ///wsns indicates hypo/hypernymity so foreach (string synWord in synSet.Words) { var newWord = synWord.ToLower(); newWord = newWord.Replace("_", " "); if (rgx.IsMatch(newWord)) { continue; } int myElegance = Math.Max(0, newWord.SyllableCount() * 3); processedWords.Add(newWord); if (string.IsNullOrWhiteSpace(newWord) || newWord.All(ch => ch == '-') || newWord.IsNumeric()) { continue; } var synLex = language.CreateOrModifyLexeme(newWord, MapLexicalTypes(synSet.PartOfSpeech), newDict.Semantics.ToArray()); var synDict = synLex.GetForm(MapLexicalTypes(synSet.PartOfSpeech), newDict.Semantics.ToArray(), false); synDict.Elegance = 0; synDict.Quality = 0; synDict.Severity = 0; synDict.Context = synContext; synDict.Definition = newDict.Definition; synLex.PersistToCache(); synLex.SystemSave(); if (!newWord.Equals(word)) { newDict.MakeRelatedWord(language, newWord, true, synDict); } } } } } newLex.IsSynMapped = true; newLex.SystemSave(); newLex.PersistToCache(); } if (!newLex.MirriamIndexed) { var newDict = newLex.GetForm(0); try { var dictEntry = MirriamWebsterAPI.GetDictionaryEntry(newLex.Name); if (dictEntry != null) { //Stuff done to modify all forms of the lexeme foreach (var dict in newLex.WordForms) { dict.Vulgar = dictEntry.meta.offensive; } //Stuff done based on the dictionary return data foreach (var stemWord in dictEntry.uros) { if (newLex.GetForm(MapLexicalTypes(stemWord.fl)) == null) { var wordText = stemWord.ure.Replace("*", ""); ILexeme stemLex = ConfigDataCache.Get <ILexeme>(string.Format("{0}_{1}_{2}", ConfigDataType.Dictionary, language.Name, wordText)); if (stemLex == null) { stemLex = language.CreateOrModifyLexeme(wordText, MapLexicalTypes(stemWord.fl), null); var stemDict = stemLex.GetForm(0); stemDict.Elegance = newDict.Elegance; stemDict.Quality = newDict.Quality; stemDict.Severity = newDict.Severity; stemDict.Context = newDict.Context; stemDict.Definition = newDict.Definition; stemDict.Semantics = newDict.Semantics; processedWords.Add(wordText); stemLex.SystemSave(); stemLex.PersistToCache(); } } } newDict.Semantics = new HashSet <string>(dictEntry.sls); } } catch { //just eating it } try { var thesEntry = MirriamWebsterAPI.GetThesaurusEntry(newLex.Name); if (thesEntry != null) { foreach (var synonym in thesEntry.meta.syns.SelectMany(syn => syn)) { var newWord = synonym.ToLower(); newWord = newWord.Replace("_", " "); if (rgx.IsMatch(newWord) || string.IsNullOrWhiteSpace(newWord) || newWord.All(ch => ch == '-')) { continue; } var synLex = language.CreateOrModifyLexeme(newWord, MapLexicalTypes(thesEntry.fl), newDict.Semantics.ToArray()); var synDict = synLex.GetForm(MapLexicalTypes(thesEntry.fl), newDict.Semantics.ToArray(), false); synDict.Elegance = 0; synDict.Quality = 0; synDict.Severity = 0; synDict.Context = newDict.Context; synDict.Definition = newDict.Definition; synLex.PersistToCache(); synLex.SystemSave(); processedWords.Add(newWord); if (!newWord.Equals(word)) { newDict.MakeRelatedWord(language, newWord, true, synDict); } } foreach (var antonym in thesEntry.meta.ants.SelectMany(syn => syn)) { var newWord = antonym.ToLower(); newWord = newWord.Replace("_", " "); if (rgx.IsMatch(newWord) || string.IsNullOrWhiteSpace(newWord) || newWord.All(ch => ch == '-')) { continue; } var synLex = language.CreateOrModifyLexeme(newWord, MapLexicalTypes(thesEntry.fl), newDict.Semantics.ToArray()); var synDict = synLex.GetForm(MapLexicalTypes(thesEntry.fl), newDict.Semantics.ToArray(), false); synDict.Elegance = 0; synDict.Quality = 0; synDict.Severity = 0; synDict.Context = newDict.Context; synDict.Definition = newDict.Definition; synLex.PersistToCache(); synLex.SystemSave(); processedWords.Add(newWord); if (!newWord.Equals(word)) { newDict.MakeRelatedWord(language, newWord, false, synDict); } } } } catch { //just eating it } newLex.MirriamIndexed = true; newLex.SystemSave(); newLex.PersistToCache(); } if (!newLex.IsTranslated) { } return(newLex); }
private static IDictata GetObscuredWord(IDictata word, IEnumerable <IDictata> possibleWords, short obscureStrength) { if (word == null || possibleWords.Count() == 0 || obscureStrength == 0) { return(word); } //try to downgrade word Dictionary <IDictata, int> rankedWords = new Dictionary <IDictata, int>(); foreach (IDictata possibleWord in possibleWords) { int rating = Math.Abs(word.Quality + (Math.Abs(obscureStrength) * -1) - possibleWord.Quality); rankedWords.Add(possibleWord, rating); } KeyValuePair <IDictata, int> closestWord = rankedWords.OrderBy(pair => pair.Value).FirstOrDefault(); IDictata newWord = closestWord.Key; LexicalType[] descriptiveWordTypes = new LexicalType[] { LexicalType.Adjective, LexicalType.Adverb }; LexicalType[] remainderWordTypes = new LexicalType[] { LexicalType.Verb, LexicalType.Preposition, LexicalType.Conjunction, LexicalType.Article }; LexicalType[] nounWordTypes = new LexicalType[] { LexicalType.Pronoun, LexicalType.ProperNoun, LexicalType.Noun }; if (newWord != null) { //Adjectives/adverbs/articles get eaten if (descriptiveWordTypes.Contains(newWord.WordType)) { newWord = null; } //if it's a verb or preposition or structural leave it alone if (remainderWordTypes.Contains(newWord.WordType)) { newWord = word; } //pronouns become "it" if (nounWordTypes.Contains(newWord.WordType)) { LexicalContext itContext = new LexicalContext(null) { Determinant = false, Plural = false, Possessive = false, Tense = LexicalTense.None, Language = word.Language, Perspective = NarrativePerspective.None }; newWord = GetWord(itContext, LexicalType.Pronoun); } //TODO: if it's a noun try to downgrade it to a shape or single aspect } else { newWord = word; } return(newWord); }
/// <summary> /// Try to add a modifier to a lexica /// </summary> /// <param name="modifier">the lexica that is the modifier</param> /// <returns>Whether or not it succeeded</returns> public ILexica TryModify(LexicalType type, GrammaticalType role, string phrase, bool passthru = false) { return(Event.TryModify(type, role, phrase, passthru)); }
/* * TODO: Wow this is inefficient, maybe clean up how many loops we do */ private IEnumerable <IDictata> ParseAction(IList <Tuple <string, bool> > words, bool push, IDictata lastSubject) { /* * I kick the can * kick the can * kicks the can * kick the red can * kick the large red can */ List <IDictata> returnList = new List <IDictata>(); Dictionary <string, IDictata> brandedWords = BrandWords(words); IDictata currentVerb = null; //Find unknown nouns potentially with conjunctions foreach ((KeyValuePair <string, IDictata> value, int i)item in brandedWords.Where(ctx => ctx.Value == null).Select((value, i) => (value, i)).OrderByDescending(keypair => keypair.i)) { KeyValuePair <string, IDictata> value = item.value; int index = item.i; if (index < brandedWords.Count() - 1 && index > 0) { IDictata wordAfter = brandedWords.ElementAt(index + 1).Value; IDictata wordBefore = brandedWords.ElementAt(index - 1).Value; if (wordBefore != null && wordBefore.WordType == LexicalType.Adverb && wordAfter != null && wordAfter.WordType == LexicalType.Verb) { brandedWords[value.Key] = new Dictata() { Name = value.Key, WordType = LexicalType.Adverb }; continue; } if ((wordBefore != null && (wordBefore.WordType == LexicalType.Adjective) || wordBefore.WordType == LexicalType.Article) && (wordAfter != null && (wordAfter.WordType == LexicalType.Noun) || wordAfter.WordType == LexicalType.ProperNoun)) { brandedWords[value.Key] = new Dictata() { Name = value.Key, WordType = LexicalType.Adjective }; continue; } continue; } if (index < brandedWords.Count() - 1) { IDictata wordAfter = brandedWords.ElementAt(index + 1).Value; if (wordAfter != null && wordAfter.WordType == LexicalType.Noun) { brandedWords[value.Key] = new Dictata() { Name = value.Key, WordType = LexicalType.Adjective }; continue; } if (wordAfter != null && wordAfter.WordType == LexicalType.Verb) { brandedWords[value.Key] = new Dictata() { Name = value.Key, WordType = LexicalType.Adverb }; continue; } } if (index > 0) { IDictata wordBefore = brandedWords.ElementAt(index - 1).Value; if (wordBefore != null && (wordBefore.WordType == LexicalType.Article || wordBefore.WordType == LexicalType.Adjective)) { brandedWords[value.Key] = new Dictata() { Name = value.Key, WordType = LexicalType.Noun }; continue; } if (wordBefore != null && wordBefore.WordType == LexicalType.Adverb) { brandedWords[value.Key] = new Dictata() { Name = value.Key, WordType = LexicalType.Verb }; continue; } } } //No verb? if (!brandedWords.Any(ctx => ctx.Value != null && ctx.Value.WordType == LexicalType.Verb)) { string verbWord = brandedWords.First(ctx => ctx.Value == null).Key; currentVerb = new Dictata() { Name = verbWord, WordType = LexicalType.Verb }; brandedWords[verbWord] = currentVerb; } else { currentVerb = brandedWords.FirstOrDefault(ctx => ctx.Value != null && ctx.Value.WordType == LexicalType.Verb).Value; } //We might have nouns already if (!brandedWords.Any(ctx => ctx.Value == null || (ctx.Value != null && (ctx.Value.WordType == LexicalType.Noun || ctx.Value.WordType == LexicalType.ProperNoun)))) { bool lastSubjectReplaced = false; if (lastSubject != null) { List <string> keyList = new List <string>(); foreach (KeyValuePair <string, IDictata> word in brandedWords.Where(ctx => ctx.Value != null && ctx.Value.WordType == LexicalType.Pronoun)) { keyList.Add(word.Key); lastSubjectReplaced = true; } foreach (string key in keyList) { brandedWords[key] = (IDictata)lastSubject.Clone(); } } if (!lastSubjectReplaced) { string targetWord = string.Empty; //No valid nouns to make the target? Pick the last one if (!brandedWords.Any(ctx => ctx.Value == null)) { targetWord = brandedWords.LastOrDefault().Key; } else { targetWord = brandedWords.LastOrDefault(ctx => ctx.Value == null).Key; } brandedWords[targetWord] = new Dictata() { Name = targetWord, WordType = LexicalType.Noun }; } } List <IDictata> descriptors = new List <IDictata>(); foreach ((KeyValuePair <string, IDictata> value, int i)item in brandedWords.Where(ctx => ctx.Value == null).Select((value, i) => (value, i))) { KeyValuePair <string, IDictata> value = item.value; int index = item.i; LexicalType wordType = LexicalType.Adjective; if (index == brandedWords.Count() - 1) { IDictata wordAfter = brandedWords.ElementAt(index + 1).Value; if (wordAfter != null) { if (wordAfter.WordType == LexicalType.Verb) { wordType = LexicalType.Adverb; } if (wordAfter.WordType == LexicalType.Pronoun) { wordType = LexicalType.Article; } } } descriptors.Add(new Dictata() { Name = value.Key, WordType = wordType }); } //Add the nonadjectives and the adjectives returnList.AddRange(brandedWords.Where(bws => bws.Value != null).Select(bws => bws.Value)); returnList.AddRange(descriptors.Select(desc => desc)); if (push) { foreach (IDictata item in returnList) { LexicalProcessor.VerifyLexeme(item.GetLexeme()); } } return(returnList); }
public DictataPhraseRuleElement(LexicalType wordType) { MinimumNumber = -1; WordType = wordType; Primary = false; }