private static void ProcessSystemVerbs(ILanguage language) { Assembly commandsAssembly = Assembly.GetAssembly(typeof(CommandParameterAttribute)); IEnumerable <Type> loadedCommands = commandsAssembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(ICommand))); foreach (Type comm in loadedCommands) { IEnumerable <string> commandVerbs = comm.GetCustomAttributes <CommandKeywordAttribute>().Where(att => !att.PreventBecomingAVerb).Select(att => att.Keyword); foreach (string verb in commandVerbs) { Dictata newVerb = new Dictata() { Name = verb, Determinant = false, Feminine = false, Plural = false, Positional = LexicalPosition.None, Perspective = NarrativePerspective.None, Possessive = false, Tense = LexicalTense.Present, Semantics = new HashSet <string>() { "system_command" }, WordType = LexicalType.Verb, Language = language }; LexicalProcessor.VerifyLexeme(newVerb.GetLexeme()); } } }
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); }
private Dictionary <string, IDictata> BrandWords(IList <Tuple <string, bool> > words) { Dictionary <string, IDictata> brandedWords = new Dictionary <string, IDictata>(); //Brand all the words with their current meaning. Continues are in there because the listword inflation might cause collision foreach (Tuple <string, bool> word in words.Distinct()) { if (brandedWords.ContainsKey(word.Item1)) { continue; } //We have a comma/and list if (word.Item2) { string[] listWords = word.Item1.Split(new string[] { "and", ",", " " }, StringSplitOptions.RemoveEmptyEntries); IDictata listMeaning = null; foreach (string listWord in listWords) { if (listMeaning != null) { break; } if (brandedWords.ContainsKey(listWord)) { listMeaning = brandedWords[listWord]; } if (listMeaning == null) { listMeaning = GetExistingMeaning(listWord); } } foreach (string listWord in listWords) { if (brandedWords.ContainsKey(listWord)) { continue; } Dictata meaning = new Dictata() { Name = listWord, WordType = listMeaning.WordType }; brandedWords.Add(listWord, meaning); } continue; } brandedWords.Add(word.Item1, GetExistingMeaning(word.Item1)); } return(brandedWords); }
public AddEditDictataViewModel(ILexeme parent) { ParentObject = (Lexeme)parent; ValidLanguages = ConfigDataCache.GetAll <ILanguage>(); DataObject = new Dictata(); ValidWords = ConfigDataCache.GetAll <ILexeme>().Where(lex => lex.Language == parent.Language && lex != parent).SelectMany(lex => lex.WordForms).OrderBy(form => form.Name); }
public ActionResult AddRelatedWord(string lexemeId, string id, AddEditDictataViewModel vModel) { ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId()); ILexeme lex = ConfigDataCache.Get<ILexeme>(new ConfigDataCacheKey(typeof(ILexeme), lexemeId, ConfigDataType.Dictionary)); if (lex == null) { return RedirectToAction("Index", new { Message = "That does not exist" }); } IDictata dict = lex.WordForms.FirstOrDefault(form => form.UniqueKey == id); if (dict == null) { return RedirectToAction("Index", new { Message = "That does not exist" }); } Lexeme relatedLex = new Lexeme { Name = vModel.Word, Language = lex.Language }; Dictata relatedWord = new Dictata() { Name = vModel.Word, Severity = dict.Severity + vModel.Severity, Quality = dict.Quality + vModel.Quality, Elegance = dict.Elegance + vModel.Elegance, Tense = dict.Tense, Language = dict.Language, WordType = dict.WordType, Feminine = dict.Feminine, Possessive = dict.Possessive, Plural = dict.Plural, Determinant = dict.Determinant, Positional = dict.Positional, Perspective = dict.Perspective, Semantics = dict.Semantics }; HashSet<IDictata> synonyms = dict.Synonyms; synonyms.Add(dict); if (vModel.Synonym) { relatedWord.Synonyms = synonyms; relatedWord.Antonyms = dict.Antonyms; relatedWord.PhraseSynonyms = dict.PhraseSynonyms; relatedWord.PhraseAntonyms = dict.PhraseAntonyms; } else { relatedWord.Synonyms = dict.Antonyms; relatedWord.Antonyms = synonyms; relatedWord.PhraseSynonyms = dict.PhraseAntonyms; relatedWord.PhraseAntonyms = dict.PhraseSynonyms; } relatedLex.AddNewForm(relatedWord); string message; if (relatedLex.Save(authedUser.GameAccount, authedUser.GetStaffRank(User))) { if (vModel.Synonym) { HashSet<IDictata> mySynonyms = dict.Synonyms; mySynonyms.Add(relatedWord); dict.Synonyms = mySynonyms; } else { HashSet<IDictata> antonyms = dict.Antonyms; antonyms.Add(relatedWord); dict.Antonyms = antonyms; } lex.Save(authedUser.GameAccount, authedUser.GetStaffRank(User)); relatedLex.Save(authedUser.GameAccount, authedUser.GetStaffRank(User)); LoggingUtility.LogAdminCommandUsage("*WEB* - EditLexeme[" + lex.UniqueKey + "]", authedUser.GameAccount.GlobalIdentityHandle); message = "Edit Successful."; } else { message = "Error; Edit failed."; } return RedirectToAction("Index", new { Message = message }); }
/* * 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); }