Class: DarwinCore::ClassificationNormalizer
- Inherits:
-
Object
- Object
- DarwinCore::ClassificationNormalizer
- Defined in:
- lib/dwc-archive/classification_normalizer.rb
Instance Attribute Summary collapse
-
#error_names ⇒ Object
readonly
Returns the value of attribute error_names.
-
#normalized_data ⇒ Object
readonly
Returns the value of attribute normalized_data.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
- #add_name_string(name_string) ⇒ Object
- #add_vernacular_name_string(name_string) ⇒ Object
-
#initialize(dwc_instance) ⇒ ClassificationNormalizer
constructor
A new instance of ClassificationNormalizer.
- #name_strings(opts = {}) ⇒ Object
- #normalize(opts = {}) ⇒ Object
- #vernacular_name_strings(opts = {}) ⇒ Object
Constructor Details
#initialize(dwc_instance) ⇒ ClassificationNormalizer
Returns a new instance of ClassificationNormalizer.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dwc-archive/classification_normalizer.rb', line 31 def initialize(dwc_instance) @dwc = dwc_instance @core_fields = get_fields(@dwc.core) @extensions = @dwc.extensions.map { |e| [e, get_fields(e)] } @normalized_data = {} @synonyms = {} @parser = ParsleyStore.new(1,2) @name_strings = {} @vernacular_name_strings = {} @error_names = [] @tree = {} end |
Instance Attribute Details
#error_names ⇒ Object (readonly)
Returns the value of attribute error_names.
29 30 31 |
# File 'lib/dwc-archive/classification_normalizer.rb', line 29 def error_names @error_names end |
#normalized_data ⇒ Object (readonly)
Returns the value of attribute normalized_data.
29 30 31 |
# File 'lib/dwc-archive/classification_normalizer.rb', line 29 def normalized_data @normalized_data end |
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
29 30 31 |
# File 'lib/dwc-archive/classification_normalizer.rb', line 29 def tree @tree end |
Instance Method Details
#add_name_string(name_string) ⇒ Object
44 45 46 |
# File 'lib/dwc-archive/classification_normalizer.rb', line 44 def add_name_string(name_string) @name_strings[name_string] = 1 unless @name_strings[name_string] end |
#add_vernacular_name_string(name_string) ⇒ Object
48 49 50 |
# File 'lib/dwc-archive/classification_normalizer.rb', line 48 def add_vernacular_name_string(name_string) @vernacular_name_strings[name_string] = 1 unless @vernacular_name_strings[name_string] end |
#name_strings(opts = {}) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/dwc-archive/classification_normalizer.rb', line 52 def name_strings(opts = {}) opts = { with_hash: false }.merge(opts) if !!opts[:with_hash] @name_strings else @name_strings.keys end end |
#normalize(opts = {}) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/dwc-archive/classification_normalizer.rb', line 70 def normalize(opts = {}) opts = { :with_canonical_names => true, :with_extensions => true }.merge(opts) @with_canonical_names = !!opts[:with_canonical_names] DarwinCore.logger_write(@dwc.object_id, "Started normalization of the classification") ingest_core DarwinCore.logger_write(@dwc.object_id, "Calculating the classification parent/child paths") has_parent_id? ? calculate_classification_path : @normalized_data.keys.each { |id| @tree[id] = {} } DarwinCore.logger_write(@dwc.object_id, "Ingesting data from extensions") if !!opts[:with_extensions] ingest_extensions end @normalized_data end |
#vernacular_name_strings(opts = {}) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/dwc-archive/classification_normalizer.rb', line 61 def vernacular_name_strings(opts = {}) opts = { with_hash: false }.merge(opts) if !!opts[:with_hash] @vernacular_name_strings else @vernacular_name_strings.keys end end |