Class: ConceptQL::CLI

Inherits:
Thor
  • Object
show all
Includes:
Sequelizer
Defined in:
lib/conceptql/cli.rb

Instance Method Summary collapse

Instance Method Details

#annotate_statement(statement_file) ⇒ Object



49
50
51
52
# File 'lib/conceptql/cli.rb', line 49

def annotate_statement(statement_file)
  q = ConceptQL::Query.new(db(options), criteria_from_file(statement_file))
  pp q.annotate
end

#dumpit(path) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/conceptql/cli.rb', line 117

def dumpit(path)
  path = Pathname.new(path)
  path.mkpath unless path.exist?
  headers_path = path + 'headers'
  headers_path.mkpath unless headers_path.exist?
  db.tables.each do |table|
    puts "Dumping #{table}..."
    ds = db[table]
    rows = ds.select_map(ds.columns)
    CSV.open(path + "#{table}.csv", "wb") do |csv|
      rows.each { |row| csv << row }
    end
    CSV.open(headers_path + "#{table}.csv", "wb") do |csv|
      csv << ds.columns
    end
  end
end

#fake_graph(file) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/conceptql/cli.rb', line 69

def fake_graph(file)
  require_relative 'fake_annotater'
  annotated = ConceptQL::FakeAnnotater.new(criteria_from_file(file)).annotate
  pp annotated
  ConceptQL::AnnotateGrapher.new.graph_it(annotated, '/tmp/graph.pdf')
  system('open /tmp/graph.pdf')
end

#knit(file) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/conceptql/cli.rb', line 108

def knit(file)
  opts = {}
  if options[:ignore_cache]
    opts[:cache_options] = { ignore: true }
  end
  ConceptQL::Knitter.new(ConceptQL::Database.new(db), file, opts).knit
end

#metadataObject



78
79
80
81
82
83
84
# File 'lib/conceptql/cli.rb', line 78

def 
  File.write('metadata.js', "$metadata = #{ConceptQL.(warn: true).to_json};")
  File.write('metadata.json', ConceptQL..to_json)
  if system("which", "json_pp", out: File::NULL, err: File::NULL)
    system("cat metadata.json | json_pp", out: "metadata_pp.json")
  end
end

#run_statement(statement_file) ⇒ Object



41
42
43
44
45
46
# File 'lib/conceptql/cli.rb', line 41

def run_statement(statement_file)
  q = cdb(options).query(criteria_from_file(statement_file))
  puts q.sql
  puts JSON.pretty_generate(q.statement)
  pp q.query.all
end

#selection_operatorsObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/conceptql/cli.rb', line 87

def selection_operators
  require 'csv'
  CSV.open('selection_operators.tsv', 'w', col_sep: "\t") do |csv|
    csv << ["name"]
    ConceptQL.[:operators].values.select { |v| v[:basic_type] == :selection }.map { |v| v[:preferred_name] }.each do |name|
      csv << [name]
    end
  end

  CSV.open('domains.tsv', 'w', col_sep: "\t") do |csv|
    csv << ["name"]
    ConceptQL::Operators::TABLE_COLUMNS.each do |domain, columns|
      next unless columns.include?(:person_id)
      next if domain.to_s =~ /era\Z/
      csv << [domain]
    end
  end
end

#show_and_tell_file(file) ⇒ Object



64
65
66
# File 'lib/conceptql/cli.rb', line 64

def show_and_tell_file(file)
  show_and_tell(criteria_from_file(file), options)
end

#show_graph(file) ⇒ Object



56
57
58
59
# File 'lib/conceptql/cli.rb', line 56

def show_graph(file)
  graph_it(criteria_from_file(file))
  system('open /tmp/graph.pdf')
end