Sha256: b3214571c1438fa15536ab209d6a212db6eba33c8f31d15bc2e7fb1716af642f

Contents?: true

Size: 1.11 KB

Versions: 36

Compression:

Stored size: 1.11 KB

Contents

module Qa::Authorities
  module MeshTools
    class MeshImporter
      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

      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

36 entries across 36 versions & 1 rubygems

Version Path
qa-5.13.0 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.12.0 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.11.0 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.10.0 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.9.0 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.8.1 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.8.0 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.7.0 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.6.0 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.5.2 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-4.3.0 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-3.1.0 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-2.3.0 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.5.1 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.5.0 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.4.0 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.3.1 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.3.0 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.2.0 lib/qa/authorities/mesh_tools/mesh_importer.rb
qa-5.1.0 lib/qa/authorities/mesh_tools/mesh_importer.rb