Example #1
0
        public int GetPostFixIndex(WordAmount amount, WordCase aCase)
        {
            switch (amount)
            {
            case WordAmount.Plural:
            {
                if (pluralPostfixSelector.ContainsKey(aCase))
                {
                    return(pluralPostfixSelector[aCase]);
                }
                break;
            }

            case WordAmount.Singular:
            {
                if (singularPostfixSelector.ContainsKey(aCase))
                {
                    return(singularPostfixSelector[aCase]);
                }
                break;
            }
            }

            return(0);
        }
Example #2
0
        public static string TransformToCase(this string str, WordCase wordCase)
        {
            if (str == null)
            {
                throw new ArgumentNullException("str");
            }
            switch (wordCase)
            {
            case WordCase.Default:
                return(str);

            case WordCase.LowerCase:
                return(str.ToLower());

            case WordCase.UpperCase:
                return(str.ToUpper());

            case WordCase.WithACapitalLetter:
                return(TransformToCaseWithACapitalLetter(str));

            case WordCase.Mixed:
                return(TransformToMixedLetters(str));

            default:
                throw new UnhandledCaseException(typeof(WordCase), wordCase);
            }
        }
Example #3
0
        /// <summary>
        /// Convert text from Pascal or Camel Case to words in the given case, helpful when parsing enum names to text fit for display in a user interface
        /// </summary>
        /// <param name="input"></param>
        /// <param name="wordCase"></param>
        /// <returns>words</returns>
        public static string convertPascalOrCamelCaseToWords(this string input, WordCase wordCase)
        {
            try
            {
                string output = convertToWords(input);
                switch (wordCase)
                {
                case WordCase.AllLower:
                    output = output.ToLower();
                    break;

                case WordCase.AllUpper:
                    output = output.ToUpper();
                    break;

                case WordCase.Title:
                    output = output.ToTitleCase();
                    break;

                case WordCase.Sentence:
                    output = output.ToSentenceCase();
                    break;

                default:
                    break;
                }
                return(output);
            }
            catch (Exception ex)
            {
                Exception except = new Exception(string.Format("Exception throw in {0}.{1} -- Inner Exception:\n  {2}", MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name, ex.Message), ex);
                throw except;
            }
        }
        public string GetForm(WordGenre genre, WordCase aCase, WordAmount amount,
            AdjectiveLevel level)
        {
            AdjectiveWordToken token = new AdjectiveWordToken(null, aCase, genre, amount, level);
            foreach (AdjectiveWordToken tok in irregulars)
                if (tok.Is(token))
                    return tok.Text;

            return null;
        }
Example #5
0
        public string GetForm(WordCase aCase, WordAmount amount)
        {
            WordToken token = new WordToken(null, aCase, amount);

            foreach (WordToken tok in irregulars)
            {
                if (tok.Is(token))
                {
                    return(tok.Text);
                }
            }

            return(null);
        }
Example #6
0
        public void SetPostIndex(WordCase aCase, WordAmount amount, int postFixIndex)
        {
            switch (amount)
            {
            case WordAmount.Plural:
            {
                if (postFixIndex > 0)
                {
                    if (pluralPostfixSelector.ContainsKey(aCase))
                    {
                        pluralPostfixSelector[aCase] = postFixIndex;
                    }
                    else
                    {
                        pluralPostfixSelector.Add(aCase, postFixIndex);
                    }
                }
                else
                if (pluralPostfixSelector.ContainsKey(aCase))
                {
                    pluralPostfixSelector.Remove(aCase);
                }

                break;
            }

            case WordAmount.Singular:
            {
                if (postFixIndex > 0)
                {
                    if (singularPostfixSelector.ContainsKey(aCase))
                    {
                        singularPostfixSelector[aCase] = postFixIndex;
                    }
                    else
                    {
                        singularPostfixSelector.Add(aCase, postFixIndex);
                    }
                }
                else
                if (singularPostfixSelector.ContainsKey(aCase))
                {
                    singularPostfixSelector.Remove(aCase);
                }

                break;
            }
            }
        }
        public string GetForm(WordGenre genre, WordCase aCase, WordAmount amount,
                              AdjectiveLevel level)
        {
            AdjectiveWordToken token = new AdjectiveWordToken(null, aCase, genre, amount, level);

            foreach (AdjectiveWordToken tok in irregulars)
            {
                if (tok.Is(token))
                {
                    return(tok.Text);
                }
            }

            return(null);
        }
