<reponame>prof-cordell-classes/f19-technologies-of-text-nolanjac
#!/usr/bin/env PYTHONIOENCODING=UTF-8 /usr/local/bin/python3
# -*- coding: utf-8 -*-

# I did not write this function and claim no credit for it.
# It turns out determining whether an 'a' should be an 'a' or an 'an' or really difficult, so in the spirit of the internet,
# I found someone who had already implemented it. By the MIT license, I am alowed to use it in my own projects free of charge

# original copyright notice

# Copyright (c) 2009-2010, <NAME>, <NAME>
# Released under terms of the MIT/X/Expat Licence. See COPYING for details.
#
# The indefinite_article function follows an algorithm by <NAME>
# as published in CPAN package Lingua-EN-Inflect-1.891 under the GNU GPL
# (version 1 or later) and Artistic License 1.0.

import re

def indefinite_article(noun_phrase):
    # algorithm adapted from CPAN package Lingua-EN-Inflect-1.891 by <NAME>
    m = re.search('\w+', noun_phrase, re.UNICODE)
    if m:
        word = m.group(0)
    else:
        return 'an'

    wordi = word.lower()
    for anword in ('euler', 'heir', 'honest', 'hono'):
        if wordi.startswith(anword):
            return 'an'

    if wordi.startswith('hour') and not wordi.startswith('houri'):
        return 'an'

    if len(word) == 1:
        if wordi in 'aedhilmnorsx':
            return 'an'
        else:
            return 'a'

    if re.match(r'(?!FJO|[HLMNS]Y.|RY[EO]|SQU|'
                  r'(F[LR]?|[HL]|MN?|N|RH?|S[CHKLMNPTVW]?|X(YL)?)[AEIOU])'
                  r'[FHLMNRSX][A-Z]', word):
        return 'an'

    for regex in (r'^e[uw]', r'^onc?e\b',
                    r'^uni([^nmd]|mo)','^u[bcfhjkqrst][aeiou]'):
        if re.match(regex, wordi):
            return 'a'

    # original regex was /^U[NK][AIEO]?/ but that matches UK, UN, etc.
    if re.match('^U[NK][AIEO]', word):
        return 'a'
    elif word == word.upper():
        if wordi[0] in 'aedhilmnorsx':
            return 'an'
        else:
            return 'a'

    if wordi[0] in 'aeiou':
        return 'an'

    if re.match(r'^y(b[lor]|cl[ea]|fere|gg|p[ios]|rou|tt)', wordi):
        return 'an'
    else:
        return 'a'


#!/usr/bin/env PYTHONIOENCODING=UTF-8 /usr/local/bin/python3
# -*- coding: utf-8 -*-

# I did not write this function and claim no credit for it.
# It turns out determining whether an 'a' should be an 'a' or an 'an' or really difficult, so in the spirit of the internet,
# I found someone who had already implemented it. By the MIT license, I am alowed to use it in my own projects free of charge

# original copyright notice

# Copyright (c) 2009-2010, <NAME>, <NAME>
# Released under terms of the MIT/X/Expat Licence. See COPYING for details.
#
# The indefinite_article function follows an algorithm by <NAME>
# as published in CPAN package Lingua-EN-Inflect-1.891 under the GNU GPL
# (version 1 or later) and Artistic License 1.0.

import re

def indefinite_article(noun_phrase):
    # algorithm adapted from CPAN package Lingua-EN-Inflect-1.891 by <NAME>
    m = re.search('\w+', noun_phrase, re.UNICODE)
    if m:
        word = m.group(0)
    else:
        return 'an'

    wordi = word.lower()
    for anword in ('euler', 'heir', 'honest', 'hono'):
        if wordi.startswith(anword):
            return 'an'

    if wordi.startswith('hour') and not wordi.startswith('houri'):
        return 'an'

    if len(word) == 1:
        if wordi in 'aedhilmnorsx':
            return 'an'
        else:
            return 'a'

    if re.match(r'(?!FJO|[HLMNS]Y.|RY[EO]|SQU|'
                  r'(F[LR]?|[HL]|MN?|N|RH?|S[CHKLMNPTVW]?|X(YL)?)[AEIOU])'
                  r'[FHLMNRSX][A-Z]', word):
        return 'an'

    for regex in (r'^e[uw]', r'^onc?e\b',
                    r'^uni([^nmd]|mo)','^u[bcfhjkqrst][aeiou]'):
        if re.match(regex, wordi):
            return 'a'

    # original regex was /^U[NK][AIEO]?/ but that matches UK, UN, etc.
    if re.match('^U[NK][AIEO]', word):
        return 'a'
    elif word == word.upper():
        if wordi[0] in 'aedhilmnorsx':
            return 'an'
        else:
            return 'a'

    if wordi[0] in 'aeiou':
        return 'an'

    if re.match(r'^y(b[lor]|cl[ea]|fere|gg|p[ios]|rou|tt)', wordi):
        return 'an'
    else:
        return 'a'
#!/usr/bin/env PYTHONIOENCODING=UTF-8 /usr/local/bin/python3 # -*- coding: utf-8 -*- # I did not write this function and claim no credit for it. # It turns out determining whether an 'a' should be an 'a' or an 'an' or really difficult, so in the spirit of the internet, # I found someone who had already implemented it. By the MIT license, I am alowed to use it in my own projects free of charge # original copyright notice # Copyright (c) 2009-2010, <NAME>, <NAME> # Released under terms of the MIT/X/Expat Licence. See COPYING for details. # # The indefinite_article function follows an algorithm by <NAME> # as published in CPAN package Lingua-EN-Inflect-1.891 under the GNU GPL # (version 1 or later) and Artistic License 1.0. # algorithm adapted from CPAN package Lingua-EN-Inflect-1.891 by <NAME> # original regex was /^U[NK][AIEO]?/ but that matches UK, UN, etc.