Esempio n. 1
0
 internal GenderRulesContainer()
 {
     m_rulesByNamePart = new PartGenderRules[Enum.GetValues(typeof(NamePart)).Length];
     for (int i = 0; i < m_rulesByNamePart.Length; ++i)
     {
         m_rulesByNamePart[i] = new PartGenderRules();
     }
 }
Esempio n. 2
0
        public Gender GetGender(string namePartValue, NamePart namePart)
        {
            if (namePartValue == null)
            {
                throw new ArgumentNullException(nameof(namePartValue));
            }
            PartGenderRules rules = m_rules.genderRules[namePart];
            Gender          gender;

            if (rules.TryMatch(namePartValue, out gender))
            {
                return(gender);
            }
            return(Gender.Androgynous);
        }
        private void ParseGenderRules(PartGenderRules rules)
        {
            m_parser.AssertNextTokenTypeAndConsume(JsonParser.TokenType.ObjectStart);
            while (!m_parser.CheckNextTokenTypeAndConsumeIfTrue(JsonParser.TokenType.ObjectEnd))
            {
                string section = m_parser.GetNextPropertyName();

                if (section == "exceptions")
                {
                    m_parser.AssertNextTokenTypeAndConsume(JsonParser.TokenType.ObjectStart);
                    while (!m_parser.CheckNextTokenTypeAndConsumeIfTrue(JsonParser.TokenType.ObjectEnd))
                    {
                        //read exceptions rules
                        string genderStr = m_parser.GetNextPropertyName();
                        Gender gender    = ParseGender(genderStr);
                        m_parser.AssertNextTokenTypeAndConsume(JsonParser.TokenType.ArrayStart);
                        while (!m_parser.CheckNextTokenTypeAndConsumeIfTrue(JsonParser.TokenType.ArrayEnd))
                        {
                            string word = m_parser.GetNextStringValue();
                            rules.AddExplicitMatchRule(word, gender);
                        }
                    }
                }
                else if (section == "suffixes")
                {
                    m_parser.AssertNextTokenTypeAndConsume(JsonParser.TokenType.ObjectStart);
                    while (!m_parser.CheckNextTokenTypeAndConsumeIfTrue(JsonParser.TokenType.ObjectEnd))
                    {
                        //read suffixes rule
                        string genderStr = m_parser.GetNextPropertyName();
                        Gender gender    = ParseGender(genderStr);
                        m_parser.AssertNextTokenTypeAndConsume(JsonParser.TokenType.ArrayStart);
                        while (!m_parser.CheckNextTokenTypeAndConsumeIfTrue(JsonParser.TokenType.ArrayEnd))
                        {
                            string suffix = m_parser.GetNextStringValue();
                            rules.AddSuffixRule(suffix, gender);
                        }
                    }
                }
                else
                {
                    throw new ParseException($"Unexpected section '{section}'");
                }
            }
        }