gn_list_resolver 3.0.1 → 3.0.1.1

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
  SHA1:
3
- metadata.gz: b725622af097eb866e964ccfae00b98fa3013540
4
- data.tar.gz: e8aba7af13734755675f9b7264cfde77c6a588cf
3
+ metadata.gz: 7c042e74b667b59e965c894c4e86c6b743e31a89
4
+ data.tar.gz: ef827961489aa0512591fdf5a23e3ecb9ac8e07f
5
5
  SHA512:
6
- metadata.gz: f53de2beb644a5aac548551155d9d2e0df24e027ebe1857da09cd507cc24d2145d1cb264520b6cdd34e529678fccb99580e9ad5576b90e419d732041941df97a
7
- data.tar.gz: 871f89a6d87f3d4f864a7164765f6a08d29c01a6b39763dd1d311229c22d659c50e0100b80fd38c8982145d4656c01880a7fd8ce9af6d76407549cbae187b567
6
+ metadata.gz: 3351e75cc0f45bed0d9924c0c970628bfb843d4c16e123d16d26a7609584069ac81ff80661c7e89aa3a1603150288e83e96ad8f34d6d995f1bbb5db1d3f19293
7
+ data.tar.gz: 44d14f9feeafd840d0de88fc0a6ca5a5af98daee2740d5799fc0d932431918f75090243c473198b01932246c079cd58818097fe343d0c24bc032dfff24ab3493
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # ``gn_list_resolver`` CHANGELOG
2
2
 
3
+ ## 3.0.1.1
4
+
5
+ * @dimus - refactoring, GnListResolver.run returns stats
6
+
3
7
  ## 3.0.1
4
8
 
5
9
  * @dimus - fixes #31 bug: prevent csv row to get squashed
data/README.md CHANGED
@@ -63,6 +63,12 @@ cat my_list.csv | crossmap -i my_list.csv -s
63
63
 
64
64
  ### Usage as Ruby Library (API description)
65
65
 
66
+ #### Changing default url for gnindex API
67
+
68
+ Default URL for API is `http://index-api.globalnames.org/api/graphql`
69
+
70
+ if you want to change it, set an environment variable `GN_RESOLVER_URL`
71
+
66
72
  #### `GnListResolver.run`
67
73
 
68
74
  Compares an input list to a data source from [GN Resolver][resolver] and
@@ -94,9 +100,6 @@ from original data. Otherwise all original data is preserved. If there is no
94
100
  : (array) empty array by default. If `alt_headers` are not empty they are used
95
101
  instead of the headers supplied with the file
96
102
 
97
- ``resolver_url``
98
- : URL to globalnames' resolver. Default is ``http://resolver.globalnames.org``
99
-
100
103
  #### `GnListResolver.logger=`
101
104
 
102
105
  Allows to set logger to a custom logger (default is `STDERR`)
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.name = "gn_list_resolver"
13
13
  gem.version = GnListResolver::VERSION
14
14
  gem.license = "MIT"
15
- gem.authors = ["Dmitry Mozzherin"]
15
+ gem.authors = ["Dmitry Mozzherin", "Alexander Myltsev"]
16
16
  gem.email = ["dmozzherin@gmail.com"]
17
17
 
18
18
  gem.summary = "Resolves a list of scientific names to names from " \
@@ -8,6 +8,10 @@ require "logger"
8
8
  require "logger/colors"
9
9
  require "biodiversity"
10
10
  require "gn_uuid"
11
+ require "graphql/client"
12
+ require "graphql/client/http"
13
+ require "gn_list_resolver/constants"
14
+ require "gn_list_resolver/graphql"
11
15
  require "gn_list_resolver/errors"
12
16
  require "gn_list_resolver/version"
13
17
  require "gn_list_resolver/reader"
@@ -21,10 +25,6 @@ require "gn_list_resolver/stats"
21
25
 
22
26
  # Namespace module for resolving lists with GN sources
23
27
  module GnListResolver
24
- INPUT_MODE = "r:utf-8"
25
- OUTPUT_MODE = "w:utf-8"
26
- MATCH_TYPE_EMPTY = "EmptyMatch"
27
-
28
28
  class << self
29
29
  attr_writer :logger
30
30
 
@@ -36,7 +36,7 @@ module GnListResolver
36
36
  writer = create_writer(reader, output_io, opts)
37
37
  resolver = create_resolver(writer, opts)
38
38
  block_given? ? resolver.resolve(data, &Proc.new) : resolver.resolve(data)
39
- opts.output
39
+ resolver.stats
40
40
  end
41
41
 
42
42
  def logger
@@ -54,7 +54,7 @@ module GnListResolver
54
54
  private
55
55
 
56
56
  def create_resolver(writer, opts)
57
- Resolver.new(writer, opts.data_source_id, opts.resolver_url, opts.stats)
57
+ Resolver.new(writer, opts.data_source_id, opts.stats)
58
58
  end
59
59
 
60
60
  def create_writer(reader, output_io, opts)
@@ -67,12 +67,7 @@ module GnListResolver
67
67
  end
68
68
 
69
69
  def opts_struct(opts)
70
- # resolver_url = "http://gnresolver.globalnames.org/api/graphql".freeze
71
- # resolver_url = "http://localhost:8888/api/graphql".freeze
72
- # resolver_url = "http://localhost:8080/api/graphql".freeze
73
- resolver_url = "http://index-api.globalnames.org/api/graphql"
74
- OpenStruct.new({ stats: Stats.new, alt_headers: [],
75
- resolver_url: resolver_url }.merge(opts))
70
+ OpenStruct.new({ stats: Stats.new, alt_headers: [] }.merge(opts))
76
71
  end
