summaryrefslogtreecommitdiff
path: root/parse.rb
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-06-17 13:59:02 +0200
committerPatrick Simianer <p@simianer.de>2014-06-17 13:59:02 +0200
commitae3bc3e1870d009c4d54c55416ebb4b7c07a483f (patch)
tree1e80f227fc9aa5b690648be8fecdec9e9ae14751 /parse.rb
parent1651cfb83e0d95f9ada0b9acae6ede84e605720b (diff)
Parse module, zipf lib
Diffstat (limited to 'parse.rb')
-rw-r--r--parse.rb16
1 files changed, 11 insertions, 5 deletions
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
+