summaryrefslogtreecommitdiff
path: root/lib/nlp_ruby/SparseVector.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nlp_ruby/SparseVector.rb')
-rw-r--r--lib/nlp_ruby/SparseVector.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/nlp_ruby/SparseVector.rb b/lib/nlp_ruby/SparseVector.rb
index 9919a65..964ef4e 100644
--- a/lib/nlp_ruby/SparseVector.rb
+++ b/lib/nlp_ruby/SparseVector.rb
@@ -53,10 +53,21 @@ class SparseVector < Hash
return Math.sqrt(sum)
end
- def to_kv
+ # FIXME
+ def from_kv_file fn, sep=' '
+ f = ReadFile.new(fn)
+ while line = f.gets
+ key, value = line.strip.split sep
+ value = value.to_f
+ self[key] = value
+ end
+ end
+
+ # FIXME
+ def to_kv sep='='
a = []
self.each_pair { |k,v|
- a << "#{k}=#{v}"
+ a << "#{k}#{sep}#{v}"
}
return a.join ' '
end