Skip to content

Commit

Permalink
Merge pull request #227 from samvera/ldpath_config2
Browse files Browse the repository at this point in the history
Update search/term configs to be able to read in results config specified as ldpath
  • Loading branch information
elrayle committed Apr 22, 2019
2 parents bc9c75a + 42f1baa commit 0942f23
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 1 deletion.
24 changes: 24 additions & 0 deletions lib/qa/authorities/linked_data/config/search_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,36 @@ def results
search_config[:results]
end

# Return results id_ldpath
# @return [String] the configured predicate to use to extract the id from the results
def results_id_ldpath
Config.config_value(results, :id_ldpath)
end

# Return results id_predicate
# @return [String] the configured predicate to use to extract the id from the results
def results_id_predicate
Config.predicate_uri(results, :id_predicate)
end

# Return results label_ldpath
# @return [String] the configured predicate to use to extract label values from the results
def results_label_ldpath
Config.config_value(results, :label_ldpath)
end

# Return results label_predicate
# @return [String] the configured predicate to use to extract label values from the results
def results_label_predicate
Config.predicate_uri(results, :label_predicate)
end

# Return results altlabel_ldpath
# @return [String] the configured predicate to use to extract altlabel values from the results
def results_altlabel_ldpath
Config.config_value(results, :altlabel_ldpath)
end

# Return results altlabel_predicate
# @return [String] the configured predicate to use to extract altlabel values from the results
def results_altlabel_predicate
Expand All @@ -71,6 +89,12 @@ def supports_sort?
false
end

# Return results sort_predicate
# @return [String] the configured predicate to use for sorting results from the query search
def results_sort_ldpath
Config.config_value(results, :sort_ldpath)
end

# Return results sort_predicate
# @return [String] the configured predicate to use for sorting results from the query search
def results_sort_predicate
Expand Down
38 changes: 38 additions & 0 deletions lib/qa/authorities/linked_data/config/term_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
module Qa::Authorities
module LinkedData
class TermConfig
attr_reader :prefixes

# @param [Hash] config the term portion of the config
def initialize(config, prefixes = {})
@term_config = config
Expand Down Expand Up @@ -58,36 +60,72 @@ def term_results
Config.config_value(term_config, :results)
end

# Return results id_ldpath
# @return [String] the configured predicate to use to extract the id from the results
def term_results_id_ldpath
Config.config_value(term_results, :id_ldpath)
end

# Return results id_predicate
# @return [String] the configured predicate to use to extract the id from the results
def term_results_id_predicate
Config.predicate_uri(term_results, :id_predicate)
end

# Return results label_ldpath
# @return [String] the configured predicate to use to extract label values from the results
def term_results_label_ldpath
Config.config_value(term_results, :label_ldpath)
end

# Return results label_predicate
# @return [String] the configured predicate to use to extract label values from the results
def term_results_label_predicate
Config.predicate_uri(term_results, :label_predicate)
end

# Return results altlabel_ldpath
# @return [String] the configured predicate to use to extract altlabel values from the results
def term_results_altlabel_ldpath
Config.config_value(term_results, :altlabel_ldpath)
end

# Return results altlabel_predicate
# @return [String] the configured predicate to use to extract altlabel values from the results
def term_results_altlabel_predicate
Config.predicate_uri(term_results, :altlabel_predicate)
end

# Return results broader_ldpath
# @return [String] the configured predicate to use to extract URIs for broader terms from the results
def term_results_broader_ldpath
Config.config_value(term_results, :broader_ldpath)
end

# Return results broader_predicate
# @return [String] the configured predicate to use to extract URIs for broader terms from the results
def term_results_broader_predicate
Config.predicate_uri(term_results, :broader_predicate)
end

# Return results narrower_ldpath
# @return [String] the configured predicate to use to extract URIs for narrower terms from the results
def term_results_narrower_ldpath
Config.config_value(term_results, :narrower_ldpath)
end

# Return results narrower_predicate
# @return [String] the configured predicate to use to extract URIs for narrower terms from the results
def term_results_narrower_predicate
Config.predicate_uri(term_results, :narrower_predicate)
end

# Return results sameas_ldpath
# @return [String] the configured predicate to use to extract URIs for sameas terms from the results
def term_results_sameas_ldpath
Config.config_value(term_results, :sameas_ldpath)
end

# Return results sameas_predicate
# @return [String] the configured predicate to use to extract URIs for sameas terms from the results
def term_results_sameas_predicate
Expand Down
73 changes: 72 additions & 1 deletion spec/lib/authorities/linked_data/search_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@
require 'qa/authorities/linked_data/config/search_config'