Example #8
0
        private static char GetChar(int index, WordCase wordCase)
        {
            char minChar;
            char maxChar;

            switch (wordCase)
            {
            case WordCase.LowerCase:
                minChar = 'a';
                maxChar = 'z';
                break;

            case WordCase.UpperCase:
                minChar = 'A';
                maxChar = 'Z';
                break;

            case WordCase.Mixed:
                if (RandomHelper.GetBool())
                {
                    minChar = 'a';
                    maxChar = 'z';
                }
                else
                {
                    minChar = 'A';
                    maxChar = 'Z';
                }
                break;

            case WordCase.Default:
            case WordCase.WithACapitalLetter:
                minChar = index == 0
                        ? 'A'
                        : 'a';
                maxChar = index == 0
                        ? 'Z'
                        : 'z';
                break;

            default:
                throw new Exception();
            }
            return(RandomHelper.GetChar(minChar, maxChar));
        }
Example #9
0
        public static IEnumerable <string> Split(string compoundString, CompoundWordCase fromCase,
                                                 WordCase toCase = WordCase.Any)
        {
            if (string.IsNullOrEmpty(compoundString))
            {
                return(Enumerable.Empty <string>());
            }

            if (fromCase.HasSeparator)
            {
                return(compoundString.Split(new[] { fromCase.Separator }, StringSplitOptions.RemoveEmptyEntries)
                       .Select(s => s.ToCase(toCase)));
            }
            if (fromCase.Case == WordCase.TitleCase)
            {
                return(SplitOnTitleCase(compoundString)
                       .Select(s => s.ToCase(toCase)));
            }
            return(new[] { compoundString.ToCase(toCase) });
        }
Example #10
0
        public static string ToCase(string str, WordCase wordCase)
        {
            if (string.IsNullOrEmpty(str) || wordCase == WordCase.Any)
            {
                return(str);
            }

            switch (wordCase)
            {
            case WordCase.LowerCase:
                return(str.ToLower());

            case WordCase.TitleCase:
                return(char.ToUpper(str[0]) + str.Substring(1).ToLower());

            case WordCase.UpperCase:
                return(str.ToUpper());

            default:
                return(str);
            }
        }
Example #11
0
        public static string GetWord(int minLength, int maxLength, WordCase wordCase = WordCase.WithACapitalLetter)
        {
            if (minLength <= 0)
            {
                throw new ArgumentException("minLength must be positive", nameof(minLength));
            }
            if (maxLength <= 0)
            {
                throw new ArgumentException("maxLength must be positive", nameof(maxLength));
            }
            if (minLength > maxLength)
            {
                throw new ArgumentException("maxLength must be more than minLength");
            }
            var length = RandomHelper.GetInt(minLength, maxLength);
            var signs  = new char[length];

            for (int i = 0; i < length; i++)
            {
                signs[i] = GetChar(i, wordCase);
            }
            return(new string(signs));
        }
        public static string DeclinateMonth(this string monthName, WordCase wordCase)
        {
            var month = monthName.ToLower();

            var namesArray = new string[]
            {
                "январь", "февраль", "март", "апрель", "май", "июнь", "июль", "август", "сентябрь", "октябрь", "ноябрь", "декабрь",
                "января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря",
                "январю", "февралю", "марту", "апрелю", "маю", "июню", "июлю", "августу", "сентябрю", "октябрю", "ноябрю", "декабрю",
                "январь", "февраль", "март", "апрель", "май", "июнь", "июль", "август", "сентябрь", "октябрь", "ноябрь", "декабрь",
                "январем", "февралем", "мартом", "апрелем", "маем", "июнем", "июлем", "августом", "сентябрем", "октябрем", "ноябрем", "декабрем",
                "январе", "феврале", "марте", "апреле", "мае", "июне", "июле", "августе", "сентябре", "октябре", "ноябре", "декабре",
            };

            var monthInArray = namesArray.FirstOrDefault(c => month.Contains(c));

            if (monthInArray != null)
            {
                var declinatedMonth = namesArray[Array.IndexOf(namesArray, monthInArray) + (int)wordCase * 12];
                return(month.Replace(monthInArray, declinatedMonth));
            }

            return(monthName);
        }
        public static string DeclinateMonth(this int month, WordCase wordCase)
        {
            string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month);

            return(monthName.DeclinateMonth(wordCase));
        }
