Module: Linguistics::EN::Conjugation
- Extended by:
- Loggability
- Defined in:
- lib/linguistics/en/conjugation.rb
Overview
This file contains functions for conjugating verbs.
Version
$Id: conjugation.rb,v 08d2e43206b3 2015/03/12 20:32:17 ged $
Authors
-
Robert Berry <[email protected]>
-
Michael Granger <[email protected]>
Copyright
Based on MorphAdorner (morphadorner.northwestern.edu/), which is licensed under the following terms:
Copyright © 2006-2009 by Northwestern University. All rights reserved.
Developed by: Academic and Research Technologies Northwestern University www.it.northwestern.edu/about/departments/at/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimers.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimers in the documentation
and/or other materials provided with the distribution.
Neither the names of Academic and Research Technologies, Northwestern
University, nor the names of its contributors may be used to endorse or
promote products derived from this Software without specific prior written
permission.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
Constant Summary collapse
- IRREGULAR_VERBS =
Hash of irregular verb infinitives, read from the DATA section of the file
{}
- DOUBLING_VERBS =
Array of doubling verbs, read from the DATA section of the file
[]
Class Method Summary collapse
-
.included(mod) ⇒ Object
Inclusion hook – load the verb data when the module is first included.
-
.load_doubling_verbs(data) ⇒ Object
Load the doubling verbs from the given
data
and return the resulting Array. -
.load_irregular_verbs(data) ⇒ Object
Parse irregular verbs from the given
data
, and return the resulting Hash.
Instance Method Summary collapse
-
#conjugate(tense, person = nil) ⇒ Object
Conjugate the receiving string as an infinitive with the specified
tense
andperson
. -
#past_participle(person = nil) ⇒ Object
Return the past participle of the word.
-
#past_tense(person = nil) ⇒ Object
Return the past tense of the word.
-
#present_participle(person = nil) ⇒ Object
Return the present participle of the word.
-
#present_tense(person = nil) ⇒ Object
Return the present tense of the word.
Class Method Details
.included(mod) ⇒ Object
Inclusion hook – load the verb data when the module is first included.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/linguistics/en/conjugation.rb', line 206 def self::included( mod ) # :nodoc: if IRREGULAR_VERBS.empty? self.log.debug "Loading conjunctions data." data = File.read( __FILE__ ).split( /^__END__$/ ).last irrverb_data, doublverb_data = data.split( /^#\n# Doubling Verbs.*\n#\n/, 2 ) IRREGULAR_VERBS.replace( self.load_irregular_verbs(irrverb_data) ) self.log.debug " loaded %d irregular verbs" % [ IRREGULAR_VERBS.length ] DOUBLING_VERBS.replace( self.load_doubling_verbs(doublverb_data) ) self.log.debug " loaded %d doubling verbs" % [ DOUBLING_VERBS.length ] end super end |
.load_doubling_verbs(data) ⇒ Object
Load the doubling verbs from the given data
and return the resulting Array.
250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/linguistics/en/conjugation.rb', line 250 def self::load_doubling_verbs( data ) self.log.debug " loading doubling verbs." results = [] data.each_line do |line| next if line =~ /^(#|\s*$)/ # Skip comments and blank lines results << line.chomp end self.log.debug " %d doubling verbs loaded." % [ results.length ] return results end |
.load_irregular_verbs(data) ⇒ Object
Parse irregular verbs from the given data
, and return the resulting Hash.
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/linguistics/en/conjugation.rb', line 223 def self::load_irregular_verbs( data ) self.log.debug " loading irregular verbs from %d bytes of data." % [ data.length ] results = {} data.each_line do |line| if line =~ /^(#|\s*$)/ # Skip comments and blank lines # self.log.debug " skipping line: %p" % [ line ] next end infinitive, person, tense, conjugation = line.chomp.split( /\s+/, 4 ) # self.log.debug " line split into: %p" % # [[ infinitive, person, tense, conjugation ]] raise "malformed line: %p" % [ line ] unless infinitive && person && tense && conjugation results[ infinitive ] ||= {} results[ infinitive ][ person.to_sym ] ||= {} results[ infinitive ][ person.to_sym ][ tense.to_sym ] = conjugation end self.log.debug " %d infinitives loaded." % [ results.length ] return results end |
Instance Method Details
#conjugate(tense, person = nil) ⇒ Object
Conjugate the receiving string as an infinitive with the specified tense
and person
.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/linguistics/en/conjugation.rb', line 97 def conjugate( tense, person=nil ) self.log.debug "Conjugating %p in %s tense, %s person" % [ self.to_s, tense, person || "any" ] person ||= :* verb = self.to_s.downcase if result = get_irregular( verb, person, tense ) self.log.debug " verb %p is irregular: %p" % [ verb, result ] return result end self.log.debug " regular verb: conjugating by tense" return case tense when :present conjugate_present( verb, person ) when :present_participle conjugate_present_participle( verb ) when :past conjugate_past( verb ) when :past_participle conjugate_past_participle( verb ) else verb end end |
#past_participle(person = nil) ⇒ Object
Return the past participle of the word
77 78 79 |
# File 'lib/linguistics/en/conjugation.rb', line 77 def past_participle( person=nil ) return self.conjugate( :past_participle, person ) end |
#past_tense(person = nil) ⇒ Object
Return the past tense of the word
71 72 73 |
# File 'lib/linguistics/en/conjugation.rb', line 71 def past_tense( person=nil ) return self.conjugate( :past, person ) end |
#present_participle(person = nil) ⇒ Object
Return the present participle of the word
89 90 91 |
# File 'lib/linguistics/en/conjugation.rb', line 89 def present_participle( person=nil ) return self.conjugate( :present_participle, person ) end |
#present_tense(person = nil) ⇒ Object
Return the present tense of the word
83 84 85 |
# File 'lib/linguistics/en/conjugation.rb', line 83 def present_tense( person=nil ) return self.conjugate( :present, person ) end |