Class: Krikri::Enrichments::DedupNodes

Inherits:
Object
  • Object
show all
Includes:
Audumbla::FieldEnrichment
Defined in:
lib/krikri/enrichments/dedup_nodes.rb

Overview

Enrichment to remove duplicate blank nodes from an ActiveTriples::Resource, where “duplicate” means having the same ‘providedLabel`. URIs and Literal values are retained.

Examples:

# given a SourceResource
sourceResource.creator
# => [#<DPLA::MAP::Agent:0x3fa8828e08e0(default)>,
      #<DPLA::MAP::Agent:0x3fa882910220(default)>,
      #<DPLA::MAP::Agent:0x3fa882942ce8(default)>]

sourceResource.creator.map(&:rdf_subject)
# => [#<RDF::Node:0x3fa8828e0674(_:g69992977401460)>,
      #<RDF::Node:0x3fa882913d08(_:g69992977612040)>,
      #<RDF::URI:0x3fa882942748 URI:http://example.org/moomin>]
sourceResource.creator.map(&:providedLabel)
# => [["moomin"], ["moomin"], ["moomin"]]

enrich = Krikri::Enrichments::DedupNodes.new
new_sr = enrich.enrich_value(sourceResource)

new_sr.creator
# => [#<DPLA::MAP::Agent:0x3fa8828e08e0(default)>,
      #<DPLA::MAP::Agent:0x3fa882942ce8(default)>]

sourceResource.creator.map(&:rdf_subject)
# => [#<RDF::Node:0x3fa8828e0674(_:g69992977401460)>,
      #<RDF::URI:0x3fa882942748 URI:http://example.org/moomin>]

Instance Method Summary collapse

Instance Method Details

#enrich_value(value) ⇒ Object

Returns the original value altered to remove nodes with the same ‘providedLabel`, if any.

Parameters:

  • value (Object)

Returns:

  • (Object)

    the original value altered to remove nodes with the same ‘providedLabel`, if any



40
41
42
43
44
# File 'lib/krikri/enrichments/dedup_nodes.rb', line 40

def enrich_value(value)
  return value unless value.is_a? ActiveTriples::Resource
  deduplicate_resource(value)
  value
end