• Jump To … +
    abbreviations.js adjectives.js convertables.js dates.js demonyms.js firstnames.js honourifics.js irregular_nouns.js irregular_verbs.js misc.js multiples.js numbers.js organisations.js phrasal_verbs.js places.js uncountables.js verbs.js fns.js index.js lexicon.js negate.js passive_voice.js contractions.js fancy_lumping.js grammar_rules.js parts_of_speech.js phrasal_verbs.js tagger.js word_rules.js question.js sentence.js statement.js tense.js adjective.js to_adverb.js to_comparative.js to_noun.js to_superlative.js adverb.js to_adjective.js is_acronym.js article.js date.js date_rules.js is_date.js parse_date.js is_plural.js is_uncountable.js noun.js is_organisation.js organisation.js gender.js is_person.js parse_name.js person.js is_place.js place.js pluralize.js pronoun.js singularize.js is_value.js numbers.js to_number.js units.js value.js term.js conjugate.js from_infinitive.js predict_form.js suffix_rules.js to_actor.js to_infinitive.js negate.js verb.js sentence_parser.js text.js
  • article.js

  • ¶
    'use strict';
    
    const is_acronym = require('../is_acronym.js');
  • ¶

    chooses an indefinite aricle ‘a/an’ for a word

    const irregulars = {
      'hour': 'an',
      'heir': 'an',
      'heirloom': 'an',
      'honest': 'an',
      'honour': 'an',
      'honor': 'an',
      'uber': 'an' //german u
    };
    
    const indefinite_article = function(str) {
      if (!str) {
        return null;
      }
  • ¶

    pronounced letters of acronyms that get a ‘an’

      const an_acronyms = {
        A: true,
        E: true,
        F: true,
        H: true,
        I: true,
        L: true,
        M: true,
        N: true,
        O: true,
        R: true,
        S: true,
        X: true
      };
  • ¶

    ‘a’ regexes

      const a_regexs = [
        /^onc?e/i, //'wu' sound of 'o'
        /^u[bcfhjkqrstn][aeiou]/i, // 'yu' sound for hard 'u'
        /^eul/i
      ];
  • ¶

    begin business time ////////////////// explicit irregular forms

      if (irregulars.hasOwnProperty(str)) {
        return irregulars[str];
      }
  • ¶

    spelled-out acronyms

      if (is_acronym(str) && an_acronyms.hasOwnProperty(str.substr(0, 1))) {
        return 'an';
      }
  • ¶

    ‘a’ regexes

      for (let i = 0; i < a_regexs.length; i++) {
        if (str.match(a_regexs[i])) {
          return 'a';
        }
      }
  • ¶

    basic vowel-startings

      if (str.match(/^[aeiou]/i)) {
        return 'an';
      }
      return 'a';
    };
    
    module.exports = indefinite_article;
  • ¶

    console.log(indefinite_article(‘N.D.A’));