Ejemplo n.º 1
0
        /// <summary>
        /// Create or modify a lexeme within this language
        /// </summary>
        /// <param name="word">the word we're making</param>
        /// <returns></returns>
        public ILexeme CreateOrModifyLexeme(string word, LexicalType form, string[] semantics)
        {
            word = word.ToLower();

            Regex rgx = new Regex("[^a-z -]");

            word = rgx.Replace(word, "");

            if (string.IsNullOrWhiteSpace(word) || word.All(ch => ch == '-') || word.IsNumeric())
            {
                return(null);
            }

            ILexeme lex = ConfigDataCache.Get <ILexeme>(string.Format("{0}_{1}_{2}", ConfigDataType.Dictionary, Name, word));

            if (lex == null)
            {
                lex = new Lexeme()
                {
                    Name     = word,
                    Language = this
                };

                lex.SystemSave();
                lex.PersistToCache();
            }

            if (form != LexicalType.None && lex.GetForm(form, semantics, false) == null)
            {
                var newDict = new Dictata()
                {
                    Name      = word,
                    WordType  = form,
                    Language  = this,
                    Semantics = new HashSet <string>(semantics)
                };

                lex.AddNewForm(newDict);
            }

            return(lex);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// creates a related dictata and lexeme with a new word
        /// </summary>
        /// <param name="synonym"></param>
        /// <returns></returns>
        public ILexeme MakeRelatedWord(ILanguage language, string word, bool synonym, IDictata existingWord = null)
        {
            ILexeme possibleLex = ConfigDataCache.Get <ILexeme>(new ConfigDataCacheKey(typeof(ILexeme), string.Format("{0}_{1}", language.Name, word), ConfigDataType.Dictionary));

            if (possibleLex == null)
            {
                possibleLex = new Lexeme()
                {
                    Name        = word,
                    IsSynMapped = false,
                    Language    = language
                };
            }

            IDictata newDict = existingWord;

            if (newDict == null)
            {
                newDict = new Dictata()
                {
                    Name        = word,
                    Language    = language,
                    Severity    = Severity,
                    Quality     = Quality,
                    Elegance    = Elegance,
                    Tense       = Tense,
                    WordType    = WordType,
                    Feminine    = Feminine,
                    Possessive  = Possessive,
                    Plural      = Plural,
                    Determinant = Determinant,
                    Positional  = Positional,
                    Perspective = Perspective,
                    Semantics   = Semantics
                };
            }

            HashSet <IDictata> synonyms = Synonyms;

            synonyms.Add(this);

            if (synonym)
            {
                newDict.Synonyms = synonyms;
                newDict.Antonyms = Antonyms;

                HashSet <IDictata> mySynonyms = Synonyms;
                mySynonyms.Add(newDict);

                Synonyms = mySynonyms;
            }
            else
            {
                newDict.Synonyms = Antonyms;
                newDict.Antonyms = synonyms;

                HashSet <IDictata> antonyms = Antonyms;
                antonyms.Add(newDict);

                Antonyms = antonyms;
            }

            possibleLex.AddNewForm(newDict);
            possibleLex.PersistToCache();
            possibleLex.SystemSave();

            possibleLex.MapSynNet();

            var myLex = GetLexeme();

            myLex.SystemSave();
            myLex.PersistToCache();

            return(possibleLex);
        }