Class: DS::Extractor::BaseTerm

Inherits:
Object
  • Object
show all
Defined in:
lib/ds/extractor/base_term.rb

Overview

BaseTerm is a composite object for multi-value term sets, like subjects, names, and titles, that may have complex representation in source records. For example, names in MARC records, have as recorded values, but also have roles (like author, scribe, etc.) and may also have vernacular script versions.

The BaseTerm has the :as_recorded attribute, which all term types must have.

The BaseTerm also has a ‘#to_a’ method which returns the as_recorded value:

term = BaseTerm.new as_recorded: 'Some value'
term.to_a => ['Some value']

Implementing classes should add other relevant attributes (:vernacular, :role, etc.) and implement #to_a.

NB: BaseTerm instances are used by extractors and the #to_a by the ReconBuilder, which assumes values returned are in the order of the first columns of each corresponding recon CSV. For example, the languages.csv has these columns:

language_as_recorded,language_code,authorized_label,structured_value
Arabic,ara,Arabic,Q13955

The authorized_label and structured_value columns are added by the ReconBuilder which expects term.to_a an array containing the first two column values:

term.to_a  # => ['Arabic', 'ara']

@todo: This might be better handle by a #to_h method with

keys that map to the recon CSV columns. However, for this
to work, the recon CSVs columns would need to be changed
from names like 'language_as_recorded' to 'as_recorded' and
so on. The change would need to made throughout the software
and the change approved by thd DS Project Manager.

Direct Known Subclasses

Genre, Language, Material, Name, Place, Subject, Title

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(as_recorded:) ⇒ BaseTerm

Returns a new instance of BaseTerm.



48
49
50
# File 'lib/ds/extractor/base_term.rb', line 48

def initialize as_recorded:
  @as_recorded = as_recorded
end

Instance Attribute Details

#as_recordedObject

Returns the value of attribute as_recorded.



46
47
48
# File 'lib/ds/extractor/base_term.rb', line 46

def as_recorded
  @as_recorded
end

Instance Method Details

#==(other) ⇒ Object



61
62
63
64
# File 'lib/ds/extractor/base_term.rb', line 61

def ==(other)
  self.class == other.class &&
    self.to_h == other.to_h
end

#eql?(other) ⇒ Boolean

Override ‘#eql?’ for Set equivalence

Returns:

  • (Boolean)


68
69
70
# File 'lib/ds/extractor/base_term.rb', line 68

def eql?(other)
  self == other
end

#hashObject

Override ‘#hash’ for Set equivalence



74
75
76
# File 'lib/ds/extractor/base_term.rb', line 74

def hash
  to_h.hash
end

#to_aObject



52
53
54
# File 'lib/ds/extractor/base_term.rb', line 52

def to_a
  [as_recorded]
end

#to_hObject



56
57
58
# File 'lib/ds/extractor/base_term.rb', line 56

def to_h
  { as_recorded: as_recorded }
end