Example #14
0
        public int GetPostFixIndex(WordAmount amount, WordCase aCase)
        {
            switch (amount)
            {
                case WordAmount.Plural:
                    {
                        if (pluralPostfixSelector.ContainsKey(aCase))
                            return pluralPostfixSelector[aCase];
                        break;
                    }

                case WordAmount.Singular:
                    {
                        if (singularPostfixSelector.ContainsKey(aCase))
                            return singularPostfixSelector[aCase];
                        break;
                    }
            }

            return 0;
        }
Example #15
0
 public static string GetWord(int length, WordCase wordCase = WordCase.WithACapitalLetter)
 {
     return(GetWord(length, length, wordCase));
 }
Example #16
0
 public static string ToCase(this string str, WordCase wordCase)
 => CompoundWordCase.ToCase(str, wordCase);
Example #17
0
        public bool AnalyzeLine(string line)
        {
            if (!string.IsNullOrEmpty(line))
            {
                string[] elements = line.Split('|');

                this.Root = elements[0]; // always will be at last one element in nonempty string

                if (elements.Length > 1)
                {
                    for (int i = 1; i < elements.Length; i++)
                    {
                        string str = elements[i];
                        if (string.IsNullOrEmpty(str))
                        {
                            continue;
                        }

                        switch (str[0])
                        {
                            #region Irregular levelling

                        case '*':
                        {
                            if (str.Length > 1)
                            {
                                this.IsLevelledComplex = false;

                                if (str[1] == '+')
                                {
                                    this.LevelHighestForm = str.Substring(2);
                                }
                                else
                                {
                                    this.LevelHigherForm = str.Substring(1);
                                }
                            }
                            else
                            {
                                // err
                                return(false);
                            }

                            break;
                        }

                            #endregion

                            #region Nondeclinative item

                        case '#':
                        {
                            this.IsConstant = true;

                            break;
                        }

                        case '!':
                        {
                            this.canBeLevelled = false;

                            break;
                        }

                            #endregion

                            #region Exception Cases

                        case '%':
                        {
                            if (str.Length > 5)
                            {
                                this.IsException = true;
                                WordCase       aCase  = EnumHelper.GetWordCase(str[1]);
                                WordAmount     amount = EnumHelper.GetWordAmount(str[2]);
                                WordGenre      genre  = EnumHelper.GetWordGenre(str[3]);
                                AdjectiveLevel level  = EnumHelper.GetAdjectiveLevel(str[4]);
                                string         txt    = str.Substring(5);

                                AdjectiveWordToken token = new
                                                           AdjectiveWordToken(txt, aCase, genre, amount, level);
                                this.Irregulars.Add(token);
                            }
                            else
                            {
                                // err
                                return(false);
                            }

                            break;
                        }

                            #endregion

                            #region Categories

                        case '$':
                        {
                            string cats = str.Substring(1);
                            categories.Clear();
                            if (!string.IsNullOrEmpty(cats))
                            {
                                string[] arr = cats.Split(',');
                                foreach (string catId in arr)
                                {
                                    int id = int.Parse(catId);

                                    if (!categories.Contains(id))
                                    {
                                        categories.Add(id);
                                    }
                                }
                            }

                            break;
                        }

                            #endregion
                        }
                    }
                }
                else
                {
                    // set defaults
                    this.IsException = false;
                    this.IsConstant  = false;
                }

                //if (adj.IsException && adj.IsLevelledComplex)
                //{
                //    // not supported
                //}
                //else

                return(true);
            }

            return(false);
        }
