# Provide service for mapping predicates to object values. module Qa module LinkedData module Mapper class GraphMapperService class_attribute :graph_service self.graph_service = Qa::LinkedData::GraphService # Extract predicates specified in the predicate_map from the graph and return as a value map for a single subject URI. # @param graph [RDF::Graph] the graph from which to extract result values # @param predicate_map [Hash] value either maps to a predicate in the graph or is :subject_uri indicating to use the subject uri as the value # @example predicate_map # { # uri: :subject_uri, # id: [#], # label: [#], # altlabel: [#], # sort: [#]' # } # @param subject_uri [RDF::URI] the subject within the graph for which the values are being extracted # @return [>] mapped result values with hash of map key = array of object values for predicates identified in predicate_map. # @example value map for a single result # {:uri=>[#], # :id=>[#], # :label=>[#], # :altlabel=>[], # :sort=>[#]} def self.map_values(graph:, predicate_map:, subject_uri:) value_map = {} predicate_map.each do |key, predicate| values = predicate == :subject_uri ? [subject_uri] : graph_service.object_values(graph: graph, subject: subject_uri, predicate: predicate) value_map[key] = values end value_map = yield value_map if block_given? value_map end end end end end