module Linguistics::EN::Conjugation

This file contains functions for conjugating verbs.

Version

$Id: conjugation.rb,v 08d2e43206b3 2015/03/12 20:32:17 ged $

Authors

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.

Public Instance Methods

conjugate( tense, person=nil ) click to toggle source

Conjugate the receiving string as an infinitive with the specified tense and person.

# 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 ) click to toggle source

Return the past participle of the word

# File lib/linguistics/en/conjugation.rb, line 77
def past_participle( person=nil )
        return self.conjugate( :past_participle, person )
end
past_tense( person=nil ) click to toggle source

Return the past tense of the word

# File lib/linguistics/en/conjugation.rb, line 71
def past_tense( person=nil )
        return self.conjugate( :past, person )
end
present_participle( person=nil ) click to toggle source

Return the present participle of the word

# File lib/linguistics/en/conjugation.rb, line 89
def present_participle( person=nil )
        return self.conjugate( :present_participle, person )
end
present_tense( person=nil ) click to toggle source

Return the present tense of the word

# File lib/linguistics/en/conjugation.rb, line 83
def present_tense( person=nil )
        return self.conjugate( :present, person )
end

Private Instance Methods

conjugate_past( verb ) click to toggle source

Conjugate the specified verb in the past tense; also used to conjugate the past participle.

# File lib/linguistics/en/conjugation.rb, line 167
def conjugate_past( verb )
        case verb
        when /e$/
                return verb + 'd'
        when /[^aeiou]y$/
                return verb[ 0..-2 ] + 'ied'
        else
                if DOUBLING_VERBS.include?( verb )
                        verb = verb + verb[ -1 ] + 'ed'
                else
                        return verb + 'ed'
                end
        end
end
Also aliased as: conjugate_past_participle
conjugate_past_participle( verb )
Alias for: conjugate_past
conjugate_present( verb, person=:third_person_singular ) click to toggle source

Conjugate the specified verb in the present tense in the given person. The only person that is

# File lib/linguistics/en/conjugation.rb, line 130
def conjugate_present( verb, person=:third_person_singular )
        return verb unless person == :third_person_singular

        case verb
        when /(ch|s|sh|x|z)$/
                return verb + 'es'
        when /(ay|ey|oy|uy)$/
                return verb + 's'
        when /[^aeiou]y$/
                return verb[ 0..-2 ] + 'ies'
        else
                return verb + 's'
        end
end
conjugate_present_participle( verb ) click to toggle source

Convugate the given verb as a present participle.

# File lib/linguistics/en/conjugation.rb, line 147
def conjugate_present_participle( verb )
        case verb
        when /[^aeiou]e$/
                return verb[ 0..-2 ] + 'ing'
        when /ie$/
                return verb[ 0..-3 ] + 'y' + 'ing'
        when /[aou]e$/
                return verb[ 0..-2 ] + 'ing'
        else
                if DOUBLING_VERBS.include?( verb )
                        return verb + verb[ -1 ] + 'ing'
                else
                        return verb + 'ing'
                end
        end
end
get_irregular( verb, person, tense ) click to toggle source

If the given verb is irregular in the given +person_ and

# File lib/linguistics/en/conjugation.rb, line 185
def get_irregular( verb, person, tense )
        self.log.debug "  looking for irregular verb: %p, %p person, %p tense" %
                [ verb, person, tense ]

        irregular = IRREGULAR_VERBS[ verb ] or return nil
        self.log.debug "    %p is irregular: %p, selecting %p variant" %
                [ verb, irregular, person ]
        irrperson = irregular[ person ] || irregular[ :* ] or return nil
        self.log.debug "    selected %p. Using %p tense: %p" %
                [ irrperson, tense, irrperson[tense] ]
        word = irrperson[ tense ] or return nil

        return word.sub( /\|.*/, '' )
end