Exemple #1
0
        /// <summary>
        /// Alter the lex entirely including all of its sublex
        /// </summary>
        /// <param name="context">Contextual nature of the request.</param>
        /// <param name="obfuscationLevel">-100 to 100 range.</param>
        /// <returns>the new lex</returns>
        private ILexica Mutate(MessagingType sensoryType, short obfuscationLevel = 0)
        {
            IDictata dict   = GetDictata();
            ILexica  newLex = Clone();

            if (dict != null)
            {
                IDictata newDict = null;
                if (obfuscationLevel != 0)
                {
                    newDict = Thesaurus.ObscureWord(dict, obfuscationLevel);
                }
                else if (Type != LexicalType.ProperNoun &&
                         (Context.Severity + Context.Elegance + Context.Quality > 0 ||
                          Context.Language != dict.Language ||
                          Context.Plural != dict.Plural ||
                          Context.Possessive != dict.Possessive ||
                          Context.Tense != dict.Tense ||
                          Context.Perspective != dict.Perspective ||
                          Context.Determinant != dict.Determinant ||
                          Context.GenderForm.Feminine != dict.Feminine))
                {
                    newDict = Thesaurus.GetSynonym(dict, Context);
                }

                if (newDict != null)
                {
                    newLex.Phrase = newDict.Name;
                }
            }

            return(newLex);
        }
Exemple #2
0
        /// <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();
        }