How to use inflect - 10 common examples

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
def test_partition_word(self):
        p = inflect.engine()
        for txt, part in (
            (' cow ', (' ', 'cow', ' ')),
            ('cow', ('', 'cow', '')),
            ('   cow', ('   ', 'cow', '')),
            ('cow   ', ('', 'cow', '   ')),
            ('  cow   ', ('  ', 'cow', '   ')),
            ('', ('', '', '')),
            ('bottle of beer', ('', 'bottle of beer', '')),
            # spaces give weird results
            # (' '),('', ' ', '')),
            # ('  '),(' ', ' ', '')),
            # ('   '),('  ', ' ', '')),
        ):
            self.assertEqual(p.partition_word(txt), part)
github jazzband / inflect / tests / test_compounds.py View on Github external
import inflect

p = inflect.engine()


def test_compound_1():
    assert p.singular_noun("hello-out-there") == "hello-out-there"


def test_compound_2():
    assert p.singular_noun("hello out there") == "hello out there"


def test_compound_3():
    assert p.singular_noun("continue-to-operate") == "continue-to-operate"


def test_compound_4():
    assert p.singular_noun("case of diapers") == "case of diapers"
github jazzband / inflect / tests / test_classical_person.py View on Github external
def test_ancient_1():
    p = inflect.engine()

    # DEFAULT...

    assert p.plural_noun("person") == "people"

    # "person" PLURALS ACTIVATED...

    p.classical(persons=True)
    assert p.plural_noun("person") == "persons"

    # OTHER CLASSICALS NOT ACTIVATED...

    assert p.plural_noun("wildebeest") == "wildebeests"
    assert p.plural_noun("formula") == "formulas"
    assert p.plural_noun("error", 0) == "errors"
    assert p.plural_noun("brother") == "brothers"
github jazzband / inflect / tests.py View on Github external
def test_classical(self):
        # classical dicts
        self.assertEqual(set(inflect.def_classical.keys()), set(inflect.all_classical.keys()))
        self.assertEqual(set(inflect.def_classical.keys()), set(inflect.no_classical.keys()))

        # def classical
        p = inflect.engine()
        self.assertEqual(p.classical_dict, inflect.def_classical)

        p.classical()
        self.assertEqual(p.classical_dict, inflect.all_classical)

        p.classical(0)
        self.assertEqual(p.classical_dict, inflect.no_classical)

        p.classical(1)
        self.assertEqual(p.classical_dict, inflect.all_classical)
        
        p.classical(all=0)
        self.assertEqual(p.classical_dict, inflect.no_classical)
github jazzband / inflect / tests.py View on Github external
def test_classical(self):
        # classical dicts
        self.assertEqual(set(inflect.def_classical.keys()), set(inflect.all_classical.keys()))
        self.assertEqual(set(inflect.def_classical.keys()), set(inflect.no_classical.keys()))

        # def classical
        p = inflect.engine()
        self.assertEqual(p.classical_dict, inflect.def_classical)

        p.classical()
        self.assertEqual(p.classical_dict, inflect.all_classical)

        p.classical(0)
        self.assertEqual(p.classical_dict, inflect.no_classical)

        p.classical(1)
        self.assertEqual(p.classical_dict, inflect.all_classical)
        
        p.classical(all=0)
github GeneralizedLearningUtilities / SuperGLU / python_module / SuperGLU / Services / TextProcessing / Tests / Inflect / test_pwd.py View on Github external
def test_classical(self):
        # classical dicts
        self.assertEqual(set(inflect.def_classical.keys()), set(inflect.all_classical.keys()))
        self.assertEqual(set(inflect.def_classical.keys()), set(inflect.no_classical.keys()))

        # def classical
        p = inflect.engine()
        self.assertEqual(p.classical_dict, inflect.def_classical)

        p.classical()
        self.assertEqual(p.classical_dict, inflect.all_classical)

        self.assertRaises(TypeError, p.classical, 0)
        self.assertRaises(TypeError, p.classical, 1)
        self.assertRaises(TypeError, p.classical, 'names')
        self.assertRaises(TypeError, p.classical, 'names', 'zero')
        self.assertRaises(TypeError, p.classical, 'all')

        p.classical(all=False)
github jazzband / inflect / tests / test_pwd.py View on Github external
def test_classical(self):
        # classical dicts
        self.assertEqual(
            set(inflect.def_classical.keys()), set(inflect.all_classical.keys())
        )
        self.assertEqual(
            set(inflect.def_classical.keys()), set(inflect.no_classical.keys())
        )

        # def classical
        p = inflect.engine()
        self.assertEqual(p.classical_dict, inflect.def_classical)

        p.classical()
        self.assertEqual(p.classical_dict, inflect.all_classical)

        self.assertRaises(TypeError, p.classical, 0)
        self.assertRaises(TypeError, p.classical, 1)
        self.assertRaises(TypeError, p.classical, "names")
        self.assertRaises(TypeError, p.classical, "names", "zero")
github jazzband / inflect / tests / test_pwd.py View on Github external
self.assertEqual(p.classical_dict, inflect.def_classical)

        p.classical()
        self.assertEqual(p.classical_dict, inflect.all_classical)

        self.assertRaises(TypeError, p.classical, 0)
        self.assertRaises(TypeError, p.classical, 1)
        self.assertRaises(TypeError, p.classical, "names")
        self.assertRaises(TypeError, p.classical, "names", "zero")
        self.assertRaises(TypeError, p.classical, "all")

        p.classical(all=False)
        self.assertEqual(p.classical_dict, inflect.no_classical)

        p.classical(names=True, zero=True)
        mydict = inflect.def_classical.copy()
        mydict.update(dict(names=1, zero=1))
        self.assertEqual(p.classical_dict, mydict)

        p.classical(all=True)
        self.assertEqual(p.classical_dict, inflect.all_classical)

        p.classical(all=False)
        p.classical(names=True, zero=True)
        mydict = inflect.def_classical.copy()
        mydict.update(dict(names=True, zero=True))
        self.assertEqual(p.classical_dict, mydict)

        p.classical(all=False)
        p.classical(names=True, zero=False)
        mydict = inflect.def_classical.copy()
        mydict.update(dict(names=True, zero=False))
github GeneralizedLearningUtilities / SuperGLU / python_module / SuperGLU / Services / TextProcessing / Tests / Inflect / test_pwd.py View on Github external
mydict = inflect.def_classical.copy()
        mydict.update(dict(names=1, zero=1))
        self.assertEqual(p.classical_dict, mydict)

        p.classical(all=True)
        self.assertEqual(p.classical_dict, inflect.all_classical)

        p.classical(all=False)
        p.classical(names=True, zero=True)
        mydict = inflect.def_classical.copy()
        mydict.update(dict(names=True, zero=True))
        self.assertEqual(p.classical_dict, mydict)

        p.classical(all=False)
        p.classical(names=True, zero=False)
        mydict = inflect.def_classical.copy()
        mydict.update(dict(names=True, zero=False))
        self.assertEqual(p.classical_dict, mydict)

        self.assertRaises(UnknownClassicalModeError, p.classical, bogus=True)
github jazzband / inflect / tests.py View on Github external
def test_millfn(self):
        p = inflect.engine()
        millfn = p.millfn
        self.assertEqual(millfn(1), ' thousand')
        self.assertEqual(millfn(2), ' million')
        self.assertEqual(millfn(3), ' billion')
        self.assertEqual(millfn(0), '')
        self.assertEqual(millfn(11), ' decillion')
        inflect.STDOUT_ON = False
        self.assertRaises(NumOutOfRangeError, millfn, 12)
        inflect.STDOUT_ON = True