RSpec.describe Qa::Authorities::LinkedData::SearchConfig do
before do
Qa::LinkedData::AuthorityService.load_authorities
end

let(:full_config) { Qa::Authorities::LinkedData::Config.new(:LOD_FULL_CONFIG).search }
let(:min_config) { Qa::Authorities::LinkedData::Config.new(:LOD_MIN_CONFIG).search }
let(:term_only_config) { Qa::Authorities::LinkedData::Config.new(:LOD_TERM_ONLY_CONFIG).search }
let(:encoding_config) { Qa::Authorities::LinkedData::Config.new(:LOD_ENCODING_CONFIG).search }

let(:ldpath_results_config) do
{
id_ldpath: 'schema:identifier ::xsd:string',
label_ldpath: 'skos:prefLabel ::xsd:string',
altlabel_ldpath: 'skos:altLabel ::xsd:string',
sort_ldpath: 'skos:prefLabel ::xsd:string'
}
end

describe '#search_config' do
let(:full_search_config) do
{
Expand Down Expand Up @@ -186,6 +199,19 @@
end
end

describe '#results_id_ldpath' do
it 'returns nil if only term configuration is defined' do
expect(term_only_config.results_id_ldpath).to eq nil
end

context 'when id specified as ldpath' do
before { allow(full_config).to receive(:results).and_return(ldpath_results_config) }
it 'returns the ldpath' do
expect(full_config.results_id_ldpath).to eq 'schema:identifier ::xsd:string'
end
end
end

describe '#results_label_predicate' do
it 'returns nil if only term configuration is defined' do
expect(term_only_config.results_label_predicate).to eq nil
Expand All @@ -195,18 +221,47 @@
end
end

describe '#results_label_ldpath' do
it 'returns nil if only term configuration is defined' do
expect(term_only_config.results_label_ldpath).to eq nil
end

context 'when label specified as ldpath' do
before { allow(full_config).to receive(:results).and_return(ldpath_results_config) }
it 'returns the ldpath' do
expect(full_config.results_label_ldpath).to eq 'skos:prefLabel ::xsd:string'
end
end
end

describe '#results_altlabel_predicate' do
it 'returns nil if only term configuration is defined' do
expect(term_only_config.results_altlabel_predicate).to eq nil
end
it 'return nil if altlabel predicate is not defined' do
it 'returns nil if altlabel predicate is not defined' do
expect(min_config.results_altlabel_predicate).to eq nil
end
it 'returns the predicate that holds the altlabel in search results' do
expect(full_config.results_altlabel_predicate).to eq RDF::URI('http://www.w3.org/2004/02/skos/core#altLabel')
end
end

describe '#results_altlabel_ldpath' do
it 'returns nil if only term configuration is defined' do
expect(term_only_config.results_altlabel_ldpath).to eq nil
end
it 'returns nil if altlabel ldpath is not defined' do
expect(min_config.results_altlabel_ldpath).to eq nil
end

context 'when altlabel specified as ldpath' do
before { allow(full_config).to receive(:results).and_return(ldpath_results_config) }
it 'returns the ldpath' do
expect(full_config.results_altlabel_ldpath).to eq 'skos:altLabel ::xsd:string'
end
end
end

describe '#supports_sort?' do
it 'returns false if only term configuration is defined' do
expect(term_only_config.supports_sort?).to eq false
Expand All @@ -231,6 +286,22 @@
end
end

describe '#results_sort_ldpath' do
it 'returns nil if only term configuration is defined' do
expect(term_only_config.results_sort_ldpath).to eq nil
end
it 'returns nil if sort ldpath is not defined' do
expect(min_config.results_sort_ldpath).to eq nil
end

context 'when sort specified as ldpath' do
before { allow(full_config).to receive(:results).and_return(ldpath_results_config) }
it 'returns the ldpath' do
expect(full_config.results_sort_ldpath).to eq 'skos:prefLabel ::xsd:string'
end
end
end

describe '#supports_context?' do
it 'returns false if only term configuration is defined' do
expect(term_only_config.supports_context?).to eq false
Expand Down
101 changes: 101 additions & 0 deletions spec/lib/authorities/linked_data/term_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
let(:search_only_config) { Qa::Authorities::LinkedData::Config.new(:LOD_SEARCH_ONLY_CONFIG).term }
let(:encoding_config) { Qa::Authorities::LinkedData::Config.new(:LOD_ENCODING_CONFIG).term }

let(:ldpath_results_config) do
{
id_ldpath: 'schema:identifier ::xsd:string',
label_ldpath: 'skos:prefLabel ::xsd:string',
altlabel_ldpath: 'skos:altLabel ::xsd:string',
broader_ldpath: 'skos:broader ::xsd:string',
narrower_ldpath: 'skos:narrower ::xsd:string',
sameas_ldpath: 'skos:exactMatch ::xsd:string'
}
end

describe '#term_config' do
let(:full_term_config) do
{
Expand Down Expand Up @@ -204,6 +215,19 @@
end
end

describe '#term_results_id_ldpath' do
it 'returns nil if only search configuration is defined' do
expect(search_only_config.term_results_id_ldpath).to eq nil
end

context 'when id specified as ldpath' do
before { allow(full_config).to receive(:term_results).and_return(ldpath_results_config) }
it 'returns the ldpath' do
expect(full_config.term_results_id_ldpath).to eq 'schema:identifier ::xsd:string'
end
end
end

describe '#term_results_label_predicate' do
it 'returns nil if only search configuration is defined' do
expect(search_only_config.term_results_label_predicate).to eq nil
Expand All @@ -213,6 +237,19 @@
end
end

describe '#term_results_label_ldpath' do
it 'returns nil if only search configuration is defined' do
expect(search_only_config.term_results_label_ldpath).to eq nil
end

context 'when label specified as ldpath' do
before { allow(full_config).to receive(:term_results).and_return(ldpath_results_config) }
it 'returns the ldpath' do
expect(full_config.term_results_label_ldpath).to eq 'skos:prefLabel ::xsd:string'
end
end
end

describe '#term_results_altlabel_predicate' do
it 'returns nil if only search configuration is defined' do
expect(search_only_config.term_results_altlabel_predicate).to eq nil
Expand All @@ -225,6 +262,22 @@
end
end

describe '#term_results_altlabel_ldpath' do
it 'returns nil if only search configuration is defined' do
expect(search_only_config.term_results_altlabel_ldpath).to eq nil
end
it 'return nil if altlabel predicate is not defined' do
expect(min_config.term_results_altlabel_ldpath).to eq nil
end

context 'when altlabel specified as ldpath' do
before { allow(full_config).to receive(:term_results).and_return(ldpath_results_config) }
it 'returns the ldpath' do
expect(full_config.term_results_altlabel_ldpath).to eq 'skos:altLabel ::xsd:string'
end
end
end

describe '#term_results_broader_predicate' do
it 'returns nil if only search configuration is defined' do
expect(search_only_config.term_results_broader_predicate).to eq nil
Expand All @@ -237,6 +290,22 @@
end
end

describe '#term_results_broader_ldpath' do
it 'returns nil if only search configuration is defined' do
expect(search_only_config.term_results_broader_ldpath).to eq nil
end
it 'return nil if broader predicate is not defined' do
expect(min_config.term_results_broader_ldpath).to eq nil
end

context 'when broader specified as ldpath' do
before { allow(full_config).to receive(:term_results).and_return(ldpath_results_config) }
it 'returns the ldpath' do
expect(full_config.term_results_broader_ldpath).to eq 'skos:broader ::xsd:string'
end
end
end

describe '#term_results_narrower_predicate' do
it 'returns nil if only search configuration is defined' do
expect(search_only_config.term_results_narrower_predicate).to eq nil
Expand All @@ -249,6 +318,22 @@
end
end

describe '#term_results_narrower_ldpath' do
it 'returns nil if only search configuration is defined' do
expect(search_only_config.term_results_narrower_ldpath).to eq nil
end
it 'return nil if narrower predicate is not defined' do
expect(min_config.term_results_narrower_ldpath).to eq nil
end

context 'when narrower specified as ldpath' do
before { allow(full_config).to receive(:term_results).and_return(ldpath_results_config) }
it 'returns the ldpath' do
expect(full_config.term_results_narrower_ldpath).to eq 'skos:narrower ::xsd:string'
end
end
end

describe '#term_results_sameas_predicate' do
it 'returns nil if only search configuration is defined' do
expect(search_only_config.term_results_sameas_predicate).to eq nil
Expand All @@ -261,6 +346,22 @@
end
end

describe '#term_results_sameas_ldpath' do
it 'returns nil if only search configuration is defined' do
expect(search_only_config.term_results_sameas_ldpath).to eq nil
end
it 'return nil if sameas predicate is not defined' do
expect(min_config.term_results_sameas_ldpath).to eq nil
end

context 'when sameas specified as ldpath' do
before { allow(full_config).to receive(:term_results).and_return(ldpath_results_config) }
it 'returns the ldpath' do
expect(full_config.term_results_sameas_ldpath).to eq 'skos:exactMatch ::xsd:string'
end
end
end

describe '#supports_language_parameter?' do
it 'returns false if only search configuration is defined' do
expect(search_only_config.supports_language_parameter?).to eq false
Expand Down

0 comments on commit 0942f23

Please sign in to comment.