qa 2.0.0 → 2.0.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 +4 -4
- data/README.md +2 -0
- data/lib/qa/authorities/linked_data/config.rb +8 -2
- data/lib/qa/authorities/linked_data/config/search_config.rb +16 -2
- data/lib/qa/authorities/linked_data/config/term_config.rb +17 -3
- data/lib/qa/version.rb +1 -1
- data/spec/fixtures/authorities/linked_data/lod_encoding_config.json +91 -0
- data/spec/fixtures/authorities/linked_data/lod_term_id_param_config.json +27 -0
- data/spec/lib/authorities/linked_data/search_config_spec.rb +10 -0
- data/spec/lib/authorities/linked_data/term_config_spec.rb +10 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 975793a758ca32fe1b35d6f8301a7c418e57f0a4
|
4
|
+
data.tar.gz: 6559c2e07eac3ecb9e0312d703108cf4ac2e6d73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08a4dfabf5896a359ededc1266bf3e3231b892816608638127c3b1be0b5287f85581fcdbdf67020c7092865c02c5a83ec70195c2264dbef39509c0d9a11a8b76'
|
7
|
+
data.tar.gz: 85e3c2a1be10878ab183f0561fb20ebb37e1b3e09754e313dcdab458cb274db6dfcd58a448d4f7fdd599ad15283eea0e640720557cff2f470b3400c886f26685
|
data/README.md
CHANGED
@@ -385,6 +385,8 @@ gem 'rdf-rdfxml'
|
|
385
385
|
|
386
386
|
#### Configuring a LOD Authority
|
387
387
|
|
388
|
+
There are a number of authority configurations that are available. See (ld4l-labs/linked_data_authorities)[https://github.com/ld4l-labs/linked_data_authorities] for configurations and instructions on how to use them. These are updated periodically, so check back from time to time to see what's new.
|
389
|
+
|
388
390
|
Access to LOD authorities can be configured. Currently, a configuration exists in QA for OCLC Fast Linked Data, Library of
|
389
391
|
Congress (terms only), and Agrovoc. Look for configuration files in
|
390
392
|
[/config/authorities/linked_data](https://github.com/samvera/questioning_authority/tree/master/config/authorities/linked_data).
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'qa/authorities/linked_data/config/term_config'.freeze
|
2
2
|
require 'qa/authorities/linked_data/config/search_config'.freeze
|
3
3
|
require 'json'
|
4
|
+
require 'erb'
|
4
5
|
|
5
6
|
# Provide attr_reader methods for linked data authority configurations. Some default configurations are provided for several
|
6
7
|
# linked data authorities and can be found at /config/authorities/linked_data. You can add configurations for new authorities by
|
@@ -17,6 +18,10 @@ require 'json'
|
|
17
18
|
module Qa::Authorities
|
18
19
|
module LinkedData
|
19
20
|
class Config
|
21
|
+
class << self
|
22
|
+
include ERB::Util
|
23
|
+
end
|
24
|
+
|
20
25
|
attr_reader :authority_name
|
21
26
|
attr_reader :authority_config
|
22
27
|
|
@@ -56,7 +61,8 @@ module Qa::Authorities
|
|
56
61
|
pred_uri
|
57
62
|
end
|
58
63
|
|
59
|
-
def self.replace_pattern(url, pattern, value)
|
64
|
+
def self.replace_pattern(url, pattern, value, encode = false)
|
65
|
+
value = url_encode(value).gsub(".", "%2E") if encode
|
60
66
|
url.gsub("{?#{pattern}}", value)
|
61
67
|
end
|
62
68
|
|
@@ -71,7 +77,7 @@ module Qa::Authorities
|
|
71
77
|
config.each do |param_key, rep_pattern|
|
72
78
|
s_param_key = param_key.to_s
|
73
79
|
value = replacements[param_key] || replacements[s_param_key] || rep_pattern[:default]
|
74
|
-
url = replace_pattern(url, param_key, value)
|
80
|
+
url = replace_pattern(url, param_key, value, rep_pattern[:encode])
|
75
81
|
end
|
76
82
|
url
|
77
83
|
end
|
@@ -95,12 +95,26 @@ module Qa::Authorities
|
|
95
95
|
search_config.fetch(:qa_replacement_patterns)
|
96
96
|
end
|
97
97
|
|
98
|
+
# Should the replacement pattern be encoded?
|
99
|
+
# @return [Boolean] true, if the pattern should be encoded; otherwise, false
|
100
|
+
def qa_replacement_encoded?(pattern_key)
|
101
|
+
map_key = qa_replacement_patterns[pattern_key].to_sym
|
102
|
+
replacement_encoded? map_key
|
103
|
+
end
|
104
|
+
|
98
105
|
# Are there replacement parameters configured for search query?
|
99
106
|
# @return [True|False] true if there are replacement parameters configured for search query; otherwise, false
|
100
107
|
def replacements?
|
101
108
|
replacement_count.positive?
|
102
109
|
end
|
103
110
|
|
111
|
+
# Should the replacement parameter be encoded?
|
112
|
+
# @return [True|False] true if the replacement parameter should be encoded; otherwise, false
|
113
|
+
def replacement_encoded?(map_key)
|
114
|
+
return false unless url_mappings[map_key].key? :encode
|
115
|
+
url_mappings[map_key][:encode]
|
116
|
+
end
|
117
|
+
|
104
118
|
# Return the number of possible replacement values to make in the search URL
|
105
119
|
# @return [Integer] the configured number of possible replacements in the search url
|
106
120
|
def replacement_count
|
@@ -159,8 +173,8 @@ module Qa::Authorities
|
|
159
173
|
# @return [String] the search encoded url
|
160
174
|
def url_with_replacements(query, sub_auth = nil, search_replacements = {})
|
161
175
|
return nil unless supports_search?
|
162
|
-
sub_auth = sub_auth.to_sym if sub_auth.
|
163
|
-
url = Config.replace_pattern(url_template, qa_replacement_patterns[:query], query)
|
176
|
+
sub_auth = sub_auth.to_sym if sub_auth.present?
|
177
|
+
url = Config.replace_pattern(url_template, qa_replacement_patterns[:query], query, qa_replacement_encoded?(:query))
|
164
178
|
url = Config.process_subauthority(url, subauthority_replacement_pattern, subauthorities, sub_auth) if subauthorities?
|
165
179
|
url = Config.apply_replacements(url, replacements, search_replacements) if replacements?
|
166
180
|
url
|
@@ -112,12 +112,26 @@ module Qa::Authorities
|
|
112
112
|
Config.config_value(term_config, :qa_replacement_patterns)
|
113
113
|
end
|
114
114
|
|
115
|
+
# Should the replacement pattern be encoded?
|
116
|
+
# @return [Boolean] true, if the pattern should be encoded; otherwise, false
|
117
|
+
def term_qa_replacement_encoded?(pattern_key)
|
118
|
+
map_key = term_qa_replacement_patterns[pattern_key].to_sym
|
119
|
+
term_replacement_encoded? map_key
|
120
|
+
end
|
121
|
+
|
115
122
|
# Are there replacement parameters configured for term fetch?
|
116
|
-
# @return [
|
123
|
+
# @return [Boolean] true if there are replacement parameters configured for term fetch; otherwise, false
|
117
124
|
def term_replacements?
|
118
125
|
term_replacement_count.positive?
|
119
126
|
end
|
120
127
|
|
128
|
+
# Should the replacement parameter be encoded?
|
129
|
+
# @return [Boolean] true if the replacement parameter should be encoded; otherwise, false
|
130
|
+
def term_replacement_encoded?(map_key)
|
131
|
+
return false unless term_url_mappings[map_key].key? :encode
|
132
|
+
term_url_mappings[map_key][:encode]
|
133
|
+
end
|
134
|
+
|
121
135
|
# Return the number of possible replacement values to make in the term URL
|
122
136
|
# @return [Integer] the configured number of possible replacements in the term url
|
123
137
|
def term_replacement_count
|
@@ -129,7 +143,7 @@ module Qa::Authorities
|
|
129
143
|
def term_replacements
|
130
144
|
return @term_replacements unless @term_replacements.nil?
|
131
145
|
@term_replacements = {}
|
132
|
-
@term_replacements = term_url_mappings.select { |k, _v| !term_qa_replacement_patterns.
|
146
|
+
@term_replacements = term_url_mappings.select { |k, _v| !term_qa_replacement_patterns.value?(k.to_s) } unless term_config.nil? || term_url_mappings.nil?
|
133
147
|
@term_replacements
|
134
148
|
end
|
135
149
|
|
@@ -176,7 +190,7 @@ module Qa::Authorities
|
|
176
190
|
def term_url_with_replacements(id, sub_auth = nil, replacements = {})
|
177
191
|
return nil unless supports_term?
|
178
192
|
sub_auth = sub_auth.to_sym if sub_auth.is_a? String
|
179
|
-
url = Config.replace_pattern(term_url_template, term_qa_replacement_patterns[:term_id], id)
|
193
|
+
url = Config.replace_pattern(term_url_template, term_qa_replacement_patterns[:term_id], id, term_qa_replacement_encoded?(:term_id))
|
180
194
|
url = Config.process_subauthority(url, term_subauthority_replacement_pattern, term_subauthorities, sub_auth) if term_subauthorities?
|
181
195
|
url = Config.apply_replacements(url, term_replacements, replacements) if term_replacements?
|
182
196
|
url
|
data/lib/qa/version.rb
CHANGED
@@ -0,0 +1,91 @@
|
|
1
|
+
{
|
2
|
+
"term": {
|
3
|
+
"url": {
|
4
|
+
"@context": "http://www.w3.org/ns/hydra/context.jsonld",
|
5
|
+
"@type": "IriTemplate",
|
6
|
+
"template": "http://localhost/test_default/term?uri={?term_uri}&{?encode_true}&{?encode_false}&{?encode_not_specified}",
|
7
|
+
"variableRepresentation": "BasicRepresentation",
|
8
|
+
"mapping": [
|
9
|
+
{
|
10
|
+
"@type": "IriTemplateMapping",
|
11
|
+
"variable": "term_uri",
|
12
|
+
"property": "hydra:freetextQuery",
|
13
|
+
"required": true,
|
14
|
+
"encode": true
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"@type": "IriTemplateMapping",
|
18
|
+
"variable": "encode_true",
|
19
|
+
"property": "hydra:freetextQuery",
|
20
|
+
"required": true,
|
21
|
+
"encode": true
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"@type": "IriTemplateMapping",
|
25
|
+
"variable": "encode_false",
|
26
|
+
"property": "hydra:freetextQuery",
|
27
|
+
"required": true,
|
28
|
+
"encode": false
|
29
|
+
},
|
30
|
+
{
|
31
|
+
"@type": "IriTemplateMapping",
|
32
|
+
"variable": "encode_not_specified",
|
33
|
+
"property": "hydra:freetextQuery",
|
34
|
+
"required": true
|
35
|
+
}
|
36
|
+
]
|
37
|
+
},
|
38
|
+
"qa_replacement_patterns": {
|
39
|
+
"term_id": "term_uri"
|
40
|
+
},
|
41
|
+
"term_id": "URI",
|
42
|
+
"results": {
|
43
|
+
"id_predicate": "http://id.loc.gov/vocabulary/identifiers/lccn",
|
44
|
+
"label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel"
|
45
|
+
}
|
46
|
+
},
|
47
|
+
"search": {
|
48
|
+
"url": {
|
49
|
+
"@context": "http://www.w3.org/ns/hydra/context.jsonld",
|
50
|
+
"@type": "IriTemplate",
|
51
|
+
"template": "http://localhost/test_default/search?query={?query}&{?encode_true}&{?encode_false}&{?encode_not_specified}",
|
52
|
+
"variableRepresentation": "BasicRepresentation",
|
53
|
+
"mapping": [
|
54
|
+
{
|
55
|
+
"@type": "IriTemplateMapping",
|
56
|
+
"variable": "query",
|
57
|
+
"property": "hydra:freetextQuery",
|
58
|
+
"required": true,
|
59
|
+
"encode": true
|
60
|
+
},
|
61
|
+
{
|
62
|
+
"@type": "IriTemplateMapping",
|
63
|
+
"variable": "encode_true",
|
64
|
+
"property": "hydra:freetextQuery",
|
65
|
+
"required": true,
|
66
|
+
"encode": true
|
67
|
+
},
|
68
|
+
{
|
69
|
+
"@type": "IriTemplateMapping",
|
70
|
+
"variable": "encode_false",
|
71
|
+
"property": "hydra:freetextQuery",
|
72
|
+
"required": true,
|
73
|
+
"encode": false
|
74
|
+
},
|
75
|
+
{
|
76
|
+
"@type": "IriTemplateMapping",
|
77
|
+
"variable": "encode_not_specified",
|
78
|
+
"property": "hydra:freetextQuery",
|
79
|
+
"required": true
|
80
|
+
}
|
81
|
+
]
|
82
|
+
},
|
83
|
+
"qa_replacement_patterns": {
|
84
|
+
"query": "query"
|
85
|
+
},
|
86
|
+
"results": {
|
87
|
+
"id_predicate": "http://purl.org/dc/terms/identifier",
|
88
|
+
"label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel"
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"term": {
|
3
|
+
"url": {
|
4
|
+
"@context": "http://www.w3.org/ns/hydra/context.jsonld",
|
5
|
+
"@type": "IriTemplate",
|
6
|
+
"template": "http://localhost/test_default/term/{?term_id}",
|
7
|
+
"variableRepresentation": "BasicRepresentation",
|
8
|
+
"mapping": [
|
9
|
+
{
|
10
|
+
"@type": "IriTemplateMapping",
|
11
|
+
"variable": "term_id",
|
12
|
+
"property": "hydra:freetextQuery",
|
13
|
+
"required": true
|
14
|
+
}
|
15
|
+
]
|
16
|
+
},
|
17
|
+
"qa_replacement_patterns": {
|
18
|
+
"term_id": "term_id"
|
19
|
+
},
|
20
|
+
"term_id": "ID",
|
21
|
+
"results": {
|
22
|
+
"id_predicate": "http://id.loc.gov/vocabulary/identifiers/lccn",
|
23
|
+
"label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel"
|
24
|
+
}
|
25
|
+
},
|
26
|
+
"search": {}
|
27
|
+
}
|
@@ -4,6 +4,7 @@ RSpec.describe Qa::Authorities::LinkedData::SearchConfig do
|
|
4
4
|
let(:full_config) { Qa::Authorities::LinkedData::Config.new(:LOD_FULL_CONFIG).search }
|
5
5
|
let(:min_config) { Qa::Authorities::LinkedData::Config.new(:LOD_MIN_CONFIG).search }
|
6
6
|
let(:term_only_config) { Qa::Authorities::LinkedData::Config.new(:LOD_TERM_ONLY_CONFIG).search }
|
7
|
+
let(:encoding_config) { Qa::Authorities::LinkedData::Config.new(:LOD_ENCODING_CONFIG).search }
|
7
8
|
|
8
9
|
describe '#search_config' do
|
9
10
|
let(:full_search_config) do
|
@@ -381,5 +382,14 @@ RSpec.describe Qa::Authorities::LinkedData::SearchConfig do
|
|
381
382
|
expect(min_config.url_with_replacements('Smith', nil, fake_replacement_key: 'fake_value')).to eq expected_url
|
382
383
|
end
|
383
384
|
end
|
385
|
+
|
386
|
+
context 'with encoding specified in config' do
|
387
|
+
it 'returns the uri as the url' do
|
388
|
+
expected_url = 'http://localhost/test_default/search?query=encoded%20because%3Aencode%3Dtrue&yes%3Aencoded%20here&no:encoding here&defaults:to not encoded'
|
389
|
+
query = 'encoded because:encode=true'
|
390
|
+
replacements = { encode_true: 'yes:encoded here', encode_false: 'no:encoding here', encode_not_specified: 'defaults:to not encoded' }
|
391
|
+
expect(encoding_config.url_with_replacements(query, nil, replacements)).to eq expected_url
|
392
|
+
end
|
393
|
+
end
|
384
394
|
end
|
385
395
|
end
|
@@ -4,6 +4,7 @@ describe Qa::Authorities::LinkedData::TermConfig do
|
|
4
4
|
let(:full_config) { Qa::Authorities::LinkedData::Config.new(:LOD_FULL_CONFIG).term }
|
5
5
|
let(:min_config) { Qa::Authorities::LinkedData::Config.new(:LOD_MIN_CONFIG).term }
|
6
6
|
let(:search_only_config) { Qa::Authorities::LinkedData::Config.new(:LOD_SEARCH_ONLY_CONFIG).term }
|
7
|
+
let(:encoding_config) { Qa::Authorities::LinkedData::Config.new(:LOD_ENCODING_CONFIG).term }
|
7
8
|
|
8
9
|
describe '#term_config' do
|
9
10
|
let(:full_term_config) do
|
@@ -415,5 +416,14 @@ describe Qa::Authorities::LinkedData::TermConfig do
|
|
415
416
|
expect(min_config.term_url_with_replacements('C123', nil, fake_replacement_key: 'fake_value')).to eq expected_url
|
416
417
|
end
|
417
418
|
end
|
419
|
+
|
420
|
+
context 'with encoding specified in config' do
|
421
|
+
it 'returns the uri as the url' do
|
422
|
+
expected_url = 'http://localhost/test_default/term?uri=http%3A%2F%2Fencoded%2Ebecause%3Fencode%3Dtrue&yes%3Aencoded%20here&no:encoding here&defaults:to not encoded'
|
423
|
+
term_uri = 'http://encoded.because?encode=true'
|
424
|
+
replacements = { encode_true: 'yes:encoded here', encode_false: 'no:encoding here', encode_not_specified: 'defaults:to not encoded' }
|
425
|
+
expect(encoding_config.term_url_with_replacements(term_uri, nil, replacements)).to eq expected_url
|
426
|
+
end
|
427
|
+
end
|
418
428
|
end
|
419
429
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Anderson
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date:
|
18
|
+
date: 2018-02-22 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rails
|
@@ -354,6 +354,7 @@ files:
|
|
354
354
|
- spec/fixtures/authorities/authority_B.yml
|
355
355
|
- spec/fixtures/authorities/authority_C.yml
|
356
356
|
- spec/fixtures/authorities/authority_D.yml
|
357
|
+
- spec/fixtures/authorities/linked_data/lod_encoding_config.json
|
357
358
|
- spec/fixtures/authorities/linked_data/lod_full_config.json
|
358
359
|
- spec/fixtures/authorities/linked_data/lod_lang_defaults.json
|
359
360
|
- spec/fixtures/authorities/linked_data/lod_lang_multi_defaults.json
|
@@ -362,6 +363,7 @@ files:
|
|
362
363
|
- spec/fixtures/authorities/linked_data/lod_min_config.json
|
363
364
|
- spec/fixtures/authorities/linked_data/lod_search_only_config.json
|
364
365
|
- spec/fixtures/authorities/linked_data/lod_sort.json
|
366
|
+
- spec/fixtures/authorities/linked_data/lod_term_id_param_config.json
|
365
367
|
- spec/fixtures/authorities/linked_data/lod_term_only_config.json
|
366
368
|
- spec/fixtures/funders-find-response.json
|
367
369
|
- spec/fixtures/funders-noquery.json
|
@@ -458,7 +460,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
458
460
|
version: '0'
|
459
461
|
requirements: []
|
460
462
|
rubyforge_project:
|
461
|
-
rubygems_version: 2.6.
|
463
|
+
rubygems_version: 2.6.14
|
462
464
|
signing_key:
|
463
465
|
specification_version: 4
|
464
466
|
summary: You should question your authorities.
|
@@ -474,6 +476,7 @@ test_files:
|
|
474
476
|
- spec/fixtures/authorities/authority_B.yml
|
475
477
|
- spec/fixtures/authorities/authority_C.yml
|
476
478
|
- spec/fixtures/authorities/authority_D.yml
|
479
|
+
- spec/fixtures/authorities/linked_data/lod_encoding_config.json
|
477
480
|
- spec/fixtures/authorities/linked_data/lod_full_config.json
|
478
481
|
- spec/fixtures/authorities/linked_data/lod_lang_defaults.json
|
479
482
|
- spec/fixtures/authorities/linked_data/lod_lang_multi_defaults.json
|
@@ -482,6 +485,7 @@ test_files:
|
|
482
485
|
- spec/fixtures/authorities/linked_data/lod_min_config.json
|
483
486
|
- spec/fixtures/authorities/linked_data/lod_search_only_config.json
|
484
487
|
- spec/fixtures/authorities/linked_data/lod_sort.json
|
488
|
+
- spec/fixtures/authorities/linked_data/lod_term_id_param_config.json
|
485
489
|
- spec/fixtures/authorities/linked_data/lod_term_only_config.json
|
486
490
|
- spec/fixtures/funders-find-response.json
|
487
491
|
- spec/fixtures/funders-noquery.json
|