Class: Qa::Authorities::MeshTools::MeshImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/qa/authorities/mesh_tools/mesh_importer.rb

Instance Method Summary collapse

Instance Method Details

#import_from_file(f) ⇒ Object

rubocop:disable Metrics/MethodLength



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/qa/authorities/mesh_tools/mesh_importer.rb', line 4

def import_from_file(f) # rubocop:disable Metrics/MethodLength
  entries = []
  trees = []
  mesh = Qa::Authorities::MeshTools::MeshDataParser.new(f)
  mesh.each_mesh_record do |record|
    entry = []
    entry << record['UI'].first
    entry << record['MH'].first
    entry << record['MH'].first.downcase
    entry << get_synonyms(record).join('|')
    entries << entry
    next if record['MN'].nil?
    trees += record['MN'].map do |tree_number|
      [record['UI'].first,
       tree_number]
    end
  end
  Qa::SubjectMeshTerm.import([:term_id, :term, :term_lower, :synonyms], entries)
  Qa::MeshTree.import([:term_id, :tree_number], trees)
end