Example #18
0
 public string Join(IEnumerable <string> ss, string separator, WordCase wordCase)
 => string.Join(separator, ss.Select(s => s.ToCase(wordCase)));
Example #19
0
        /// <summary>
        /// Склонение фамилии человека
        /// </summary>
        /// <param name="human"></param>
        /// <param name="wordCase"></param>
        /// <returns></returns>
        public static string LastNameDeclension(HumanModel human, WordCase wordCase)
        {
            var fullNameDecl = GetFullNameDeclensionByHuman(human);

            return(fullNameDecl.LastName.GetByWordCase(wordCase));
        }
Example #20
0
        /// <summary>
        /// Склонение Отчества человека
        /// </summary>
        /// <param name="human"></param>
        /// <param name="wordCase"></param>
        /// <returns></returns>
        public static string PatronymicDeclension(HumanModel human, WordCase wordCase)
        {
            var fullNameDecl = GetFullNameDeclensionByHuman(human);

            return(fullNameDecl.Patronymic.GetByWordCase(wordCase));
        }
Example #21
0
        public bool AnalyzeLine(string line)
        {
            this.irregulars.Clear();
            this.categories.Clear();
            this.singularPostfixSelector.Clear();
            this.pluralPostfixSelector.Clear();

            if (!string.IsNullOrEmpty(line))
            {
                string[] elements = line.Split('|');
                this.root = elements[0];    // always will be at last one element in nonempty string

                if (elements.Length > 1)
                {
                    for (int i = 1; i < elements.Length; i++)
                    {
                        string str = elements[i];
                        if (string.IsNullOrEmpty(str))
                        {
                            continue;
                        }

                        switch (str[0])
                        {
                            #region Nondeclinative item

                        case '#':
                        {
                            this.IsConstant = true;
                            break;
                        }

                            #endregion

                            #region Main Data

                        case '!':
                        {
                            if (str.Length > 1)
                            {
                                this.genre = EnumHelper.GetWordGenre(str[1]);
                                // TODO: read more details
                                if (str.Length > 3)
                                {
                                    this.declinationType = str.Substring(2, 2);
                                }
                            }
                            else
                            {
                                // err
                                return(false);
                            }

                            break;
                        }

                        case '*':
                        {
                            if (str.Length > 1)
                            {
                                this.IrregularGenre = EnumHelper.GetWordGenre(str[1]);
                                // TODO: read more details
                                this.HasIrregularGenre = this.irrGenre != WordGenre._Unknown;
                            }
                            else
                            {
                                // err
                                return(false);
                            }

                            break;
                        }


                        case '@':
                        {
                            if (str.Length > 1)
                            {
                                // take root for other cases then Nominative
                                this.rootOther = str.Substring(1);
                            }
                            else
                            {
                                // err
                                return(false);
                            }

                            break;
                        }

                        case '+':
                        {
                            if (str.Length > 2)
                            {
                                // Specifies other than first index is used
                                WordAmount amount       = EnumHelper.GetWordAmount(str[1]);
                                WordCase   aCase        = EnumHelper.GetWordCase(str[2]);
                                int        postFixIndex = int.Parse(str.Substring(3));

                                switch (amount)
                                {
                                case WordAmount.Singular:
                                {
                                    if (!singularPostfixSelector.ContainsKey(aCase))
                                    {
                                        singularPostfixSelector.Add(aCase, postFixIndex);
                                    }
                                    else
                                    {
                                        singularPostfixSelector[aCase] = postFixIndex;
                                    }
                                    break;
                                }

                                case WordAmount.Plural:
                                {
                                    if (!pluralPostfixSelector.ContainsKey(aCase))
                                    {
                                        pluralPostfixSelector.Add(aCase, postFixIndex);
                                    }
                                    else
                                    {
                                        pluralPostfixSelector[aCase] = postFixIndex;
                                    }
                                    break;
                                }
                                }
                            }
                            else
                            {
                                // err
                                return(false);
                            }

                            break;
                        }
                            #endregion

                            #region Exception Cases

                        case '%':
                        {
                            if (str.Length > 3)
                            {
                                this.IsException = true;
                                WordCase   aCase  = EnumHelper.GetWordCase(str[1]);
                                WordAmount amount = EnumHelper.GetWordAmount(str[2]);
                                string     txt    = str.Substring(3);

                                WordToken token = new
                                                  WordToken(txt, aCase, amount);
                                this.irregulars.Add(token);
                            }
                            else
                            {
                                // err
                                return(false);
                            }

                            break;
                        }

                        case '^':
                        {
                            if (str.Length == 2)
                            {
                                // only singular/plural word - no sense meaning or grammar
                                WordAmount amount = EnumHelper.GetWordAmount(str[1]);
                                if (amount == WordAmount.Plural)
                                {
                                    this.canBePlural = false;
                                }
                                else if (amount == WordAmount.Singular)
                                {
                                    this.canBeSingular = false;
                                }
                            }
                            else
                            {
                                // err
                                return(false);
                            }

                            break;
                        }

                            #endregion

                            #region Categories

                        case '$':
                        {
                            string cats = str.Substring(1);
                            categories.Clear();
                            if (!string.IsNullOrEmpty(cats))
                            {
                                string[] arr = cats.Split(',');
                                foreach (string catId in arr)
                                {
                                    int id = int.Parse(catId);

                                    if (!categories.Contains(id))
                                    {
                                        categories.Add(id);
                                    }
                                }
                            }

                            break;
                        }

                            #endregion
                        }
                    }
                }

                // check all data is specified
                if (this.genre == WordGenre._Unknown)
                {
                    return(false);
                }

                return(true);
            }

            return(false);
        }
