From ae3bc3e1870d009c4d54c55416ebb4b7c07a483f Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Tue, 17 Jun 2014 13:59:02 +0200 Subject: Parse module, zipf lib --- parse.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'parse.rb') diff --git a/parse.rb b/parse.rb index c9cbd7c..8005401 100644 --- a/parse.rb +++ b/parse.rb @@ -1,8 +1,11 @@ -require 'nlp_ruby' +require 'zipf' require_relative 'grammar' -def visit i, l, r, x=0 +module Parse + + +def Parse::visit i, l, r, x=0 i.upto(r-x) { |span| l.upto(r-span) { |k| yield k, k+span @@ -76,7 +79,7 @@ class Item < Grammar::Rule end end -def init input, n, active_chart, passive_chart, grammar +def Parse::init input, n, active_chart, passive_chart, grammar grammar.flat.each { |r| input.each_index { |i| if input[i, r.rhs.size] == r.rhs.map { |x| x.word } @@ -86,7 +89,7 @@ def init input, n, active_chart, passive_chart, grammar } end -def scan item, input, limit, passive_chart +def Parse::scan item, input, limit, passive_chart while item.rhs[item.dot].class == Grammar::T return false if item.right==limit if item.rhs[item.dot].word == input[item.right] @@ -99,7 +102,7 @@ def scan item, input, limit, passive_chart return true end -def parse input, n, active_chart, passive_chart, grammar +def Parse::parse input, n, active_chart, passive_chart, grammar visit(1, 0, n) { |i,j| STDERR.write " span(#{i},#{j})\n" @@ -168,3 +171,6 @@ def parse input, n, active_chart, passive_chart, grammar } end + +end #module + -- cgit v1.2.3