Class: Inferno::Terminology::Tasks::RunUMLSJar

Inherits:
Object
  • Object
show all
Includes:
TempDir
Defined in:
lib/inferno/terminology/tasks/run_umls_jar.rb

Overview

Constant Summary collapse

VERSIONED_PROPS =
{
  '2019' => 'inferno_2019.prop',
  '2020' => 'inferno_2020.prop',
  '2021' => 'inferno_2021.prop',
  '2022' => 'inferno_2022.prop',
  '2023' => 'inferno_2023.prop',
  '2024' => 'inferno_2024.prop'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TempDir

#pipe_files, #umls_dir, #umls_subset_dir, #umls_zip_path, #versioned_temp_dir

Constructor Details

#initialize(version:) ⇒ RunUMLSJar

Returns a new instance of RunUMLSJar.



22
23
24
# File 'lib/inferno/terminology/tasks/run_umls_jar.rb', line 22

def initialize(version:)
  @version = version
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



20
21
22
# File 'lib/inferno/terminology/tasks/run_umls_jar.rb', line 20

def version
  @version
end

Instance Method Details

#platformObject



66
67
68
69
70
71
72
73
74
# File 'lib/inferno/terminology/tasks/run_umls_jar.rb', line 66

def platform
  if !(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM).nil?
    'windows64'
  elsif !(/darwin/ =~ RUBY_PLATFORM).nil?
    'macos'
  else
    'linux'
  end
end

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/inferno/terminology/tasks/run_umls_jar.rb', line 26

def run
  Inferno.logger.info "#{platform} system detected"
  config_file = File.join(Dir.pwd, 'resources', VERSIONED_PROPS[version])
  output_dir = File.join(Dir.pwd, versioned_temp_dir, 'umls_subset')
  FileUtils.mkdir(output_dir)

  Inferno.logger.info "Using #{config_file}"
  Dir.chdir(Dir[File.join(Dir.pwd, versioned_temp_dir, '/umls/20*')][0]) do
    Inferno.logger.info Dir.pwd
    Dir['lib/*.jar'].each do |jar|
      File.chmod(0o555, jar)
    end
    Dir["jre/#{platform}/bin/*"].each do |file|
      File.chmod(0o555, file)
    end

    Inferno.logger.info 'Running MetamorphoSys (this may take a while)...'
    output = system("./jre/#{platform}/bin/java " \
                    '-Djava.awt.headless=true ' \
                    '-cp .:lib/jpf-boot.jar ' \
                    '-Djpf.boot.config=./etc/subset.boot.properties ' \
                    '-Dlog4j.configuration=./etc/log4j.properties ' \
                    '-Dinput.uri=. ' \
                    "-Doutput.uri=#{output_dir} " \
                    "-Dmmsys.config.uri=#{config_file} " \
                    '-Xms300M -Xmx8G ' \
                    'org.java.plugin.boot.Boot')
    unless output
      Inferno.logger.info 'MetamorphoSys run failed'
      # The cwd at this point is 2 directories above where umls_subset
      # is, so we have to navigate up to it
      umls_subset_directory = File.join(Dir.pwd, '..', '..', 'umls_subset')
      FileUtils.remove_dir(umls_subset_directory) if File.directory?(umls_subset_directory)
      exit 1
    end
  end

  Inferno.logger.info 'done'
end