Module: Linguistics::EN::Articles

Defined in:
lib/linguistics/en/articles.rb

Overview

Indefinite article methods for the English-language Linguistics module.

Constant Summary collapse

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!)

%r{
	^(
		(?!
			FJO       |
			[HLMNS]Y. |
			RY[EO]    |
			SQU       |
			(
				F[LR]?         |
				[HL]           |
				MN?            |
				N              |
				RH?            |
				S[CHKLMNPTVW]? |
				X(YL)?
			) [AEIOU]
		)
	[FHLMNRSX][A-Z]
	)
}x
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.

%r{^(y(?:b[lor]|cl[ea]|fere|gg|p[ios]|rou|tt))}i
A_explicit_an =

Exceptions to exceptions

Regexp.union( /euler/i, /hour(?!i)/i, /heir/i, /honest/i, /hono/i )
PL_count_zero =

Words which always indicate zero quantity

Regexp.union( "0", "no", "zero", "nil" )

Instance Method Summary collapse

Instance Method Details

#a(count = nil) ⇒ Object Also known as: an

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



106
107
108
109
110
111
112
113
114
115
116
# 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

#indef_article(count = nil) ⇒ Object

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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# 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

#no(count = nil) ⇒ Object

Translate zero-quantified phrase to “no phrase.plural



123
124
125
126
127
128
129
130
131
132
133
134
# 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