mesh-medical-subject-headings 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e0d8d67721e16e0e016d35056b1ce147d318bd3
4
- data.tar.gz: 31ec3da2e71025e3bff77a82fe5178531aff3eeb
3
+ metadata.gz: cd1eb2f1f911abc7f2421de83fb5e7d6c83dc3cb
4
+ data.tar.gz: 70b0081953e3cdfb68335d8cd33d4841b6424205
5
5
  SHA512:
6
- metadata.gz: 3ea3dd0a355ca538a471afb7846aa5ab35ab206de3440719217722c6f70ec97488fc15a30610e929be39dad7e9eeb8c560b06e277567bdacc6f2b8715c68eadd
7
- data.tar.gz: db140b61b574f7baa5bd26bba5e5b7d9570851f0992e208da8ce61549233bea5c98016c10ad66ae90ac7b45604a9485df4f2859be87bef56e4fea18c97f2a9e2
6
+ metadata.gz: 8b4d63674735db2a1675056d65446fadec07be1b3f81d0d157008c5073f8c1733b165a2c785f220e9578c8e3e53173657c621abe4ba97da9821fcbc79ede1280
7
+ data.tar.gz: cd889c0a8a95d462d4df42b26980ce3506d9e2e52a4ad973aac0f45dd0e1a63af3c5a241e812cdf134e63d577074a69766991f937d005e812863f8890cba3709
@@ -1,3 +1,6 @@
1
+ #2.2.1 / 2014-07-18
2
+ * [FEATURE] Headings now have forward references
3
+
1
4
  #2.2.0 / 2014-07-10
2
5
  * [FEATURE] Headings now have structured_entries which include semantic and lexical information
