summaryrefslogtreecommitdiff
path: root/lib/nlp_ruby/stringutil.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nlp_ruby/stringutil.rb')
-rw-r--r--lib/nlp_ruby/stringutil.rb20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/nlp_ruby/stringutil.rb b/lib/nlp_ruby/stringutil.rb
index e9a3bc9..4091994 100644
--- a/lib/nlp_ruby/stringutil.rb
+++ b/lib/nlp_ruby/stringutil.rb
@@ -3,8 +3,8 @@ def tokenize s
s.strip.split
end
-def splitpipe s
- s.strip.split(/\s*\|\|\|\s*/)
+def splitpipe s, n=3
+ s.strip.split("|"*n)
end
def downcase? s
@@ -32,3 +32,19 @@ def read_feature_string s
return map
end
+
+def read_cfg fn
+ f = ReadFile.new fn
+ cfg = {}
+ while line = f.gets
+ line.strip!
+ next if /^\s*$/.match line
+ next if line[0]=='#'
+ content = line.split('#', 2).first
+ k, v = content.split(/\s*=\s*/, 2)
+ k.strip!; v.strip!
+ cfg[k] = v
+ end
+ return cfg
+end
+