Sha256: 04888889606dd8d5d8e976ee0e4564a467530b33c2bb11b22a73785f9cf82b7b
Contents?: true
Size: 1.16 KB
Versions: 5
Compression:
Stored size: 1.16 KB
Contents
#!/usr/bin/env ruby require 'rubygems' gem_name = RUBY_VERSION.split('.')[0..1].join('').to_i > 18 ? 'biodiversity19' : 'biodiversity' gem gem_name rescue nil $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib")) require 'biodiversity' require 'json' def parser_error(name) {'scientificName' => {'parsed' => false, 'verbatim' => name, 'error' => 'Parser error'}}.to_json end 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 parser_error(name) if ruby_min_version < 19 $KCODE = old_kcode end rescue parsed_data = parser_error(name) end o.write parsed_data + "\n" end
Version data entries
5 entries across 5 versions & 2 rubygems
Version | Path |
---|---|
biodiversity19-0.6.2 | bin/nnparse |
biodiversity19-0.6.1 | bin/nnparse |
biodiversity-0.6.1 | bin/nnparse |
biodiversity-0.6.0 | bin/nnparse |
biodiversity19-0.6.0 | bin/nnparse |