Home:ALL Converter>Matching plural words in Treetop

Matching plural words in Treetop

Ask Time:2012-09-21T21:57:52         Author:Josh Voigts

Json Formatter

Is there a way to programmatically match plural words using Treetop. The Linguistics gem will pluralize a word, but how can that be inserted back into the parser.

Here's an example of what I'm trying to do:

#!/usr/bin/env ruby
require 'treetop'
require 'linguistics'
include Linguistics::EN
Treetop.load_from_string DATA.read

parser = RecipeParser.new

p parser.parse('cans')

__END__
grammar Recipe
   rule units
      unit &{|s| plural(s[0].text_value) }  
   end
   rule unit
      'can'
   end
end

Author:Josh Voigts,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/12532010/matching-plural-words-in-treetop
yy