Class: Qa::LinkedData::Config::ContextPropertyMap

Inherits:
Object
  • Object
show all
Defined in:
app/models/qa/linked_data/config/context_property_map.rb

Constant Summary collapse

VALUE_ON_ERROR =
[].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property_map = {}, prefixes = {}) ⇒ ContextPropertyMap

Returns a new instance of ContextPropertyMap.

Examples:

property_map example

{
  "group_id": "dates",
  "property_label_i18n": "qa.linked_data.authority.locnames_ld4l_cache.birth_date",
  "property_label_default": "Birth",
  "ldpath": "madsrdf:identifiesRWO/madsrdf:birthDate/schema:label",
  "selectable": false,
  "drillable": false
}

Parameters:

  • property_map (Hash) (defaults to: {})

    defining information to return to provide context

  • shortcut (Hash)

    names for URI prefixes with key = part of predicate that is the same for all terms (e.g. { “madsrdf”: “www.loc.gov/mads/rdf/v1#” })

Options Hash (property_map):

  • :group_id (String) — default: optional

    default label to use for a property (default: no label)

  • :property_label_i18n (String) — default: optional

    i18n key to use to get the label for a property (default: property_label_default OR no label if neither are defined)

  • :property_label_default (String) — default: optional

    default label to use for a property (default: no label)

  • :ldpath (String) — default: required

    identifies the values to extract from the graph (based on marmotta.apache.org/ldpath/language.html)

  • :selectable (Boolean) — default: optional

    if true, this property can selected as the value (default: false)

  • :drillable (Boolean) — default: optional

    if true, the label for this property can be used to execute a second query allowing navi (default: false)



33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/qa/linked_data/config/context_property_map.rb', line 33

def initialize(property_map = {}, prefixes = {})
  @property_map = property_map
  @group_id = Qa::LinkedData::Config::Helper.fetch_symbol(property_map, :group_id, nil)
  @label = extract_label
  @ldpath = Qa::LinkedData::Config::Helper.fetch_required(property_map, :ldpath, false)
  @selectable = Qa::LinkedData::Config::Helper.fetch_boolean(property_map, :selectable, false)
  @drillable = Qa::LinkedData::Config::Helper.fetch_boolean(property_map, :drillable, false)
  @optional = Qa::LinkedData::Config::Helper.fetch_boolean(property_map, :optional, Qa.config.property_map_default_for_optional)
  @expansion_label_ldpath = Qa::LinkedData::Config::Helper.fetch(property_map, :expansion_label_ldpath, nil)
  @expansion_id_ldpath = Qa::LinkedData::Config::Helper.fetch(property_map, :expansion_id_ldpath, nil)
  @prefixes = prefixes
end

Instance Attribute Details

#group_idObject (readonly)

id that identifies which group the property should be in



10
11
12
# File 'app/models/qa/linked_data/config/context_property_map.rb', line 10

def group_id
  @group_id
end

#labelObject (readonly)

id that identifies which group the property should be in



10
11
12
# File 'app/models/qa/linked_data/config/context_property_map.rb', line 10

def label
  @label
end

Instance Method Details

#drillable?Boolean

Can this property be used as a new query

Returns:

  • (Boolean)

    true if this property’s value can be used to drill up/down to another level; otherwise, false



54
55
56
# File 'app/models/qa/linked_data/config/context_property_map.rb', line 54

def drillable?
  @drillable
end

#expand_uri?Boolean

Should this URI value be expanded to include its label?

Returns:

  • (Boolean)

    true if this property’s value is expected to be a URI and its label should be included in the value; otherwise, false



70
71
72
# File 'app/models/qa/linked_data/config/context_property_map.rb', line 70

def expand_uri?
  expansion_label_ldpath.present?
end

#expanded_values(graph, subject_uri) ⇒ Array<Hash>

Values of this property for a specfic subject URI with URI values expanded to include id and label.

Examples:

returned values

[{
  uri: "http://id.loc.gov/authorities/genreForms/gf2014026551",
  id: "gf2014026551",
  label: "Space operas"
}]

Returns:

  • (Array<Hash>)

    expanded values for this property



88
89
90
91
92
93
94
95
96
# File 'app/models/qa/linked_data/config/context_property_map.rb', line 88

def expanded_values(graph, subject_uri)
  values = values(graph, subject_uri)
  return values unless expand_uri?
  return values unless values.respond_to? :map!
  values.map! do |uri|
    { uri: uri, id: expansion_id(graph, uri), label: expansion_label(graph, uri) }
  end
  values
end

#group?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'app/models/qa/linked_data/config/context_property_map.rb', line 64

def group?
  group_id.present?
end

#optional?Boolean

Should this property always be included in the extended context or is it optional (i.e. only shown if it has a value)

Returns:

  • (Boolean)

    true if this property is optional and will only be included in extended context if it has a value; otherwise, false



60
61
62
# File 'app/models/qa/linked_data/config/context_property_map.rb', line 60

def optional?
  @optional
end

#selectable?Boolean

Can this property be the selected value?

Returns:

  • (Boolean)

    true if this property’s value can be selected; otherwise, false



48
49
50
# File 'app/models/qa/linked_data/config/context_property_map.rb', line 48

def selectable?
  @selectable
end

#values(graph, subject_uri) ⇒ Array<String>

Values of this property for a specfic subject URI

Returns:

  • (Array<String>)

    values for this property



76
77
78
# File 'app/models/qa/linked_data/config/context_property_map.rb', line 76

def values(graph, subject_uri)
  Qa::LinkedData::LdpathService.ldpath_evaluate(program: basic_program, graph: graph, subject_uri: subject_uri)
end