gnfinder 0.15.5 → 0.18.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 +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/README.md +51 -26
- data/lib/gnfinder/client.rb +30 -17
- data/lib/gnfinder/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ff9a965f8ae94b254f1719f14400257bdc10d5bd40a7e889894363f2c9d8467
|
4
|
+
data.tar.gz: ba2bdb53c528385e1e5df6b843fa4416151932da9911aa6e25367fa6707c53ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 729654107c13040303a2764c1e4046c909b9c3669115c0f95cf7d0d089cca76df94d0bf252fe8d734adbba450cb272483447fafca5c00545c96d5e16ca8c3873
|
7
|
+
data.tar.gz: 2500251bb7da19028f9dcb0cb5c24156cf821e6e5e0c9f285f73b275e3ea0ea553041c257cb38d2cab217b4397224cdf0f9b14adbb513b6b0910fdab393cb476
|
data/.github/workflows/ruby.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,31 +1,37 @@
|
|
1
1
|
# gnfinder
|
2
2
|
|
3
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
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
29
|
This gem uses REST API to access a running [GNfinder] server. You can find how
|
23
|
-
to run it in [GNfinder] README file.
|
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 a Ruby proect install it using Gemfile, or manually:
|
28
|
-
|
29
35
|
```bash
|
30
36
|
gem install gnfinder
|
31
37
|
```
|
@@ -37,7 +43,7 @@ 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
44
|
the original Go-lang [GNfinder] README file.
|
39
45
|
|
40
|
-
First you need to create
|
46
|
+
First you need to create an instance of a `gnfinder` client
|
41
47
|
|
42
48
|
```ruby
|
43
49
|
require 'gnfinder'
|
@@ -45,19 +51,18 @@ require 'gnfinder'
|
|
45
51
|
gf = Gnfinder::Client.new
|
46
52
|
```
|
47
53
|
|
48
|
-
By default the client will try to connect to
|
49
|
-
have another location for the
|
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
|
63
|
+
gf = Gnfinder::Client.new(host = 'finder.example.org', port = 80)
|
59
64
|
|
60
|
-
# localhost,
|
65
|
+
# localhost, port 8000
|
61
66
|
gf = Gnfinder::Client.new(host = '0.0.0.0', port = 8000)
|
62
67
|
```
|
63
68
|
|
@@ -85,7 +90,27 @@ puts res.names[0].value
|
|
85
90
|
puts res.names[0].odds
|
86
91
|
```
|
87
92
|
|
88
|
-
|
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:
|
89
114
|
|
90
115
|
* value: name-string cleaned up for verification.
|
91
116
|
* verbatim: name-string as it was found in the text.
|
data/lib/gnfinder/client.rb
CHANGED
@@ -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/
|
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,6 +21,15 @@ module Gnfinder
|
|
21
21
|
@site['/ping'].get.body
|
22
22
|
end
|
23
23
|
|
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
|
+
|
24
33
|
def find_url(url, opts = {})
|
25
34
|
return to_open_struct({ "names": [] }) if url.to_s.strip == ''
|
26
35
|
|
@@ -39,29 +48,33 @@ module Gnfinder
|
|
39
48
|
|
40
49
|
# rubocop:disable all
|
41
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)
|
42
69
|
params[:noBayes] = true if opts[:no_bayes]
|
43
70
|
params[:oddsDetails] = true if opts[:odds_details]
|
44
71
|
params[:language] = opts[:language] if opts[:language].to_s.strip != ''
|
45
72
|
|
46
|
-
if opts[:words_around] && opts[:words_around]
|
47
|
-
params[:wordsAround] = opts[:words_around]
|
48
|
-
end
|
73
|
+
params[:wordsAround] = opts[:words_around] if opts[:words_around] && opts[:words_around].positive?
|
49
74
|
|
50
75
|
params[:verification] = true if opts[:verification]
|
51
76
|
|
52
|
-
if opts[:sources] && !opts[:sources].empty?
|
53
|
-
params[:sources] = opts[:sources]
|
54
|
-
end
|
55
|
-
|
56
|
-
res = @site['find'].post params.to_json, {content_type: :json, accept: :json}
|
57
|
-
output = JSON.parse(res.body)
|
58
|
-
res = output["metadata"]
|
59
|
-
res["names"] = output["names"] || []
|
60
|
-
res = res.deep_transform_keys(&:underscore)
|
61
|
-
if res["names"].nil?
|
62
|
-
res["names"] = []
|
63
|
-
end
|
64
|
-
to_open_struct(res)
|
77
|
+
params[:sources] = opts[:sources] if opts[:sources] && !opts[:sources].empty?
|
65
78
|
end
|
66
79
|
# rubocop:enable all
|
67
80
|
|
data/lib/gnfinder/version.rb
CHANGED
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.
|
4
|
+
version: 0.18.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:
|
11
|
+
date: 2022-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|