/// <summary> /// Put it in the cache /// </summary> /// <returns>success status</returns> public override bool PersistToCache() { try { LexicalContext collectiveContext = new LexicalContext(null) { Determinant = true, Perspective = NarrativePerspective.ThirdPerson, Plural = false, Position = LexicalPosition.None, Tense = LexicalTense.Present }; List <IDictata> dictatas = new List <IDictata> { new Dictata(new Lexica(LexicalType.ProperNoun, GrammaticalType.Subject, Name, collectiveContext)) }; dictatas.AddRange(Descriptives.Select(desc => desc.Event.GetDictata())); foreach (IDictata dictata in dictatas) { LexicalProcessor.VerifyLexeme(dictata.GetLexeme()); } TemplateCache.Add(this); } catch (Exception ex) { LoggingUtility.LogError(ex, LogChannels.SystemWarnings); return(false); } return(true); }
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()); } } }
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(); }
/// <summary> /// Generate a new dictata from this /// </summary> /// <returns></returns> public IDictata GenerateDictata() { if (string.IsNullOrWhiteSpace(Phrase)) { return(null); } Dictata dict = new Dictata(this); Lexeme lex = new Lexeme() { Name = Phrase, Language = dict.Language }; lex.AddNewForm(dict); LexicalProcessor.VerifyLexeme(lex); return(dict); }
private void EnsureDictionary() { if (!string.IsNullOrWhiteSpace(BaseWords.ArticleDeterminant)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.ArticleDeterminant, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.ArticleDeterminant, Determinant = true, Feminine = false, Plural = false, Positional = LexicalPosition.None, Perspective = NarrativePerspective.None, Possessive = false, Tense = LexicalTense.None, WordType = LexicalType.Article, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.ArticleNonDeterminant)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.ArticleNonDeterminant, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.ArticleNonDeterminant, Determinant = false, Feminine = false, Plural = false, Positional = LexicalPosition.None, Perspective = NarrativePerspective.None, Possessive = false, Tense = LexicalTense.None, WordType = LexicalType.Article, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.Conjunction)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.Conjunction, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.Conjunction, Determinant = false, Feminine = false, Plural = false, Positional = LexicalPosition.None, Perspective = NarrativePerspective.None, Possessive = false, Tense = LexicalTense.None, WordType = LexicalType.Conjunction, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.NeutralPronounFirstPersonPossessive)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.NeutralPronounFirstPersonPossessive, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.NeutralPronounFirstPersonPossessive, Determinant = false, Feminine = false, Plural = false, Positional = LexicalPosition.None, Perspective = NarrativePerspective.FirstPerson, Possessive = true, Tense = LexicalTense.None, WordType = LexicalType.Pronoun, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.NeutralPronounFirstPersonSingular)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.NeutralPronounFirstPersonSingular, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.NeutralPronounFirstPersonSingular, Determinant = false, Feminine = false, Plural = false, Positional = LexicalPosition.None, Perspective = NarrativePerspective.FirstPerson, Possessive = false, Tense = LexicalTense.None, WordType = LexicalType.Pronoun, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.NeutralPronounSecondPersonPlural)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.NeutralPronounSecondPersonPlural, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.NeutralPronounSecondPersonPlural, Determinant = false, Feminine = false, Plural = true, Positional = LexicalPosition.None, Perspective = NarrativePerspective.SecondPerson, Possessive = false, Tense = LexicalTense.None, WordType = LexicalType.Pronoun, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.NeutralPronounSecondPersonPossessive)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.NeutralPronounSecondPersonPossessive, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.NeutralPronounSecondPersonPossessive, Determinant = false, Feminine = false, Plural = false, Positional = LexicalPosition.None, Perspective = NarrativePerspective.SecondPerson, Possessive = true, Tense = LexicalTense.None, WordType = LexicalType.Pronoun, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.NeutralPronounSecondPersonSingular)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.NeutralPronounSecondPersonSingular, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.NeutralPronounSecondPersonSingular, Determinant = false, Feminine = false, Plural = false, Positional = LexicalPosition.None, Perspective = NarrativePerspective.SecondPerson, Possessive = false, Tense = LexicalTense.None, WordType = LexicalType.Pronoun, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.VerbExistentialPlural)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.VerbExistentialPlural, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.VerbExistentialPlural, Determinant = false, Feminine = false, Plural = true, Positional = LexicalPosition.None, Perspective = NarrativePerspective.None, Possessive = false, Semantics = new HashSet <string>() { "existential" }, Tense = LexicalTense.Present, WordType = LexicalType.Verb, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.VerbExistentialSingular)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.VerbExistentialSingular, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.VerbExistentialSingular, Determinant = false, Feminine = false, Plural = false, Positional = LexicalPosition.None, Perspective = NarrativePerspective.None, Possessive = false, Semantics = new HashSet <string>() { "existential" }, Tense = LexicalTense.Present, WordType = LexicalType.Verb, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.PrepositionAround)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.PrepositionAround, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.PrepositionAround, Determinant = false, Feminine = false, Plural = false, Positional = LexicalPosition.Around, Perspective = NarrativePerspective.None, Possessive = false, WordType = LexicalType.Preposition, Tense = LexicalTense.None, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.PrepositionAttached)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.PrepositionAttached, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.PrepositionAttached, Determinant = false, Feminine = false, Plural = false, Positional = LexicalPosition.Attached, Perspective = NarrativePerspective.None, Possessive = false, Tense = LexicalTense.None, WordType = LexicalType.Preposition, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.PrepositionFar)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.PrepositionFar, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.PrepositionFar, Determinant = false, Feminine = false, Plural = false, Positional = LexicalPosition.Far, Perspective = NarrativePerspective.None, Possessive = false, Tense = LexicalTense.None, WordType = LexicalType.Preposition, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.PrepositionInside)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.PrepositionInside, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.PrepositionInside, Determinant = false, Feminine = false, Plural = false, Positional = LexicalPosition.InsideOf, Perspective = NarrativePerspective.None, Possessive = false, Tense = LexicalTense.None, WordType = LexicalType.Preposition, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.PrepositionNear)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.PrepositionNear, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.PrepositionNear, Determinant = false, Feminine = false, Plural = false, Positional = LexicalPosition.Near, Perspective = NarrativePerspective.None, Possessive = false, Tense = LexicalTense.None, WordType = LexicalType.Preposition, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.PrepositionOn)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.PrepositionOn, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.PrepositionOn, Determinant = false, Feminine = false, Plural = false, Positional = LexicalPosition.On, Perspective = NarrativePerspective.None, Possessive = false, Tense = LexicalTense.None, WordType = LexicalType.Preposition, Language = this } } }); } if (!string.IsNullOrWhiteSpace(BaseWords.PrepositionOf)) { LexicalProcessor.VerifyLexeme(new Lexeme() { Name = BaseWords.PrepositionOf, Language = this, WordForms = new IDictata[] { new Dictata() { Name = BaseWords.PrepositionOf, Determinant = false, Feminine = false, Plural = false, Positional = LexicalPosition.PartOf, Perspective = NarrativePerspective.None, Possessive = false, Tense = LexicalTense.None, WordType = LexicalType.Preposition, Language = this } } }); } }
/* * 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); }
private void EnsureDictionary() { Lexeme collective = new Lexeme() { Name = Collective, WordForms = new IDictata[] { new Dictata() { Name = Collective, Determinant = false, Feminine = Feminine, Plural = true, Positional = LexicalPosition.None, Perspective = NarrativePerspective.None, Possessive = false, Tense = LexicalTense.None, Semantics = new HashSet <string>() { "gender" }, WordType = LexicalType.Pronoun } } }; Lexeme possessive = new Lexeme() { Name = Possessive, WordForms = new IDictata[] { new Dictata() { Name = Possessive, Determinant = false, Feminine = Feminine, Plural = false, Positional = LexicalPosition.None, Perspective = NarrativePerspective.None, Possessive = true, Tense = LexicalTense.None, Semantics = new HashSet <string>() { "gender" }, WordType = LexicalType.Pronoun } } }; Lexeme baseWord = new Lexeme() { Name = Base, WordForms = new IDictata[] { new Dictata() { Name = Base, Determinant = false, Feminine = Feminine, Plural = false, Positional = LexicalPosition.None, Perspective = NarrativePerspective.None, Possessive = false, Tense = LexicalTense.None, Semantics = new HashSet <string>() { "gender" }, WordType = LexicalType.Pronoun } } }; Lexeme adult = new Lexeme() { Name = Adult, WordForms = new IDictata[] { new Dictata() { Name = Adult, Determinant = false, Feminine = Feminine, Plural = false, Positional = LexicalPosition.None, Perspective = NarrativePerspective.None, Semantics = new HashSet <string>() { "adult", "gender" }, Possessive = false, Tense = LexicalTense.None, WordType = LexicalType.Noun } } }; Lexeme child = new Lexeme() { Name = Child, WordForms = new IDictata[] { new Dictata() { Name = Child, Determinant = false, Feminine = Feminine, Plural = false, Positional = LexicalPosition.None, Perspective = NarrativePerspective.None, Semantics = new HashSet <string>() { "child", "gender" }, Possessive = false, Tense = LexicalTense.None, WordType = LexicalType.Noun } } }; LexicalProcessor.VerifyLexeme(child); LexicalProcessor.VerifyLexeme(adult); LexicalProcessor.VerifyLexeme(baseWord); LexicalProcessor.VerifyLexeme(possessive); LexicalProcessor.VerifyLexeme(collective); }