gnfinder 0.15.4 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b44ef459356568026904e4b42664ab39b3b7cfef043c33e62d95c47f7081ec7b
4
- data.tar.gz: 5da9930ce9d03c4184b51055a6a17d5d63510246460a742b768b56d940f6f536
3
+ metadata.gz: 184b18622694218dde5a93d5aeaec67b4653761ab4be512e79df7be1d8f1b67d
4
+ data.tar.gz: 2a3be26a7008ee7e5e4834cb62146d95c2d15cf069d2a9df50d327da4813f8fd
5
5
  SHA512:
6
- metadata.gz: 2d37282d56d4d41d913f74765d86b6ea38ccb8ececcd957a672bf1296fb3dfb5fb50a373fb64f4e0c981cfd658eb884a4eb6179434e82c7b619cd54c8dcf21f0
7
- data.tar.gz: 27ac046cd874aa9a099d44290d818d61d85282e9bd10f3fb384c37293ace1dd4f50b47f2693ee2220b46c4980535d7a8936b29c01c3ca597cf577ad3ffd0f91a
6
+ metadata.gz: d3b61878fa159a360ef5825bb807084ffbc4b0fc1b3e1cc6af9b82012ff487951df0d017e9dbf3b560b08dc281c354b134d6c3a3201912d158cdff2910b80d5c
7
+ data.tar.gz: 25b30a86f4b4c54ece188ffe41db5c35c5467ebde0699b74f5b3205170e4e84924909990733e18a1e331d1b1c26b1c5a2de2ea3f1416dbff8a2dfb61efb9edea
@@ -0,0 +1,41 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ${{ matrix.os }}
20
+ strategy:
21
+ matrix:
22
+ os: [ubuntu-latest, macos-latest, windows-latest]
23
+ ruby: [2.6, 2.7, 3.0]
24
+
25
+ steps:
26
+ - uses: actions/checkout@v2
27
+ - name: Set up Ruby
28
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
29
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
30
+ # uses: ruby/setup-ruby@v1
31
+ uses: ruby/setup-ruby@fdcfbcf14ec9672f6f615cb9589a1bc5dd69d262
32
+ with:
33
+ ruby-version: ${{ matrix.ruby }}
34
+ - name: Install dependencies
35
+ run: bundle install
36
+ - name: Show environment
37
+ run: gem environment
38
+ - name: Run tests
39
+ run: bundle exec rake
40
+ - name: Checking install works
41
+ run: rake install
data/.rubocop.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  AllCops:
2
2
  NewCops: disable
3
- TargetRubyVersion: 3.0
3
+ TargetRubyVersion: 2.6
4
4
  Exclude:
5
5
  - 'lib/protob_pb.rb'
