Class: Opencdd::Parcel::ReferencedIrdis

Inherits:
Object
  • Object
show all
Defined in:
lib/opencdd/parcel/referenced_irdis.rb

Overview

Walks a sharded downloads directory and collects every IRDI referenced by a class .xls that points to a non-class entity (property, unit, value-list, value-term). The output manifest drives the per-entity scraper Pass 2 — see TODO.cdd-editor/43-scraper-pass-2-per-entity.md.

Source columns on the CLASS .xls (parsed by Opencdd::Klass):

applicable_property_irdis   (MDC_P014) → property
imported_property_irdis     (MDC_P090) → property (cross-dict)
is_case_of_irdis            (MDC_P013) → class (cross-dict)
sub_class_selection_irdis   (MDC_P016) → class

Cross-dictionary IRDIs are partitioned by their source scheme so the scraper can pick the right Dictionary config. Properties referenced in applicable_property_irdis of a class in dict A that point at dict B's IRDI space are emitted with source_scheme: B.

Defined Under Namespace

Classes: Entry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ReferencedIrdis

Returns a new instance of ReferencedIrdis.



32
33
34
# File 'lib/opencdd/parcel/referenced_irdis.rb', line 32

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



30
31
32
# File 'lib/opencdd/parcel/referenced_irdis.rb', line 30

def path
  @path
end

Instance Method Details

#as_jsonObject



58
59
60
# File 'lib/opencdd/parcel/referenced_irdis.rb', line 58

def as_json
  collect.transform_values { |entries| entries.map(&:to_h) }
end

#collectObject

Returns Hash{ source_scheme => Array<Entry> }.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/opencdd/parcel/referenced_irdis.rb', line 37

def collect
  reader = Opencdd::Parcel::ShardedDirReader.new(@path)
  database = Opencdd::Database.new
  reader.load_into(database)

  by_irdi = {}
  database.classes.each do |klass|
    record_each(by_irdi, klass, klass.applicable_property_irdis, :property)
    record_each(by_irdi, klass, klass.imported_property_irdis,   :property)
    record_each(by_irdi, klass, klass.is_case_of_irdis,          :class)
    record_each(by_irdi, klass, klass.sub_class_selection_irdis, :class)
  end

  by_scheme = {}
  by_irdi.each_value do |entry|
    bucket = by_scheme[entry.source_scheme] ||= []
    bucket << entry
  end
  by_scheme.transform_values { |entries| entries.sort_by { |e| e.irdi.to_s } }
end

#to_json(*args) ⇒ Object



62
63
64
65
# File 'lib/opencdd/parcel/referenced_irdis.rb', line 62

def to_json(*args)
  require "json"
  JSON.pretty_generate(as_json, *args)
end