Sha256: 2d7ee69868ac3c71c4cb57aadf79062a64795d5cc084a7711c2d4bfe502faebd

Contents?: true

Size: 887 Bytes

Versions: 6

Compression:

Stored size: 887 Bytes

Contents

class Qa::MeshTree < ActiveRecord::Base
  belongs_to :subject_mesh_term, foreign_key: "term_id", primary_key: 'term_id'

  def self.classify_all_trees
    MeshTreeStructure.find_each(&:classify_tree!)
  end

  def eval_tree_path
    trees = read_attribute(:eval_tree_path) || write_attribute(:eval_tree_path, "")
    if trees
      trees.split("|")
    else
      []
    end
  end

  def classify_tree
    tree_levels = initial_segements_of(tree_structure)
    tree_levels.map(&:lookup_tree_term)
  end

  def classify_tree!
    unless classify_tree.empty?
      tree_path = classify_tree.join('|')
      puts "After Join #{tree_path.inspect}"
      update_attribute(:eval_tree_path, tree_path)
    end
  end

  # given a tree id, return the main subject term
  # e.g. 'C03.752.530' returns 'Malaria'
  def lookup_tree_term(tree_id)
    self.class.get_term(tree_id).first.term
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
qa-2.0.1 app/models/qa/mesh_tree.rb
qa-2.0.0 app/models/qa/mesh_tree.rb
qa-1.2.0 app/models/qa/mesh_tree.rb
qa-1.1.0 app/models/qa/mesh_tree.rb
qa-1.0.0 app/models/qa/mesh_tree.rb
qa-0.11.1 app/models/qa/mesh_tree.rb