Skip to content

Commit

Permalink
Fixed field extraction in open and index
Browse files Browse the repository at this point in the history
  • Loading branch information
mikisvaz committed Sep 8, 2010
1 parent 9c5e81f commit 23f6a8b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/rbbt/util/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Index
# where each element points to the first element in the row. +lexicon+
# is the file containing the data.
def self.index(lexicon, options = {})
options = {:sep => "\t|\\|", :case_sensitive => true}.merge(options)
options = {:sep => "\t", :sep2 => '\|', :case_sensitive => true}.merge(options)


data = Open.to_hash(lexicon, options)
Expand Down
9 changes: 6 additions & 3 deletions lib/rbbt/util/open.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ def self.func_match_field(entities, options = {})
end

def self.fields(line, sep = "\t")
chunks = line.chomp.split(/(#{sep})/).select{|c| c !~ /^#{sep}$/ }
line << sep
line << "PLACEHOLDER"
chunks = line.split(/(#{sep})/).select{|c| c !~ /^#{sep}$/ }
if line =~ /#{sep}$/
chunks << ""
end
chunks.pop
chunks
end

Expand Down Expand Up @@ -197,7 +200,7 @@ def self.to_hash(input, options = {})
sep2 = options[:sep2] || "|"
single = options[:single]
single = false if single.nil?
flatten = options[:flatten] || single
flatten = options[:flatten]
flatten = single if flatten.nil?

extra = [extra] if extra && ! extra.is_a?( Array)
Expand All @@ -214,7 +217,7 @@ def self.to_hash(input, options = {})
next if exclude and exclude.call(l)
next if select and ! select.call(l)

row_fields = self.fields(l, sep)
row_fields = self.fields(l.chomp, sep)
id = row_fields[native]
next if id.nil? || id == ""

Expand Down

0 comments on commit 23f6a8b

Please sign in to comment.