Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect indefinite article "an" returned when handling uncommon abbreviations #136

Closed
tonywu7 opened this issue Aug 4, 2021 · 5 comments · Fixed by #182
Closed

Incorrect indefinite article "an" returned when handling uncommon abbreviations #136

tonywu7 opened this issue Aug 4, 2021 · 5 comments · Fixed by #182

Comments

@tonywu7
Copy link

tonywu7 commented Aug 4, 2021

Version

inflect==5.3.0 python==3.9.6

Problem

inflect.engine.a() returns the article "an" instead of "a" for some abbreviations that do not begin with vowel phonemes. Observe:

>>> import inflect
>>> p = inflect.engine()
>>> p.a('JSON code block')
'a JSON code block'
>>> p.a('YAML code block')
'an YAML code block'
>>> p.a('Core ML function')
'an Core ML function'
>>> p.a('TLS connection')
'an TLS connection'
>>> p.a('CSS selector')
'an CSS selector'

Seems to be caused by the A_abbrev regex:

inflect/inflect.py

Lines 1806 to 1813 in 98e19e3

A_abbrev = re.compile(
r"""
(?! FJO | [HLMNS]Y. | RY[EO] | SQU
| ( F[LR]? | [HL] | MN? | N | RH? | S[CHKLMNPTVW]? | X(YL)?) [AEIOU])
[FHLMNRSX][A-Z]
""",
re.VERBOSE,
)

which is missing the ^ start-of-line assertion, and so it matches parts of the abbreviations that would otherwise require "an," even thought they are not at the beginning of the word:

>>> A_abbrev.search('TLS connection')
<re.Match object; span=(1, 3), match='LS'>

After fixing it:

>>> p.a('JSON code block')
'a JSON code block'
>>> p.a('YAML code block')
'a YAML code block'
>>> p.a('Core ML function')
'a Core ML function'
>>> p.a('TLS connection')
'a TLS connection'
>>> p.a('SSL connection')
'an SSL connection'
>>> p.a('RSA algorithm')
'an RSA algorithm'
@jaraco
Copy link
Owner

jaraco commented Mar 23, 2022

Seems reasonable. Can you supply a patch?

@kimgerdes
Copy link
Contributor

I've added tonywu7's modification on https://github.com/kimgerdes/inflect (the smallest fork of all times, just a little ^)

@alex-bancroft-techlabs
Copy link

@kimgerdes is it okay if I use your fork, and does it have the same license as this repo? I am running into the same issue. Thank you!

@kimgerdes
Copy link
Contributor

sure thing. same license :)

@jaraco jaraco linked a pull request Apr 6, 2023 that will close this issue
@jaraco
Copy link
Owner

jaraco commented Apr 6, 2023

Fixed in 6.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants