Class: Qa::LinkedData::Mapper::SearchResultsMapperService

Inherits:
Object
  • Object
show all
Defined in:
app/services/qa/linked_data/mapper/search_results_mapper_service.rb

Class Method Summary collapse

Class Method Details

.map_values(graph:, predicate_map:, sort_key:, preferred_language: nil, context_map: nil) ⇒ Array<Hash<Symbol><Array<Object>>>

Extract predicates specified in the predicate_map from the graph and return as an array of value maps for each search result subject URI. If a sort key is present, a subject will only be included in the results if it has a statement with the sort predicate.

Examples:

predicate map

{
  uri: :subject_uri,
  id: 'http://id.loc.gov/vocabulary/identifiers/lccn',
  label: 'http://www.w3.org/2004/02/skos/core#prefLabel',
  altlabel: 'http://www.w3.org/2004/02/skos/core#altLabel',
  sort: 'http://vivoweb.org/ontology/core#rank'
}

value map for a single result

[
  {:uri=>[#<RDF::URI:0x3fcff54a829c URI:http://id.loc.gov/authorities/names/n2010043281>],
   :id=>[#<RDF::Literal:0x3fcff4a367b4("n 2010043281")>],
   :label=>[#<RDF::Literal:0x3fcff54a9a98("Valli, Sabrina"@en)>],
   :altlabel=>[],
   :sort=>[#<RDF::Literal:0x3fcff54b4c18("2")>]}
]

Parameters:

  • graph (RDF::Graph)

    the graph from which to extract result values

  • predicate_map (Hash<Symbol><String||Symbol>)

    value either maps to a predicate in the graph or is :subject_uri indicating to use the subject uri as the value

  • sort_key (Symbol)

    the key in the predicate map for the value on which to sort

  • context_map (Qa::LinkedData::Config::ContextMap) (defaults to: nil)

    map of additional context to include in the results

Returns:

  • (Array<Hash<Symbol><Array<Object>>>)

    mapped result values with each result as an element in the array with hash of map key = array of object values for predicates identified in map parameter.



36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/services/qa/linked_data/mapper/search_results_mapper_service.rb', line 36

def map_values(graph:, predicate_map:, sort_key:, preferred_language: nil, context_map: nil)
  search_matches = []
  graph.subjects.each do |subject|
    next if subject.anonymous? # skip blank nodes
    values = graph_mapper_service.map_values(graph: graph, predicate_map: predicate_map, subject_uri: subject) do |value_map|
      map_context(graph, sort_key, context_map, value_map, subject)
    end
    search_matches << values if result_subject? values, sort_key
  end
  search_matches = deep_sort_service.new(search_matches, sort_key, preferred_language).sort
  search_matches
end