How to use the inflect.engine 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
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 wzpan / Learn-Python-The-Hard-Way / Python3 / game / skeleton / ex48 / lexicon.py View on Github external
def scan(line):
    ' scan a line and split into words '
    words = line.split(' ')
    # analyse words
    result = []
    # for each word, send it to the analyzer to analyse
    for word in words:
        # singular noun
        p = inflect.engine()
        # the inflect will singular 'princess' into 'princes' that I don't want   
        if word != 'princess' and p.singular_noun(word):
            word = p.singular_noun(word)

        # Make sure the scanner handles user input in any capitalization and case.
        type = analyse(word.lower())
        result.append((type, word))
    return result
github cs-education / classTranscribe / archive / p2fa-vislab-master / align.py View on Github external
def prep_mlf(trsfile, mlffile, word_dictionary, surround, between,
    dialog_file=False):
    
    dict_tmp = {}
    
    infl = inflect.engine()
    
    # Read in the dictionary to ensure all of the words
    # we put in the MLF file are in the dictionary. Words
    # that are not are skipped with a warning.
    f = open(word_dictionary, 'r')
    dictionary = { } # build hash table
    for line in f.readlines():
        if line != "\n" and line != "" :
            dictionary[line.split()[0]] = True
    f.close()
    
    speakers = None
    emotions = None

    if dialog_file:
        dialog = json.load(open(trsfile, 'r'))
github yougov / pmxbot / pmxbot / web / viewer.py View on Github external
def pday(dayfmt):
    """
    P the day

    >>> print(pday('2012-08-24'))
    Friday the 24th
    """

    year, month, day = map(int, dayfmt.split('-'))
    return '{day} the {number}'.format(
        day=calendar.day_name[calendar.weekday(year, month, day)],
        number=inflect.engine().ordinal(day),
    )
github thomaxxl / safrs / expose_existing / sqlacodegen / sqlacodegen / codegen.py View on Github external
def create_inflect_engine(self):
        if self.noinflect:
            return _DummyInflectEngine()
        else:
            import inflect

            return inflect.engine()
github douban / sa-tools-core / sa_tools_core / icinga.py View on Github external
from sa_tools_core.libs.permission import require_user
from sa_tools_core.libs.sentry import report, send_sentry
from sa_tools_core.libs.template import render_notification
from sa_tools_core.libs.icinga import get_icinga_api
from sa_tools_core.libs.notification_gateway import add_notification
from sa_tools_core.notify import NOTIFY_TYPES, Notifier
from sa_tools_core.utils import get_os_username, AttrDict, import_string
from sa_tools_core.consts import ICINGA_EMAIL, ICINGA_CLUSTER_CONFIG_CLASS, ALERT_WIKI_BASE_URL

requests_logger = logging.getLogger('requests')

logger = logging.getLogger(__name__)

icinga_cluster_config = import_string(ICINGA_CLUSTER_CONFIG_CLASS)

inflect_engine = inflect.engine()


@require_user
def show(args):
    icinga_api = get_icinga_api(icinga_cluster_config)
    params = {}
    if args.attrs:
        params['attrs'] = args.attrs
    if args.filter:
        params['filter'] = args.filter
    res = (icinga_api.api.objects.url(inflect_engine.plural(args.type)).get(**params))
    if args.raw:
        print(res)
    else:
        pprint(res)
github gutfeeling / word_forms / word_forms / word_forms.py View on Github external
def singularize(noun):
    """
    args
        - noun : a noun e.g "man"

    returns the singular form of the word if it finds one. Otherwise,
    returns the word itself.
    """
    singular = inflect.engine().singular_noun(noun)
    if singular in ALL_WORDNET_WORDS:
        return singular
    return noun
github korymath / talk-generator / talkgenerator / sources / wikihow.py View on Github external
def get_related_wikihow_actions_advanced_search(seed_word):
    page = _advanced_search_wikihow(seed_word)
    # Try again but with plural if nothing is found
    if not page:
        page = _advanced_search_wikihow(inflect.engine().plural(seed_word))
    if page:
        soup = BeautifulSoup(page.content, "html.parser")
        actions_elements = soup.find_all("div", class_="mw-search-result-heading")
        actions = [clean_wikihow_action(x.find("a")["title"]) for x in actions_elements]
        return actions
    return []