qa 1.0.0 → 1.1.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/README.md +284 -2
- data/app/controllers/qa/linked_data_terms_controller.rb +127 -0
- data/config/authorities/linked_data/agrovoc.json +61 -0
- data/config/authorities/linked_data/loc.json +46 -0
- data/config/authorities/linked_data/oclc_fast.json +78 -0
- data/config/initializers/linked_data_authorities.rb +17 -0
- data/config/routes.rb +3 -0
- data/lib/qa.rb +15 -0
- data/lib/qa/authorities.rb +2 -0
- data/lib/qa/authorities/base.rb +1 -1
- data/lib/qa/authorities/crossref.rb +16 -0
- data/lib/qa/authorities/crossref/generic_authority.rb +63 -0
- data/lib/qa/authorities/geonames.rb +2 -1
- data/lib/qa/authorities/linked_data.rb +10 -0
- data/lib/qa/authorities/linked_data/config.rb +80 -0
- data/lib/qa/authorities/linked_data/config/search_config.rb +170 -0
- data/lib/qa/authorities/linked_data/config/term_config.rb +186 -0
- data/lib/qa/authorities/linked_data/find_term.rb +148 -0
- data/lib/qa/authorities/linked_data/generic_authority.rb +49 -0
- data/lib/qa/authorities/linked_data/rdf_helper.rb +102 -0
- data/lib/qa/authorities/linked_data/search_query.rb +143 -0
- data/lib/qa/version.rb +1 -1
- data/spec/controllers/linked_data_terms_controller_spec.rb +202 -0
- data/spec/fixtures/authorities/linked_data/lod_full_config.json +111 -0
- data/spec/fixtures/authorities/linked_data/lod_lang_defaults.json +54 -0
- data/spec/fixtures/authorities/linked_data/lod_lang_multi_defaults.json +54 -0
- data/spec/fixtures/authorities/linked_data/lod_lang_no_defaults.json +52 -0
- data/spec/fixtures/authorities/linked_data/lod_lang_param.json +66 -0
- data/spec/fixtures/authorities/linked_data/lod_min_config.json +49 -0
- data/spec/fixtures/authorities/linked_data/lod_search_only_config.json +55 -0
- data/spec/fixtures/authorities/linked_data/lod_sort.json +27 -0
- data/spec/fixtures/authorities/linked_data/lod_term_only_config.json +59 -0
- data/spec/fixtures/funders-find-response.json +1 -0
- data/spec/fixtures/funders-noquery.json +1 -0
- data/spec/fixtures/funders-noresults.json +1 -0
- data/spec/fixtures/funders-result.json +1 -0
- data/spec/fixtures/journals-find-response-two-issn.json +1 -0
- data/spec/fixtures/journals-find-response.json +1 -0
- data/spec/fixtures/journals-noquery.json +1 -0
- data/spec/fixtures/journals-noresults.json +1 -0
- data/spec/fixtures/journals-result.json +705 -0
- data/spec/fixtures/lod_agrovoc_query_many_results.json +1 -0
- data/spec/fixtures/lod_agrovoc_query_no_results.json +1 -0
- data/spec/fixtures/lod_agrovoc_term_found.rdf.xml +217 -0
- data/spec/fixtures/lod_lang_search_en.rdf.xml +42 -0
- data/spec/fixtures/lod_lang_search_enfr.rdf.xml +48 -0
- data/spec/fixtures/lod_lang_search_enfrde.rdf.xml +54 -0
- data/spec/fixtures/lod_lang_search_fr.rdf.xml +42 -0
- data/spec/fixtures/lod_lang_term_en.rdf.xml +65 -0
- data/spec/fixtures/lod_lang_term_enfr.rdf.xml +71 -0
- data/spec/fixtures/lod_lang_term_enfr_noalt.rdf.xml +69 -0
- data/spec/fixtures/lod_lang_term_enfrde.rdf.xml +79 -0
- data/spec/fixtures/lod_lang_term_fr.rdf.xml +65 -0
- data/spec/fixtures/lod_loc_term_found.rdf.xml +262 -0
- data/spec/fixtures/lod_oclc_all_query_3_results.rdf.xml +142 -0
- data/spec/fixtures/lod_oclc_personalName_query_3_results.rdf.xml +128 -0
- data/spec/fixtures/lod_oclc_query_no_results.rdf.xml +13 -0
- data/spec/fixtures/lod_oclc_term_found.rdf.xml +51 -0
- data/spec/lib/authorities/crossref_spec.rb +180 -0
- data/spec/lib/authorities/geonames_spec.rb +2 -2
- data/spec/lib/authorities/linked_data/config_spec.rb +143 -0
- data/spec/lib/authorities/linked_data/find_term_spec.rb +5 -0
- data/spec/lib/authorities/linked_data/generic_authority_spec.rb +580 -0
- data/spec/lib/authorities/linked_data/search_config_spec.rb +385 -0
- data/spec/lib/authorities/linked_data/search_query_spec.rb +79 -0
- data/spec/lib/authorities/linked_data/term_config_spec.rb +419 -0
- data/spec/routing/linked_data_route_spec.rb +35 -0
- data/spec/spec_helper.rb +2 -0
- metadata +184 -39
@@ -28,9 +28,9 @@ describe Qa::Authorities::Geonames do
|
|
28
28
|
|
29
29
|
context "with default label" do
|
30
30
|
it "has id and label keys" do
|
31
|
-
expect(subject.first).to eq("id" => 'http://sws.geonames.org/2088122',
|
31
|
+
expect(subject.first).to eq("id" => 'http://sws.geonames.org/2088122/',
|
32
32
|
"label" => "Port Moresby, National Capital, Papua New Guinea")
|
33
|
-
expect(subject.last).to eq("id" => 'http://sws.geonames.org/377039',
|
33
|
+
expect(subject.last).to eq("id" => 'http://sws.geonames.org/377039/',
|
34
34
|
"label" => "Port Sudan, Red Sea, Sudan")
|
35
35
|
expect(subject.size).to eq(10)
|
36
36
|
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Qa::Authorities::LinkedData::Config do
|
4
|
+
let(:full_config) { described_class.new(:LOD_FULL_CONFIG) }
|
5
|
+
|
6
|
+
describe '#new' do
|
7
|
+
context 'without an authority' do
|
8
|
+
it 'raises an exception' do
|
9
|
+
expect { described_class.new }.to raise_error ArgumentError, /wrong number of arguments/
|
10
|
+
end
|
11
|
+
end
|
12
|
+
context 'with an invalid authority' do
|
13
|
+
it 'raises an exception' do
|
14
|
+
expect { described_class.new(:FOO) }.to raise_error Qa::InvalidLinkedDataAuthority, /Unable to initialize linked data authority 'FOO'/
|
15
|
+
end
|
16
|
+
end
|
17
|
+
context 'with a valid authority' do
|
18
|
+
it 'creates the authority' do
|
19
|
+
expect(described_class.new(:OCLC_FAST)).to be_kind_of described_class
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#auth_config' do
|
25
|
+
let(:full_auth_config) do
|
26
|
+
{
|
27
|
+
term: {
|
28
|
+
url: {
|
29
|
+
:@context => 'http://www.w3.org/ns/hydra/context.jsonld',
|
30
|
+
:@type => 'IriTemplate',
|
31
|
+
template: 'http://localhost/test_default/term/{?subauth}/{?term_id}?param1={?param1}¶m2={?param2}',
|
32
|
+
variableRepresentation: 'BasicRepresentation',
|
33
|
+
mapping: [
|
34
|
+
{
|
35
|
+
:@type => 'IriTemplateMapping',
|
36
|
+
variable: 'term_id',
|
37
|
+
property: 'hydra:freetextQuery',
|
38
|
+
required: true
|
39
|
+
},
|
40
|
+
{
|
41
|
+
:@type => 'IriTemplateMapping',
|
42
|
+
variable: 'subauth',
|
43
|
+
property: 'hydra:freetextQuery',
|
44
|
+
required: false,
|
45
|
+
default: 'term_sub2_name'
|
46
|
+
},
|
47
|
+
{
|
48
|
+
:@type => 'IriTemplateMapping',
|
49
|
+
variable: 'param1',
|
50
|
+
property: 'hydra:freetextQuery',
|
51
|
+
required: false,
|
52
|
+
default: 'alpha'
|
53
|
+
},
|
54
|
+
{
|
55
|
+
:@type => 'IriTemplateMapping',
|
56
|
+
variable: 'param2',
|
57
|
+
property: 'hydra:freetextQuery',
|
58
|
+
required: false,
|
59
|
+
default: 'beta'
|
60
|
+
}
|
61
|
+
]
|
62
|
+
},
|
63
|
+
qa_replacement_patterns: {
|
64
|
+
term_id: 'term_id',
|
65
|
+
subauth: 'subauth'
|
66
|
+
},
|
67
|
+
term_id: 'ID',
|
68
|
+
language: ['en'],
|
69
|
+
results: {
|
70
|
+
id_predicate: 'http://purl.org/dc/terms/identifier',
|
71
|
+
label_predicate: 'http://www.w3.org/2004/02/skos/core#prefLabel',
|
72
|
+
altlabel_predicate: 'http://www.w3.org/2004/02/skos/core#altLabel',
|
73
|
+
broader_predicate: 'http://www.w3.org/2004/02/skos/core#broader',
|
74
|
+
narrower_predicate: 'http://www.w3.org/2004/02/skos/core#narrower',
|
75
|
+
sameas_predicate: 'http://www.w3.org/2004/02/skos/core#exactMatch'
|
76
|
+
},
|
77
|
+
subauthorities: {
|
78
|
+
term_sub1_key: 'term_sub1_name',
|
79
|
+
term_sub2_key: 'term_sub2_name',
|
80
|
+
term_sub3_key: 'term_sub3_name'
|
81
|
+
}
|
82
|
+
},
|
83
|
+
search: {
|
84
|
+
url: {
|
85
|
+
:@context => 'http://www.w3.org/ns/hydra/context.jsonld',
|
86
|
+
:@type => 'IriTemplate',
|
87
|
+
template: 'http://localhost/test_default/search?subauth={?subauth}&query={?query}¶m1={?param1}¶m2={?param2}',
|
88
|
+
variableRepresentation: 'BasicRepresentation',
|
89
|
+
mapping: [
|
90
|
+
{
|
91
|
+
:@type => 'IriTemplateMapping',
|
92
|
+
variable: 'query',
|
93
|
+
property: 'hydra:freetextQuery',
|
94
|
+
required: true
|
95
|
+
},
|
96
|
+
{
|
97
|
+
:@type => 'IriTemplateMapping',
|
98
|
+
variable: 'subauth',
|
99
|
+
property: 'hydra:freetextQuery',
|
100
|
+
required: false,
|
101
|
+
default: 'search_sub1_name'
|
102
|
+
},
|
103
|
+
{
|
104
|
+
:@type => 'IriTemplateMapping',
|
105
|
+
variable: 'param1',
|
106
|
+
property: 'hydra:freetextQuery',
|
107
|
+
required: false,
|
108
|
+
default: 'delta'
|
109
|
+
},
|
110
|
+
{
|
111
|
+
:@type => 'IriTemplateMapping',
|
112
|
+
variable: 'param2',
|
113
|
+
property: 'hydra:freetextQuery',
|
114
|
+
required: false,
|
115
|
+
default: 'echo'
|
116
|
+
}
|
117
|
+
]
|
118
|
+
},
|
119
|
+
qa_replacement_patterns: {
|
120
|
+
query: 'query',
|
121
|
+
subauth: 'subauth'
|
122
|
+
},
|
123
|
+
language: ['en', 'fr', 'de'],
|
124
|
+
results: {
|
125
|
+
id_predicate: 'http://purl.org/dc/terms/identifier',
|
126
|
+
label_predicate: 'http://www.w3.org/2004/02/skos/core#prefLabel',
|
127
|
+
altlabel_predicate: 'http://www.w3.org/2004/02/skos/core#altLabel',
|
128
|
+
sort_predicate: 'http://www.w3.org/2004/02/skos/core#prefLabel'
|
129
|
+
},
|
130
|
+
subauthorities: {
|
131
|
+
search_sub1_key: 'search_sub1_name',
|
132
|
+
search_sub2_key: 'search_sub2_name',
|
133
|
+
search_sub3_key: 'search_sub3_name'
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'returns hash of the full authority configuration' do
|
140
|
+
expect(full_config.auth_config).to eq full_auth_config
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,580 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Qa::Authorities::LinkedData::GenericAuthority do
|
4
|
+
describe '#search' do
|
5
|
+
let(:lod_oclc) { described_class.new(:OCLC_FAST) }
|
6
|
+
let(:lod_agrovoc) { described_class.new(:AGROVOC) }
|
7
|
+
|
8
|
+
context 'in OCLC_FAST authority' do
|
9
|
+
context '0 search results' do
|
10
|
+
let :results do
|
11
|
+
stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=cql.any%20all%20%22supercalifragilisticexpialidocious%22&sortKeys=usage')
|
12
|
+
.to_return(status: 200, body: webmock_fixture('lod_oclc_query_no_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
13
|
+
lod_oclc.search('supercalifragilisticexpialidocious', replacements: { 'maximumRecords' => '3' })
|
14
|
+
end
|
15
|
+
it 'returns an empty array' do
|
16
|
+
expect(results).to eq([])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context '3 search results' do
|
21
|
+
let :results do
|
22
|
+
stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=cql.any%20all%20%22cornell%22&sortKeys=usage')
|
23
|
+
.to_return(status: 200, body: webmock_fixture('lod_oclc_all_query_3_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
24
|
+
lod_oclc.search('cornell', replacements: { 'maximumRecords' => '3' })
|
25
|
+
end
|
26
|
+
it 'is correctly parsed' do
|
27
|
+
expect(results.count).to eq(3)
|
28
|
+
expect(results.first).to eq(uri: 'http://id.worldcat.org/fast/530369', id: '530369', label: 'Cornell University')
|
29
|
+
expect(results.second).to eq(uri: 'http://id.worldcat.org/fast/5140', id: '5140', label: 'Cornell, Joseph')
|
30
|
+
expect(results.third).to eq(uri: 'http://id.worldcat.org/fast/557490', id: '557490', label: 'New York State School of Industrial and Labor Relations')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'in OCLC_FAST authority and personal_name subauthority' do
|
36
|
+
context '0 search results' do
|
37
|
+
let :results do
|
38
|
+
stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=oclc.personalName%20all%20%22supercalifragilisticexpialidocious%22&sortKeys=usage')
|
39
|
+
.to_return(status: 200, body: webmock_fixture('lod_oclc_query_no_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
40
|
+
lod_oclc.search('supercalifragilisticexpialidocious', subauth: 'personal_name', replacements: { 'maximumRecords' => '3' })
|
41
|
+
end
|
42
|
+
it 'returns an empty array' do
|
43
|
+
expect(results).to eq([])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context '3 search results' do
|
48
|
+
let :results do
|
49
|
+
stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=3&query=oclc.personalName%20all%20%22cornell%22&sortKeys=usage')
|
50
|
+
.to_return(status: 200, body: webmock_fixture('lod_oclc_personalName_query_3_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
51
|
+
lod_oclc.search('cornell', subauth: 'personal_name', replacements: { 'maximumRecords' => '3' })
|
52
|
+
end
|
53
|
+
it 'is correctly parsed' do
|
54
|
+
expect(results.count).to eq(3)
|
55
|
+
expect(results.first).to eq(uri: 'http://id.worldcat.org/fast/409667', id: '409667', label: 'Cornell, Ezra, 1807-1874')
|
56
|
+
expect(results.second).to eq(uri: 'http://id.worldcat.org/fast/5140', id: '5140', label: 'Cornell, Joseph')
|
57
|
+
expect(results.third).to eq(uri: 'http://id.worldcat.org/fast/72456', id: '72456', label: 'Cornell, Sarah Maria, 1802-1832')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'in AGROVOC authority' do
|
63
|
+
context '0 search results' do
|
64
|
+
let :results do
|
65
|
+
stub_request(:get, 'http://aims.fao.org/skosmos/rest/v1/search/?lang=en&query=*supercalifragilisticexpialidocious*')
|
66
|
+
.to_return(status: 200, body: webmock_fixture('lod_agrovoc_query_no_results.json'), headers: { 'Content-Type' => 'application/json' })
|
67
|
+
lod_agrovoc.search('supercalifragilisticexpialidocious')
|
68
|
+
end
|
69
|
+
it 'returns an empty array' do
|
70
|
+
expect(results).to eq([])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context '3 search results' do
|
75
|
+
let :results do
|
76
|
+
stub_request(:get, 'http://aims.fao.org/skosmos/rest/v1/search/?lang=en&query=*milk*')
|
77
|
+
.to_return(status: 200, body: webmock_fixture('lod_agrovoc_query_many_results.json'), headers: { 'Content-Type' => 'application/json' })
|
78
|
+
lod_agrovoc.search('milk')
|
79
|
+
end
|
80
|
+
it 'is correctly parsed' do
|
81
|
+
expect(results.count).to eq(64)
|
82
|
+
expect(results.first).to eq(uri: 'http://aims.fao.org/aos/agrovoc/c_8602', id: 'http://aims.fao.org/aos/agrovoc/c_8602', label: 'acidophilus milk')
|
83
|
+
expect(results.second).to eq(uri: 'http://aims.fao.org/aos/agrovoc/c_16076', id: 'http://aims.fao.org/aos/agrovoc/c_16076', label: 'buffalo milk')
|
84
|
+
expect(results.third).to eq(uri: 'http://aims.fao.org/aos/agrovoc/c_9513', id: 'http://aims.fao.org/aos/agrovoc/c_9513', label: 'buttermilk')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# context 'in LOC authority' do
|
90
|
+
# ###################################
|
91
|
+
# ### SEARCH NOT SUPPORTED BY LOC ###
|
92
|
+
# ###################################
|
93
|
+
# # let(:lod_loc) { Qa::Authorities::LinkedData::GenericAuthority.new(:LOC) }
|
94
|
+
# end
|
95
|
+
|
96
|
+
describe "language processing" do
|
97
|
+
context "when filtering #search results" do
|
98
|
+
context "and lang NOT passed in" do
|
99
|
+
context "and NO default defined in config" do
|
100
|
+
let(:lod_lang_no_defaults) { described_class.new(:LOD_LANG_NO_DEFAULTS) }
|
101
|
+
let :results do
|
102
|
+
stub_request(:get, "http://localhost/test_no_default/search?query=milk")
|
103
|
+
.to_return(status: 200, body: webmock_fixture("lod_lang_search_enfr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
|
104
|
+
lod_lang_no_defaults.search('milk')
|
105
|
+
end
|
106
|
+
it "is not filtered" do
|
107
|
+
expect(results.first[:label]).to eq('[buttermilk, Babeurre] (yummy, délicieux)')
|
108
|
+
expect(results.second[:label]).to eq('[condensed milk, lait condensé] (creamy, crémeux)')
|
109
|
+
expect(results.third[:label]).to eq('[dried milk, lait en poudre] (powdery, poudreux)')
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "and default IS defined in config" do
|
114
|
+
let(:lod_lang_defaults) { described_class.new(:LOD_LANG_DEFAULTS) }
|
115
|
+
let :results do
|
116
|
+
stub_request(:get, "http://localhost/test_default/search?query=milk")
|
117
|
+
.to_return(status: 200, body: webmock_fixture("lod_lang_search_enfr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
|
118
|
+
lod_lang_defaults.search('milk')
|
119
|
+
end
|
120
|
+
it "is filtered to default" do
|
121
|
+
expect(results.first[:label]).to eq('buttermilk (yummy)')
|
122
|
+
expect(results.second[:label]).to eq('condensed milk (creamy)')
|
123
|
+
expect(results.third[:label]).to eq('dried milk (powdery)')
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "and multiple defaults ARE defined in config" do
|
129
|
+
let(:lod_lang_multi_defaults) { described_class.new(:LOD_LANG_MULTI_DEFAULTS) }
|
130
|
+
let :results do
|
131
|
+
stub_request(:get, "http://localhost/test_default/search?query=milk")
|
132
|
+
.to_return(status: 200, body: webmock_fixture("lod_lang_search_enfrde.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
|
133
|
+
lod_lang_multi_defaults.search('milk')
|
134
|
+
end
|
135
|
+
it "is filtered to default" do
|
136
|
+
expect(results.first[:label]).to eq('[buttermilk, Babeurre] (yummy, délicieux)')
|
137
|
+
expect(results.second[:label]).to eq('[condensed milk, lait condensé] (creamy, crémeux)')
|
138
|
+
expect(results.third[:label]).to eq('[dried milk, lait en poudre] (powdery, poudreux)')
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context "and lang IS passed in" do
|
143
|
+
let(:lod_lang_defaults) { described_class.new(:LOD_LANG_DEFAULTS) }
|
144
|
+
let :results do
|
145
|
+
stub_request(:get, "http://localhost/test_default/search?query=milk")
|
146
|
+
.to_return(status: 200, body: webmock_fixture("lod_lang_search_enfr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
|
147
|
+
lod_lang_defaults.search('milk', language: :fr)
|
148
|
+
end
|
149
|
+
it "is filtered to specified language" do
|
150
|
+
expect(results.first[:label]).to eq('Babeurre (délicieux)')
|
151
|
+
expect(results.second[:label]).to eq('lait condensé (crémeux)')
|
152
|
+
expect(results.third[:label]).to eq('lait en poudre (poudreux)')
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context "when replacement on authority search URL" do
|
157
|
+
context "and using default" do
|
158
|
+
let(:lod_lang_param) { described_class.new(:LOD_LANG_PARAM) }
|
159
|
+
let :results do
|
160
|
+
stub_request(:get, "http://localhost/test_replacement/search?lang=en&query=milk")
|
161
|
+
.to_return(status: 200, body: webmock_fixture("lod_lang_search_en.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
|
162
|
+
lod_lang_param.search("milk")
|
163
|
+
end
|
164
|
+
it "is correctly parsed" do
|
165
|
+
expect(results.first[:label]).to eq('buttermilk (yummy)')
|
166
|
+
expect(results.second[:label]).to eq('condensed milk (creamy)')
|
167
|
+
expect(results.third[:label]).to eq('dried milk (powdery)')
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "and lang specified" do
|
172
|
+
let(:lod_lang_param) { described_class.new(:LOD_LANG_PARAM) }
|
173
|
+
let :results do
|
174
|
+
stub_request(:get, "http://localhost/test_replacement/search?query=milk&lang=fr")
|
175
|
+
.to_return(status: 200, body: webmock_fixture("lod_lang_search_fr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
|
176
|
+
lod_lang_param.search("milk", replacements: { 'lang' => 'fr' })
|
177
|
+
end
|
178
|
+
it "is correctly parsed" do
|
179
|
+
expect(results.first[:label]).to eq('Babeurre (délicieux)')
|
180
|
+
expect(results.second[:label]).to eq('lait condensé (crémeux)')
|
181
|
+
expect(results.third[:label]).to eq('lait en poudre (poudreux)')
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe '#find' do
|
190
|
+
let(:lod_oclc) { described_class.new(:OCLC_FAST) }
|
191
|
+
let(:lod_agrovoc) { described_class.new(:AGROVOC) }
|
192
|
+
let(:lod_loc) { described_class.new(:LOC) }
|
193
|
+
|
194
|
+
context 'basic parameter testing' do
|
195
|
+
context 'with bad id' do
|
196
|
+
before do
|
197
|
+
stub_request(:get, 'http://id.worldcat.org/fast/FAKE_ID')
|
198
|
+
.to_return(status: 404, body: '', headers: {})
|
199
|
+
end
|
200
|
+
it 'raises a TermNotFound exception' do
|
201
|
+
expect { lod_oclc.find('FAKE_ID') }.to raise_error Qa::TermNotFound, /.*\/FAKE_ID\ Not Found - Term may not exist at LOD Authority./
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
# context 'with language specified' do
|
206
|
+
# before do
|
207
|
+
# stub_request(:get, 'http://id.worldcat.org/fast/FAKE_ID')
|
208
|
+
# .to_return(status: 404, body: '', headers: {})
|
209
|
+
# end
|
210
|
+
# it 'raises a TermNotFound exception' do
|
211
|
+
# expect { lod_oclc.find('FAKE_ID', language: :en) }.to raise_error Qa::TermNotFound, /.*\/FAKE_ID\ Not Found - Term may not exist at LOD Authority./
|
212
|
+
# end
|
213
|
+
# end
|
214
|
+
#
|
215
|
+
# context 'with replacements specified' do
|
216
|
+
# before do
|
217
|
+
# stub_request(:get, 'http://id.worldcat.org/fast/FAKE_ID')
|
218
|
+
# .to_return(status: 404, body: '', headers: {})
|
219
|
+
# end
|
220
|
+
# it 'raises a TermNotFound exception' do
|
221
|
+
# expect { lod_oclc.find('FAKE_ID') }.to raise_error Qa::TermNotFound, /.*\/FAKE_ID\ Not Found - Term may not exist at LOD Authority./
|
222
|
+
# end
|
223
|
+
# end
|
224
|
+
#
|
225
|
+
# context 'with subauth specified' do
|
226
|
+
# before do
|
227
|
+
# stub_request(:get, 'http://id.worldcat.org/fast/FAKE_ID')
|
228
|
+
# .to_return(status: 404, body: '', headers: {})
|
229
|
+
# end
|
230
|
+
# it 'raises a TermNotFound exception' do
|
231
|
+
# expect { lod_oclc.find('FAKE_ID') }.to raise_error Qa::TermNotFound, /.*\/FAKE_ID\ Not Found - Term may not exist at LOD Authority./
|
232
|
+
# end
|
233
|
+
# end
|
234
|
+
end
|
235
|
+
|
236
|
+
context 'in OCLC_FAST authority' do
|
237
|
+
context 'term found' do
|
238
|
+
let :results do
|
239
|
+
stub_request(:get, 'http://id.worldcat.org/fast/530369')
|
240
|
+
.to_return(status: 200, body: webmock_fixture('lod_oclc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
241
|
+
lod_oclc.find('530369')
|
242
|
+
end
|
243
|
+
it 'has correct primary predicate values' do
|
244
|
+
expect(results[:uri]).to eq('http://id.worldcat.org/fast/530369')
|
245
|
+
expect(results[:id]).to eq('530369')
|
246
|
+
expect(results[:label]).to eq ['Cornell University']
|
247
|
+
expect(results[:altlabel]).to include('Ithaca (N.Y.). Cornell University', "Kornel\\xCA\\xB9skii universitet", "K\\xCA\\xBBang-nai-erh ta hs\\xC3\\xBCeh")
|
248
|
+
expect(results[:altlabel].size).to eq 3
|
249
|
+
expect(results[:sameas]).to include('http://id.loc.gov/authorities/names/n79021621', 'https://viaf.org/viaf/126293486')
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'has correct number of predicates in pred-obj list' do
|
253
|
+
expect(results['predicates'].count).to eq 7
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'has primary predicates in pred-obj list' do
|
257
|
+
expect(results['predicates']['http://purl.org/dc/terms/identifier']).to eq ['530369']
|
258
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#prefLabel']).to eq ['Cornell University']
|
259
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#altLabel']).to include('Ithaca (N.Y.). Cornell University', "Kornel\\xCA\\xB9skii universitet", "K\\xCA\\xBBang-nai-erh ta hs\\xC3\\xBCeh")
|
260
|
+
expect(results['predicates']['http://schema.org/sameAs']).to include('http://id.loc.gov/authorities/names/n79021621', 'https://viaf.org/viaf/126293486')
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'has unspecified predicate values' do
|
264
|
+
expect(results['predicates']['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']).to eq ['http://schema.org/Organization']
|
265
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#inScheme']).to include('http://id.worldcat.org/fast/ontology/1.0/#fast', 'http://id.worldcat.org/fast/ontology/1.0/#facet-Corporate')
|
266
|
+
expect(results['predicates']['http://schema.org/name']).to include('Cornell University', 'Ithaca (N.Y.). Cornell University', "Kornel\\xCA\\xB9skii universitet", "K\\xCA\\xBBang-nai-erh ta hs\\xC3\\xBCeh")
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
context 'in AGROVOC authority' do
|
272
|
+
context 'term found' do
|
273
|
+
let :results do
|
274
|
+
stub_request(:get, 'http://aims.fao.org/skosmos/rest/v1/data?uri=http://aims.fao.org/aos/agrovoc/c_9513')
|
275
|
+
.to_return(status: 200, body: webmock_fixture('lod_agrovoc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
276
|
+
lod_agrovoc.find('c_9513')
|
277
|
+
end
|
278
|
+
it 'has correct primary predicate values' do
|
279
|
+
expect(results[:uri]).to eq('http://aims.fao.org/aos/agrovoc/c_9513')
|
280
|
+
expect(results[:id]).to eq('http://aims.fao.org/aos/agrovoc/c_9513')
|
281
|
+
expect(results[:label]).to eq ['buttermilk']
|
282
|
+
expect(results[:broader]).to eq ['http://aims.fao.org/aos/agrovoc/c_4830']
|
283
|
+
expect(results[:sameas]).to include('http://cat.aii.caas.cn/concept/c_26308', 'http://lod.nal.usda.gov/nalt/20627', 'http://d-nb.info/gnd/4147072-2')
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'has correct number of predicates in pred-obj list' do
|
287
|
+
expect(results['predicates'].count).to eq 12
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'has primary predicates in pred-obj list' do
|
291
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#prefLabel']).to eq ['buttermilk']
|
292
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#broader']).to eq ['http://aims.fao.org/aos/agrovoc/c_4830']
|
293
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#exactMatch']).to include('http://cat.aii.caas.cn/concept/c_26308', 'http://lod.nal.usda.gov/nalt/20627', 'http://d-nb.info/gnd/4147072-2')
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'has skos predicate values' do
|
297
|
+
expect(results['predicates']['http://www.w3.org/2008/05/skos-xl#prefLabel']).to include('http://aims.fao.org/aos/agrovoc/xl_es_1299487482038', 'http://aims.fao.org/aos/agrovoc/xl_it_1299487482154', 'http://aims.fao.org/aos/agrovoc/xl_ko_1299487482210', 'http://aims.fao.org/aos/agrovoc/xl_pl_1299487482273', 'http://aims.fao.org/aos/agrovoc/xl_sk_1299487482378', 'http://aims.fao.org/aos/agrovoc/xl_en_1299487482019', 'http://aims.fao.org/aos/agrovoc/xl_tr_9513_1321792194941', 'http://aims.fao.org/aos/agrovoc/xl_de_1299487482000', 'http://aims.fao.org/aos/agrovoc/xl_fa_1299487482058', 'http://aims.fao.org/aos/agrovoc/xl_th_1299487482417', 'http://aims.fao.org/aos/agrovoc/xl_fr_1299487482080', 'http://aims.fao.org/aos/agrovoc/xl_hi_1299487482102', 'http://aims.fao.org/aos/agrovoc/xl_ar_1299487481966', 'http://aims.fao.org/aos/agrovoc/xl_ja_1299487482181', 'http://aims.fao.org/aos/agrovoc/xl_lo_1299487482240', 'http://aims.fao.org/aos/agrovoc/xl_ru_1299487482341', 'http://aims.fao.org/aos/agrovoc/xl_cs_1299487481982', 'http://aims.fao.org/aos/agrovoc/xl_zh_1299487482458', 'http://aims.fao.org/aos/agrovoc/xl_pt_1299487482307', 'http://aims.fao.org/aos/agrovoc/xl_hu_1299487482127')
|
298
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#inScheme']).to eq ['http://aims.fao.org/aos/agrovoc']
|
299
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#closeMatch']).to eq ['http://dbpedia.org/resource/Buttermilk']
|
300
|
+
expect(results['predicates']['http://www.w3.org/2008/05/skos-xl#altLabel']).to eq ['http://aims.fao.org/aos/agrovoc/xl_fa_1299487482544']
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'has more unspecified predicate values' do
|
304
|
+
expect(results['predicates']['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']).to eq ['http://www.w3.org/2004/02/skos/core#Concept']
|
305
|
+
expect(results['predicates']['http://purl.org/dc/terms/created']).to eq ['2011-11-20T20:29:54Z']
|
306
|
+
expect(results['predicates']['http://purl.org/dc/terms/modified']).to eq ['2014-07-03T18:51:03Z']
|
307
|
+
expect(results['predicates']['http://rdfs.org/ns/void#inDataset']).to eq ['http://aims.fao.org/aos/agrovoc/void.ttl#Agrovoc']
|
308
|
+
expect(results['predicates']['http://art.uniroma2.it/ontologies/vocbench#hasStatus']).to eq ['Published']
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
context 'in LOC authority' do
|
314
|
+
context 'term found' do
|
315
|
+
let :results do
|
316
|
+
stub_request(:get, 'http://id.loc.gov/authorities/subjects/sh85118553')
|
317
|
+
.to_return(status: 200, body: webmock_fixture('lod_loc_term_found.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
|
318
|
+
lod_loc.find('sh85118553', subauth: 'subjects')
|
319
|
+
end
|
320
|
+
it 'has correct primary predicate values' do
|
321
|
+
expect(results[:uri]).to eq 'http://id.loc.gov/authorities/subjects/sh85118553'
|
322
|
+
expect(results[:id]).to eq 'sh 85118553'
|
323
|
+
expect(results[:label]).to eq ['Science']
|
324
|
+
expect(results[:altlabel]).to include('Natural science', 'Science of science', 'Sciences')
|
325
|
+
end
|
326
|
+
|
327
|
+
it 'has correct number of predicates in pred-obj list' do
|
328
|
+
expect(results['predicates'].count).to eq 14
|
329
|
+
end
|
330
|
+
|
331
|
+
it 'has primary predicates in pred-obj list' do
|
332
|
+
expect(results['predicates']['http://id.loc.gov/vocabulary/identifiers/lccn']).to eq ['sh 85118553']
|
333
|
+
expect(results['predicates']['http://www.loc.gov/mads/rdf/v1#authoritativeLabel']).to eq ['Science']
|
334
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#prefLabel']).to eq ['Science']
|
335
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#altLabel']).to include('Natural science', 'Science of science', 'Sciences')
|
336
|
+
end
|
337
|
+
|
338
|
+
it 'has loc mads predicate values' do
|
339
|
+
expect(results['predicates']['http://www.loc.gov/mads/rdf/v1#classification']).to eq ['Q']
|
340
|
+
expect(results['predicates']['http://www.loc.gov/mads/rdf/v1#isMemberOfMADSCollection']).to include('http://id.loc.gov/authorities/subjects/collection_LCSHAuthorizedHeadings', 'http://id.loc.gov/authorities/subjects/collection_LCSH_General', 'http://id.loc.gov/authorities/subjects/collection_SubdivideGeographically')
|
341
|
+
expect(results['predicates']['http://www.loc.gov/mads/rdf/v1#hasCloseExternalAuthority']).to include('http://data.bnf.fr/ark:/12148/cb12321484k', 'http://data.bnf.fr/ark:/12148/cb119673416', 'http://data.bnf.fr/ark:/12148/cb119934236', 'http://data.bnf.fr/ark:/12148/cb12062047t', 'http://data.bnf.fr/ark:/12148/cb119469567', 'http://data.bnf.fr/ark:/12148/cb11933232c', 'http://data.bnf.fr/ark:/12148/cb122890536', 'http://data.bnf.fr/ark:/12148/cb121155321', 'http://data.bnf.fr/ark:/12148/cb15556043g', 'http://data.bnf.fr/ark:/12148/cb123662513', 'http://d-nb.info/gnd/4066562-8', 'http://data.bnf.fr/ark:/12148/cb120745812', 'http://data.bnf.fr/ark:/12148/cb11973101n', 'http://data.bnf.fr/ark:/12148/cb13328497r')
|
342
|
+
expect(results['predicates']['http://www.loc.gov/mads/rdf/v1#isMemberOfMADSScheme']).to eq ['http://id.loc.gov/authorities/subjects']
|
343
|
+
expect(results['predicates']['http://www.loc.gov/mads/rdf/v1#editorialNote']).to eq ['headings beginning with the word [Scientific;] and subdivision [Science] under ethnic groups and individual wars, e.g. [World War, 1939-1945--Science]']
|
344
|
+
end
|
345
|
+
|
346
|
+
it 'has more unspecified predicate values' do
|
347
|
+
expect(results['predicates']['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']).to include('http://www.loc.gov/mads/rdf/v1#Topic', 'http://www.loc.gov/mads/rdf/v1#Authority', 'http://www.w3.org/2004/02/skos/core#Concept')
|
348
|
+
expect(results['predicates']['http://www.w3.org/2002/07/owl#sameAs']).to include('info:lc/authorities/sh85118553', 'http://id.loc.gov/authorities/sh85118553#concept')
|
349
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#closeMatch']).to include('http://data.bnf.fr/ark:/12148/cb12321484k', 'http://data.bnf.fr/ark:/12148/cb119673416', 'http://data.bnf.fr/ark:/12148/cb119934236', 'http://data.bnf.fr/ark:/12148/cb12062047t', 'http://data.bnf.fr/ark:/12148/cb119469567', 'http://data.bnf.fr/ark:/12148/cb11933232c', 'http://data.bnf.fr/ark:/12148/cb122890536', 'http://data.bnf.fr/ark:/12148/cb121155321', 'http://data.bnf.fr/ark:/12148/cb15556043g', 'http://data.bnf.fr/ark:/12148/cb123662513', 'http://d-nb.info/gnd/4066562-8', 'http://data.bnf.fr/ark:/12148/cb120745812', 'http://data.bnf.fr/ark:/12148/cb11973101n', 'http://data.bnf.fr/ark:/12148/cb13328497r')
|
350
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#editorial']).to eq ['headings beginning with the word [Scientific;] and subdivision [Science] under ethnic groups and individual wars, e.g. [World War, 1939-1945--Science]']
|
351
|
+
expect(results['predicates']['http://www.w3.org/2004/02/skos/core#inScheme']).to eq ['http://id.loc.gov/authorities/subjects']
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
describe "language processing" do
|
357
|
+
context "when filtering #find result" do
|
358
|
+
context "and lang NOT passed in" do
|
359
|
+
context "and NO default defined in config" do
|
360
|
+
let(:lod_lang_no_defaults) { described_class.new(:LOD_LANG_NO_DEFAULTS) }
|
361
|
+
let :results do
|
362
|
+
stub_request(:get, "http://localhost/test_no_default/term/c_9513")
|
363
|
+
.to_return(status: 200, body: webmock_fixture("lod_lang_term_enfr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
|
364
|
+
lod_lang_no_defaults.find('c_9513')
|
365
|
+
end
|
366
|
+
it "is not filtered" do
|
367
|
+
expect(results[:label]).to eq ['buttermilk', 'Babeurre']
|
368
|
+
expect(results[:altlabel]).to eq ['yummy', 'délicieux']
|
369
|
+
expect(results["predicates"]["http://www.w3.org/2004/02/skos/core#prefLabel"]).to include("buttermilk", "Babeurre")
|
370
|
+
expect(results["predicates"]["http://www.w3.org/2004/02/skos/core#altLabel"]).to include("yummy", "délicieux")
|
371
|
+
end
|
372
|
+
end
|
373
|
+
context "and default IS defined in config" do
|
374
|
+
let(:lod_lang_defaults) { described_class.new(:LOD_LANG_DEFAULTS) }
|
375
|
+
let :results do
|
376
|
+
stub_request(:get, "http://localhost/test_default/term/c_9513")
|
377
|
+
.to_return(status: 200, body: webmock_fixture("lod_lang_term_enfr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
|
378
|
+
lod_lang_defaults.find('c_9513')
|
379
|
+
end
|
380
|
+
it "is filtered to default" do
|
381
|
+
expect(results[:label]).to eq ['buttermilk']
|
382
|
+
expect(results[:altlabel]).to eq ['yummy']
|
383
|
+
expect(results["predicates"]["http://www.w3.org/2004/02/skos/core#prefLabel"]).to eq ['buttermilk']
|
384
|
+
expect(results["predicates"]["http://www.w3.org/2004/02/skos/core#altLabel"]).to eq ['yummy']
|
385
|
+
end
|
386
|
+
end
|
387
|
+
context "and multiple defaults ARE defined in config" do
|
388
|
+
let(:lod_lang_multi_defaults) { described_class.new(:LOD_LANG_MULTI_DEFAULTS) }
|
389
|
+
let :results do
|
390
|
+
stub_request(:get, "http://localhost/test_default/term/c_9513")
|
391
|
+
.to_return(status: 200, body: webmock_fixture("lod_lang_term_enfrde.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
|
392
|
+
lod_lang_multi_defaults.find('c_9513')
|
393
|
+
end
|
394
|
+
it "is filtered to default" do
|
395
|
+
expect(results[:label]).to eq ['buttermilk', 'Babeurre']
|
396
|
+
expect(results[:altlabel]).to eq ['yummy', 'délicieux']
|
397
|
+
expect(results["predicates"]["http://www.w3.org/2004/02/skos/core#prefLabel"]).to include("buttermilk", "Babeurre")
|
398
|
+
expect(results["predicates"]["http://www.w3.org/2004/02/skos/core#altLabel"]).to include("yummy", "délicieux")
|
399
|
+
end
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
context "and lang IS passed in" do
|
404
|
+
let(:lod_lang_defaults) { described_class.new(:LOD_LANG_DEFAULTS) }
|
405
|
+
let :results do
|
406
|
+
stub_request(:get, "http://localhost/test_default/term/c_9513")
|
407
|
+
.to_return(status: 200, body: webmock_fixture("lod_lang_term_enfr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
|
408
|
+
lod_lang_defaults.find('c_9513', language: 'fr')
|
409
|
+
end
|
410
|
+
it "is filtered to specified language" do
|
411
|
+
expect(results[:label]).to eq ['Babeurre']
|
412
|
+
expect(results[:altlabel]).to eq ['délicieux']
|
413
|
+
expect(results["predicates"]["http://www.w3.org/2004/02/skos/core#prefLabel"]).to eq ['Babeurre']
|
414
|
+
expect(results["predicates"]["http://www.w3.org/2004/02/skos/core#altLabel"]).to eq ['délicieux']
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
context "and result does not have altlabel" do
|
419
|
+
let(:lod_lang_defaults) { described_class.new(:LOD_LANG_DEFAULTS) }
|
420
|
+
let :results do
|
421
|
+
stub_request(:get, "http://localhost/test_default/term/c_9513")
|
422
|
+
.to_return(status: 200, body: webmock_fixture("lod_lang_term_enfr_noalt.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
|
423
|
+
lod_lang_defaults.find('c_9513', language: 'fr')
|
424
|
+
end
|
425
|
+
it "is filtered to specified language" do
|
426
|
+
expect(results[:label]).to eq ['Babeurre']
|
427
|
+
expect(results["predicates"]["http://www.w3.org/2004/02/skos/core#prefLabel"]).to eq ['Babeurre']
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
context "when replacement on authority term URL" do
|
432
|
+
context "and using default" do
|
433
|
+
let(:lod_lang_param) { described_class.new(:LOD_LANG_PARAM) }
|
434
|
+
let :results do
|
435
|
+
stub_request(:get, "http://localhost/test_replacement/term/c_9513?lang=en")
|
436
|
+
.to_return(status: 200, body: webmock_fixture("lod_lang_term_en.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
|
437
|
+
lod_lang_param.find("c_9513")
|
438
|
+
end
|
439
|
+
it "is correctly parsed" do
|
440
|
+
expect(results[:label]).to eq ['buttermilk']
|
441
|
+
expect(results[:altlabel]).to eq ['yummy']
|
442
|
+
expect(results["predicates"]["http://www.w3.org/2004/02/skos/core#prefLabel"]).to eq ['buttermilk']
|
443
|
+
expect(results["predicates"]["http://www.w3.org/2004/02/skos/core#altLabel"]).to eq ['yummy']
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
context "and lang specified" do
|
448
|
+
let(:lod_lang_param) { described_class.new(:LOD_LANG_PARAM) }
|
449
|
+
let :results do
|
450
|
+
stub_request(:get, "http://localhost/test_replacement/term/c_9513?lang=fr")
|
451
|
+
.to_return(status: 200, body: webmock_fixture("lod_lang_term_fr.rdf.xml"), headers: { 'Content-Type' => 'application/rdf+xml' })
|
452
|
+
lod_lang_param.find("c_9513", replacements: { 'lang' => 'fr' })
|
453
|
+
end
|
454
|
+
it "is correctly parsed" do
|
455
|
+
expect(results[:label]).to eq ['Babeurre']
|
456
|
+
expect(results[:altlabel]).to eq ['délicieux']
|
457
|
+
expect(results["predicates"]["http://www.w3.org/2004/02/skos/core#prefLabel"]).to eq ['Babeurre']
|
458
|
+
expect(results["predicates"]["http://www.w3.org/2004/02/skos/core#altLabel"]).to eq ['délicieux']
|
459
|
+
end
|
460
|
+
end
|
461
|
+
end
|
462
|
+
end
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
describe '#new' do
|
467
|
+
context 'without an authority' do
|
468
|
+
it 'raises an exception' do
|
469
|
+
expect { described_class.new }.to raise_error ArgumentError, /wrong number of arguments/
|
470
|
+
end
|
471
|
+
end
|
472
|
+
context 'with an invalid authority' do
|
473
|
+
it 'raises an exception' do
|
474
|
+
expect { described_class.new(:FOO) }.to raise_error Qa::InvalidLinkedDataAuthority, /Unable to initialize linked data authority 'FOO'/
|
475
|
+
end
|
476
|
+
end
|
477
|
+
context 'with a valid authority' do
|
478
|
+
it 'creates the authority' do
|
479
|
+
expect(described_class.new(:OCLC_FAST)).to be_kind_of described_class
|
480
|
+
end
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
context 'testing delegated method' do
|
485
|
+
let(:full_authority) { described_class.new(:LOD_FULL_CONFIG) }
|
486
|
+
let(:min_authority) { described_class.new(:LOD_MIN_CONFIG) }
|
487
|
+
let(:search_only_authority) { described_class.new(:LOD_SEARCH_ONLY_CONFIG) }
|
488
|
+
let(:term_only_authority) { described_class.new(:LOD_TERM_ONLY_CONFIG) }
|
489
|
+
|
490
|
+
describe '#supports_search?' do
|
491
|
+
it 'returns false if search is NOT configured' do
|
492
|
+
expect(term_only_authority.supports_search?).to eq false
|
493
|
+
end
|
494
|
+
it 'returns true if search is configured' do
|
495
|
+
expect(full_authority.supports_search?).to eq true
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
describe '#search_subauthorities?' do
|
500
|
+
it 'returns false if only term configuration is defined' do
|
501
|
+
expect(term_only_authority.search_subauthorities?).to eq false
|
502
|
+
end
|
503
|
+
it 'returns false if the configuration does NOT define subauthorities' do
|
504
|
+
expect(min_authority.search_subauthorities?).to eq false
|
505
|
+
end
|
506
|
+
it 'returns true if the configuration defines subauthorities' do
|
507
|
+
expect(full_authority.search_subauthorities?).to eq true
|
508
|
+
end
|
509
|
+
end
|
510
|
+
|
511
|
+
describe '#search_subauthority?' do
|
512
|
+
it 'returns false if only term configuration is defined' do
|
513
|
+
expect(term_only_authority.search_subauthority?('fake_subauth')).to eq false
|
514
|
+
end
|
515
|
+
it 'returns false if there are no subauthorities configured' do
|
516
|
+
expect(min_authority.search_subauthority?('fake_subauth')).to eq false
|
517
|
+
end
|
518
|
+
it 'returns false if the requested subauthority is NOT configured' do
|
519
|
+
expect(full_authority.search_subauthority?('fake_subauth')).to eq false
|
520
|
+
end
|
521
|
+
it 'returns true if the requested subauthority is configured' do
|
522
|
+
expect(full_authority.search_subauthority?('search_sub2_key')).to eq true
|
523
|
+
end
|
524
|
+
end
|
525
|
+
|
526
|
+
describe '#supports_term?' do
|
527
|
+
it 'returns false if term is NOT configured' do
|
528
|
+
expect(search_only_authority.supports_term?).to eq false
|
529
|
+
end
|
530
|
+
it 'returns true if term is configured' do
|
531
|
+
expect(full_authority.supports_term?).to eq true
|
532
|
+
end
|
533
|
+
end
|
534
|
+
|
535
|
+
describe '#term_subauthorities?' do
|
536
|
+
it 'returns false if only search configuration is defined' do
|
537
|
+
expect(search_only_authority.term_subauthorities?).to eq false
|
538
|
+
end
|
539
|
+
it 'returns false if the configuration does NOT define subauthorities' do
|
540
|
+
expect(min_authority.term_subauthorities?).to eq false
|
541
|
+
end
|
542
|
+
it 'returns true if the configuration defines subauthorities' do
|
543
|
+
expect(full_authority.term_subauthorities?).to eq true
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
describe '#term_subauthority?' do
|
548
|
+
it 'returns false if only search configuration is defined' do
|
549
|
+
expect(search_only_authority.term_subauthority?('fake_subauth')).to eq false
|
550
|
+
end
|
551
|
+
it 'returns false if there are no subauthorities configured' do
|
552
|
+
expect(min_authority.term_subauthority?('fake_subauth')).to eq false
|
553
|
+
end
|
554
|
+
it 'returns false if the requested subauthority is NOT configured' do
|
555
|
+
expect(full_authority.term_subauthority?('fake_subauth')).to eq false
|
556
|
+
end
|
557
|
+
it 'returns true if the requested subauthority is configured' do
|
558
|
+
expect(full_authority.term_subauthority?('term_sub2_key')).to eq true
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
562
|
+
describe '#term_id_expects_id?' do
|
563
|
+
it 'returns false if term_id specifies a URI is required' do
|
564
|
+
expect(min_authority.term_id_expects_id?).to eq false
|
565
|
+
end
|
566
|
+
it 'returns true if term_id specifies an ID is required' do
|
567
|
+
expect(full_authority.term_id_expects_id?).to eq true
|
568
|
+
end
|
569
|
+
end
|
570
|
+
|
571
|
+
describe '#term_id_expects_uri?' do
|
572
|
+
it 'returns false if term_id specifies a ID is required' do
|
573
|
+
expect(full_authority.term_id_expects_uri?).to eq false
|
574
|
+
end
|
575
|
+
it 'returns true if term_id specifies an URI is required' do
|
576
|
+
expect(min_authority.term_id_expects_uri?).to eq true
|
577
|
+
end
|
578
|
+
end
|
579
|
+
end
|
580
|
+
end
|