summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--hg.rb4
-rw-r--r--parse.rb16
-rwxr-xr-xtest_parse.rb8
4 files changed, 17 insertions, 12 deletions
diff --git a/README.md b/README.md
index fa50235..4cdcf31 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,7 @@ not much to see here, yet
helpful stuff
* https://github.com/jweese/thrax/wiki/Glue-grammar
* http://aclweb.org/aclwiki/index.php?title=Hypergraph_Format
+ * http://kheafield.com/code/kenlm/developers/
todo
====
diff --git a/hg.rb b/hg.rb
index abd8777..e252ced 100644
--- a/hg.rb
+++ b/hg.rb
@@ -1,6 +1,4 @@
-#!/usr/bin/env ruby
-
-require 'nlp_ruby'
+require 'zipf'
require_relative 'grammar'
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
+
diff --git a/test_parse.rb b/test_parse.rb
index 0187675..d184892 100755
--- a/test_parse.rb
+++ b/test_parse.rb
@@ -57,12 +57,12 @@ def main
#grammar.add_pass_through_rules input
STDERR.write "> initializing charts\n"
- passive_chart = Chart.new n
- active_chart = Chart.new n
- init input, n, active_chart, passive_chart, grammar
+ passive_chart = Parse::Chart.new n
+ active_chart = Parse::Chart.new n
+ Parse::init input, n, active_chart, passive_chart, grammar
STDERR.write "> parsing\n"
- parse input, n, active_chart, passive_chart, grammar
+ Parse::parse input, n, active_chart, passive_chart, grammar
#puts "\n---\npassive chart"
#visit(1, 0, 5) { |i,j| puts "#{i},#{j}"; passive_chart.at(i,j).each { |item| puts " #{j} #{item.to_s}" }; puts }