3
6
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mesh-medical-subject-headings (2.2.0)
4
+ mesh-medical-subject-headings (2.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,8 +1,10 @@
1
1
  module MESH
2
2
  class Heading
3
3
 
4
+ @@descriptor_classes = [:make_array_start_at_1, :topical_descriptor, :publication_type, :check_tag, :geographic_descriptor]
5
+
4
6
  include Comparable
5
- attr_accessor :unique_id, :tree_numbers, :roots, :parents, :children, :useful, :descriptor_class, :default_locale, :semantic_types, :wikipedia_links, :structured_entries
7
+ attr_accessor :unique_id, :tree_numbers, :roots, :parents, :children, :useful, :descriptor_class, :default_locale, :semantic_types, :wikipedia_links, :structured_entries, :forward_references
6
8
  attr_reader :linkified_summary
7
9
 
8
10
  def <=> other
@@ -100,25 +102,94 @@ module MESH
100
102
  @summary[locale] = summary
101
103
  end
102
104
 
105
+ def connect_to_parents
106
+ if !@connected_to_parents
107
+ @tree_numbers.each do |tree_number|
108
+ #D03.438.221.173
109
+ parts = tree_number.split('.')
110
+ if parts.size > 1
111
+ parts.pop
112
+ parent_tree_number = parts.join '.'
113
+ parent = @tree.find_by_tree_number(parent_tree_number)
114
+ @parents << parent unless parent.nil? || @parents.include?(parent)
115
+ parent.children << self unless parent.nil? || parent.children.include?(self)
116
+ end
117
+ end
118
+ @connected_to_parents = true
119
+ end
120
+ end
121
+
122
+ def connect_to_forward_references
123
+ if !@connected_to_forward_references
124
+ @forward_references = @forward_reference_terms.map do |term|
125
+ @tree.find_by_original_heading(term)
126
+ end
127
+ @connected_to_forward_references = true
128
+ end
129
+ end
130
+
103
131
  private
104
132
 
105
- def initialize(tree)
133
+ def initialize(tree, default_locale, lines)
106
134
  @tree = tree
135
+ @default_locale = default_locale
107
136
  @useful = true
108
137
  @tree_numbers = []
109
138
  @semantic_types = []
110
139
  @roots = []
111
140
  @parents = []
112
141
  @children = []
113
- @entries = {}
142
+ @forward_references = []
143
+ @forward_reference_terms = []
144
+ @entries = {@default_locale => []}
114
145
  @structured_entries = []
115
146
  @original_heading = {}
116
147
  @natural_language_name = {}
117
148
  @summary = {}
118
149
  @wikipedia_links = []
119
- end
120
150
 
151
+ lines.each do |line|
152
+ case
153
+
154
+ when matches = line.match(/^UI = (.*)/)
155
+ @unique_id = matches[1]
156
+
157
+ when matches = line.match(/^MN = (.*)/)
158
+ @tree_numbers << matches[1]
159
+ @roots << matches[1][0] unless @roots.include?(matches[1][0])
121
160
 
161
+ when matches = line.match(/^MS = (.*)/)
162
+ set_summary(matches[1])
163
+
164
+ when matches = line.match(/^DC = (.*)/)
165
+ @descriptor_class = @@descriptor_classes[matches[1].to_i]
166
+
167
+ when matches = line.match(/^ST = (.*)/)
168
+ @semantic_types << MESH::SemanticTypes[matches[1]]
169
+
170
+ when matches = line.match(/^MH = (.*)/)
171
+ mh = matches[1]
172
+ set_original_heading(mh)
173
+ @entries[@default_locale] << mh unless @entries.include? mh
174
+ librarian_parts = mh.match(/(.*), (.*)/)
175
+ nln = librarian_parts.nil? ? mh : "#{librarian_parts[2]} #{librarian_parts[1]}"
176
+ set_natural_language_name(nln)
177
+
178
+ when matches = line.match(/^(?:PRINT )?ENTRY = (.*)/)
179
+ entry = matches[1]
180
+ term = entry.match(/([^|]+)/)
181
+ @entries[@default_locale] << term[1] unless @entries.include? term[1]
182
+ @structured_entries << MESH::Entry.new(self, entry)
183
+
184
+ when matches = line.match(/^FX = (.*)/)
185
+ @forward_reference_terms << matches[1]
186
+
187
+ end
188
+
189
+ end
190
+ @entries[@default_locale].sort!
191
+
192
+ end
122
193
  end
123
194
  end
124
195
 
@@ -2,7 +2,6 @@ module MESH
2
2
 
3
3
  class Tree
4
4
 
5
- @@descriptor_classes = [:make_array_start_at_1, :topical_descriptor, :publication_type, :check_tag, :geographic_descriptor]
6
5
  @@default_locale = :en_us
7
6
 
8
7
  def initialize
@@ -18,85 +17,42 @@ module MESH
18
17
  gzipped_file = File.open(filename)
19
18
  file = Zlib::GzipReader.new(gzipped_file)
20
19
 
21
- current_heading = MESH::Heading.new(self)
22
- current_heading.default_locale = @@default_locale
20
+ lines = []
23
21
  file.each_line do |line|
24
-
25
22
  case
26
-
27
23
  when line.match(/^\*NEWRECORD$/)
28
- unless current_heading.unique_id.nil?
29
- current_heading.entries.sort!
30
- @headings << current_heading
31
- @by_unique_id[current_heading.unique_id] = current_heading
32
- @by_original_heading[current_heading.original_heading] = current_heading
33
- current_heading.tree_numbers.each do |tree_number|
34
- raise if @by_tree_number[tree_number]
35
- @by_tree_number[tree_number] = current_heading
36
- end
37
- match_headings = current_heading.entries.map { |e| entry_match_key(e) }.uniq
38
- match_headings.each do |entry|
39
- raise "#{@by_entry[entry]} vs #{current_heading} on #{entry}\n\n#{@by_entry[entry].entries}\n\n#{current_heading.entries}" if @by_entry[entry]
40
- @by_entry[entry] = current_heading
41
- end
24
+ unless lines.empty?
25
+ mh = MESH::Heading.new(self, @@default_locale, lines)
26
+ add_heading_to_hashes(mh)
27
+ lines = [line]
42
28
  end
43
- current_heading = MESH::Heading.new(self)
44
- current_heading.default_locale = @@default_locale
45
-
46
- when matches = line.match(/^UI = (.*)/)
47
- current_heading.unique_id = matches[1]
48
-
49
- when matches = line.match(/^MN = (.*)/)
50
- current_heading.tree_numbers << matches[1]
51
- current_heading.roots << matches[1][0] unless current_heading.roots.include?(matches[1][0])
52
-
53
- when matches = line.match(/^MS = (.*)/)
54
- current_heading.set_summary(matches[1])
55
-
56
- when matches = line.match(/^DC = (.*)/)
57
- current_heading.descriptor_class = @@descriptor_classes[matches[1].to_i]
58
-
59
- when matches = line.match(/^ST = (.*)/)
60
- current_heading.semantic_types << MESH::SemanticTypes[matches[1]]
61
-
62
- when matches = line.match(/^MH = (.*)/)
63
- mh = matches[1]
64
- current_heading.set_original_heading(mh)
65
- current_heading.entries << mh unless current_heading.entries.include? mh
66
- librarian_parts = mh.match(/(.*), (.*)/)
67
- nln = librarian_parts.nil? ? mh : "#{librarian_parts[2]} #{librarian_parts[1]}"
68
- current_heading.set_natural_language_name(nln)
69
-
70
- # when matches = line.match(/^(?:PRINT )?ENTRY = ([^|]+)/)
71
- # entry = matches[1].chomp
72
- # current_heading.entries << entry unless current_heading.entries.include? entry
73
- #
74
- when matches = line.match(/^(?:PRINT )?ENTRY = (.*)/)
75
- entry = matches[1]
76
- term = entry.match(/([^|]+)/)
77
- current_heading.entries << term[1] unless current_heading.entries.include? term[1]
78
- current_heading.structured_entries << MESH::Entry.new(current_heading, entry)
79
-
29
+ else
30
+ lines << line
80
31
  end
81
-
82
32
  end
83
33
 
84
- @by_unique_id.each do |id, heading|
85
- heading.tree_numbers.each do |tree_number|
86
- #D03.438.221.173
87
- parts = tree_number.split('.')
88
- if parts.size > 1
89
- parts.pop
90
- parent_tree_number = parts.join '.'
91
- parent = @by_tree_number[parent_tree_number]
92
- heading.parents << parent unless parent.nil? || heading.parents.include?(parent)
93
- parent.children << heading unless parent.nil? || parent.children.include?(heading)
94
- end
95
- end
34
+ @headings.each do |heading|
35
+ heading.connect_to_parents
36
+ heading.connect_to_forward_references
96
37
  end
97
38
 
98
39
  end
99
40
 
41
+ def add_heading_to_hashes(mh)
42
+ @headings << mh
43
+ @by_unique_id[mh.unique_id] = mh
44
+ @by_original_heading[mh.original_heading] = mh
45
+ mh.tree_numbers.each do |tree_number|
46
+ raise if @by_tree_number[tree_number]
47
+ @by_tree_number[tree_number] = mh
48
+ end
49
+ match_headings = mh.entries.map { |e| entry_match_key(e) }.uniq
50
+ match_headings.each do |entry|
51
+ raise if @by_entry[entry]
52
+ @by_entry[entry] = mh
53
+ end
54
+ end
55
+
100
56
  def entry_match_key(e)
101
57
  e.strip.upcase
102
58
  end
@@ -1,3 +1,3 @@
1
1
  module Mesh
2
- VERSION = "2.2.0"
2
+ VERSION = '2.2.1'
3
3
  end
@@ -336,6 +336,24 @@ module MESH
336
336
  end
337
337
  end
338
338
 
339
+ def test_has_one_forward_reference
340
+ mh = @mesh_tree.find_by_original_heading('Abdominal Muscles')
341
+ fx = @mesh_tree.find_by_original_heading('Abdominal Wall')
342
+ assert_equal [fx], mh.forward_references
343
+ end
344
+
345
+ def test_has_several_forward_references
346
+ mh = @mesh_tree.find_by_original_heading('Acquired Immunodeficiency Syndrome')
347
+ fx1 = @mesh_tree.find_by_original_heading('AIDS Arteritis, Central Nervous System')
348
+ fx2 = @mesh_tree.find_by_original_heading('AIDS Dementia Complex')
349
+ fx3 = @mesh_tree.find_by_original_heading('AIDS Serodiagnosis')
350
+ fx4 = @mesh_tree.find_by_original_heading('HIV Seropositivity')
351
+ fx5 = @mesh_tree.find_by_original_heading('HIV Seroprevalence')
352
+ fx6 = @mesh_tree.find_by_original_heading('Lymphoma, AIDS-Related')
353
+
354
+ assert_equal [fx1, fx2, fx3, fx4, fx5, fx6], mh.forward_references
355
+ end
356
+
339
357
  def test_have_the_correct_siblings
340
358
  skip
341
359
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mesh-medical-subject-headings
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Styles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-11 00:00:00.000000000 Z
11
+ date: 2014-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler