gnfinder 0.15.5 → 0.16.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbac598ce79e8e9db5ad0fd4f24b5004b2cf4f91d3f5fae0ece871b525d1f488
4
- data.tar.gz: 36abaa471d385f27ae6bfa32f6f960bb7bc3a1b258b0b2a5402826e41d629d6f
3
+ metadata.gz: ac89d96503cd4b2030ab6a681e97201959b3acb46035c36b5af6524ee8ef725b
4
+ data.tar.gz: ce28eb276f6ce689210c16c43aa162ef4f35715eae46453779b176893394822f
5
5
  SHA512:
6
- metadata.gz: 5e6a3e825edfaa873e0d178a7323d7a9b6124292e940e504834b48d8127e18ae08298044458b15fc1125abf9b98afcd1faa292eadfb6edf64f80d6b3d89d43d7
7
- data.tar.gz: 68e7871b2ce105ca751c63b391ca7477a33ce965c88d6ef87235635fd8aebbfba18e856c549d0e0a26d2a4228f0a0bf46ab8cce58892c677824273f6c1f9d259
6
+ metadata.gz: d95363b28362959633773ec570217b1b9824a140e1c7000196de791adc88b191fceaf190b5e7384f4ea7b3c57949f1879306a17c9ca85cf4e647ed90d055599c
7
+ data.tar.gz: b32921b2b52d449ebb8582acca511fd5d9acdf6f10898a75b7357af535f34160dd8c13e2883e03a53a0a56dd9ea2132f1408f30e4474d9495f28b41fe262a3d1
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 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)
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/v1`
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 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,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 `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/v1`. 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
 
@@ -85,7 +90,27 @@ puts res.names[0].value
85
90
  puts res.names[0].odds
86
91
  ```
87
92
 
88
- Returned result will have the following methods for each name:
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/v1/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.
@@ -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] > 0
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
 
@@ -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.5'
6
+ VERSION = '0.16.1'
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.5
4
+ version: 0.16.1
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-10-13 00:00:00.000000000 Z
11
+ date: 2021-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client