public void SaveGlobalTest() { IGlobalConfig config = null; ConfigManager.Create(out config); ConfigManager.Save(config); }
public AccountConfig(IAccount account) { _account = account; Acquaintences = new List <IAcquaintence>(); Notifications = new List <IPlayerMessage>(); Playlists = new HashSet <IPlaylist>(); Combos = Enumerable.Empty <IFightingArtCombination>(); UIModules = Enumerable.Empty <Tuple <IUIModule, int> >(); if (string.IsNullOrWhiteSpace(Name)) { Name = _account.GlobalIdentityHandle; } IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); if (globalConfig != null) { UILanguage = globalConfig.BaseLanguage; } UITutorialMode = true; MusicMuted = true; GossipSubscriber = true; }
public ActionResult GlobalConfig(DashboardViewModel vModel) { ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId()); IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); globalConfig.WebsocketPortalActive = vModel.WebsocketPortalActive; globalConfig.AdminsOnly = vModel.AdminsOnly; globalConfig.UserCreationActive = vModel.UserCreationActive; globalConfig.BaseLanguage = vModel.BaseLanguage; globalConfig.AzureTranslationKey = vModel.AzureTranslationKey; globalConfig.TranslationActive = vModel.TranslationActive; globalConfig.DeepLexActive = vModel.DeepLexActive; globalConfig.MirriamDictionaryKey = vModel.MirriamDictionaryKey; globalConfig.MirriamThesaurusKey = vModel.MirriamThesaurusKey; string message; if (globalConfig.Save(authedUser.GameAccount, authedUser.GetStaffRank(User))) { LoggingUtility.LogAdminCommandUsage("*WEB* - EditGlobalConfig[" + globalConfig.UniqueKey.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle); message = "Edit Successful."; } else { message = "Error; Edit failed."; } return(RedirectToAction("Index", new { Message = message })); }
/// <summary> /// Verify the dictionary has this word already /// </summary> /// <param name="lexeme">dictata to check</param> public static ILexeme VerifyLexeme(ILexeme lexeme) { if (lexeme == null || string.IsNullOrWhiteSpace(lexeme.Name) || lexeme.Name.IsNumeric()) { return(null); } //Set the language to default if it is absent and save it, if it has a language it already exists if (lexeme.Language == null) { IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); if (globalConfig.BaseLanguage != null) { lexeme.Language = globalConfig.BaseLanguage; } } ConfigDataCacheKey cacheKey = new ConfigDataCacheKey(lexeme); ILexeme maybeLexeme = ConfigDataCache.Get <ILexeme>(cacheKey); if (maybeLexeme != null) { lexeme = maybeLexeme; } lexeme.IsSynMapped = false; lexeme.MapSynNet(); lexeme.FillLanguages(); return(lexeme); }
/// <summary> /// Make a dictata from a lexica /// </summary> /// <param name="lexica">the incoming lexica phrase</param> public Dictata(ILexica lexica) { Name = ""; Antonyms = new HashSet <IDictata>(); Synonyms = new HashSet <IDictata>(); PhraseAntonyms = new HashSet <IDictataPhrase>(); PhraseSynonyms = new HashSet <IDictataPhrase>(); Semantics = new HashSet <string>(); IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); if (lexica.Context?.Language == null) { if (globalConfig?.BaseLanguage == null) { Language = ConfigDataCache.GetAll <ILanguage>().FirstOrDefault(); } else { Language = globalConfig.BaseLanguage; } } else { Language = lexica.Context.Language; } ILexeme maybeLex = ConfigDataCache.Get <ILexeme>( new ConfigDataCacheKey(typeof(ILexeme), string.Format("{0}_{1}", Language.Name, lexica.Phrase), ConfigDataType.Dictionary)); if (maybeLex == null) { Name = lexica.Phrase; WordType = lexica.Type; } else if (maybeLex.WordForms.Any(form => form.WordType == lexica.Type)) { IDictata wordForm = maybeLex.WordForms.FirstOrDefault(form => form.WordType == lexica.Type); Name = lexica.Phrase; WordType = lexica.Type; Synonyms = wordForm.Synonyms; Antonyms = wordForm.Antonyms; PhraseSynonyms = wordForm.PhraseSynonyms; PhraseAntonyms = wordForm.PhraseAntonyms; Determinant = wordForm.Determinant; Elegance = wordForm.Elegance; Feminine = wordForm.Feminine; Perspective = wordForm.Perspective; Plural = wordForm.Plural; Positional = wordForm.Positional; Possessive = wordForm.Possessive; Quality = wordForm.Quality; Semantics = wordForm.Semantics; Severity = wordForm.Severity; Tense = wordForm.Tense; } }
public KafkaEventService( ILogger <KafkaEventService> logger, ICommonMessageService commonMessageService, IBotService botService, IGlobalConfig globalConfig) { _logger = logger; _commonMessageService = commonMessageService; _botService = botService; _httpClient = new HttpClient(); _globalConfig = globalConfig; }
private void SetLanguage(ILanguage language) { if (language == null || language.SentenceRules == null || !language.SentenceRules.Any()) { IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); Language = globalConfig.BaseLanguage; } else { Language = language; } }
public static IDictataPhrase GetPhrase(LexicalContext context) { if (context.Language == null) { IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); context.Language = globalConfig.BaseLanguage; } IEnumerable <IDictataPhrase> possibleWords = ConfigDataCache.GetAll <IDictataPhrase>().Where(dict => dict.Language == context.Language && dict.SuitableForUse); return(possibleWords.OrderByDescending(word => GetSynonymRanking(word, context)).FirstOrDefault()); }
public ActionResult Register() { IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); RegisterViewModel vModel = new RegisterViewModel(); if (!globalConfig.UserCreationActive) { ModelState.AddModelError("", "New account registration is currently locked."); vModel.NewUserLocked = true; } return(View(vModel)); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } ApplicationUser potentialUser = UserManager.FindByName(model.Email); if (potentialUser != null) { IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); if (globalConfig.AdminsOnly && potentialUser.GetStaffRank(User) == StaffRank.Player) { ModelState.AddModelError("", "The system is currently locked to staff members only. Please try again later and check the home page for any announcements and news."); return(View(model)); } } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true SignInStatus result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: //Check for a valid character, zone and account Account account = potentialUser.GameAccount; if (account == null) { ModelState.AddModelError("", "Your account is having technical difficulties. Please contact an administrator."); return(View(model)); } return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } }
public AccountConfig() { Acquaintences = new List <IAcquaintence>(); Notifications = new List <IPlayerMessage>(); Playlists = new HashSet <IPlaylist>(); UIModules = Enumerable.Empty <Tuple <IUIModule, int> >(); IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); if (globalConfig != null) { UILanguage = globalConfig.BaseLanguage; } }
public static IDictata ObscureWord(IDictata word, short obscureStrength) { if (word.Language == null) { IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); word.Language = globalConfig.BaseLanguage; } IEnumerable <IDictata> possibleWords = ConfigDataCache.GetAll <IDictata>().Where(dict => dict.GetLexeme().SuitableForUse && dict.Language == word.Language && dict.WordType == word.WordType); return(GetObscuredWord(word, possibleWords, obscureStrength)); }
/// <summary> /// Load an existing global settings configuration from disk. /// </summary> /// <param name="config">global settings configuration</param> public static void Load(out IGlobalConfig config) { config = null; using (FileStream stream = ReadStream("GlobalSettings")) { if (stream == null) { throw new ArgumentNullException("stream", "A valid stream must be provided."); } XmlSerializer serializer = new XmlSerializer(typeof(GlobalSettings)); config = (IGlobalConfig)serializer.Deserialize(stream); stream.Dispose(); } }
public Lexeme() { WordForms = new IDictata[0]; Name = string.Empty; IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); if (globalConfig?.BaseLanguage == null) { Language = ConfigDataCache.GetAll <ILanguage>().FirstOrDefault(); } else { Language = globalConfig.BaseLanguage; } }
/// <summary> /// Map the synnet of this word /// </summary> public bool MapSynNet() { //Not a whole lot of point here if (IsSynMapped) { return(true); } IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); if (globalConfig?.DeepLexActive ?? false) { Processor.StartSubscriptionLoop("WordNetMapping", DeepLex, 2000, true); } return(true); }
public Dictata() { IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); if (globalConfig?.BaseLanguage == null) { Language = ConfigDataCache.GetAll <ILanguage>().FirstOrDefault(); } else { Language = globalConfig.BaseLanguage; } Name = ""; WordType = LexicalType.None; Antonyms = new HashSet <IDictata>(); Synonyms = new HashSet <IDictata>(); Semantics = new HashSet <string>(); }
private static string RunProcessing(string testName, int stepNumber, string format, IEnumerable <XElement> values) { Validate(testName, stepNumber, format, values); if ((string.IsNullOrEmpty(format)) && ((values != null) && (values.Count() > 0))) { return(values.Aggregate("", (a, n) => String.IsNullOrEmpty(a) ? n.Value : " " + n.Value)); } else { IGlobalConfig globalConfig = null; ConfigManager.Load(out globalConfig); foreach (string token in format.Split(new char[] { '{', '}' }, StringSplitOptions.RemoveEmptyEntries).Where(t => t.Contains("Global."))) { string name = token.Trim().Replace("Global.", ""); format = format.Replace("{" + token + "}", Convert.ToString(typeof(IGlobalConfig).GetProperty(name).GetValue(globalConfig, null))); } return(format); } }
public DictataPhrase() { Words = new HashSet <IDictata>(); Antonyms = new HashSet <IDictata>(); Synonyms = new HashSet <IDictata>(); PhraseAntonyms = new HashSet <IDictataPhrase>(); PhraseSynonyms = new HashSet <IDictataPhrase>(); Semantics = new HashSet <string>(); Name = string.Empty; IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); if (globalConfig?.BaseLanguage == null) { Language = ConfigDataCache.GetAll <ILanguage>().FirstOrDefault(); } else { Language = globalConfig.BaseLanguage; } }
public UIConfigProperties(string name, IGlobalConfig globalConfig, ISerialConfig serialConfig1, ISerialConfig serialConfig2, ISerialConfig serialConfig3, ISerialConfig serialConfig4, IGpibConfig sigGenConfig1, IGpibConfig sigGenConfig2, IGpibConfig powerConfig1, IGpibConfig powerConfig2, IGpibConfig powerConfig3, IGpibConfig powerConfig4, IGpibConfig powerMeter, ITelnetConfig telentConfig) { Name = name; SerialConfig1 = serialConfig1; SerialConfig2 = serialConfig2; SerialConfig3 = serialConfig3; SerialConfig4 = serialConfig4; GlobalConfig = globalConfig; SigGenConfig1 = sigGenConfig1; SigGenConfig2 = sigGenConfig2; PowerConfig1 = powerConfig1; PowerConfig2 = powerConfig2; PowerConfig3 = powerConfig3; PowerConfig4 = powerConfig4; PowerMeter = powerMeter; TelnetConfig = telentConfig; }
public Dictata(string name, short formGrouping) { IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); if (globalConfig?.BaseLanguage == null) { Language = ConfigDataCache.GetAll <ILanguage>().FirstOrDefault(); } else { Language = globalConfig.BaseLanguage; } Name = name.ToLower(); FormGroup = formGrouping; WordType = LexicalType.None; Antonyms = new HashSet <IDictata>(); Synonyms = new HashSet <IDictata>(); PhraseAntonyms = new HashSet <IDictataPhrase>(); PhraseSynonyms = new HashSet <IDictataPhrase>(); Semantics = new HashSet <string>(); }
/// <summary> /// Verify the dictionary has this word already /// </summary> /// <param name="lexeme">dictata to check</param> public static ILexeme VerifyLexeme(ILexeme lexeme) { if (lexeme == null || string.IsNullOrWhiteSpace(lexeme.Name) || lexeme.Name.IsNumeric()) { return(null); } var deepLex = false; //Set the language to default if it is absent and save it, if it has a language it already exists if (lexeme.Language == null) { IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); if (globalConfig.BaseLanguage != null) { lexeme.Language = globalConfig.BaseLanguage; } deepLex = globalConfig?.DeepLexActive ?? false; } ILexeme maybeLexeme = ConfigDataCache.Get <ILexeme>(string.Format("{0}_{1}_{2}", ConfigDataType.Dictionary, lexeme.Language, lexeme.Name)); if (maybeLexeme != null) { lexeme = maybeLexeme; } lexeme.IsSynMapped = false; lexeme.PersistToCache(); lexeme.SystemSave(); lexeme.MapSynNet(); return(lexeme); }
//Also called Dashboard in most of the html public ActionResult Index() { IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); IGossipConfig gossipConfig = ConfigDataCache.Get <IGossipConfig>(new ConfigDataCacheKey(typeof(IGossipConfig), "GossipSettings", ConfigDataType.GameWorld)); DashboardViewModel dashboardModel = new DashboardViewModel { AuthedUser = UserManager.FindById(User.Identity.GetUserId()), Inanimates = TemplateCache.GetAll <IInanimateTemplate>(), NPCs = TemplateCache.GetAll <INonPlayerCharacterTemplate>(), Zones = TemplateCache.GetAll <IZoneTemplate>(), Worlds = TemplateCache.GetAll <IGaiaTemplate>(), Locales = TemplateCache.GetAll <ILocaleTemplate>(), Rooms = TemplateCache.GetAll <IRoomTemplate>(), HelpFiles = TemplateCache.GetAll <IHelp>(), Races = TemplateCache.GetAll <IRace>(), Celestials = TemplateCache.GetAll <ICelestial>(), Journals = TemplateCache.GetAll <IJournalEntry>(), DimensionalModels = TemplateCache.GetAll <IDimensionalModelData>(), Flora = TemplateCache.GetAll <IFlora>(), Fauna = TemplateCache.GetAll <IFauna>(), Minerals = TemplateCache.GetAll <IMineral>(), Materials = TemplateCache.GetAll <IMaterial>(), DictionaryWords = ConfigDataCache.GetAll <ILexeme>(), Languages = ConfigDataCache.GetAll <ILanguage>(), Genders = TemplateCache.GetAll <IGender>(), UIModules = ConfigDataCache.GetAll <IUIModule>(), FightingArts = TemplateCache.GetAll <IFightingArt>(), LiveTaskTokens = Processor.GetAllLiveTaskStatusTokens(), LivePlayers = LiveCache.GetAll <IPlayer>().Count(), LiveInanimates = LiveCache.GetAll <IInanimate>().Count(), LiveNPCs = LiveCache.GetAll <INonPlayerCharacter>().Count(), LiveZones = LiveCache.GetAll <IZone>().Count(), LiveWorlds = LiveCache.GetAll <IGaia>().Count(), LiveLocales = LiveCache.GetAll <ILocale>().Count(), LiveRooms = LiveCache.GetAll <IRoom>().Count(), ConfigDataObject = globalConfig, WebsocketPortalActive = globalConfig.WebsocketPortalActive, AdminsOnly = globalConfig.AdminsOnly, UserCreationActive = globalConfig.UserCreationActive, BaseLanguage = globalConfig.BaseLanguage, AzureTranslationKey = globalConfig.AzureTranslationKey, TranslationActive = globalConfig.TranslationActive, DeepLexActive = globalConfig.DeepLexActive, MirriamDictionaryKey = globalConfig.MirriamDictionaryKey, MirriamThesaurusKey = globalConfig.MirriamThesaurusKey, QualityChange = new string[0], QualityChangeValue = new int[0], ValidZones = TemplateCache.GetAll <IZoneTemplate>(true), ValidLanguages = ConfigDataCache.GetAll <ILanguage>(), GossipConfigDataObject = gossipConfig, GossipActive = gossipConfig.GossipActive, ClientId = gossipConfig.ClientId, ClientSecret = gossipConfig.ClientSecret, ClientName = gossipConfig.ClientName, SuspendMultiplier = gossipConfig.SuspendMultiplier, SuspendMultiplierMaximum = gossipConfig.SuspendMultiplierMaximum, SupportedChannels = gossipConfig.SupportedChannels, SupportedFeatures = gossipConfig.SupportedFeatures }; return(View(dashboardModel)); }
/// <summary> /// Save the global settings configuration for the given process. /// </summary> /// <param name="config">global settings configuration</param> public static void Save(IGlobalConfig config) { Save("GlobalSettings", (object)config); }
public GlobalConfigProperties(string name, IGlobalConfig globalConfig) { Name = name; GlobalConfig = globalConfig; }
/// <summary> /// Create a new global settings configuration filled with default values. /// </summary> /// <param name="config">global settings configuration</param> public static void Create(out IGlobalConfig config) { config = new GlobalSettings(); }
public GlobalConfigInfo(IGlobalConfig globalConfig) : base(globalConfig) { }
/// <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> /// Add language translations for this /// </summary> public void FillLanguages() { IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); //Don't do this if: we have no config, translation is turned off or lacking in the azure key, the language is not a human-ui language //it isn't an approved language, the word is a proper noun or the language isnt the base language at all if (globalConfig == null || !globalConfig.TranslationActive || string.IsNullOrWhiteSpace(globalConfig.AzureTranslationKey) || !Language.UIOnly || !Language.SuitableForUse || ContainedTypes().Contains(LexicalType.ProperNoun) || Language != globalConfig.BaseLanguage) { return; } IEnumerable <ILanguage> otherLanguages = ConfigDataCache.GetAll <ILanguage>().Where(lang => lang != Language && lang.SuitableForUse && lang.UIOnly); foreach (ILanguage language in otherLanguages) { short formGrouping = -1; string newName = string.Empty; Lexeme newLexeme = new Lexeme() { Language = language }; foreach (IDictata word in WordForms) { LexicalContext context = new LexicalContext(null) { Language = language, Perspective = word.Perspective, Tense = word.Tense, Position = word.Positional, Determinant = word.Determinant, Plural = word.Plural, Possessive = word.Possessive, Elegance = word.Elegance, Quality = word.Quality, Semantics = word.Semantics, Severity = word.Severity, GenderForm = new Gender() { Feminine = word.Feminine } }; IDictata translatedWord = Thesaurus.GetSynonym(word, context); //no linguistic synonym if (translatedWord == this) { string newWord = Thesaurus.GetTranslatedWord(globalConfig.AzureTranslationKey, Name, Language, language); if (!string.IsNullOrWhiteSpace(newWord)) { newName = newWord; newLexeme.Name = newName; Dictata newDictata = new Dictata(newWord, formGrouping++) { Elegance = word.Elegance, Severity = word.Severity, Quality = word.Quality, Determinant = word.Determinant, Plural = word.Plural, Perspective = word.Perspective, Feminine = word.Feminine, Positional = word.Positional, Possessive = word.Possessive, Semantics = word.Semantics, Antonyms = word.Antonyms, Synonyms = word.Synonyms, PhraseAntonyms = word.PhraseAntonyms, PhraseSynonyms = word.PhraseSynonyms, Tense = word.Tense, WordType = word.WordType }; newDictata.Synonyms = new HashSet <IDictata>(word.Synonyms) { word }; word.Synonyms = new HashSet <IDictata>(word.Synonyms) { newDictata }; newLexeme.AddNewForm(newDictata); } } } if (newLexeme.WordForms.Count() > 0) { newLexeme.SystemSave(); newLexeme.PersistToCache(); } } SystemSave(); PersistToCache(); }
/// <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); }
public static void PreloadSupportingEntities() { //Load the "config" data first ConfigData.LoadEverythingToCache(); LexicalProcessor.LoadWordnet(); IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); //We dont move forward without a global config if (globalConfig == null) { globalConfig = new GlobalConfig(); globalConfig.SystemSave(); } if (globalConfig.BaseLanguage == null) { ILanguage baseLanguage = ConfigDataCache.GetAll <ILanguage>().FirstOrDefault(); if (baseLanguage == null) { LoggingUtility.Log("There are no valid languages. Generating new base language.", LogChannels.SystemErrors, true); baseLanguage = new Language() { Name = "English", GoogleLanguageCode = "en-us", AntecendentPunctuation = true, PrecedentPunctuation = false, Gendered = false, UIOnly = true }; baseLanguage.SystemSave(); } globalConfig.BaseLanguage = baseLanguage; globalConfig.SystemSave(); } //Ensure we have base words for the language every time globalConfig.BaseLanguage.SystemSave(); //Hoover up all the verbs from commands that someone might have coded ProcessSystemVerbs(globalConfig.BaseLanguage); IGossipConfig gossipConfig = ConfigDataCache.Get <IGossipConfig>(new ConfigDataCacheKey(typeof(IGossipConfig), "GossipSettings", ConfigDataType.GameWorld)); HttpApplication instance = HttpContext.Current.ApplicationInstance; Assembly asm = instance.GetType().BaseType.Assembly; Version v = asm.GetName().Version; //We dont move forward without a global config if (gossipConfig == null) { gossipConfig = new GossipConfig { ClientName = "Warrens: White Sands" }; } //Update version gossipConfig.Version = string.Format(CultureInfo.InvariantCulture, @"{0}.{1}.{2} (r{3})", v.Major, v.Minor, v.Build, v.Revision); gossipConfig.SystemSave(); //Load structural data next Templates.LoadEverythingToCache(); HotBackup hotBack = new HotBackup(); //Our live data restore failed, reload the entire world from backing data if (!hotBack.RestoreLiveBackup()) { hotBack.NewWorldFallback(); } if (gossipConfig.GossipActive) { Func <Member[]> playerList = () => LiveCache.GetAll <IPlayer>() .Where(player => player.Descriptor != null && player.Template <IPlayerTemplate>().Account.Config.GossipSubscriber) .Select(player => new Member() { Name = player.AccountHandle, WriteTo = (message) => player.WriteTo(new string[] { message }), BlockedMembers = player.Template <IPlayerTemplate>().Account.Config.Acquaintences.Where(acq => !acq.IsFriend).Select(acq => acq.PersonHandle), Friends = player.Template <IPlayerTemplate>().Account.Config.Acquaintences.Where(acq => acq.IsFriend).Select(acq => acq.PersonHandle) }).ToArray(); void exceptionLogger(Exception ex) => LoggingUtility.LogError(ex); void activityLogger(string message) => LoggingUtility.Log(message, LogChannels.GossipServer); GossipClient gossipServer = new GossipClient(gossipConfig, exceptionLogger, activityLogger, playerList); Task.Run(() => gossipServer.Launch()); LiveCache.Add(gossipServer, "GossipWebClient"); } Func <bool> backupFunction = hotBack.WriteLiveBackup; Func <bool> backingDataBackupFunction = Templates.WriteFullBackup; //every 30 minutes after half an hour Processor.StartSingeltonChainedLoop("HotBackup", 30 * 60, 30 * 60, -1, backupFunction); //every 2 hours after 1 hour Processor.StartSingeltonChainedLoop("BackingDataFullBackup", 60 * 60, 120 * 60, -1, backingDataBackupFunction); }
public ActionResult WordFight(short wordOneId, string wordOneName, short wordTwoId, string wordTwoName, WordFightViewModel vModel) { string message = string.Empty; IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); ILexeme lexOne = ConfigDataCache.Get <ILexeme>(string.Format("{0}_{1}_{2}", ConfigDataType.Dictionary, globalConfig.BaseLanguage.Name, wordOneName)); ILexeme lexTwo = ConfigDataCache.Get <ILexeme>(string.Format("{0}_{1}_{2}", ConfigDataType.Dictionary, globalConfig.BaseLanguage.Name, wordTwoName)); if (lexOne != null && lexTwo != null) { IDictata wordOne = lexOne.GetForm(wordOneId); IDictata wordTwo = lexTwo.GetForm(wordTwoId); if (wordOne != null || wordTwo != null) { switch (vModel.Elegance) { case 1: wordOne.Elegance += 1; wordTwo.Elegance -= 1; break; case 2: wordOne.Elegance -= 1; wordTwo.Elegance += 1; break; } switch (vModel.Severity) { case 1: wordOne.Severity += 1; wordTwo.Severity -= 1; break; case 2: wordOne.Severity -= 1; wordTwo.Severity += 1; break; } switch (vModel.Quality) { case 1: wordOne.Quality += 1; wordTwo.Quality -= 1; break; case 2: wordOne.Quality -= 1; wordTwo.Quality += 1; break; } wordOne.TimesRated += 1; wordTwo.TimesRated += 1; lexOne.PersistToCache(); lexOne.SystemSave(); lexTwo.PersistToCache(); lexTwo.SystemSave(); } else { message = "Invalid data"; } } else { message = "Invalid data"; } return(RedirectToAction("WordFight", new { Message = message })); }