Ejemplo n.º 1
0
        private PartRules ParsePartRulesList()
        {
            PartRules result = new PartRules();

            m_parser.AssertNextTokenTypeAndConsume(JsonParser.TokenType.ObjectStart);
            while (!m_parser.CheckNextTokenTypeAndConsumeIfTrue(JsonParser.TokenType.ObjectEnd))
            {
                bool   ruleGroupIsSuffix;
                string ruleGroupName = m_parser.GetNextPropertyName();
                switch (ruleGroupName)
                {
                case "exceptions":
                    ruleGroupIsSuffix = false;
                    break;

                case "suffixes":
                    ruleGroupIsSuffix = true;
                    break;

                default:
                    throw new ParseException("Unexpected rule group '" + ruleGroupName + "'");
                }

                m_parser.AssertNextTokenTypeAndConsume(JsonParser.TokenType.ArrayStart);
                while (!m_parser.CheckNextTokenTypeAndConsumeIfTrue(JsonParser.TokenType.ArrayEnd))
                {
                    IRule rule = ParseRule(ruleGroupIsSuffix);
                    result.Add(rule);
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        private void ParseRuleSet()
        {
            string    rulePartName = m_parser.GetNextPropertyName();
            NamePart  rulePart     = ParseNamePart(rulePartName);
            PartRules rules        = ParsePartRulesList();

            m_data[rulePart] = rules;
        }
Ejemplo n.º 3
0
        public string Inflect(string namePartValue, NamePart namePart, Case targetCase, Gender?gender = null)
        {
            if (namePartValue == null)
            {
                throw new ArgumentNullException(nameof(namePartValue));
            }
            if (gender == null)
            {
                gender = GetGender(namePartValue, namePart);
            }

            PartRules partRules = m_rules[namePart];

            string[] chunks = namePartValue.Split(NAME_CHUNK_SPLIT);
            for (int i = 0; i < chunks.Length; ++i)
            {
                Tags tags = i == 0 ? Tags.FirstWord : Tags.None;
                chunks[i] = partRules.InflectChunk(chunks[i], gender.Value, tags, targetCase);
            }
            return(String.Join("-", chunks));
        }