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:, prefixes: {}, ldpath_map: nil, predicate_map: nil, 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:

prefixes

{
  locid: 'http://id.loc.gov/vocabulary/identifiers/',
  skos: 'http://www.w3.org/2004/02/skos/core#',
  vivo: 'http://vivoweb.org/ontology/core#'
}

ldpath map

{
  uri: :subject_uri,
  id: 'locid:lccn :: xsd::string',
  label: 'skos:prefLabel :: xsd::string',
  altlabel: 'skos:altLabel :: xsd::string',
  sort: 'vivo:rank :: xsd::integer'
}

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":"http://id.loc.gov/authorities/genreForms/gf2011026181","id":"gf2011026181","label":"Stop-motion animation films",
    "context":[
      { "property":"Authoritative Label","values":["Stop-motion animation films"],"selectable":true,"drillable":false },
      { "property":"Variant Label","values":["Object animation films, Frame-by-frame animation films"],"selectable":false,"drillable":false },
      { "group":"Hierarchy","property":"Narrower: ",
        "values":[
          { "uri":"http://id.loc.gov/authorities/genreForms/gf2011026140","id":"gf2011026140","label":"Clay animation films"}
        ],
        "selectable":true,"drillable":true },
      { "group":"Hierarchy","property":"Broader: ",
        "values":[
          { "uri":"http://id.loc.gov/authorities/genreForms/gf2011026049","id":"gf2011026049","label":"Animated films"}
        ],
        "selectable":true,"drillable":true }
    ]
  }
]

Parameters:

  • graph (RDF::Graph)

    the graph from which to extract result values

  • prefixes (Hash<Symbol><String>) (defaults to: {})

    URL map of prefixes to use with ldpaths

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

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

  • predicate_map (Hash<Symbol><String||Symbol>) (defaults to: nil)

    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

  • preferred_language (Array<Symbol>) (defaults to: nil)

    sort multiple literals for a value with preferred language first

  • 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.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/services/qa/linked_data/mapper/search_results_mapper_service.rb', line 65

def map_values(graph:, prefixes: {}, ldpath_map: nil, predicate_map: nil, sort_key:, preferred_language: nil, context_map: nil) # rubocop:disable Metrics/ParameterLists
  search_matches = []
  graph.subjects.each do |subject|
    next if subject.anonymous? # skip blank nodes
    values = if ldpath_map.present?
               map_values_with_ldpath_map(graph: graph, ldpath_map: ldpath_map, prefixes: prefixes, subject_uri: subject, sort_key: sort_key, context_map: context_map)
             else
               map_values_with_predicate_map(graph: graph, predicate_map: predicate_map, subject_uri: subject, sort_key: sort_key, context_map: context_map)
             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