Skip to content

Commit

Permalink
use maintain_literals in ldpath to support language sorting
Browse files Browse the repository at this point in the history
NOTE: This commit references a branch in ldpath.  It needs to be removed when PR #18 is merged into the ldpath gem.
  • Loading branch information
elrayle committed Nov 22, 2019
1 parent 6986cfa commit fce0947
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
project: qa

- samvera/engine_cart_generate:
cache_key: v7-internal-test-app-{{ checksum "qa.gemspec" }}-{{ checksum "spec/test_app_templates/lib/generators/test_app_generator.rb" }}-{{ checksum "lib/generators/qa/install/install_generator.rb" }}-<< parameters.rails_version >>-<< parameters.ruby_version >>
cache_key: v10-internal-test-app-{{ checksum "qa.gemspec" }}-{{ checksum "spec/test_app_templates/lib/generators/test_app_generator.rb" }}-{{ checksum "lib/generators/qa/install/install_generator.rb" }}-<< parameters.rails_version >>-<< parameters.ruby_version >>

- samvera/bundle_for_gem:
ruby_version: << parameters.ruby_version >>
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ group :development, :test do
gem 'simplecov', require: false
end

gem 'ldpath', github: 'samvera-labs/ldpath', branch: 'maintain_literals'

# BEGIN ENGINE_CART BLOCK
# engine_cart: 0.10.0
# engine_cart stanza: 0.10.0
Expand Down
6 changes: 3 additions & 3 deletions app/services/qa/linked_data/ldpath_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def ldpath_program_code(ldpath:, prefixes: {}, languages: [])
# @param limit_to_context [Boolean] if true, the evaluation process will not make any outside network calls.
# It will limit results to those found in the context graph.
## @return [Array<RDF::Literal>] the extracted values based on the ldpath
def ldpath_evaluate(program:, graph:, subject_uri:, limit_to_context: Qa.config.limit_ldpath_to_context?)
def ldpath_evaluate(program:, graph:, subject_uri:, limit_to_context: Qa.config.limit_ldpath_to_context?, maintain_literals: false)
raise ArgumentError, "You must specify a program when calling ldpath_evaluate" if program.blank?
output = program.evaluate(subject_uri, context: graph, limit_to_context: limit_to_context)
property_implode(output)
output = program.evaluate(subject_uri, context: graph, limit_to_context: limit_to_context, maintain_literals: maintain_literals)
maintain_literals ? property_implode(output) : output.values.flatten.uniq
rescue ParseError => e
Rails.logger.warn("WARNING: #{I18n.t('qa.linked_data.ldpath.evaluate_logger_error')} (cause: #{e.message}")
raise ParseError, I18n.t("qa.linked_data.ldpath.evaluate_error") + "... cause: #{e.message}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def self.map_values(graph:, ldpath_map:, subject_uri:, prefixes: {})
ldpath_map.each do |key, ldpath|
next value_map[key] = [subject_uri] if ldpath == :subject_uri
ldpath_program = ldpath_service.ldpath_program(ldpath: ldpath, prefixes: prefixes)
values = ldpath_service.ldpath_evaluate(program: ldpath_program, graph: graph, subject_uri: subject_uri)
values = ldpath_service.ldpath_evaluate(program: ldpath_program, graph: graph, subject_uri: subject_uri, maintain_literals: true)
value_map[key] = values
end
value_map = yield value_map if block_given?
Expand Down
2 changes: 1 addition & 1 deletion qa.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.add_dependency 'activerecord-import'
s.add_dependency 'deprecation'
s.add_dependency 'faraday'
s.add_dependency 'ldpath'
# s.add_dependency 'ldpath'
s.add_dependency 'nokogiri', '~> 1.6'
s.add_dependency 'rails', '~> 5.0'
s.add_dependency 'rdf'
Expand Down
17 changes: 10 additions & 7 deletions spec/fixtures/authorities/linked_data/lod_lang_defaults.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"QA_CONFIG_VERSION": "2.0",
"prefixes": {
"dcterms": "http://purl.org/dc/terms/"
},
"term": {
"url": {
"@context": "http://www.w3.org/ns/hydra/context.jsonld",
Expand All @@ -21,9 +24,9 @@
"term_id": "URI",
"language": [ "fr" ],
"results": {
"id_predicate": "http://id.loc.gov/vocabulary/identifiers/lccn",
"label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"altlabel_predicate": "http://www.w3.org/2004/02/skos/core#altLabel"
"id_ldpath": "loc:lccn",
"label_ldpath": "skos:prefLabel",
"altlabel_ldpath": "skos:altLabel"
}
},
"search": {
Expand All @@ -46,10 +49,10 @@
},
"language": [ "fr" ],
"results": {
"id_predicate": "http://purl.org/dc/terms/identifier",
"label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"altlabel_predicate": "http://www.w3.org/2004/02/skos/core#altLabel",
"sort_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel"
"id_ldpath": "dcterms:identifier",
"label_ldpath": "skos:prefLabel",
"altlabel_ldpath": "skos:altLabel",
"sort_ldpath": "skos:prefLabel"
}
}
}
17 changes: 10 additions & 7 deletions spec/fixtures/authorities/linked_data/lod_lang_multi_defaults.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"QA_CONFIG_VERSION": "2.0",
"prefixes": {
"dcterms": "http://purl.org/dc/terms/"
},
"term": {
"url": {
"@context": "http://www.w3.org/ns/hydra/context.jsonld",
Expand All @@ -21,9 +24,9 @@
"term_id": "URI",
"language": [ "en", "fr" ],
"results": {
"id_predicate": "http://purl.org/dc/terms/identifier",
"label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"altlabel_predicate": "http://www.w3.org/2004/02/skos/core#altLabel"
"id_ldpath": "dcterms:identifier",
"label_ldpath": "skos:prefLabel",
"altlabel_ldpath": "skos:altLabel"
}
},
"search": {
Expand All @@ -46,10 +49,10 @@
},
"language": [ "en", "fr" ],
"results": {
"id_predicate": "http://purl.org/dc/terms/identifier",
"label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"altlabel_predicate": "http://www.w3.org/2004/02/skos/core#altLabel",
"sort_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel"
"id_ldpath": "dcterms:identifier",
"label_ldpath": "skos:prefLabel",
"altlabel_ldpath": "skos:altLabel",
"sort_ldpath": "skos:prefLabel"
}
}
}
15 changes: 9 additions & 6 deletions spec/fixtures/authorities/linked_data/lod_lang_no_defaults.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"QA_CONFIG_VERSION": "2.0",
"prefixes": {
"dcterms": "http://purl.org/dc/terms/"
},
"term": {
"url": {
"@context": "http://www.w3.org/ns/hydra/context.jsonld",
Expand All @@ -20,8 +23,8 @@
},
"term_id": "URI",
"results": {
"label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"altlabel_predicate": "http://www.w3.org/2004/02/skos/core#altLabel"
"label_ldpath": "skos:prefLabel",
"altlabel_ldpath": "skos:altLabel"
}
},
"search": {
Expand All @@ -43,10 +46,10 @@
"query": "query"
},
"results": {
"id_predicate": "http://purl.org/dc/terms/identifier",
"label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"altlabel_predicate": "http://www.w3.org/2004/02/skos/core#altLabel",
"sort_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel"
"id_ldpath": "dcterms:identifier",
"label_ldpath": "skos:prefLabel",
"altlabel_ldpath": "skos:altLabel",
"sort_ldpath": "skos:prefLabel"
}
}
}
18 changes: 11 additions & 7 deletions spec/fixtures/authorities/linked_data/lod_lang_param.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"QA_CONFIG_VERSION": "2.0",
"prefixes": {
"dcterms": "http://purl.org/dc/terms/",
"loc": "http://id.loc.gov/vocabulary/identifiers/"
},
"term": {
"url": {
"@context": "http://www.w3.org/ns/hydra/context.jsonld",
Expand Down Expand Up @@ -27,9 +31,9 @@
},
"term_id": "URI",
"results": {
"id_predicate": "http://id.loc.gov/vocabulary/identifiers/lccn",
"label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"altlabel_predicate": "http://www.w3.org/2004/02/skos/core#altLabel"
"id_ldpath": "loc:lccn",
"label_ldpath": "skos:prefLabel",
"altlabel_ldpath": "skos:altLabel"
}
},
"search": {
Expand Down Expand Up @@ -58,10 +62,10 @@
"query": "query"
},
"results": {
"id_predicate": "http://purl.org/dc/terms/identifier",
"label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
"altlabel_predicate": "http://www.w3.org/2004/02/skos/core#altLabel",
"sort_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel"
"id_ldpath": "dcterms:identifier",
"label_ldpath": "skos:prefLabel",
"altlabel_ldpath": "skos:altLabel",
"sort_ldpath": "skos:prefLabel"
}
}
}
9 changes: 6 additions & 3 deletions spec/fixtures/authorities/linked_data/lod_min_config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"QA_CONFIG_VERSION": "2.0",
"prefixes": {
"loc": "http://id.loc.gov/vocabulary/identifiers/"
},
"term": {
"url": {
"@context": "http://www.w3.org/ns/hydra/context.jsonld",
Expand All @@ -20,8 +23,8 @@
},
"term_id": "URI",
"results": {
"id_predicate": "http://id.loc.gov/vocabulary/identifiers/lccn",
"label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel"
"id_ldpath": "loc:lccn",
"label_ldpath": "skos:prefLabel"
}
},
"search": {
Expand All @@ -43,7 +46,7 @@
"query": "query"
},
"results": {
"label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel"
"label_ldpath": "skos:prefLabel"
}
}
}
6 changes: 3 additions & 3 deletions spec/models/linked_data/config/context_property_map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@
allow(Ldpath::Program).to receive(:parse).with("property = madsrdf:identifiesRWO/madsrdf:birthDate/schema:label ;\n").and_return(basic_program)
allow(Ldpath::Program).to receive(:parse).with("property = skos:prefLabel ::xsd:string ;\n").and_return(expanded_label_program)
allow(Ldpath::Program).to receive(:parse).with("property = loc:lccn ::xsd:string ;\n").and_return(expanded_id_program)
allow(basic_program).to receive(:evaluate).with(subject_uri, context: graph, limit_to_context: true).and_return('property' => [expanded_uri])
allow(expanded_label_program).to receive(:evaluate).with(RDF::URI.new(subject_uri), context: graph, limit_to_context: true).and_return('property' => [expanded_label])
allow(expanded_id_program).to receive(:evaluate).with(RDF::URI.new(subject_uri), context: graph, limit_to_context: true).and_return('property' => [expanded_id])
allow(basic_program).to receive(:evaluate).with(subject_uri, context: graph, limit_to_context: true, maintain_literals: false).and_return('property' => [expanded_uri])
allow(expanded_label_program).to receive(:evaluate).with(RDF::URI.new(subject_uri), context: graph, limit_to_context: true, maintain_literals: false).and_return('property' => [expanded_label])
allow(expanded_id_program).to receive(:evaluate).with(RDF::URI.new(subject_uri), context: graph, limit_to_context: true, maintain_literals: false).and_return('property' => [expanded_id])
end
it 'returns the uri, id, label for the expanded uri value' do
expanded_values = subject.expanded_values(graph, subject_uri).first
Expand Down
Loading

0 comments on commit fce0947

Please sign in to comment.