From 33fda7f79c02b8ef152b88a11f3810c9a25a7381 Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Wed, 18 Jun 2014 13:26:05 +0200 Subject: integration --- test/hg.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 test/hg.rb (limited to 'test/hg.rb') diff --git a/test/hg.rb b/test/hg.rb new file mode 100755 index 0000000..16e6b6f --- /dev/null +++ b/test/hg.rb @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby + +require_relative '../hg' + + +def main + # viterbi + semiring = ViterbiSemiring.new + hypergraph, nodes_by_id = HG::read_hypergraph_from_json('../example/toy/toy.json', semiring, true) + #hypergraph, nodes_by_id = HG::read_hypergraph_from_json('../example/glue/glue.json', semiring, true) + #hypergraph, nodes_by_id = HG::read_hypergraph_from_json('../example/3/3.json', semiring, true) + path, score = HG::viterbi_path hypergraph, nodes_by_id[-1], semiring + s = HG::derive path, path.last.head, [] + puts "#{s.map { |i| i.word }.join ' '}" + puts Math.log score + puts + + # all paths + hypergraph.reset + paths = HG::all_paths hypergraph, nodes_by_id[-1] + paths.each_with_index { |p,i| + s = HG::derive p, p.last.head, [] + puts "#{i+1}. #{s.map { |x| x.word }.join ' '}" + } +end + + +main + -- cgit v1.2.3