Python Forum
A function for correctly using "a/an" before a word - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: A function for correctly using "a/an" before a word (/thread-21620.html)



A function for correctly using "a/an" before a word - Exsul1 - Oct-07-2019

I want to make a function that, when passed a string containing a single word, returns that word preceded by the indefinite article "a" or "an," depending on which is correct. This would be easy enough to do if the rule we were taught as kids were correct: "a" before a consonant, "an" before a vowel. But it isn't. It's "a" before a consonant sound and "an" before a vowel sound; hence, "an umbrella" but "a unicorn" (YOO-ni-corn). How would you go about writing this function? Would you try to compile an exhaustive list of "exceptions" from online sources or work with some kind of API or what? Also, how would you find out if someone has already done this?


RE: A function for correctly using "a/an" before a word - buran - Oct-07-2019

(Oct-07-2019, 05:51 PM)Exsul1 Wrote: Also, how would you find out if someone has already done this?
Did you try to google it?
First result is close to what you want - https://stackoverflow.com/questions/20336524/verify-correct-use-of-a-and-an-in-english-texts-python

Then looking at the answers you see that you probably will need NLTK


RE: A function for correctly using "a/an" before a word - newbieAuggie2019 - Oct-07-2019

(Oct-07-2019, 05:51 PM)Exsul1 Wrote: [ ... ] word preceded by the indefinite article "a" or "an," depending on which is correct. This would be easy enough to do if the rule we were taught as kids were correct: "a" before a consonant, "an" before a vowel. But it isn't. It's "a" before a consonant sound and "an" before a vowel sound; hence, "an umbrella" but "a unicorn" (YOO-ni-corn).

Hi!

Just a thought on linguistics, not on Python:

Although, it seems that the rule for words beginning with an 'h' depends on the sound, it seems that for native speakers, it actually depends on tradition, even on the place you have been grown up, or studied.

Some people say 'a historic occasion', while others 'an historic occasion'.
Some people say 'a herb', while others 'an herb'.
Some people say 'a hotel', while others 'an hotel'.

The same could apply to some other words I've heard using either 'a' or 'an' before them: hysterical, heroic, horrific, and human, and the list is not over.

More on this issue:

http://editingandwritingservices.com/a-or-an-before-words-beginning-with-h/

http://www.scribe.com.au/tip-w005.html

https://www.quora.com/Which-article-should-one-use-before-the-word-hospital-A-or-an

https://www.writing-skills.com/hit-or-myth-use-an-before-h-words

http://www.stgeorges.co.uk/blog/a-or-an-before-h-a-or-an-hotel

https://english.stackexchange.com/questions/629/when-should-i-use-a-versus-an-in-front-of-a-word-beginning-with-the-letter-h

https://www.lexico.com/en/grammar/a-historic-event-or-an-historic-event

https://www.merriam-webster.com/words-at-play/is-it-a-or-an

All the best,