Sha256: 8c3acdb91a461167a53758cf7f2b31807517e2a4ddce27aa22583fda63073637
Contents?: true
Size: 1.08 KB
Versions: 2
Compression:
Stored size: 1.08 KB
Contents
#!/usr/bin/env ruby require 'rubygems' gem 'biodiversity' rescue nil $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib")) require 'biodiversity' require 'json' if ARGV.empty? puts "Usage:\n\nnnparse file_with_scientific_names [output_file]\n\ndefault output_file is parsed.json\n\n" exit end input = ARGV[0] output = ARGV[1] || 'parsed.json' ruby_min_version = RUBY_VERSION.split(".")[0..1].join('').to_i p = ScientificNameParser.new o = open(output, 'w') count = 0 puts 'Parsing...' IO.foreach(input) do |line| count += 1 puts("%s lines parsed" % count) if count % 10000 == 0 name = line.gsub(/^[\d]*\s*/, '').strip begin if ruby_min_version < 19 old_kcode = $KCODE $KCODE = 'NONE' end p.parse(name) parsed_data = p.parsed.all_json rescue {'scientificName' => {'parsed' => false, 'verbatim' => name, 'error' => 'Parser error'}}.to_json if ruby_min_version < 19 $KCODE = old_kcode end rescue parsed_data = {'parsed' => false, 'verbatim' => name, 'error' => 'Parser error'}.to_json end o.write parsed_data + "\n" end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
biodiversity19-0.5.16 | bin/nnparse |
biodiversity-0.5.16 | bin/nnparse |