Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 69 lines (57 sloc) 1.22 KB
#!/usr/bin/env ruby
# input lines are name=value pairs, with other crap strewn about, e.g.
#
# t=0 i=0 label=1 pred=1
# blabla t=2 i=0 label=1 pred=0.999988 OMG!!!
# t=1 i=1993 label=0 pred=0
# t=1 i=1996 label=0 pred=9.16984e-06
#
# this is an easy debug format to output from a C program.
# combined with grep, use this to get tables of useful event-like data
class String
def matches(regex)
ret = []
scan(regex) do |match_groups|
ret << $~
end
ret
end
end
class Regexp
def matches(str)
str.matches(self)
end
end
def parse_line(line)
# >> (/(\S+)=(\S+)/.matches("t=1 i=1996 label=0 pred=9.16984e-06"))[0][1..2]
matches = /(\S*[a-zA-Z0-9])=(\S+)/.matches(line)
ret = {}
for m in matches
k,v = m[1..2]
ret[k] = v
end
ret
end
def puts_nas(n)
puts( (["NA"]*n).join("\t") )
end
names = nil
buildup = 0
for line in STDIN
if line !~ /[a-zA-Z0-9]=\S/
next unless ARGV.member?('-a')
if names.nil?
buildup += 1
else
puts_nas(names.size)
end
next
end
record = parse_line(line.chomp)
if names.nil?
names = record.keys.sort
puts names.join("\t")
buildup.times { puts_nas(names.size) }
end
puts names.map{|k| record[k]}.join("\t")
end