summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-07-02 15:41:51 +0200
committerPatrick Simianer <p@simianer.de>2014-07-02 15:41:51 +0200
commite06dbc7fc9b7c24a7d66c4578f56e1596188abf8 (patch)
treeb98aeb4f97f2f6a5078da39588526d32fcaca577
parente9009f3bb8d2b86250b601e76f6d6e697c71e611 (diff)
canceled
-rwxr-xr-xmain.rb3
-rw-r--r--parse.rb32
2 files changed, 6 insertions, 29 deletions
diff --git a/main.rb b/main.rb
index 7dc7370..e41d0f1 100755
--- a/main.rb
+++ b/main.rb
@@ -52,15 +52,12 @@ def main
STDERR.write "> parsing\n"
Parse::parse input, n, active_chart, passive_chart, grammar
- exit
-
weights = SparseVector.from_kv(ReadFile.read(cfg[:weights]), ' ', "\n")
if !weights
weights = SparseVector.new
end
hypergraph = passive_chart.to_hg weights
- puts hypergraph.to_json weights
STDERR.write "> viterbi\n"
semiring = ViterbiSemiring.new
diff --git a/parse.rb b/parse.rb
index 8860b8c..1f69c91 100644
--- a/parse.rb
+++ b/parse.rb
@@ -155,22 +155,8 @@ def Parse::parse input, n, active_chart, passive_chart, grammar
# parse
new_symbols = []
remaining_items = []
-
- num_threads = 2
- slice_sz = active_chart.at(i,j).size/num_threads
- slices = []
- num_threads.times {
- slices << active_chart.at(i,j).shift(slice_sz+1)
- }
- m = Mutex.new
- threads = []
-
- slices.each_with_index { |slice,ti|
- threads << Thread.new(ti) {
- #while !active_chart.at(i,j).empty?
- while !slice.empty?
- #active_item = active_chart.at(i,j).pop
- active_item = slice.pop
+ while !active_chart.at(i,j).empty?
+ active_item = active_chart.at(i,j).pop
advanced = false
visit(1, i, j, 1) { |k,l|
if passive_chart.has active_item.rhs[active_item.dot].symbol, k, l
@@ -180,16 +166,13 @@ def Parse::parse input, n, active_chart, passive_chart, grammar
if scan new_item, input, j, passive_chart
if new_item.dot == new_item.rhs.size
if new_item.left == i && new_item.right == j
- #new_symbols << new_item.lhs.symbol if !new_symbols.include? new_item.lhs.symbol
- m.synchronize { new_symbols << new_item.lhs.symbol if !new_symbols.include? new_item.lhs.symbol }
- #passive_chart.add new_item, i, j
- m.synchronize { passive_chart.add new_item, i, j }
+ new_symbols << new_item.lhs.symbol if !new_symbols.include? new_item.lhs.symbol
+ passive_chart.add new_item, i, j
advanced = true
end
else
if new_item.right+(new_item.rhs.size-(new_item.dot)) <= j
- #active_chart.at(i,j) << new_item
- slice << new_item
+ active_chart.at(i,j) << new_item
advanced = true
end
end
@@ -198,13 +181,10 @@ def Parse::parse input, n, active_chart, passive_chart, grammar
end
}
if !advanced
- m.synchronize { remaining_items << active_item }
+ remaining_items << active_item
end
end
- }
- }
- threads.each { |t| t.join }
# 'self-filling' step
new_symbols.each { |s|