Class: DarwinCore::ClassificationNormalizer
- Inherits:
- 
      Object
      
        - Object
- DarwinCore::ClassificationNormalizer
 
- Defined in:
- lib/dwc_archive/classification_normalizer.rb
Overview
Returns tree representation of Darwin Core file with vernacular and and synonyms attached to the taxon nodes
Instance Attribute Summary collapse
- 
  
    
      #dwc  ⇒ Object 
    
    
      (also: #darwin_core)
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute dwc. 
- 
  
    
      #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.
| 10 11 12 13 14 15 16 17 18 19 20 | # File 'lib/dwc_archive/classification_normalizer.rb', line 10 def initialize(dwc_instance) @dwc = dwc_instance @core_fields = find_fields(@dwc.core) @extensions = @dwc.extensions.map { |e| [e, find_fields(e)] } @normalized_data = {} @synonyms = {} @name_strings = {} @vernacular_name_strings = {} @error_names = [] @tree = {} end | 
Instance Attribute Details
#dwc ⇒ Object (readonly) Also known as: darwin_core
Returns the value of attribute dwc.
| 7 8 9 | # File 'lib/dwc_archive/classification_normalizer.rb', line 7 def dwc @dwc end | 
#error_names ⇒ Object (readonly)
Returns the value of attribute error_names.
| 7 8 9 | # File 'lib/dwc_archive/classification_normalizer.rb', line 7 def error_names @error_names end | 
#normalized_data ⇒ Object (readonly)
Returns the value of attribute normalized_data.
| 7 8 9 | # File 'lib/dwc_archive/classification_normalizer.rb', line 7 def normalized_data @normalized_data end | 
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
| 7 8 9 | # File 'lib/dwc_archive/classification_normalizer.rb', line 7 def tree @tree end | 
Instance Method Details
#add_name_string(name_string) ⇒ Object
| 22 23 24 | # File 'lib/dwc_archive/classification_normalizer.rb', line 22 def add_name_string(name_string) @name_strings[name_string] = 1 unless @name_strings[name_string] end | 
#add_vernacular_name_string(name_string) ⇒ Object
| 26 27 28 29 30 | # File 'lib/dwc_archive/classification_normalizer.rb', line 26 def add_vernacular_name_string(name_string) return if @vernacular_name_strings[name_string] @vernacular_name_strings[name_string] = 1 end | 
#name_strings(opts = {}) ⇒ Object
| 32 33 34 | # File 'lib/dwc_archive/classification_normalizer.rb', line 32 def name_strings(opts = {}) process_strings(@name_strings, opts) end | 
#normalize(opts = {}) ⇒ Object
| 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | # File 'lib/dwc_archive/classification_normalizer.rb', line 40 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" ) if parent_id? calculate_classification_path else @normalized_data.keys.each { |id| @tree[id] = {} } end DarwinCore.logger_write(@dwc.object_id, "Ingesting data from extensions") ingest_extensions if opts[:with_extensions] @normalized_data end | 
#vernacular_name_strings(opts = {}) ⇒ Object
| 36 37 38 | # File 'lib/dwc_archive/classification_normalizer.rb', line 36 def vernacular_name_strings(opts = {}) process_strings(@vernacular_name_strings, opts) end |