qa 2.0.1 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -3
- data/app/controllers/qa/application_controller.rb +22 -0
- data/app/controllers/qa/linked_data_terms_controller.rb +16 -10
- data/app/controllers/qa/terms_controller.rb +7 -2
- data/app/models/qa/mesh_tree.rb +5 -9
- data/app/models/qa/subject_mesh_term.rb +2 -7
- data/config/initializers/linked_data_authorities.rb +1 -1
- data/config/routes.rb +8 -0
- data/lib/generators/qa/install/install_generator.rb +4 -0
- data/lib/generators/qa/install/templates/config/initializers/qa.rb +7 -0
- data/lib/generators/qa/local/tables/mysql/mysql_generator.rb +1 -1
- data/lib/generators/qa/local/tables/tables_generator.rb +1 -1
- data/lib/qa.rb +16 -0
- data/lib/qa/authorities/assign_fast_subauthority.rb +3 -3
- data/lib/qa/authorities/getty/tgn.rb +1 -1
- data/lib/qa/authorities/getty/ulan.rb +1 -1
- data/lib/qa/authorities/linked_data/find_term.rb +2 -2
- data/lib/qa/authorities/linked_data/rdf_helper.rb +15 -0
- data/lib/qa/authorities/linked_data/search_query.rb +19 -3
- data/lib/qa/authorities/loc_subauthority.rb +2 -2
- data/lib/qa/authorities/local.rb +2 -4
- data/lib/qa/authorities/local/file_based_authority.rb +1 -1
- data/lib/qa/authorities/local/mysql_table_based_authority.rb +11 -2
- data/lib/qa/authorities/local/table_based_authority.rb +2 -1
- data/lib/qa/authorities/mesh_tools/mesh_data_parser.rb +1 -1
- data/lib/qa/authorities/mesh_tools/mesh_importer.rb +1 -1
- data/lib/qa/authorities/oclcts/generic_oclc_authority.rb +1 -3
- data/lib/qa/configuration.rb +16 -0
- data/lib/qa/version.rb +1 -1
- data/lib/tasks/mesh.rake +3 -3
- data/spec/controllers/linked_data_terms_controller_spec.rb +65 -14
- data/spec/controllers/terms_controller_spec.rb +85 -10
- data/spec/fixtures/{lexvo_snippet.rdf → lexvo_snippet.rdf.xml} +1 -0
- data/spec/lib/authorities/assign_fast_spec.rb +3 -1
- data/spec/lib/authorities/file_based_authority_spec.rb +19 -11
- data/spec/lib/authorities/geonames_spec.rb +3 -3
- data/spec/lib/authorities/getty/aat_spec.rb +2 -1
- data/spec/lib/authorities/getty/tgn_spec.rb +6 -2
- data/spec/lib/authorities/getty/ulan_spec.rb +4 -2
- data/spec/lib/authorities/getty_spec.rb +2 -1
- data/spec/lib/authorities/linked_data/generic_authority_spec.rb +54 -12
- data/spec/lib/authorities/linked_data/search_config_spec.rb +23 -19
- data/spec/lib/authorities/linked_data/search_query_spec.rb +67 -15
- data/spec/lib/authorities/linked_data/term_config_spec.rb +24 -20
- data/spec/lib/authorities/local_spec.rb +7 -8
- data/spec/lib/authorities/oclcts_spec.rb +27 -20
- data/spec/lib/authorities/table_based_authority_spec.rb +5 -3
- data/spec/lib/authorities_loc_subauthorities.rb +2 -2
- data/spec/lib/mesh_data_parser_spec.rb +2 -0
- data/spec/lib/services/rdf_authority_parser_spec.rb +1 -1
- data/spec/lib/tasks/mesh.rake_spec.rb +13 -12
- data/spec/models/subject_mesh_term_spec.rb +2 -0
- data/spec/requests/cors_headers_spec.rb +118 -0
- data/spec/spec_helper.rb +2 -2
- metadata +133 -142
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 044adb0de6665c9ba6499467e7f91687ae42d0bf
|
4
|
+
data.tar.gz: 4e214ad816b495b55f3a7a9d2c9d305ac5ceef79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14c63d1a98211821bd3b2e935237140f4204d71572c8748e97d1fcdef5dd95c38e0fa6d6108839f242704c705fe232095b3a923ccce12d9d49c1a7bc7001eb76
|
7
|
+
data.tar.gz: ebd6d89c1eb12fb9119f9f24323df221bdfe33cbaae070290dd530612869eb83b23d2efa899577a302ad3bbc6223417623a7c3862b59e808cf7fde5f828200c9
|
data/README.md
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
# Questioning Authority
|
2
2
|
|
3
|
-
|
3
|
+
Code:
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/qa.png)](http://badge.fury.io/rb/qa)
|
5
|
+
[![Build Status](https://travis-ci.org/samvera/questioning_authority.png?branch=master)](https://travis-ci.org/samvera/questioning_authority)
|
4
6
|
[![Coverage Status](https://coveralls.io/repos/github/samvera/questioning_authority/badge.svg?branch=master)](https://coveralls.io/github/samvera/questioning_authority?branch=master)
|
5
7
|
|
8
|
+
Docs:
|
9
|
+
[![Contribution Guidelines](http://img.shields.io/badge/CONTRIBUTING-Guidelines-blue.svg)](./CONTRIBUTING.md)
|
10
|
+
[![Apache 2.0 License](http://img.shields.io/badge/APACHE2-license-blue.svg)](./LICENSE)
|
11
|
+
|
12
|
+
Jump In: [![Slack Status](http://slack.samvera.org/badge.svg)](http://slack.samvera.org/)
|
13
|
+
|
6
14
|
You should question your authorities.
|
7
15
|
|
8
16
|
----
|
@@ -29,10 +37,12 @@ You should question your authorities.
|
|
29
37
|
* [Add javascript to support autocomplete](#add-javascript-to-support-autocomplete)
|
30
38
|
* [Developer Notes](#developer-notes)
|
31
39
|
* [Compatibility](#compatibility)
|
40
|
+
* [Product Owner & Maintenance](#product-owner--maintenance)
|
41
|
+
* [Product Owner](#product-owner)
|
32
42
|
* [Help](#help)
|
43
|
+
* [Acknowledgments](#acknowledgments)
|
33
44
|
|
34
45
|
----
|
35
|
-
|
36
46
|
## What does this do?
|
37
47
|
|
38
48
|
Provides a set of uniform RESTful routes to query any controlled vocabulary or set of authority terms.
|
@@ -639,9 +649,26 @@ Commit your features into a new branch and submit a pull request.
|
|
639
649
|
* Ruby 2.4 or the latest 2.3 version is recommended. Later versions may also work.
|
640
650
|
* Rails 5 is required. We recommend the latest Rails 5.0 release.
|
641
651
|
|
652
|
+
## Product Owner & Maintenance
|
653
|
+
|
654
|
+
Questioning Authority is a Core Component of the Samvera community. The documentation for
|
655
|
+
what this means can be found
|
656
|
+
[here](http://samvera.github.io/core_components.html#requirements-for-a-core-component).
|
657
|
+
|
658
|
+
### Product Owner
|
659
|
+
|
660
|
+
[elrayle](https://github.com/elrayle)
|
661
|
+
|
642
662
|
# Help
|
643
663
|
|
644
|
-
|
664
|
+
The Samvera community is here to help. Please see our [support guide](./SUPPORT.md).
|
665
|
+
|
666
|
+
# Acknowledgments
|
667
|
+
|
668
|
+
This software has been developed by and is brought to you by the Samvera community. Learn more at the
|
669
|
+
[Samvera website](http://samvera.org/).
|
670
|
+
|
671
|
+
![Samvera Logo](https://wiki.duraspace.org/download/thumbnails/87459292/samvera-fall-font2-200w.png?version=1&modificationDate=1498550535816&api=v2)
|
645
672
|
|
646
673
|
### Special thanks to...
|
647
674
|
|
@@ -1,4 +1,26 @@
|
|
1
1
|
module Qa
|
2
2
|
class ApplicationController < ActionController::Base
|
3
|
+
# Process the OPTIONS method for all routes
|
4
|
+
# @see route definitions in /config/routes.rb
|
5
|
+
# @note Reference: https://fetch.spec.whatwg.org/#http-access-control-allow-headers
|
6
|
+
def options
|
7
|
+
unless Qa.config.cors_headers?
|
8
|
+
head :not_implemented
|
9
|
+
return
|
10
|
+
end
|
11
|
+
response.headers['Access-Control-Allow-Origin'] = '*'
|
12
|
+
response.headers['Access-Control-Allow-Methods'] = 'GET, OPTIONS'
|
13
|
+
head :no_content
|
14
|
+
end
|
15
|
+
|
16
|
+
# Add cors headers to the passed in http response if cors_headers are enabled. Called by all controller actions
|
17
|
+
# to adjust the response.
|
18
|
+
# @param http response
|
19
|
+
# @see /lib/generators/qa/install/templates/config/initializers/qa.rb
|
20
|
+
# @note The qa.rb initializer is copied to /config/initializers/qa.rb and can be modified to enable/disable cors headers.
|
21
|
+
# @note Reference: https://fetch.spec.whatwg.org/#http-access-control-allow-headers
|
22
|
+
def self.cors_allow_origin_header(response)
|
23
|
+
response.headers['Access-Control-Allow-Origin'] = '*' if Qa.config.cors_headers?
|
24
|
+
end
|
3
25
|
end
|
4
26
|
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
# This controller is used for all requests to linked data authorities. It will verify params and figure
|
2
2
|
# out which linked data authority to query based on the 'vocab' param.
|
3
3
|
|
4
|
-
class Qa::LinkedDataTermsController < ApplicationController
|
4
|
+
class Qa::LinkedDataTermsController < ::ApplicationController
|
5
5
|
before_action :check_authority, :init_authority
|
6
6
|
before_action :check_search_subauthority, :check_query_param, only: :search
|
7
7
|
before_action :check_show_subauthority, :check_id_param, only: :show
|
8
8
|
|
9
|
+
delegate :cors_allow_origin_header, to: Qa::ApplicationController
|
10
|
+
|
9
11
|
# Provide a warning if there is a request for all terms.
|
10
12
|
def index
|
11
13
|
logger.warn 'Linked data authorities do not support retrieving all terms.'
|
@@ -14,7 +16,7 @@ class Qa::LinkedDataTermsController < ApplicationController
|
|
14
16
|
|
15
17
|
# Return a list of terms based on a query
|
16
18
|
# @see Qa::Authorities::LinkedData::SearchQuery#search
|
17
|
-
def search
|
19
|
+
def search # rubocop:disable Metrics/MethodLength
|
18
20
|
begin
|
19
21
|
terms = @authority.search(query, subauth: subauthority, language: language, replacements: replacement_params)
|
20
22
|
rescue Qa::ServiceUnavailable
|
@@ -26,16 +28,18 @@ class Qa::LinkedDataTermsController < ApplicationController
|
|
26
28
|
head :internal_server_error
|
27
29
|
return
|
28
30
|
rescue RDF::FormatError
|
29
|
-
logger.warn "RDF Format Error - Results from search query #{query} for#{subauth_warn_msg} authority #{vocab_param}
|
31
|
+
logger.warn "RDF Format Error - Results from search query #{query} for#{subauth_warn_msg} authority #{vocab_param} " \
|
32
|
+
"was not identified as a valid RDF format. You may need to include the linkeddata gem."
|
30
33
|
head :internal_server_error
|
31
34
|
return
|
32
35
|
end
|
36
|
+
cors_allow_origin_header(response)
|
33
37
|
render json: terms
|
34
38
|
end
|
35
39
|
|
36
40
|
# Return all the information for a given term
|
37
41
|
# @see Qa::Authorities::LinkedData::FindTerm#find
|
38
|
-
def show
|
42
|
+
def show # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
39
43
|
begin
|
40
44
|
term = @authority.find(id, subauth: subauthority, language: language, replacements: replacement_params)
|
41
45
|
rescue Qa::TermNotFound
|
@@ -51,17 +55,19 @@ class Qa::LinkedDataTermsController < ApplicationController
|
|
51
55
|
head :internal_server_error
|
52
56
|
return
|
53
57
|
rescue RDF::FormatError
|
54
|
-
logger.warn "RDF Format Error - Results from fetch term #{id} for#{subauth_warn_msg} authority #{vocab_param}
|
58
|
+
logger.warn "RDF Format Error - Results from fetch term #{id} for#{subauth_warn_msg} authority #{vocab_param} " \
|
59
|
+
"was not identified as a valid RDF format. You may need to include the linkeddata gem."
|
55
60
|
head :internal_server_error
|
56
61
|
return
|
57
62
|
end
|
63
|
+
cors_allow_origin_header(response)
|
58
64
|
render json: term
|
59
65
|
end
|
60
66
|
|
61
67
|
private
|
62
68
|
|
63
69
|
def check_authority
|
64
|
-
if params[:vocab].nil? || !params[:vocab].size.positive?
|
70
|
+
if params[:vocab].nil? || !params[:vocab].size.positive? # rubocop:disable Style/GuardClause
|
65
71
|
logger.warn "Required param 'vocab' is missing or empty"
|
66
72
|
head :bad_request
|
67
73
|
end
|
@@ -69,7 +75,7 @@ class Qa::LinkedDataTermsController < ApplicationController
|
|
69
75
|
|
70
76
|
def check_search_subauthority
|
71
77
|
return if subauthority.nil?
|
72
|
-
unless @authority.search_subauthority?(subauthority)
|
78
|
+
unless @authority.search_subauthority?(subauthority) # rubocop:disable Style/GuardClause
|
73
79
|
logger.warn "Unable to initialize linked data search sub-authority '#{subauthority}' for authority '#{vocab_param}'"
|
74
80
|
head :bad_request
|
75
81
|
end
|
@@ -77,7 +83,7 @@ class Qa::LinkedDataTermsController < ApplicationController
|
|
77
83
|
|
78
84
|
def check_show_subauthority
|
79
85
|
return if subauthority.nil?
|
80
|
-
unless @authority.term_subauthority?(subauthority)
|
86
|
+
unless @authority.term_subauthority?(subauthority) # rubocop:disable Style/GuardClause
|
81
87
|
logger.warn "Unable to initialize linked data term sub-authority '#{subauthority}' for authority '#{vocab_param}'"
|
82
88
|
head :bad_request
|
83
89
|
end
|
@@ -95,7 +101,7 @@ class Qa::LinkedDataTermsController < ApplicationController
|
|
95
101
|
end
|
96
102
|
|
97
103
|
def check_query_param
|
98
|
-
if params[:q].nil? || !params[:q].size.positive?
|
104
|
+
if params[:q].nil? || !params[:q].size.positive? # rubocop:disable Style/GuardClause
|
99
105
|
logger.warn "Required search param 'q' is missing or empty"
|
100
106
|
head :bad_request
|
101
107
|
end
|
@@ -107,7 +113,7 @@ class Qa::LinkedDataTermsController < ApplicationController
|
|
107
113
|
end
|
108
114
|
|
109
115
|
def check_id_param
|
110
|
-
if params[:id].nil? || !params[:id].size.positive?
|
116
|
+
if params[:id].nil? || !params[:id].size.positive? # rubocop:disable Style/GuardClause
|
111
117
|
logger.warn "Required show param 'id' is missing or empty"
|
112
118
|
head :bad_request
|
113
119
|
end
|
@@ -3,12 +3,15 @@
|
|
3
3
|
# All the authority classes inherit from a super class so they implement the
|
4
4
|
# same methods.
|
5
5
|
|
6
|
-
class Qa::TermsController < ApplicationController
|
6
|
+
class Qa::TermsController < ::ApplicationController
|
7
7
|
before_action :check_vocab_param, :init_authority
|
8
8
|
before_action :check_query_param, only: :search
|
9
9
|
|
10
|
+
delegate :cors_allow_origin_header, to: Qa::ApplicationController
|
11
|
+
|
10
12
|
# If the subauthority supports it, return a list of all terms in the authority
|
11
13
|
def index
|
14
|
+
cors_allow_origin_header(response)
|
12
15
|
render json: begin
|
13
16
|
@authority.all
|
14
17
|
rescue NotImplementedError
|
@@ -19,12 +22,14 @@ class Qa::TermsController < ApplicationController
|
|
19
22
|
# Return a list of terms based on a query
|
20
23
|
def search
|
21
24
|
terms = @authority.method(:search).arity == 2 ? @authority.search(url_search, self) : @authority.search(url_search)
|
25
|
+
cors_allow_origin_header(response)
|
22
26
|
render json: terms
|
23
27
|
end
|
24
28
|
|
25
29
|
# If the subauthority supports it, return all the information for a given term
|
26
30
|
def show
|
27
31
|
term = @authority.find(params[:id])
|
32
|
+
cors_allow_origin_header(response)
|
28
33
|
render json: term
|
29
34
|
end
|
30
35
|
|
@@ -32,7 +37,7 @@ class Qa::TermsController < ApplicationController
|
|
32
37
|
head :not_found unless params[:vocab].present?
|
33
38
|
end
|
34
39
|
|
35
|
-
def init_authority
|
40
|
+
def init_authority # rubocop:disable Metrics/MethodLength
|
36
41
|
begin
|
37
42
|
mod = authority_class.camelize.constantize
|
38
43
|
rescue NameError
|
data/app/models/qa/mesh_tree.rb
CHANGED
@@ -6,12 +6,8 @@ class Qa::MeshTree < ActiveRecord::Base
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def eval_tree_path
|
9
|
-
trees =
|
10
|
-
|
11
|
-
trees.split("|")
|
12
|
-
else
|
13
|
-
[]
|
14
|
-
end
|
9
|
+
trees = self[:eval_tree_path] || (self[:eval_tree_path] = "")
|
10
|
+
trees ? trees.split("|") : []
|
15
11
|
end
|
16
12
|
|
17
13
|
def classify_tree
|
@@ -20,10 +16,10 @@ class Qa::MeshTree < ActiveRecord::Base
|
|
20
16
|
end
|
21
17
|
|
22
18
|
def classify_tree!
|
23
|
-
unless classify_tree.empty?
|
19
|
+
unless classify_tree.empty? # rubocop:disable Style/GuardClause
|
24
20
|
tree_path = classify_tree.join('|')
|
25
|
-
|
26
|
-
update_attribute(:eval_tree_path, tree_path)
|
21
|
+
Rails.logger.info "After Join #{tree_path.inspect}"
|
22
|
+
update_attribute(:eval_tree_path, tree_path) # rubocop:disable Rails/SkipsModelValidations # TODO: Explore how to avoid use of update_attribute.
|
27
23
|
end
|
28
24
|
end
|
29
25
|
|
@@ -10,17 +10,12 @@ class Qa::SubjectMeshTerm < ActiveRecord::Base
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def synonyms
|
13
|
-
s =
|
13
|
+
s = self[:synonyms]
|
14
14
|
s.nil? ? [] : s.split("|")
|
15
15
|
end
|
16
16
|
|
17
17
|
def synonyms=(syn_list)
|
18
|
-
|
19
|
-
if syn_list.respond_to?(:join)
|
20
|
-
syn_list.join('|')
|
21
|
-
else
|
22
|
-
syn_list
|
23
|
-
end)
|
18
|
+
self[:synonyms] = syn_list.respond_to?(:join) ? syn_list.join('|') : syn_list
|
24
19
|
end
|
25
20
|
|
26
21
|
def parents
|
@@ -8,7 +8,7 @@ Dir[File.join(Qa::Engine.root, 'config', 'authorities', 'linked_data', '*.json')
|
|
8
8
|
end
|
9
9
|
|
10
10
|
# load app configured linked data authorities and overrides
|
11
|
-
Dir[
|
11
|
+
Dir[Rails.root.join('config', 'authorities', 'linked_data', '*.json')].each do |fn|
|
12
12
|
auth = File.basename(fn, '.json').upcase.to_sym
|
13
13
|
json = File.read(File.expand_path(fn, __FILE__))
|
14
14
|
cfg = JSON.parse(json).deep_symbolize_keys
|
data/config/routes.rb
CHANGED
@@ -6,4 +6,12 @@ Qa::Engine.routes.draw do
|
|
6
6
|
get "/search/:vocab(/:subauthority)", controller: :terms, action: :search
|
7
7
|
get "/show/:vocab/:id", controller: :terms, action: :show
|
8
8
|
get "/show/:vocab/:subauthority/:id", controller: :terms, action: :show
|
9
|
+
|
10
|
+
match "/search/linked_data/:vocab(/:subauthority)", to: 'application#options', via: [:options]
|
11
|
+
match "/show/linked_data/:vocab/:id", to: 'application#options', via: [:options]
|
12
|
+
match "/show/linked_data/:vocab/:subauthority/:id", to: 'application#options', via: [:options]
|
13
|
+
match "/terms/:vocab(/:subauthority)", to: 'application#options', via: [:options]
|
14
|
+
match "/search/:vocab(/:subauthority)", to: 'application#options', via: [:options]
|
15
|
+
match "/show/:vocab/:id", to: 'application#options', via: [:options]
|
16
|
+
match "/show/:vocab/:subauthority/:id", to: 'application#options', via: [:options]
|
9
17
|
end
|
@@ -7,6 +7,10 @@ class Qa::InstallGenerator < Rails::Generators::Base
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
def create_initializer_config_file
|
11
|
+
copy_file 'config/initializers/qa.rb'
|
12
|
+
end
|
13
|
+
|
10
14
|
def copy_oclcts_configs
|
11
15
|
copy_file "config/oclcts-authorities.yml", "config/oclcts-authorities.yml"
|
12
16
|
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Qa.config do |config|
|
2
|
+
# When enabled, CORS headers will be added to the responses for search and show. `OPTIONS` method will also be supported.
|
3
|
+
# Uncomment one of the lines below to enable or disable CORS headers. This configuration defaults to disabled when not set.
|
4
|
+
# More information on CORS headers at: https://fetch.spec.whatwg.org/#cors-protocol
|
5
|
+
# config.enable_cors_headers
|
6
|
+
# config.disable_cors_headers
|
7
|
+
end
|
@@ -5,7 +5,7 @@ module Qa::Local
|
|
5
5
|
source_root File.expand_path('../templates', __FILE__)
|
6
6
|
include ActiveRecord::Generators::Migration
|
7
7
|
|
8
|
-
def migrations
|
8
|
+
def migrations # rubocop:disable Metrics/MethodLength
|
9
9
|
unless defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) && ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
10
10
|
message = "Use the table based generator if you are not using mysql 'rails generate qa:local:tables'"
|
11
11
|
say_status("error", message, :red)
|
@@ -4,7 +4,7 @@ module Qa::Local
|
|
4
4
|
source_root File.expand_path('../templates', __FILE__)
|
5
5
|
include ActiveRecord::Generators::Migration
|
6
6
|
|
7
|
-
def migrations
|
7
|
+
def migrations # rubocop:disable Metrics/MethodLength
|
8
8
|
if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) && ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
9
9
|
message = "Use the mysql table based generator if you are using mysql 'rails generate qa:local:tables:mysql'"
|
10
10
|
say_status("error", message, :red)
|
data/lib/qa.rb
CHANGED
@@ -6,8 +6,24 @@ module Qa
|
|
6
6
|
extend ActiveSupport::Autoload
|
7
7
|
|
8
8
|
autoload :Authorities
|
9
|
+
autoload :Configuration
|
9
10
|
autoload :Services
|
10
11
|
|
12
|
+
# @api public
|
13
|
+
#
|
14
|
+
# Exposes the Questioning Authority configuration
|
15
|
+
#
|
16
|
+
# @yield [Qa::Configuration] if a block is passed
|
17
|
+
# @return [Qa::Configuration]
|
18
|
+
# @see Qa::Configuration for configuration options
|
19
|
+
def self.config(&block)
|
20
|
+
@config ||= Qa::Configuration.new
|
21
|
+
|
22
|
+
yield @config if block
|
23
|
+
|
24
|
+
@config
|
25
|
+
end
|
26
|
+
|
11
27
|
# Raised when the configuration directory for local authorities doesn't exist
|
12
28
|
class ConfigDirectoryNotFound < StandardError; end
|
13
29
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Encapsulate information about assignFAST subauthorities
|
2
2
|
module Qa::Authorities::AssignFastSubauthority
|
3
3
|
# Hash of subauthority names used in qa routes => 'index' used by API
|
4
|
-
|
4
|
+
SUBAUTHORITIES = {
|
5
5
|
'all' => 'suggestall',
|
6
6
|
'personal' => 'suggest00',
|
7
7
|
'corporate' => 'suggest10',
|
@@ -16,7 +16,7 @@ module Qa::Authorities::AssignFastSubauthority
|
|
16
16
|
#
|
17
17
|
# @return [Array<String>]
|
18
18
|
def subauthorities
|
19
|
-
|
19
|
+
SUBAUTHORITIES.keys
|
20
20
|
end
|
21
21
|
|
22
22
|
# Get an API index name from an English name
|
@@ -24,6 +24,6 @@ module Qa::Authorities::AssignFastSubauthority
|
|
24
24
|
# @param [String] English name
|
25
25
|
# @return [String] index name
|
26
26
|
def index_for_authority(authority)
|
27
|
-
|
27
|
+
SUBAUTHORITIES[authority]
|
28
28
|
end
|
29
29
|
end
|
@@ -16,7 +16,7 @@ module Qa::Authorities
|
|
16
16
|
# Use a regex to exclude the continent and 'world' from the query
|
17
17
|
# If only one word is entered only search the name (not the parent string)
|
18
18
|
# If more than one word is entered, one word must appear in the name, and all words in either parent or name
|
19
|
-
def sparql(q)
|
19
|
+
def sparql(q) # rubocop:disable Metrics/MethodLength
|
20
20
|
search = untaint(q)
|
21
21
|
if search.include?(' ')
|
22
22
|
ex = "(("
|
@@ -11,7 +11,7 @@ module Qa::Authorities
|
|
11
11
|
"http://vocab.getty.edu/sparql.json?query=#{URI.escape(sparql(q)).gsub('&', '%26')}&_implicit=false&implicit=true&_equivalent=false&_form=%2Fsparql"
|
12
12
|
end
|
13
13
|
|
14
|
-
def sparql(q)
|
14
|
+
def sparql(q) # rubocop:disable Metrics/MethodLength
|
15
15
|
search = untaint(q)
|
16
16
|
# if more than one term is supplied, check both preferred and alt labels
|
17
17
|
if search.include?(' ')
|
@@ -76,7 +76,7 @@ module Qa::Authorities
|
|
76
76
|
preds
|
77
77
|
end
|
78
78
|
|
79
|
-
def consolidate_term_results(results)
|
79
|
+
def consolidate_term_results(results) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize # TODO: Explore a way to simplify
|
80
80
|
consolidated_results = {}
|
81
81
|
results.each do |statement|
|
82
82
|
stmt_hash = statement.to_h
|
@@ -123,7 +123,7 @@ module Qa::Authorities
|
|
123
123
|
json_results.first
|
124
124
|
end
|
125
125
|
|
126
|
-
def predicates_with_subject_uri(graph, expected_uri)
|
126
|
+
def predicates_with_subject_uri(graph, expected_uri) # rubocop:disable Metrics/MethodLength
|
127
127
|
predicates_hash = {}
|
128
128
|
graph.statements.each do |st|
|
129
129
|
subj = st.subject.to_s
|
@@ -57,6 +57,10 @@ module Qa::Authorities
|
|
57
57
|
msg[a..z]
|
58
58
|
end
|
59
59
|
|
60
|
+
# Filter a graph to the specified languages
|
61
|
+
# @param [RDF::Graph] the graph to be filtered.
|
62
|
+
# @param [String | Symbol | Array<String|Symbol>] language for filtering graph (e.g. "en" or :en or ["en", "fr"] or [:en, :fr])
|
63
|
+
# @returns [RDF::Graph] graph of linked data filtered on the specified languages
|
60
64
|
def filter_language(graph, language)
|
61
65
|
language = normalize_language(language)
|
62
66
|
return graph if language.nil?
|
@@ -66,6 +70,17 @@ module Qa::Authorities
|
|
66
70
|
graph
|
67
71
|
end
|
68
72
|
|
73
|
+
# Filter a graph to remove any statement with a blanknode for the subject
|
74
|
+
# @param [RDF::Graph] the graph to be filtered.
|
75
|
+
# @returns [RDF::Graph] graph of linked data with blanknodes removed
|
76
|
+
def filter_out_blanknodes(graph)
|
77
|
+
return graph if graph.subjects.blank?
|
78
|
+
graph.each do |st|
|
79
|
+
graph.delete(st) if st.subject.anonymous?
|
80
|
+
end
|
81
|
+
graph
|
82
|
+
end
|
83
|
+
|
69
84
|
def normalize_language(language)
|
70
85
|
language = [language.to_sym] if language.is_a? String
|
71
86
|
language = [language] if language.is_a? Symbol
|