blob: f4e2ef8049f6055b363a742b215db80989e48e6b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#!/usr/bin/env ruby
require_relative 'hg'
semiring = ViterbiSemiring.new
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
#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 { |i| i.word }.join ' '}"
#}
|