Linguistics::EN::

Articles

module

Indefinite article methods for the English-language Linguistics module.

Constants

A_abbrev

This pattern matches strings of capitals starting with a “vowel-sound” consonant followed by another consonant, and which are not likely to be real words (oh, all right then, it's just magic!)

A_explicit_an

Exceptions to exceptions

A_y_cons

This pattern codes the beginnings of all english words begining with a 'y' followed by a consonant. Any other y-consonant prefix therefore implies an abbreviation.

PL_count_zero

Words which always indicate zero quantity

Public Instance Methods

anchor
a( count=nil )

Return the inflected phrase with the appropriate indefinite article (“a” or “an”) prepended.

# File lib/linguistics/en/articles.rb, line 106
def a( count=nil )
        count ||= 1
        phrase = self.to_s

        md = /\A(\s*)(.+?)(\s*)\Z/.match( phrase )
        pre, word, post = md.to_a[1,3]
        return phrase if word.nil? or word.empty?

        result = word.en.indef_article
        return pre + result + post
end
Also aliased as: an
anchor
an( count=nil )
Alias for: a
anchor
indef_article( count=nil )

Returns the given word with a prepended indefinite article, unless count is non-nil and not singular.

# File lib/linguistics/en/articles.rb, line 50
def indef_article( count=nil )
        word = self.to_s

        self.log.debug "Fetching the indefinite article for %p (count = %p)" % [ word, count ]
        return "#{count} #{word}" if
                count && /^(#{PL_count_one})$/i !~ count.to_s

        # Handle user-defined variants
        # return value if value = ud_match( word, A_a_user_defined )

        self.log.debug "  count wasn't a definite singular countword"
        case word

        # Handle special cases
        when /^(#{A_explicit_an})/i
                return "an #{word}"

        # Handle abbreviations
        when A_abbrev
                return "an #{word}"
        when /^[aefhilmnorsx][.-]/i
                return "an #{word}"
        when /^[a-z][.-]/i
                return "a #{word}"

        # Handle consonants
        when /^[^aeiouy]/i
                return "a #{word}"

        # Handle special vowel-forms
        when /^e[uw]/i
                return "a #{word}"
        when /^onc?e\b/i
                return "a #{word}"
        when /^uni([^nmd]|mo)/i
                return "a #{word}"
        when /^u[bcfhjkqrst][aeiou]/i
                return "a #{word}"

        # Handle vowels
        when /^[aeiou]/i
                return "an #{word}"

        # Handle y... (before certain consonants implies (unnaturalized) "i.." sound)
        when A_y_cons
                return "an #{word}"

        # Otherwise, guess "a"
        else
                return "a #{word}"
        end
end
anchor
no( count=nil )

Translate zero-quantified phrase to “no phrase.plural

# File lib/linguistics/en/articles.rb, line 123
def no( count=nil )
        phrase = self.to_s
        md = /\A(\s*)(.+?)(\s*)\Z/.match( phrase )
        pre, word, post = md.to_a[1,3]
        count ||= 0

        unless /^#{PL_count_zero}$/ =~ count.to_s
                return "#{pre}#{count} " + plural( word, count ) + post
        else
                return "#{pre}no " + word.en.plural( 0 ) + post
        end
end