Sha256: b8825302a140b4d22b4dad126fbabd55b6a476dad27a9cd3f77ffb07824877e8
Contents?: true
Size: 1.08 KB
Versions: 11
Compression:
Stored size: 1.08 KB
Contents
module Qa::Authorities module MeshTools class MeshImporter def import_from_file(f) 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 unless record['MN'].nil? trees += record['MN'].map do |tree_number| [record['UI'].first, tree_number] end end end Qa::SubjectMeshTerm.import([:term_id, :term, :term_lower, :synonyms], entries) Qa::MeshTree.import([:term_id, :tree_number], trees) end private def get_synonyms(record) first_terms(record, 'PRINT ENTRY') + first_terms(record, 'ENTRY') end def first_terms(record, field) return [] if record[field].nil? record[field].map { |s| s.split('|').first } end end end end
Version data entries
11 entries across 11 versions & 1 rubygems