Indefinite article methods for the English-language Linguistics module.
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!)
Exceptions to exceptions
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.
Words which always indicate zero quantity
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
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})$/ !~ 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})/ return "an #{word}" # Handle abbreviations when A_abbrev return "an #{word}" when /^[aefhilmnorsx][.-]/ return "an #{word}" when /^[a-z][.-]/ return "a #{word}" # Handle consonants when /^[^aeiouy]/ return "a #{word}" # Handle special vowel-forms when /^e[uw]/ return "a #{word}" when /^onc?e\b/ return "a #{word}" when /^uni([^nmd]|mo)/ return "a #{word}" when /^u[bcfhjkqrst][aeiou]/ return "a #{word}" # Handle vowels when /^[aeiou]/ 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
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
Generated with the Darkfish Rdoc Generator 2.