/// <summary> /// Render this in a short descriptive style /// </summary> /// <param name="viewer">The entity looking</param> /// <returns>the output strings</returns> public override ILexicalParagraph GetFullDescription(IEntity viewer, MessagingType[] sensoryTypes = null) { if (sensoryTypes == null || sensoryTypes.Count() == 0) { sensoryTypes = new MessagingType[] { MessagingType.Audible, MessagingType.Olefactory, MessagingType.Psychic, MessagingType.Tactile, MessagingType.Taste, MessagingType.Visible }; } LexicalContext collectiveContext = new LexicalContext(viewer) { Determinant = true, Perspective = NarrativePerspective.SecondPerson, Plural = false, Position = LexicalPosition.None, Tense = LexicalTense.Present }; LexicalContext discreteContext = new LexicalContext(viewer) { Determinant = false, Perspective = NarrativePerspective.ThirdPerson, Plural = false, Position = LexicalPosition.Far, Tense = LexicalTense.Present }; //Self becomes the first sense in the list List <ISensoryEvent> sensoryOutput = new List <ISensoryEvent>(); foreach (MessagingType sense in sensoryTypes) { ISensoryEvent me = GetSelf(sense); switch (sense) { case MessagingType.Audible: me.Strength = GetAudibleDelta(viewer); IEnumerable <ISensoryEvent> aDescs = GetAudibleDescriptives(viewer); if (aDescs.Count() == 0) { continue; } me.TryModify(aDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive)); ILexica uberSounds = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "hear", collectiveContext); uberSounds.TryModify(aDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event)); foreach (ISensoryEvent desc in aDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject)) { Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext); newDesc.TryModify(desc.Event.Modifiers); uberSounds.TryModify(newDesc); } if (uberSounds.Modifiers.Any()) { me.TryModify(uberSounds); } break; case MessagingType.Olefactory: me.Strength = GetOlefactoryDelta(viewer); IEnumerable <ISensoryEvent> oDescs = GetOlefactoryDescriptives(viewer); if (oDescs.Count() == 0) { continue; } me.TryModify(oDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive)); ILexica uberSmells = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "smell", collectiveContext); uberSmells.TryModify(oDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event)); foreach (ISensoryEvent desc in oDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject)) { Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext); newDesc.TryModify(desc.Event.Modifiers); uberSmells.TryModify(newDesc); } if (uberSmells.Modifiers.Any()) { me.TryModify(uberSmells); } break; case MessagingType.Psychic: me.Strength = GetPsychicDelta(viewer); IEnumerable <ISensoryEvent> pDescs = GetPsychicDescriptives(viewer); if (pDescs.Count() == 0) { continue; } me.TryModify(pDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive)); Lexica collectivePsy = new Lexica(LexicalType.Pronoun, GrammaticalType.Subject, "you", collectiveContext); ILexica uberPsy = collectivePsy.TryModify(LexicalType.Verb, GrammaticalType.Verb, "sense"); uberPsy.TryModify(pDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event)); foreach (ISensoryEvent desc in pDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject)) { Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext); newDesc.TryModify(desc.Event.Modifiers); uberPsy.TryModify(newDesc); } if (uberPsy.Modifiers.Any()) { me.TryModify(collectivePsy); } break; case MessagingType.Taste: continue; case MessagingType.Tactile: me.Strength = GetTactileDelta(viewer); //Add the temperature me.TryModify(LexicalType.Verb, GrammaticalType.Verb, "feels").TryModify(new Lexica[] { new Lexica(LexicalType.Adjective, GrammaticalType.Descriptive, MeteorologicalUtilities.ConvertHumidityToType(EffectiveHumidity()).ToString(), collectiveContext), new Lexica(LexicalType.Adjective, GrammaticalType.Descriptive, MeteorologicalUtilities.ConvertTemperatureToType(EffectiveTemperature()).ToString(), collectiveContext) }); break; case MessagingType.Visible: me.Strength = GetVisibleDelta(viewer); IEnumerable <ISensoryEvent> vDescs = GetVisibleDescriptives(viewer); if (vDescs.Count() > 0) { me.TryModify(vDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive)); Lexica collectiveSight = new Lexica(LexicalType.Pronoun, GrammaticalType.Subject, "you", collectiveContext); ILexica uberSight = collectiveSight.TryModify(LexicalType.Verb, GrammaticalType.Verb, "see"); uberSight.TryModify(vDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event)); foreach (ISensoryEvent desc in vDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject)) { Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext); newDesc.TryModify(desc.Event.Modifiers); uberSight.TryModify(newDesc); } if (uberSight.Modifiers.Any()) { me.TryModify(collectiveSight); } } //Describe the size and population of this zone DimensionalSizeDescription zoneSize = GeographicalUtilities.ConvertSizeToType(GetModelDimensions(), GetType()); me.TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, zoneSize.ToString()); //Render people in the zone CrowdSizeDescription populationSize = GeographicalUtilities.GetCrowdSize(GetContents <IMobile>().Count()); string crowdSize = "abandoned"; if ((short)populationSize > (short)zoneSize) { crowdSize = "crowded"; } else if (populationSize > CrowdSizeDescription.Intimate) { crowdSize = "sparsely populated"; } me.TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, crowdSize); break; } if (me != null) { sensoryOutput.Add(me); } } foreach (ICelestial celestial in GetVisibileCelestials(viewer)) { sensoryOutput.AddRange(celestial.RenderAsContents(viewer, sensoryTypes).Events); } foreach (IWeatherEvent wEvent in WeatherEvents) { sensoryOutput.AddRange(wEvent.RenderAsContents(viewer, sensoryTypes).Events); } foreach (INaturalResourceSpawn <IFlora> resource in FloraNaturalResources) { sensoryOutput.AddRange(resource.Resource.RenderResourceCollection(viewer, resource.RateFactor).Events); } foreach (INaturalResourceSpawn <IFauna> resource in FaunaNaturalResources) { sensoryOutput.AddRange(resource.Resource.RenderResourceCollection(viewer, resource.RateFactor).Events); } foreach (INaturalResourceSpawn <IMineral> resource in MineralNaturalResources) { sensoryOutput.AddRange(resource.Resource.RenderResourceCollection(viewer, resource.RateFactor).Events); } //render our locales out foreach (ILocale locale in LiveCache.GetAll <ILocale>().Where(loc => loc.ParentLocation?.TemplateId == TemplateId)) { sensoryOutput.AddRange(locale.RenderAsContents(viewer, sensoryTypes).Events); } //render our locales out foreach (IPathway path in GetPathways()) { sensoryOutput.AddRange(path.RenderAsContents(viewer, sensoryTypes).Events); } return(new LexicalParagraph(sensoryOutput)); }
/// <summary> /// Render this in a short descriptive style /// </summary> /// <param name="viewer">The entity looking</param> /// <returns>the output strings</returns> public override ILexicalParagraph GetFullDescription(IEntity viewer, MessagingType[] sensoryTypes = null) { if (sensoryTypes == null || sensoryTypes.Count() == 0) { sensoryTypes = new MessagingType[] { MessagingType.Audible, MessagingType.Olefactory, MessagingType.Psychic, MessagingType.Tactile, MessagingType.Taste, MessagingType.Visible }; } LexicalContext collectiveContext = new LexicalContext(viewer) { Determinant = true, Perspective = NarrativePerspective.SecondPerson, Plural = false, Position = LexicalPosition.Around, Tense = LexicalTense.Present }; LexicalContext discreteContext = new LexicalContext(viewer) { Determinant = true, Perspective = NarrativePerspective.ThirdPerson, Plural = false, Position = LexicalPosition.Attached, Tense = LexicalTense.Present }; //Self becomes the first sense in the list List <ISensoryEvent> messages = new List <ISensoryEvent>(); foreach (MessagingType sense in sensoryTypes) { ISensoryEvent me = GetSelf(sense); switch (sense) { case MessagingType.Audible: me.Strength = GetAudibleDelta(viewer); IEnumerable <ISensoryEvent> aDescs = GetAudibleDescriptives(viewer); me.TryModify(aDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive)); ILexica uberSounds = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "hear", collectiveContext); uberSounds.TryModify(aDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event)); foreach (ISensoryEvent desc in aDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject)) { Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.Subject, desc.Event.Phrase, discreteContext); newDesc.TryModify(desc.Event.Modifiers); me.TryModify(newDesc); } if (uberSounds.Modifiers.Any(mod => mod.Role == GrammaticalType.Subject)) { me.TryModify(uberSounds); } break; case MessagingType.Olefactory: me.Strength = GetOlefactoryDelta(viewer); IEnumerable <ISensoryEvent> oDescs = GetOlefactoryDescriptives(viewer); me.TryModify(oDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive)); Lexica uberSmells = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "smell", collectiveContext); uberSmells.TryModify(oDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event)); foreach (ISensoryEvent desc in oDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject)) { Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext); newDesc.TryModify(desc.Event.Modifiers); uberSmells.TryModify(newDesc); } if (uberSmells.Modifiers.Any(mod => mod.Role == GrammaticalType.Subject)) { me.TryModify(uberSmells); } break; case MessagingType.Psychic: me.Strength = GetPsychicDelta(viewer); IEnumerable <ISensoryEvent> pDescs = GetPsychicDescriptives(viewer); me.TryModify(pDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive)); Lexica collectivePsy = new Lexica(LexicalType.Pronoun, GrammaticalType.Subject, "you", collectiveContext); ILexica uberPsy = collectivePsy.TryModify(LexicalType.Verb, GrammaticalType.Verb, "sense"); uberPsy.TryModify(pDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event)); foreach (ISensoryEvent desc in pDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject)) { Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext); newDesc.TryModify(desc.Event.Modifiers); uberPsy.TryModify(newDesc); } if (uberPsy.Modifiers.Any(mod => mod.Role == GrammaticalType.Subject)) { me.TryModify(collectivePsy); } break; case MessagingType.Taste: me.Strength = GetTasteDelta(viewer); IEnumerable <ISensoryEvent> taDescs = GetTasteDescriptives(viewer); me.TryModify(taDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive)); Lexica uberTaste = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "taste", collectiveContext); uberTaste.TryModify(taDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event)); foreach (ISensoryEvent desc in taDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject)) { Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext); newDesc.TryModify(desc.Event.Modifiers); uberTaste.TryModify(newDesc); } if (uberTaste.Modifiers.Any(mod => mod.Role == GrammaticalType.Subject)) { me.TryModify(uberTaste); } break; case MessagingType.Tactile: me.Strength = GetTactileDelta(viewer); IEnumerable <ISensoryEvent> tDescs = GetOlefactoryDescriptives(viewer); me.TryModify(tDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive)); Lexica uberTouch = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "feel", collectiveContext); uberTouch.TryModify(tDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event)); foreach (ISensoryEvent desc in tDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject)) { Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext); newDesc.TryModify(desc.Event.Modifiers); uberTouch.TryModify(newDesc); } if (uberTouch.Modifiers.Any(mod => mod.Role == GrammaticalType.Subject)) { me.TryModify(uberTouch); } break; case MessagingType.Visible: me.Strength = GetVisibleDelta(viewer); IEnumerable <ISensoryEvent> vDescs = GetVisibleDescriptives(viewer); me.TryModify(vDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Descriptive)); Lexica uberSight = new Lexica(LexicalType.Verb, GrammaticalType.Verb, "appears", collectiveContext); uberSight.TryModify(vDescs.Where(adesc => adesc.Event.Role == GrammaticalType.DirectObject).Select(adesc => adesc.Event)); foreach (ISensoryEvent desc in vDescs.Where(adesc => adesc.Event.Role == GrammaticalType.Subject)) { Lexica newDesc = new Lexica(desc.Event.Type, GrammaticalType.DirectObject, desc.Event.Phrase, discreteContext); newDesc.TryModify(desc.Event.Modifiers); uberSight.TryModify(newDesc); } if (uberSight.Modifiers.Any(mod => mod.Role == GrammaticalType.Subject)) { me.TryModify(uberSight); } //Describe the size and population of this zone DimensionalSizeDescription objectSize = GeographicalUtilities.ConvertSizeToType(GetModelDimensions(), GetType()); me.TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, objectSize.ToString()); //Render people in the zone ObjectContainmentSizeDescription bulgeSizeAdjective = GeographicalUtilities.GetObjectContainmentSize(GetContents <IInanimate>().Sum(obj => obj.GetModelVolume()), GetModelVolume()); me.TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, bulgeSizeAdjective.ToString()); break; } messages.Add(me); } return(new LexicalParagraph(messages)); }
private ILexica RunObscura(MessagingType sensoryType, ILexica subject, IEntity observer, bool over) { LexicalContext context = new LexicalContext(observer) { Determinant = true, Perspective = NarrativePerspective.FirstPerson, Position = LexicalPosition.Around }; subject.Modifiers = new HashSet <ILexica>(); subject.Type = LexicalType.Verb; subject.Role = GrammaticalType.Verb; subject.Context = context; switch (sensoryType) { case MessagingType.Audible: subject.Phrase = "hear"; if (!over) { subject.TryModify(LexicalType.Noun, GrammaticalType.Subject, "sounds") .TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, "soft"); } else { subject.TryModify(LexicalType.Noun, GrammaticalType.Subject, "sounds") .TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, "loud"); } break; case MessagingType.Olefactory: subject.Phrase = "smell"; if (!over) { subject.TryModify(LexicalType.Noun, GrammaticalType.Subject, "something") .TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, "subtle"); } else { subject.TryModify(LexicalType.Noun, GrammaticalType.Subject, "something") .TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, "pungent"); } break; case MessagingType.Psychic: subject.Phrase = "sense"; if (!over) { subject.TryModify(LexicalType.Noun, GrammaticalType.Subject, "presence") .TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, "vague"); } else { subject.TryModify(LexicalType.Noun, GrammaticalType.Subject, "presence") .TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, "disturbing"); } break; case MessagingType.Tactile: subject.Phrase = "brushes"; context.Position = LexicalPosition.Attached; if (!over) { subject.TryModify(LexicalType.Noun, GrammaticalType.Subject, "skin") .TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, "lightly"); } else { subject.Phrase = "rubs"; context.Elegance = -5; subject.TryModify(LexicalType.Pronoun, GrammaticalType.Subject, "you"); } break; case MessagingType.Taste: subject.Phrase = "taste"; context.Position = LexicalPosition.InsideOf; if (!over) { subject.TryModify(LexicalType.Noun, GrammaticalType.Subject, "something") .TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, "subtle"); } else { context.Elegance = -5; subject.TryModify(LexicalType.Noun, GrammaticalType.Subject, "something") .TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, "offensive"); } break; case MessagingType.Visible: subject.Phrase = "see"; context.Plural = true; if (!over) { subject.TryModify(LexicalType.Noun, GrammaticalType.Subject, "shadows"); } else { subject.TryModify(LexicalType.Noun, GrammaticalType.Subject, "lights") .TryModify(LexicalType.Adjective, GrammaticalType.Descriptive, "blinding"); } break; } return(subject); }
/// <summary> /// Unpacks this applying language rules to expand and add articles/verbs where needed /// </summary> /// <param name="overridingContext">The full lexical context</param> /// <returns>A long description</returns> public IEnumerable <ILexica> Unpack(MessagingType sensoryType, short strength, LexicalContext overridingContext = null) { if (overridingContext != null) { IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); //Sentence must maintain the same language, tense and personage Context.Language = overridingContext.Language ?? Context.Language ?? globalConfig.BaseLanguage; Context.Tense = overridingContext.Tense; Context.Perspective = overridingContext.Perspective; Context.Elegance = overridingContext.Elegance; Context.Severity = overridingContext.Severity; Context.Quality = overridingContext.Quality; } ILexica newLex = Mutate(sensoryType, strength); foreach (IWordRule wordRule in Context.Language.WordRules.Where(rul => rul.Matches(newLex)) .OrderByDescending(rul => rul.RuleSpecificity())) { if (wordRule.NeedsArticle && (!wordRule.WhenPositional || Context.Position != LexicalPosition.None) && !newLex.Modifiers.Any(mod => (mod.Type == LexicalType.Article && !wordRule.WhenPositional && mod.Context.Position == LexicalPosition.None) || (mod.Type == LexicalType.Preposition && wordRule.WhenPositional && mod.Context.Position != LexicalPosition.None))) { LexicalContext articleContext = Context.Clone(); //Make it determinant if the word is plural articleContext.Determinant = Context.Plural || articleContext.Determinant; IDictata article = null; if (wordRule.SpecificAddition != null) { article = wordRule.SpecificAddition; } else { article = Thesaurus.GetWord(articleContext, wordRule.WhenPositional ? LexicalType.Preposition : LexicalType.Article); } if (article != null && !newLex.Modifiers.Any(lx => article.Name.Equals(lx.Phrase, StringComparison.InvariantCultureIgnoreCase))) { ILexica newArticle = newLex.TryModify(wordRule.WhenPositional ? LexicalType.Preposition : LexicalType.Article , GrammaticalType.Descriptive, article.Name, false); if (!wordRule.WhenPositional) { newArticle.Context.Position = LexicalPosition.None; } } } else if (wordRule.SpecificAddition != null && !newLex.Modifiers.Any(lx => wordRule.SpecificAddition.Equals(lx.GetDictata()))) { newLex.TryModify(wordRule.SpecificAddition.WordType, GrammaticalType.Descriptive, wordRule.SpecificAddition.Name); } if (!string.IsNullOrWhiteSpace(wordRule.AddPrefix) && !newLex.Phrase.StartsWith(wordRule.AddPrefix)) { newLex.Phrase = string.Format("{0}{1}", wordRule.AddPrefix, newLex.Phrase.Trim()); } if (!string.IsNullOrWhiteSpace(wordRule.AddSuffix) && !newLex.Phrase.EndsWith(wordRule.AddSuffix)) { newLex.Phrase = string.Format("{1}{0}", wordRule.AddSuffix, newLex.Phrase.Trim()); } } //Placement ordering List <Tuple <ILexica, int> > modifierList = new List <Tuple <ILexica, int> > { new Tuple <ILexica, int>(newLex, 0) }; //modification rules ordered by specificity List <ILexica> currentModifiers = new List <ILexica>(newLex.Modifiers); foreach (ILexica modifier in currentModifiers) { foreach (IWordPairRule wordRule in Context.Language.WordPairRules.Where(rul => rul.Matches(newLex, modifier)) .OrderByDescending(rul => rul.RuleSpecificity())) { if (wordRule.NeedsArticle && (!wordRule.WhenPositional || Context.Position != LexicalPosition.None) && !newLex.Modifiers.Any(mod => (mod.Type == LexicalType.Article && !wordRule.WhenPositional && mod.Context.Position == LexicalPosition.None) || (mod.Type == LexicalType.Preposition && wordRule.WhenPositional && mod.Context.Position != LexicalPosition.None))) { LexicalContext articleContext = Context.Clone(); //Make it determinant if the word is plural articleContext.Determinant = Context.Plural || articleContext.Determinant; IDictata article = null; if (wordRule.SpecificAddition != null) { article = wordRule.SpecificAddition; } else { article = Thesaurus.GetWord(articleContext, wordRule.WhenPositional ? LexicalType.Preposition : LexicalType.Article); } if (article != null && !newLex.Modifiers.Any(lx => article.Name.Equals(lx.Phrase, StringComparison.InvariantCultureIgnoreCase))) { ILexica newArticle = newLex.TryModify(wordRule.WhenPositional ? LexicalType.Preposition : LexicalType.Article , GrammaticalType.Descriptive, article.Name, false); if (!wordRule.WhenPositional) { newArticle.Context.Position = LexicalPosition.None; } } } else if (wordRule.SpecificAddition != null && !newLex.Modifiers.Any(lx => wordRule.SpecificAddition.Equals(lx.GetDictata()))) { newLex.TryModify(wordRule.SpecificAddition.WordType, GrammaticalType.Descriptive, wordRule.SpecificAddition.Name); } if (!string.IsNullOrWhiteSpace(wordRule.AddPrefix) && !newLex.Phrase.StartsWith(wordRule.AddPrefix)) { newLex.Phrase = string.Format("{0}{1}", wordRule.AddPrefix, newLex.Phrase.Trim()); } if (!string.IsNullOrWhiteSpace(wordRule.AddSuffix) && !newLex.Phrase.EndsWith(wordRule.AddSuffix)) { newLex.Phrase = string.Format("{1}{0}", wordRule.AddSuffix, newLex.Phrase.Trim()); } } } foreach (ILexica modifier in newLex.Modifiers) { IWordPairRule rule = Context.Language.WordPairRules.OrderByDescending(rul => rul.RuleSpecificity()) .FirstOrDefault(rul => rul.Matches(newLex, modifier)); if (rule != null) { int i = 0; foreach (ILexica subModifier in modifier.Unpack(sensoryType, strength, overridingContext ?? Context).Distinct()) { modifierList.Add(new Tuple <ILexica, int>(subModifier, rule.ModificationOrder + i++)); } } } return(modifierList.OrderBy(tup => tup.Item2).Select(tup => tup.Item1)); }
/// <summary> /// Create a narrative description from this /// </summary> /// <param name="overridingContext">Context to override the lexica with</param> /// <param name="anonymize">Should we omit the proper name of the initial subject entirely (and only resort to pronouns)</param> /// <returns>A long description</returns> public IEnumerable <ILexicalSentence> Unpack(LexicalContext overridingContext = null, bool anonymize = false) { List <ILexicalSentence> sentences = new List <ILexicalSentence>(); //short circuit empty lexica if (string.IsNullOrWhiteSpace(Event?.Phrase)) { return(sentences); } if (overridingContext != null) { //Sentence must maintain the same language, tense and personage as well as the weight values Event.Context.Language = overridingContext.Language; Event.Context.Tense = overridingContext.Tense; Event.Context.Perspective = overridingContext.Perspective; Event.Context.Elegance = overridingContext.Elegance; Event.Context.Severity = overridingContext.Severity; Event.Context.Quality = overridingContext.Quality; } //Language rules engine, default to base language if we have an empty language if (Event.Context.Language == null || (Event.Context.Language?.WordPairRules?.Count == 0 && Event.Context.Language?.WordRules?.Count == 0)) { IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); Event.Context.Language = globalConfig.BaseLanguage; } if (anonymize) { LexicalContext pronounContext = Event.Context.Clone(); pronounContext.Perspective = NarrativePerspective.SecondPerson; pronounContext.Position = LexicalPosition.None; pronounContext.Tense = LexicalTense.None; pronounContext.Determinant = false; pronounContext.Semantics = new HashSet <string>(); IDictata pronoun = Thesaurus.GetWord(pronounContext, LexicalType.Pronoun); Event.Phrase = pronoun.Name; Event.Type = LexicalType.Pronoun; } List <ILexica> subjects = new List <ILexica> { Event }; subjects.AddRange(Event.Modifiers.Where(mod => mod != null && mod.Role == GrammaticalType.Subject)); Event.Modifiers.RemoveWhere(mod => mod == null || mod.Role == GrammaticalType.Subject); foreach (ILexica subject in subjects) { //This is to catch directly described entities, we have to add a verb to it for it to make sense. "Complete sentence rule" if (subject.Modifiers.Any() && !subject.Modifiers.Any(mod => mod.Role == GrammaticalType.Verb)) { LexicalContext verbContext = subject.Context.Clone(); verbContext.Semantics = new HashSet <string> { "existential" }; verbContext.Determinant = false; IDictata verb = Thesaurus.GetWord(verbContext, LexicalType.Verb); ILexica verbLex = verb.GetLexica(GrammaticalType.Verb, verbContext); verbLex.TryModify(subject.Modifiers); subject.Modifiers = new HashSet <ILexica>(); subject.TryModify(verbLex); } if (subject.Modifiers.Any(mod => mod.Role == GrammaticalType.Subject)) { sentences.Add(subject.MakeSentence(SentenceType.Partial, SensoryType, Strength)); //fragment sentences foreach (ILexica subLex in subject.Modifiers.Where(mod => mod.Role == GrammaticalType.Subject)) { sentences.Add(subLex.MakeSentence(SentenceType.Statement, SensoryType, Strength)); } } else { //full obfuscation happens at 100 only if (Strength <= -100 || Strength >= 100) { ILexica lex = RunObscura(SensoryType, subject, subject.Context.Observer, Strength > 0); sentences.Add(lex.MakeSentence(SentenceType.Statement, SensoryType, Strength)); } else { sentences.Add(subject.MakeSentence(SentenceType.Statement, SensoryType, Strength)); } } } return(sentences); }