In Files
Namespace
Information
Infinitive
Functions for deriving the infinitive forms of conjugated English words.
Constants
- IRREGULAR
Irregular word => infinitive form
- RULES
Suffix Rules
- RULE_ORDER
List of rule suffixes in processing order.
- IRREGULAR_RULE
Public Class Methods
ditto_rule(suffix, suffix1, suffix2, order, number)
click to toggle source
Use the original string. (-4)
# File lib/english/infinitive.rb, line 631
631: def self.ditto_rule(suffix, suffix1, suffix2, order, number)
632: RULES[suffix] = Rule.new(:ditto, suffix, suffix1, suffix2, order, number)
633: end
infinitives(word)
click to toggle source
Returns the infinative and any acceptable alternatives.
# File lib/english/infinitive.rb, line 712
712: def self.infinitives(word)
713: information(word)[1..1]
714: end
information(word)
click to toggle source
Return the rule applies and all viable infinitive forms of the given word.
# File lib/english/infinitive.rb, line 719
719: def self.information(word)
720: word = word.to_s
721: word1 = word2 = suffix = rule = newword = ''
722:
723: if IRREGULAR.key?(word)
724: word1 = IRREGULAR[word]
725: word2 = nil
726: rule = IRREGULAR_RULE
727: else
728: prefixes = prefixes(word)
729: rule = rule(word, prefixes)
730:
731: $stderr.puts "prefixes: %p" % prefixes if $DEBUG
732:
733: if rule
734: suffix = rule.suffix
735:
736: $stderr.puts "Using rule %p (%p) for suffix %p" %
737: [rule.number, rule.type, rule.suffix] if $DEBUG
738:
739: case rule.type #shortest_prefix
740: when :long
741: word1 = prefixes[suffix][0]
742: word2 = prefixes[suffix][1]
743: when :short
744: word1 = prefixes[suffix].last + rule.suffix1
745: word2 = ''
746: when :letter
747: word1 = prefixes[suffix].last + rule.suffix1
748: word2 = prefixes[suffix].last
749: when :special
750: word1 = prefixes[suffix].last + rule.suffix1
751: word2 = prefixes[suffix].last + rule.suffix2
752: when :ditto
753: word1 = word
754: word2 = ''
755: else
756: raise IndexError, "Couldn't find rule for shortest prefix %p" % rule.type #shortest_prefix
757: end
758:
759: $stderr.puts "For %p: word1: %p, word2: %p" % [rule.type, word1, word2] if $DEBUG
760:
761: # Rules 12b and 15: Strip off 'ed' or 'ing'.
762: if rule.number == '12b' or rule.number == '15'
763: # Do we have a monosyllable of this form:
764: # o 0+ Consonants
765: # o 1+ Vowel
766: # o 2 Non-wx
767: # Eg: tipped => tipp?
768: # Then return tip and tipp.
769: # Eg: swimming => swimm?
770: # Then return tipswim and swimm.
771: if /^([^aeiou]*[aeiou]+)([^wx])\22$$/ =~ word2
772: word1 = $1 + $2
773: word2 = $1 + $2 + $2
774: end
775: end
776: else
777: word1 = word
778: word2 = nil
779: rule = IRREGULAR_RULE
780: end
781: end
782:
783: return rule, word1, word2
784: end
inifinitive(word)
click to toggle source
Returns the affinative and any acceptable alternatives.
# File lib/english/infinitive.rb, line 707
707: def self.inifinitive(word)
708: information(word)[1]
709: end
letter_rule(suffix, suffix1, suffix2, order, number)
click to toggle source
Letter rule. (-2)
# File lib/english/infinitive.rb, line 621
621: def self.letter_rule(suffix, suffix1, suffix2, order, number)
622: RULES[suffix] = Rule.new(:letter, suffix, suffix1, suffix2, order, number)
623: end
long_rule(suffix, suffix1, suffix2, order, number)
click to toggle source
Long rule (longest prefix). (0)
# File lib/english/infinitive.rb, line 606
606: def self.long_rule(suffix, suffix1, suffix2, order, number)
607: RULES[suffix] = Rule.new(:long, suffix, suffix1, suffix2, order, number)
608: end
prefixes(word)
click to toggle source
Calculate the prefixes for a given word.
# File lib/english/infinitive.rb, line 817
817: def self.prefixes(word)
818: # Build up prefix[suffix] as an array of prefixes, from longest to shortest.
819: prefix, suffix = nil, nil
820: prefixes = Hash.new{ |h,k| h[k] = [] }
821: # Build the hash of prefixes for the word
822: 1.upto(word.length) do |i|
823: prefix = word[0, i]
824: suffix = word[i..1]
825: (suffix.length - 1).downto(0) do |j|
826: newword = prefix + suffix[0,j]
827: prefixes[suffix].push(newword)
828: end
829: end
830: return prefixes
831: end
rule(word, prefixes=nil)
click to toggle source
Lookup the rule that applies to a given word.
# File lib/english/infinitive.rb, line 787
787: def self.rule(word, prefixes=nil)
788: prefixes = prefixes(word) unless prefixes
789:
790: if IRREGULAR.key?(word)
791: IRREGULAR_RULE
792: else
793: # Build up prefix[suffix] as an array of prefixes, from longest to shortest.
794: prefix, suffix = nil, nil
795: prefixes = Hash.new{ |h,k| h[k] = [] }
796: # Build the hash of prefixes for the word
797: 1.upto(word.length) do |i|
798: prefix = word[0, i]
799: suffix = word[i..1]
800: (suffix.length - 1).downto(0) do |j|
801: newword = prefix + suffix[0,j]
802: prefixes[suffix].push(newword)
803: end
804: end
805: # Now check for rules covering the prefixes for this word, picking
806: # the first one if one was found.
807: suffix = (RULE_ORDER & prefixes.keys).first
808: if suffix
809: RULES[suffix]
810: else
811: IRREGULAR_RULE
812: end
813: end
814: end
second_rule(suffix, suffix1, suffix2, order, number)
click to toggle source
Longer Rule (2nd longest prefix). (1)
# File lib/english/infinitive.rb, line 611
611: def self.second_rule(suffix, suffix1, suffix2, order, number)
612: RULES[suffix] = Rule.new(:second, suffix, suffix1, suffix2, order, number)
613: end
short_rule(suffix, suffix1, suffix2, order, number)
click to toggle source
Short Rule. (-1)
# File lib/english/infinitive.rb, line 616
616: def self.short_rule(suffix, suffix1, suffix2, order, number)
617: RULES[suffix] = Rule.new(:short, suffix, suffix1, suffix2, order, number)
618: end
Disabled; run with --debug to generate this.