diff options
author | Patrick Simianer <p@simianer.de> | 2014-06-17 13:59:02 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-06-17 13:59:02 +0200 |
commit | ae3bc3e1870d009c4d54c55416ebb4b7c07a483f (patch) | |
tree | 1e80f227fc9aa5b690648be8fecdec9e9ae14751 | |
parent | 1651cfb83e0d95f9ada0b9acae6ede84e605720b (diff) |
Parse module, zipf lib
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | hg.rb | 4 | ||||
-rw-r--r-- | parse.rb | 16 | ||||
-rwxr-xr-x | test_parse.rb | 8 |
4 files changed, 17 insertions, 12 deletions
@@ -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 ==== @@ -1,6 +1,4 @@ -#!/usr/bin/env ruby - -require 'nlp_ruby' +require 'zipf' require_relative 'grammar' @@ -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 } |