Linguistics::EN::

Infinitives

module

Methods for deriving the infinitive forms of conjugated words for the English-language Linguistics module.

Public Instance Methods

anchor
infinitive()

Return the infinitive form of the given word

# File lib/linguistics/en/infinitives.rb, line 1034
def infinitive
        word = self.to_s
        word1 = word2 = suffix = rule = newword = ''

        if IRREGULAR_INFINITIVES.key?( word )
                word1        = IRREGULAR_INFINITIVES[ word ]
                rule = 'irregular'
        else
                # Build up $prefix{$suffix} as an array of prefixes, from longest to shortest.
                prefix, suffix = nil
                prefixes = Hash::new {|hsh,key| hsh[key] = []}

                # Build the hash of prefixes for the word
                1.upto( word.length ) {|i|
                        prefix = word[0, i]
                        suffix = word[i..-1]

                        (suffix.length - 1).downto( 0 ) {|j|
                                newword = prefix + suffix[0, j]
                                prefixes[ suffix ].push( newword )
                        }
                }

                self.log.debug "prefixes: %p" % [ prefixes ]

                # Now check for rules covering the prefixes for this word, picking
                # the first one if one was found.
                if (( suffix = ((INF_SUFFIX_RULE_ORDER & prefixes.keys).first) ))
                        rule = INF_SUFFIX_RULES[ suffix ][:rule]
                        shortestPrefix = INF_SUFFIX_RULES[ suffix ][:word1]
                        self.log.debug "Using rule %p (%p) for suffix %p" %
                                [ rule, shortestPrefix, suffix ] if $DEBUG

                        case shortestPrefix
                        when 0
                                word1 = prefixes[ suffix ][ 0 ]
                                word2 = prefixes[ suffix ][ 1 ]
                                self.log.debug "For sp = 0: word1: %p, word2: %p" %
                                        [ word1, word2 ] if $DEBUG

                        when -1
                                word1 = prefixes[ suffix ].last +
                                        INF_SUFFIX_RULES[ suffix ][:suffix1]
                                word2 = ''
                                self.log.debug "For sp = -1: word1: %p, word2: %p" %
                                        [ word1, word2 ] if $DEBUG

                        when -2
                                word1 = prefixes[ suffix ].last +
                                        INF_SUFFIX_RULES[ suffix ][:suffix1]
                                word2 = prefixes[ suffix ].last
                                self.log.debug "For sp = -2: word1: %p, word2: %p" %
                                        [ word1, word2 ] if $DEBUG

                        when -3
                                word1 = prefixes[ suffix ].last +
                                        INF_SUFFIX_RULES[ suffix ][:suffix1]
                                word2 = prefixes[ suffix ].last +
                                        INF_SUFFIX_RULES[ suffix ][:suffix2]
                                self.log.debug "For sp = -3: word1: %p, word2: %p" %
                                        [ word1, word2 ] if $DEBUG

                        when -4
                                word1 = word
                                word2 = ''
                                self.log.debug "For sp = -4: word1: %p, word2: %p" %
                                        [ word1, word2 ] if $DEBUG

                        else
                                raise IndexError,
                                        "Couldn't find rule for shortest prefix %p" %
                                        shortestPrefix
                        end

                        # Rules 12b and 15: Strip off 'ed' or 'ing'.
                        if rule == '12b' or rule == '15'
                                # Do we have a monosyllable of this form:
                                # o 0+ Consonants
                                # o 1+ Vowel
                                # o        2 Non-wx
                                # Eg: tipped => tipp?
                                # Then return tip and tipp.
                                # Eg: swimming => swimm?
                                # Then return swim and swimm.

                                if /^([^aeiou]*[aeiou]+)([^wx])\2$/ =~ word2
                                        word1 = $1 + $2
                                        word2 = $1 + $2 + $2
                                end
                        end
                end
        end

        return Infinitive.new( word1, word2, suffix, rule )
end