77
72
 
78
73
  def io(input, output)
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Namespace module for resolving lists with GN sources
4
+ module GnListResolver
5
+ INPUT_MODE = "r:utf-8"
6
+ OUTPUT_MODE = "w:utf-8"
7
+ MATCH_TYPE_EMPTY = "EmptyMatch"
8
+ RESOLVER_URL = ENV["GN_RESOLVER_URL"] ||
9
+ "http://index-api.globalnames.org/api/graphql"
10
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GnListResolver
4
+ # GraphQL client for gnindex API
5
+ class GnGraphQL
6
+ attr_reader :client, :query
7
+
8
+ def initialize
9
+ http = GraphQL::Client::HTTP.new(RESOLVER_URL)
10
+ schema = GraphQL::Client.load_schema(http)
11
+ @client = GraphQL::Client.new(schema: schema, execute: http)
12
+ @query = <<~GRAPHQL_QUERY
13
+ query($names: [name!]!, $dataSourceIds: [Int!]) {
14
+ nameResolver(names: $names, dataSourceIds: $dataSourceIds) {
15
+ total suppliedId suppliedInput
16
+ results {
17
+ name { name }
18
+ canonicalName { name }
19
+ synonym
20
+ matchType { kind score editDistance }
21
+ taxonId classification { pathRanks }
22
+ score { value parsingQuality }
23
+ }
24
+ }
25
+ }
26
+ GRAPHQL_QUERY
27
+ end
28
+ end
29
+ end
@@ -1,36 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "graphql/client"
4
- require "graphql/client/http"
5
-
6
3
  # GnListResolver::test
7
4
  module GnListResolver
8
- # resolver_url = "http://gnresolver.globalnames.org/api/graphql".freeze
9
- # resolver_url = "http://localhost:8888/api/graphql".freeze
10
- # resolver_url = "http://localhost:8080/api/graphql".freeze
11
- resolver_url = "http://index-api.globalnames.org/api/graphql"
12
- HTTP = GraphQL::Client::HTTP.new(resolver_url)
13
- SCHEMA = GraphQL::Client.load_schema(HTTP)
14
- CLIENT = GraphQL::Client.new(schema: SCHEMA, execute: HTTP)
15
- NAME_RESOLVERS_QUERY = CLIENT.parse <<-'GRAPHQL'
16
- query($names: [name!]!, $dataSourceIds: [Int!]) {
17
- nameResolver(names: $names, dataSourceIds: $dataSourceIds) {
18
- total suppliedId suppliedInput
19
- results {
20
- name { name }
21
- canonicalName { name }
22
- synonym
23
- matchType { kind score editDistance }
24
- taxonId classification { pathRanks }
25
- score { value parsingQuality }
26
- }
27
- }
28
- }
29
- GRAPHQL
30
-
31
5
  # Sends data to GN Resolver and collects results
32
6
  class Resolver
33
- def initialize(writer, data_source_id, _resolver_url, stats)
7
+ GRAPHQL = GnGraphQL.new
8
+ QUERY = GRAPHQL.client.parse(GRAPHQL.query)
9
+ attr_reader :stats
10
+
11
+ def initialize(writer, data_source_id, stats)
34
12
  @stats = stats
35
13
  @processor = GnListResolver::ResultProcessor.new(writer, @stats)
36
14
  @ds_id = data_source_id
@@ -43,7 +21,12 @@ module GnListResolver
43
21
  update_stats(data.size)
44
22
  block_given? ? process(data, &Proc.new) : process(data)
45
23
  wrap_up
46
- yield(@stats.stats) if block_given?
24
+
25
+ if block_given?
26
+ yield(@stats.stats)
27
+ else
28
+ @stats.stats
29
+ end
47
30
  end
48
31
 
49
32
  private
@@ -78,7 +61,7 @@ module GnListResolver
78
61
  e = [@count, @stats.stats[:total_records]].min
79
62
  GnListResolver.log("Resolve #{s}-#{e} out of " \
80
63
  "#{@stats.stats[:total_records]} records at " \
81
- "#{@resolver_url}")
64
+ "#{RESOLVER_URL}")
82
65
  yield
83
66
  end
84
67
 
@@ -102,7 +85,7 @@ module GnListResolver
102
85
 
103
86
  def remote_resolve(names)
104
87
  batch_start = Time.now
105
- res = CLIENT.query(NAME_RESOLVERS_QUERY, variables: variables(names))
88
+ res = GRAPHQL.client.query(QUERY, variables: variables(names))
106
89
  @processor.process(res.data.name_resolver, @current_data)
107
90
  update_batch_times(batch_start)
108
91
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Namespace module for crossmapping checklists to GN sources
4
4
  module GnListResolver
5
- VERSION = "3.0.1"
5
+ VERSION = "3.0.1.1"
6
6
 
7
7
  def self.version
8
8
  VERSION
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gn_list_resolver
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Mozzherin
8
+ - Alexander Myltsev
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2017-07-18 00:00:00.000000000 Z
12
+ date: 2017-07-23 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: trollop
@@ -234,7 +235,9 @@ files:
234
235
  - lib/gn_list_resolver.rb
235
236
  - lib/gn_list_resolver/collector.rb
236
237
  - lib/gn_list_resolver/column_collector.rb
238
+ - lib/gn_list_resolver/constants.rb
237
239
  - lib/gn_list_resolver/errors.rb
240
+ - lib/gn_list_resolver/graphql.rb
238
241
  - lib/gn_list_resolver/reader.rb
239
242
  - lib/gn_list_resolver/resolver.rb
240
243
  - lib/gn_list_resolver/result_processor.rb