Example #22
0
        public void SetPostIndex(WordCase aCase, WordAmount amount, int postFixIndex)
        {
            switch (amount)
            {
                case WordAmount.Plural:
                    {
                        if (postFixIndex > 0)
                        {
                            if (pluralPostfixSelector.ContainsKey(aCase))
                                pluralPostfixSelector[aCase] = postFixIndex;
                            else
                                pluralPostfixSelector.Add(aCase, postFixIndex);
                        }
                        else
                            if (pluralPostfixSelector.ContainsKey(aCase))
                                pluralPostfixSelector.Remove(aCase);

                        break;
                    }

                case WordAmount.Singular:
                    {
                        if (postFixIndex > 0)
                        {
                            if (singularPostfixSelector.ContainsKey(aCase))
                                singularPostfixSelector[aCase] = postFixIndex;
                            else
                                singularPostfixSelector.Add(aCase, postFixIndex);
                        }
                        else
                            if (singularPostfixSelector.ContainsKey(aCase))
                                singularPostfixSelector.Remove(aCase);

                        break;
                    }
            }

        }
Example #23
0
        public string GetForm(WordCase aCase, WordAmount amount)
        {
            WordToken token = new WordToken(null, aCase, amount);
            foreach (WordToken tok in irregulars)
                if (tok.Is(token))
                    return tok.Text;

            return null;
        }