How to use the inflect.BadGenderError function in inflect

To help you get started, we’ve selected a few inflect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GeneralizedLearningUtilities / SuperGLU / python_module / SuperGLU / Services / TextProcessing / Tests / Inflect / test_pwd.py View on Github external
"singular_noun(%s) == %s != %s" % (plur, p.singular_noun(plur), sing))
            self.assertEqual(p.inflect('singular_noun(%s)' % plur), sing)

        p.gender('neuter')
        for sing, plur in (
            ('it', 'they'),
            ('itself', 'themselves'),
            ('its', 'theirs'),
            ('to it', 'to them'),
            ('to itself', 'to themselves'),
        ):
            self.assertEqual(p.singular_noun(plur), sing,
                             "singular_noun(%s) == %s != %s" % (plur, p.singular_noun(plur), sing))
            self.assertEqual(p.inflect('singular_noun(%s)' % plur), sing)

        self.assertRaises(BadGenderError, p.gender, 'male')

        for sing, plur, gen in (
            ('it', 'they', 'neuter'),
            ('she', 'they', 'feminine'),
            ('he', 'they', 'masculine'),
            ('they', 'they', 'gender-neutral'),
            ('she or he', 'they', 'feminine or masculine'),
            ('he or she', 'they', 'masculine or feminine'),
        ):
            self.assertEqual(p.singular_noun(plur, gender=gen), sing)
github jazzband / inflect / tests / test_pwd.py View on Github external
)
            self.assertEqual(p.inflect("singular_noun('%s')" % plur), sing)

        self.assertRaises(BadGenderError, p.gender, "male")

        for sing, plur, gen in (
            ("it", "they", "neuter"),
            ("she", "they", "feminine"),
            ("he", "they", "masculine"),
            ("they", "they", "gender-neutral"),
            ("she or he", "they", "feminine or masculine"),
            ("he or she", "they", "masculine or feminine"),
        ):
            self.assertEqual(p.singular_noun(plur, gender=gen), sing)

        with self.assertRaises(BadGenderError):
            p.singular_noun("cats", gender="unknown gender")
github jazzband / inflect / tests / test_pwd.py View on Github external
("it", "they"),
            ("itself", "themselves"),
            ("its", "theirs"),
            ("to it", "to them"),
            ("to itself", "to themselves"),
        ):
            self.assertEqual(
                p.singular_noun(plur),
                sing,
                "singular_noun({}) == {} != {}".format(
                    plur, p.singular_noun(plur), sing
                ),
            )
            self.assertEqual(p.inflect("singular_noun('%s')" % plur), sing)

        self.assertRaises(BadGenderError, p.gender, "male")

        for sing, plur, gen in (
            ("it", "they", "neuter"),
            ("she", "they", "feminine"),
            ("he", "they", "masculine"),
            ("they", "they", "gender-neutral"),
            ("she or he", "they", "feminine or masculine"),
            ("he or she", "they", "masculine or feminine"),
        ):
            self.assertEqual(p.singular_noun(plur, gender=gen), sing)

        with self.assertRaises(BadGenderError):
            p.singular_noun("cats", gender="unknown gender")
github jazzband / inflect / inflect.py View on Github external
def _sinoun(self, word, count=None, gender=None):
        count = self.get_count(count)

        # DEFAULT TO PLURAL

        if count == 2:
            return word

        # SET THE GENDER

        try:
            if gender is None:
                gender = self.thegender
            elif gender not in singular_pronoun_genders:
                raise BadGenderError
        except (TypeError, IndexError):
            raise BadGenderError

        # HANDLE USER-DEFINED NOUNS

        value = self.ud_match(word, self.si_sb_user_defined)
        if value is not None:
            return value

        # HANDLE EMPTY WORD, SINGULAR COUNT AND UNINFLECTED PLURALS

        if word == "":
            return word

        lower_word = word.lower()