3

Not sure if this is the correct place for this question. I am writing some code to place the correct indefinite article before a given noun. To do this I am looking at the first letter of the noun to decide whether to use 'a' or 'an'. I know this won't always give the correct output (e.g. An unicorn, A hour), as it is the sound rather than the actual letter that needs to be considered. To correct this I am looking for a list of all nouns where using the first letter will give the wrong result. Does anyone know where I can find such a list?

Keelan
  • 4,214
  • 14
  • 33
RedPython
  • 139
  • 1

3 Answers3

6

Even given a comprehensive list of such nouns, it won't be anything like sufficient. The reason is, of course, that the choice between a and an depends not on whether the head noun in the noun phrase begins with a vowel, but whether the following word begins with a vowel.

We can see this contrast in (1-4) below:

  1. an elephant
  2. a big elephant
  3. a university
  4. an unusual university

In (1) the head noun elephant begins with /e/ [or /ɛ/ if you prefer that symbol for the same phoneme]. Because the indefinite article occurs directly before this vowel, we see the form an. In (2) however, the article precedes the consonant /b/ in big and so we see the form a. We see the same kind of pattern in (3) and (4), where university begins with the consonant /j/, but unusual begins with the vowel /ʌ/.

You therefore need a list of all words spelled with consonant and pronounced with a vowel, or vice versa, that could occur after an indefinite article in English. In addition to nouns, this would have to include other determiners (e.g. numerals), prepositions, adjectives, adverbs, and verbs. It's probably safest to get a list of all such words in English regardless of their word category!

Araucaria - him
  • 4,002
  • 1
  • 15
  • 39
  • This should be a comment, not an answer. – Adam Bittlingmayer Jan 08 '23 at 08:17
  • 3
    I think this answer is critical to solving the problem, I think you correctly pointed out that this is a purely phonetic phenomenon, has nothing to do with intrinsic noun attributes (as if they were some kind of morphemic attribute or something). In a way it probably makes the problem way simpler. You don't need a list of "irregular nouns". You need data on the pronunciation of the words, only. And then a super simple computer implementation of the a / an rule (which I think is extremely regular, I do not know if there any exceptions exceptions to the rules). – Julius Hamilton Jan 09 '23 at 18:11
  • 3
    Yes. No grammar at all is needed. Sound follows sound and determines sound. – jlawler Jan 09 '23 at 18:59
4

You need a pronouncing dictionary: the CMU dictionary is pretty easy to use. Using the web interface, you can try to get "univariant",which directs you to Logios, which may generate a satisfactory pronunciation my rule.

user6726
  • 83,066
  • 4
  • 63
  • 181
1

I think it would be easier to generate your own data because then you don't need to hunt around for a resource that may or may not exist.

This isn't perfect but it's a start. Gonna update it asap.

  1. Choose a starting URL for a crawler (Google, Wikipedia, YouTube, or any website).
  2. Request the webpage HTML source; extract English text and undetermined nouns from it and store them.
  3. Continue to crawl URLs present in the webpage as long or as little as you want.

an_a.py

import scrapy
import spacy
from scrapy.exceptions import CloseSpider

class AnACrawler(scrapy.Spider): name = "ana_crawler" start_urls = [ "https://www.wikipedia.org", ] visited_urls = set() # set to store visited URLs

def parse(self, response):
    # Load the NLP model
    nlp = spacy.load("en_core_web_sm")

    # Extract the text and detect the language of each sentence
    doc = nlp(response.text)

    # Keep only the English sentences and extract the nouns with indefinite articles
    nouns = []
    for sent in doc.sents:
        if sent._.language["language"] == "en":
            for token in sent:
                if token.pos_ == "NOUN" and token.text in ["a", "an"]:
                    nouns.append((token.text, token.nbor().text))

    # Save the text and nouns to a file
    with open("text_and_nouns.txt", "a") as f:
        f.write(response.text + "\n")
        f.write(str(nouns) + "\n")

    # Follow hyperlinks to crawl more pages
    for a in response.css("a"):
        url = a.attrib["href"]
        if url not in self.visited_urls:
            self.visited_urls.add(url)
            yield scrapy.Request(url, self.parse)

Julius Hamilton
  • 523
  • 3
  • 27