lib/zenlish/inflect/inflection_table_builder.rb in zenlish-0.2.05 vs lib/zenlish/inflect/inflection_table_builder.rb in zenlish-0.2.06

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require_relative 'feature_heading' require_relative 'method_heading' require_relative 'formal_argument' require_relative 'equals_literal' require_relative 'not_equals_literal' @@ -11,23 +13,23 @@ require_relative 'concatenation' require_relative 'substitution' require_relative 'inflection_rule' require_relative 'inflection_table' - # DecisionTable: Common_form - # | NUMBER | .base_form | Common_form | - # | singular | X | base_form | - # | plural | ~ /[^aeiouy]y$/ | sub(base_form, /y$/, "ies")| - # | plural | X | base_form + "s" | - # build('Common_form') do - # feature_heading 'NUMBER' - # method_heading 'base_form' - # | NUMBER | base_form | Common_form | - # rule [equals(:singular), dont_care ], col('base_form') - # rule [equals(:plural) , matches(/[^aeiouy]y$/)], sub(col('base_form'), /y$/, 'ies') - # rule [equals(:plural) , dont_care ], concat(col('base_form'), 's') - # end +# DecisionTable: Common_form +# | NUMBER | .base_form | Common_form | +# | singular | X | base_form | +# | plural | ~ /[^aeiouy]y$/ | sub(base_form, /y$/, "ies")| +# | plural | X | base_form + "s" | +# build('Common_form') do +# feature_heading 'NUMBER' +# method_heading 'base_form' +# | NUMBER | base_form | Common_form | +# rule [equals(:singular), dont_care ], col('base_form') +# rule [equals(:plural) , matches(/[^aeiouy]y$/)], sub(col('base_form'), /y$/, 'ies') +# rule [equals(:plural) , dont_care ], concat(col('base_form'), 's') +# end module Zenlish module Inflect class InflectionTableBuilder # Name of decision table @@ -48,24 +50,24 @@ end def feature_heading(aFeatureName) hd = FeatureHeading.new(aFeatureName) headings << hd - table.add_heading(hd) if table + table&.add_heading(hd) end def method_heading(aMethodName) hd = MethodHeading.new(aMethodName) headings << hd - table.add_heading(hd) if table + table&.add_heading(hd) end def rule(conditions, consequent) @conds = [] rl = InflectionRule.new(conditions.dup, consequent) rules << rl - table.add_rule(rl) if table + table&.add_rule(rl) rl end def equals(aValue) @@ -105,10 +107,11 @@ def col(aColName) col_index = headings.find_index { |hd| hd.label == aColName } err_msg = "Cannot find heading named '#{aColName}'." raise StandardError, err_msg if col_index.nil? + formal = FormalArgument.new(col_index) InputAsIs.new(formal) end def matches(aPattern) @@ -130,11 +133,11 @@ Concatenation.new(arg1, arg2) end private - def reset() + def reset @table = nil @headings = [] @conds = [] @rules = [] end @@ -142,6 +145,6 @@ # def do_it # @headings # end end # class end # module -end # module \ No newline at end of file +end # module