Skip to content

Commit

Permalink
Replaced Biodiversity gem with local lib calling gnparser tool
Browse files Browse the repository at this point in the history
  • Loading branch information
LocoDelAssembly committed Feb 18, 2020
1 parent f7e8434 commit 0628585
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ RUN apt-get update && \
nodejs \
redis-server libhiredis-dev && \
apt clean && \
rm -rf /var/lip/abpt/lists/* /tmp/* /var/tmp/*
rm -rf /var/lip/abpt/lists/* /tmp/* /var/tmp/* && \
wget https://gitlab.com/gogna/gnparser/uploads/643872fc2c63d9218e5612c5f545c511/gnparser-v0.13.0-linux.tar.gz && \
tar xf gnparser-v0.13.0-linux.tar.gz -C /usr/local/bin

RUN locale-gen en_US.UTF-8

Expand Down
5 changes: 4 additions & 1 deletion Dockerfile.development
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ RUN apt-get update && \
cmake \
nodejs && \
apt clean && \
rm -rf /var/lip/abpt/lists/* /tmp/* /var/tmp/*
rm -rf /var/lip/abpt/lists/* /tmp/* /var/tmp/* && \
wget https://gitlab.com/gogna/gnparser/uploads/643872fc2c63d9218e5612c5f545c511/gnparser-v0.13.0-linux.tar.gz && \
tar xf gnparser-v0.13.0-linux.tar.gz -C /usr/local/bin

#
# Install ruby
# Source: https://github.com/drecom/docker-ubuntu-ruby/blob/2.4.4/Dockerfile
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ gem 'rgb'
gem 'taxonifi', '0.4.0'
gem 'sqed', '0.5.8'
gem 'dwc-archive', '~> 1.0.1'
gem 'biodiversity', '~> 4.0', '>= 4.0.2'
#gem 'biodiversity', '~> 4.0', '>= 4.0.2'
gem 'ruby-units', '~> 2.3.0', require: 'ruby_units/namespaced'

# Minor Utils/helpers
Expand Down
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ GEM
bindex (0.8.1)
binding_of_caller (0.8.0)
debug_inspector (>= 0.0.1)
biodiversity (4.0.2)
ffi (~> 1.11)
brakeman (4.7.2)
builder (3.2.4)
byebug (11.1.1)
Expand Down Expand Up @@ -538,7 +536,6 @@ DEPENDENCIES
better_errors (~> 2.4)
bibtex-ruby (~> 5.1.1)
binding_of_caller
biodiversity (~> 4.0, >= 4.0.2)
brakeman (~> 4.6, >= 4.6.1)
bundler (~> 2.0)
byebug (~> 11.1)
Expand Down
60 changes: 60 additions & 0 deletions lib/biodiversity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module Biodiversity
module Parser

def self.parse(name, simple = false)
parsed = simple ? parse_go_simple(name) : parse_go_compact(name)
output(parsed, simple)
end

def self.output(parsed, simple)
if simple
parsed = parsed.split('|')
{
id: parsed[0],
verbatim: parsed[1],
canonicalName: {
full: parsed[2],
simple: parsed[3],
stem: parsed[4]
},
authorship: parsed[5],
year: parsed[6],
quality: parsed[7]
}
else
JSON.parse(parsed, symbolize_names: true)
end
end

private

def self.start_gnparser
io = {}

['compact', 'simple'].each do |format|
stdin, stdout, stderr = Open3.popen3("gnparser --format #{format}")
io[format.to_sym] = { stdin: stdin, stdout: stdout, stderr: stderr }
end
io
end

@@semaphore = Mutex.new
@@io = start_gnparser

def self.parse_go(name, format)
@@semaphore.synchronize do
@@io[format][:stdin].puts(name)
@@io[format][:stdout].gets
end
end

def self.parse_go_compact(name)
parse_go(name, :compact)
end

def self.parse_go_simple(name)
parse_go(name, :simple)
end

end
end

0 comments on commit 0628585

Please sign in to comment.