6
6
  - 'lib/protob_services_pb.rb'
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [v0.17.0]
6
+
7
+ - Update to gnfinder v0.17.0
8
+
9
+ ## [v0.15.5]
10
+
11
+ - Add [#16]: Search names using URL.
12
+
5
13
  ## [v0.15.4]
6
14
 
7
15
  - Add [#14]: Compatibility with gnfider v0.15.4, switching to REST API.
data/README.md CHANGED
@@ -1,43 +1,49 @@
1
1
  # gnfinder
2
2
 
3
- Ruby gem to access functionality of [gnfinder] project written in Go. This gem
4
- allows to perform fast and accurate scientific name finding in UTF-8 encoded
5
- plain texts for Ruby-based projects.
6
-
7
- - [gnfinder](#gnfinder)
8
- - [Requirements](#requirements)
9
- - [Installation](#installation)
10
- - [Usage](#usage)
11
- - [Finding names in a text using default settings](#finding-names-in-a-text-using-default-settings)
12
- - [Optionally disable Bayes search](#optionally-disable-bayes-search)
13
- - [Set a language for the text](#set-a-language-for-the-text)
14
- - [Set automatic detection of text's language](#set-automatic-detection-of-texts-language)
15
- - [Set verification option](#set-verification-option)
16
- - [Set preferred data-sources list](#set-preferred-data-sources-list)
17
- - [Combination of parameters.](#combination-of-parameters)
18
- - [Development](#development)
3
+ Ruby gem to access functionality of [GNfinder] project written in Go. This gem
4
+ allows to perform fast and accurate scientific name finding in texts,
5
+ web-pages, as well as a large variety of documents. Document files can be
6
+ accessed either locally or via a URL.
7
+
8
+
9
+ <!-- vim-markdown-toc GFM -->
10
+
11
+ * [Requirements](#requirements)
12
+ * [Installation](#installation)
13
+ * [Usage](#usage)
14
+ * [Finding names in a text using default settings](#finding-names-in-a-text-using-default-settings)
15
+ * [Finding names by a URL](#finding-names-by-a-url)
16
+ * [Finding names in a file](#finding-names-in-a-file)
17
+ * [Optionally disable Bayes search](#optionally-disable-bayes-search)
18
+ * [Set a language for the text](#set-a-language-for-the-text)
19
+ * [Set automatic detection of text's language](#set-automatic-detection-of-texts-language)
20
+ * [Set verification option](#set-verification-option)
21
+ * [Set preferred data-sources list](#set-preferred-data-sources-list)
22
+ * [Combination of parameters.](#combination-of-parameters)
23
+ * [Development](#development)
24
+
25
+ <!-- vim-markdown-toc -->
19
26
 
20
27
  ## Requirements
21
28
 
22
- This gem uses gRPC to access a running [gnfinder] server. You can find how
23
- to run it in [gnfinder] README file.
29
+ This gem uses REST API to access a running [GNfinder] server. You can find how
30
+ to run it in [GNfinder] README file. By default it uses
31
+ `https://gnfinder.globalnames.org/api/v0`
24
32
 
25
33
  ## Installation
26
34
 
27
- To use the gem from Ruby proect install it using Gemfile, or manually:
28
-
29
35
  ```bash
30
36
  gem install gnfinder
31
37
  ```
32
38
 
33
39
  ## Usage
34
40
 
35
- The purpose of this gem is to access [gnfinder] functionality out of Ruby
41
+ The purpose of this gem is to access [GNfinder] functionality from Ruby
36
42
  applications. If you need to find names using other languages, use the
37
43
  [source code][client] of this gem for reference. For other usages read
38
- the original Go-lang [gnfinder] README file.
44
+ the original Go-lang [GNfinder] README file.
39
45
 
40
- First you need to create a instance of a `gnfinder` client
46
+ First you need to create an instance of a `gnfinder` client
41
47
 
42
48
  ```ruby
43
49
  require 'gnfinder'
@@ -45,25 +51,24 @@ require 'gnfinder'
45
51
  gf = Gnfinder::Client.new
46
52
  ```
47
53
 
48
- By default the client will try to connect to `localhost:8778`. If you
49
- have another location for the server use:
50
-
51
-
54
+ By default the client will try to connect to
55
+ `https://gnfinder.globalnames.org/api/v0`. If you have another location for the
56
+ server use:
52
57
 
53
58
  ```ruby
54
59
  require 'gnfinder'
55
60
 
56
61
  # you can use global public gnfinder server
57
62
  # located at finder-rpc.globalnames.org
58
- gf = Gnfinder::Client.new(host = 'finder-rpc.globalnames.org', port = 80)
63
+ gf = Gnfinder::Client.new(host = 'finder.example.org', port = 80)
59
64
 
60
- # localhost, different port
65
+ # localhost, port 8000
61
66
  gf = Gnfinder::Client.new(host = '0.0.0.0', port = 8000)
62
67
  ```
63
68
 
64
69
  ### Finding names in a text using default settings
65
70
 
66
- You can find format of returning result in [proto file] or in [tests]
71
+ You can find format of returning result in [GNfinder API docs]
67
72
 
68
73
  ```ruby
69
74
  txt = File.read('utf8-text-with-names.txt')
@@ -73,7 +78,39 @@ puts res.names[0].value
73
78
  puts res.names[0].odds
74
79
  ```
75
80
 
76
- Returned result will have the following methods for each name:
81
+ ### Finding names by a URL
82
+
83
+ If you need to find names in an HTML page, or a PDF document available on
84
+ Internet, use `find_url` method.
85
+
86
+ ```ruby
87
+ url = 'https://en.wikipedia.org/wiki/Monochamus_galloprovincialis'
88
+ res = gf.find_url(url)
89
+ puts res.names[0].value
90
+ puts res.names[0].odds
91
+ ```
92
+
93
+ ### Finding names in a file
94
+
95
+ Many different file types are supported (PDF, JPB, TIFF, MS Word, MS Excel
96
+ etc).
97
+
98
+ ```ruby
99
+ path = "/path/to/file.pdf"
100
+ res = gf.find_file(path)
101
+ puts res.names[0].value
102
+ ```
103
+
104
+ Support of file-uploading uses 'multipart/form' approach. Here is an
105
+ illustration for `curl`:
106
+
107
+ ```bash
108
+ curl -v -F sources[]=1 -F sources[]=12 -F file=@file.pdf \
109
+ https://finder.globalnames.org/api/v0/find
110
+ ```
111
+
112
+ Returned result is quite detailed and contains many accessor methods, for
113
+ example:
77
114
 
78
115
  * value: name-string cleaned up for verification.
79
116
  * verbatim: name-string as it was found in the text.
@@ -173,21 +210,6 @@ res = gf.find_names(txt, language: 'eng', sources: [1, 4, 179])
173
210
 
174
211
  ## Development
175
212
 
176
- This gem uses gRPC to access [gnfinder] server. gRPC in turn depends on a
177
- protobuf library. If you need to compile Ruby programs with protobuf you need
178
- to install [Go] language and download [gnfinder] project.
179
-
180
- ```bash
181
- go get github.com/gnames/gnfinder
182
- ```
183
- Then you need to run bundle from the root of the project and generate
184
- grpc files:
185
-
186
- ```bash
187
- bundle
188
- rake grpc
189
- ```
190
-
191
213
  If you get an error, you might need to set a ``GOPATH`` environment variable.
192
214
 
193
215
  After starting the server with default host and port (localhost:8778) you will
@@ -208,10 +230,10 @@ To run tests without rubocop
208
230
  bundle exec rspec
209
231
  ```
210
232
 
211
- [gnfinder]: https://github.com/gnames/gnfinder
233
+ [GNfinder]: https://github.com/gnames/gnfinder
212
234
  [gnfinder recent release]: https://github.com/gnames/gnfinder/releases
213
235
  [Go]: https://golang.org/doc/install
214
236
  [client]: https://github.com/GlobalNamesArchitecture/gnfinder/blob/master/lib/gnfinder/client.rb
215
237
  [data-source list]: http://index.globalnames.org/datasource
216
- [proto file]: https://github.com/GlobalNamesArchitecture/gnfinder/blob/master/lib/protob_pb.rb
217
238
  [tests]: https://github.com/GlobalNamesArchitecture/gnfinder/blob/master/spec/lib/client_spec.rb
239
+ [GNfinder API docs]: https://apidoc.globalnames.org/gnfinder
data/Rakefile CHANGED
@@ -24,16 +24,7 @@ RSpec::Core::RakeTask.new(:rcov) do |spec|
24
24
  spec.rcov = true
25
25
  end
26
26
 
27
- task :grpc do
28
- cmd = 'grpc_tools_ruby_protoc ' \
29
- '-I $GOPATH/src/github.com/gnames/gnfinder/protob ' \
30
- '--ruby_out=lib --grpc_out=lib ' \
31
- '$GOPATH/src/github.com/gnames/gnfinder/protob/protob.proto'
32
- puts cmd
33
- `#{cmd}`
34
- end
35
-
36
27
  require 'rubocop/rake_task'
37
28
  RuboCop::RakeTask.new
38
29
 
39
- task default: %i[rubocop grpc spec]
30
+ task default: %i[rubocop spec]
data/gnfinder.gemspec CHANGED
@@ -20,12 +20,14 @@ Gem::Specification.new do |gem|
20
20
  .reject { |f| f.match(%r{^(test|spec|features)/}) }
21
21
 
22
22
  gem.require_paths = ['lib']
23
- gem.required_ruby_version = '~> 3.0'
23
+ gem.required_ruby_version = '>= 2.6', '< 4'
24
24
  gem.add_dependency 'rest-client', '~> 2.1'
25
25
  gem.add_development_dependency 'bundler', '~> 2.2'
26
26
  gem.add_development_dependency 'byebug', '~> 11.1'
27
27
  gem.add_development_dependency 'rake', '~> 13.0'
28
28
  gem.add_development_dependency 'rspec', '~> 3.10'
29
- gem.add_development_dependency 'rubocop', '~> 1.20'
29
+ gem.add_development_dependency 'rubocop', '~> 1.21'
30
+ gem.add_development_dependency 'rubocop-rake', '~> 0.6.0'
31
+ gem.add_development_dependency 'rubocop-rspec', '~> 2.4'
30
32
  gem.add_development_dependency 'solargraph', '~> 0.43'
31
33
  end
@@ -4,7 +4,7 @@ module Gnfinder
4
4
  # Gnfinder::Client connects to gnfinder server
5
5
  class Client
6
6
  def initialize(host = 'https://gnfinder.globalnames.org', port = '')
7
- api_path = '/api/v1'
7
+ api_path = '/api/v0'
8
8
  url = host + api_path
9
9
  url = "#{host}:#{port}#{api_path}" if port.to_s != ''
10
10
  @site = RestClient::Resource.new(url, read_timeout: 60)
@@ -21,41 +21,63 @@ module Gnfinder
21
21
  @site['/ping'].get.body
22
22
  end
23
23
 
24
- # rubocop:disable all
24
+ def find_file(path, opts = {})
25
+ params = {}
26
+ update_params(params, opts)
27
+ file = File.new(path, 'rb')
28
+ params = params.merge(file: file)
29
+ resp = @site['find'].post(params)
30
+ prepare_result(resp)
31
+ end
32
+
33
+ def find_url(url, opts = {})
34
+ return to_open_struct({ "names": [] }) if url.to_s.strip == ''
35
+
36
+ params = { url: url }
37
+ find(params, opts)
38
+ end
39
+
25
40
  def find_names(text, opts = {})
26
- if text.to_s.strip == ''
27
- return to_open_struct({ "names": [] })
28
- end
41
+ return to_open_struct({ "names": [] }) if text.to_s.strip == ''
29
42
 
30
43
  params = { text: text }
44
+ find(params, opts)
45
+ end
46
+
47
+ private
48
+
49
+ # rubocop:disable all
50
+ def find(params, opts = {})
51
+ update_params(params, opts)
52
+
53
+ resp = @site['find'].post params.to_json, {content_type: :json, accept: :json}
54
+ prepare_result(resp)
55
+ end
56
+ # rubocop:enable all
57
+
58
+ def prepare_result(response)
59
+ output = JSON.parse(response.body)
60
+ res = output['metadata']
61
+ res['names'] = output['names'] || []
62
+ res = res.deep_transform_keys(&:underscore)
63
+ res['names'] = [] if res['names'].nil?
64
+ to_open_struct(res)
65
+ end
66
+
67
+ # rubocop:disable all
68
+ def update_params(params, opts)
31
69
  params[:noBayes] = true if opts[:no_bayes]
32
70
  params[:oddsDetails] = true if opts[:odds_details]
33
71
  params[:language] = opts[:language] if opts[:language].to_s.strip != ''
34
72
 
35
- if opts[:words_around] && opts[:words_around] > 0
36
- params[:wordsAround] = opts[:words_around]
37
- end
73
+ params[:wordsAround] = opts[:words_around] if opts[:words_around] && opts[:words_around].positive?
38
74
 
39
75
  params[:verification] = true if opts[:verification]
40
76
 
41
- if opts[:sources] && !opts[:sources].empty?
42
- params[:sources] = opts[:sources]
43
- end
44
-
45
- res = @site['find'].post params.to_json, {content_type: :json, accept: :json}
46
- output = JSON.parse(res.body)
47
- res = output["metadata"]
48
- res["names"] = output["names"] || []
49
- res = res.deep_transform_keys(&:underscore)
50
- if res["names"].nil?
51
- res["names"] = []
52
- end
53
- to_open_struct(res)
77
+ params[:sources] = opts[:sources] if opts[:sources] && !opts[:sources].empty?
54
78
  end
55
79
  # rubocop:enable all
56
80
 
57
- private
58
-
59
81
  def to_open_struct(obj)
60
82
  case obj
61
83
  when Hash
@@ -3,7 +3,7 @@
3
3
  # Gnfinder is a namespace module for gndinfer gem.
4
4
  module Gnfinder
5
5
  # Version corresponds to the minimal supported version of Go gnfinder
6
- VERSION = '0.15.4'
6
+ VERSION = '0.17.0'
7
7
 
8
8
  def self.version
9
9
  VERSION
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gnfinder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.4
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Mozzherin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-16 00:00:00.000000000 Z
11
+ date: 2022-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -86,14 +86,42 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.20'
89
+ version: '1.21'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.20'
96
+ version: '1.21'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.6.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.6.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.4'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: solargraph
99
127
  requirement: !ruby/object:Gem::Requirement
@@ -116,6 +144,7 @@ executables: []
116
144
  extensions: []
117
145
  extra_rdoc_files: []
118
146
  files:
147
+ - ".github/workflows/ruby.yml"
119
148
  - ".gitignore"
120
149
  - ".rspec"
121
150
  - ".rubocop.yml"
@@ -139,9 +168,12 @@ require_paths:
139
168
  - lib
140
169
  required_ruby_version: !ruby/object:Gem::Requirement
141
170
  requirements:
142
- - - "~>"
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '2.6'
174
+ - - "<"
143
175
  - !ruby/object:Gem::Version
144
- version: '3.0'
176
+ version: '4'
145
177
  required_rubygems_version: !ruby/object:Gem::Requirement
146
178
  requirements:
147
179
  - - ">="