lib/MESH/mesh.rb in mesh-medical-subject-headings-1.2.0 vs lib/MESH/mesh.rb in mesh-medical-subject-headings-1.2.1
- old
+ new
@@ -35,10 +35,11 @@
if line.match(/^\*NEWRECORD$/) #Then store the previous record before continuing
unless current_heading.unique_id.nil?
current_heading.entries.sort!
@@headings << current_heading
@@by_unique_id[current_heading.unique_id] = current_heading
+ @@by_original_heading[current_heading.original_heading] = current_heading
current_heading.tree_numbers.each do |tree_number|
@@by_tree_number[tree_number] = current_heading
end
end
current_heading = Mesh.new
@@ -95,10 +96,15 @@
def self.find_by_tree_number(tree_number)
raise 'MeshHeadingGraph.configure must be called before use' unless @@configured
return @@by_tree_number[tree_number]
end
+ def self.find_by_original_heading(heading)
+ raise 'MeshHeadingGraph.configure must be called before use' unless @@configured
+ return @@by_original_heading[heading]
+ end
+
def self.where(conditions)
matches = []
@@headings.each do |heading|
matches << heading if heading.matches(conditions)
end
@@ -113,10 +119,11 @@
def self.match_in_text(text)
matches = []
text = text.downcase
@@headings.each do |heading|
+ next unless heading.useful
heading.entries.each do |entry|
entry = entry.downcase
start = /^#{Regexp.quote(entry)}\W+/
middle = /\W+#{Regexp.quote(entry)}\W+/
at_end = /\W+#{Regexp.quote(entry)}$/
@@ -150,9 +157,10 @@
@@configured = false
@@headings = []
@@by_unique_id = {}
@@by_tree_number = {}
+ @@by_original_heading = {}
@@default_locale = 'en-US'
@@translator = Translator.new
def initialize
@useful = true