mesh-medical-subject-headings 1.2.0 → 1.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: e31aff857fd3cfec57c0bb1fdddc441e6cfe2bd9
4
- data.tar.gz: 271595ddd24addb8e29c088d3e10ac55da8d4418
3
+ metadata.gz: 82ad36f2c8fee0c670559cd288cbc4b919ef678f
4
+ data.tar.gz: 7606787a0e04e374231074fe3351fa2da2e709f6
5
5
  SHA512:
6
- metadata.gz: 227b2613ea9d42343672cc443cff13db4be79acac71a0cb8c7fcffcecd048f36ae21f346d6f52ccc93d16146a37794cae2f0d96b11acae4d03886b3ecd07ee35
7
- data.tar.gz: 33d0bb05e460647942ae89fcf4ce1446558583dbc360e1a62ab3d967eb8403541d89ecbe0fffafcd5cd9e1f8952201a5beef60deb775d3a10d52b92372f9e381
6
+ metadata.gz: e024eaadc34650727726d316e054c0b96cccb0c0f5b85384124582531e505075dbbcf603d0620d0f07a1328c3abb78490ac28f0336820547bda29da011f52c2b
7
+ data.tar.gz: 6d2942c939bac0cad0db958980d79697849acbcf001d51b6ff1a5d484980edf30e95e07fad3442323b8a130f9ec596cd95127b63466ffeb3054393f0ff0ac49b
data/CHANGELOG.md CHANGED
@@ -1,2 +1,5 @@
1
+ # 1.2.1 / 2014-03-04
2
+ * [BUGFIX] Fix text matching to only use 'useful' headings
3
+
1
4
  # 1.2.0 / 2014-02-27
2
5
  * [FEATURE] Initial Release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mesh-medical-subject-headings (1.2.0)
4
+ mesh-medical-subject-headings (1.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/MESH/mesh.rb CHANGED
@@ -37,6 +37,7 @@ module MESH
37
37
  current_heading.entries.sort!
38
38
  @@headings << current_heading
39
39
  @@by_unique_id[current_heading.unique_id] = current_heading
40
+ @@by_original_heading[current_heading.original_heading] = current_heading
40
41
  current_heading.tree_numbers.each do |tree_number|
41
42
  @@by_tree_number[tree_number] = current_heading
42
43
  end
@@ -97,6 +98,11 @@ module MESH
97
98
  return @@by_tree_number[tree_number]
98
99
  end
99
100
 
101
+ def self.find_by_original_heading(heading)
102
+ raise 'MeshHeadingGraph.configure must be called before use' unless @@configured
103
+ return @@by_original_heading[heading]
104
+ end
105
+
100
106
  def self.where(conditions)
101
107
  matches = []
102
108
  @@headings.each do |heading|
@@ -115,6 +121,7 @@ module MESH
115
121
  matches = []
116
122
  text = text.downcase
117
123
  @@headings.each do |heading|
124
+ next unless heading.useful
118
125
  heading.entries.each do |entry|
119
126
  entry = entry.downcase
120
127
  start = /^#{Regexp.quote(entry)}\W+/
@@ -152,6 +159,7 @@ module MESH
152
159
  @@headings = []
153
160
  @@by_unique_id = {}
154
161
  @@by_tree_number = {}
162
+ @@by_original_heading = {}
155
163
  @@default_locale = 'en-US'
156
164
  @@translator = Translator.new
157
165
 
data/lib/MESH/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mesh
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
data/match.rb ADDED
@@ -0,0 +1,9 @@
1
+ require_relative 'lib/MESH'
2
+
3
+ MESH::Mesh.configure(filename: 'data/mesh_data_2014/d2014.bin.gz')
4
+ nu_file = File.open('not_useful.txt')
5
+ nu_file.each_line do |line|
6
+ id, name = line.split(', ')
7
+ MESH::Mesh.find(id).useful = false
8
+ end
9
+
data/test/mesh_test.rb CHANGED
@@ -29,6 +29,17 @@ module MESH
29
29
  assert_equal 'D000065', mh.unique_id
30
30
  end
31
31
 
32
+ it 'should find by original heading' do
33
+ mh = MESH::Mesh.find_by_original_heading('Allergens')
34
+ refute_nil mh
35
+ assert_equal 'D000485', mh.unique_id
36
+ end
37
+
38
+ it 'should not find original heading that doesnt exist' do
39
+ mh = MESH::Mesh.find_by_original_heading('Lorem')
40
+ assert_nil mh
41
+ end
42
+
32
43
  it 'should have the correct unique id' do
33
44
  mh = MESH::Mesh.find('D000001')
34
45
  assert_equal 'D000001', mh.unique_id
@@ -186,20 +197,37 @@ module MESH
186
197
  end
187
198
 
188
199
  it 'should match headings that occur in given text' do
189
- expected_ids = %w(D001491 D001769 D001792 D001842 D001853 D001853 D002470 D002477 D002477 D002648 D002648 D002875 D002965 D002999 D003062 D003561 D003593 D003643 D004194 D004314 D004314 D004314 D004314 D004813 D004912 D005091 D005123 D005123 D005293 D005333 D005385 D005385 D005544 D005796 D006128 D006225 D006309 D006321 D006331 D006664 D007107 D007223 D007231 D007231 D007231 D007239 D007246 D007938 D008099 D008168 D008214 D008214 D008423 D008533 D008533 D008607 D008722 D009035 D009055 D009132 D009154 D009154 D009190 D009196 D009369 D009666 D010372 D010641 D011153 D012008 D012106 D012146 D012306 D012307 D012380 D012680 D012867 D013534 D013577 D013601 D013812 D013921 D013961 D014034 D014157 D014171 D014314 D014960 D015032 D015994 D015995 D016424 D016433 D017584 D017668 D018387 D018388 D019021 D019070 D019368 D019369 D032882 D036801 D036801 D038042 D041905 D052016 D055016)
200
+ expected_ids = %w(D001491 D001769 D001792 D001842 D001853 D002470 D002477 D002648 D002875 D002965 D002999 D003062 D003561 D003593 D003643 D004194 D004314 D004813 D004912 D005091 D005123 D005293 D005333 D005385 D005544 D005796 D006128 D006225 D006309 D006321 D006331 D006664 D007107 D007223 D007231 D007239 D007246 D007938 D008099 D008168 D008214 D008423 D008533 D008607 D008722 D009035 D009055 D009132 D009154 D009190 D009196 D009369 D009666 D010372 D010641 D011153 D012008 D012106 D012146 D012306 D012307 D012380 D012680 D012867 D013534 D013577 D013601 D013812 D013921 D013961 D014034 D014157 D014171 D014314 D014960 D015032 D015994 D015995 D016424 D016433 D017584 D017668 D018387 D018388 D019021 D019070 D019368 D019369 D032882 D036801 D038042 D041905 D052016 D055016)
190
201
  expected = expected_ids.map { |id| MESH::Mesh.find(id) }
191
- actual = MESH::Mesh.match_in_text(@example_text)
192
- assert expected, actual
202
+ matches = MESH::Mesh.match_in_text(@example_text)
203
+ actual = matches.map { |match| match[:heading] }.uniq
204
+ assert_equal expected, actual
205
+ end
206
+
207
+ it 'should only match useful headings that occur in given text' do
208
+ expected_ids = %w(D001491 D001769 D001792 D001842 D001853 D002470 D002648 D002875 D002965 D003062 D003561 D003593 D003643 D004194 D004314 D004813 D004912 D005091 D005123 D005293 D005333 D005385 D005544 D005796 D006128 D006225 D006309 D006321 D006331 D007107 D007231 D007239 D007938 D008099 D008168 D008214 D008423 D008607 D008722 D009035 D009055 D009132 D009154 D009190 D009196 D009369 D009666 D010372 D010641 D011153 D012008 D012106 D012146 D012306 D012307 D012380 D012680 D012867 D013534 D013577 D013601 D013812 D013921 D013961 D014034 D014157 D014171 D014314 D015032 D015994 D015995 D016424 D017584 D017668 D018387 D018388 D019021 D019070 D019368 D019369 D032882 D036801 D038042 D041905 D052016)
209
+
210
+ not_useful_ids = %w(D007246 D002477 D014960 D008533 D016433 D006664 D055016 D002999 D007223)
211
+ begin
212
+ not_useful_ids.each { |id| MESH::Mesh.find(id).useful = false }
213
+
214
+ expected = expected_ids.map { |id| MESH::Mesh.find(id) }
215
+ matches = MESH::Mesh.match_in_text(@example_text)
216
+ actual = matches.map { |match| match[:heading] }.uniq
217
+ assert_equal expected, actual
218
+ ensure
219
+ not_useful_ids.each { |id| MESH::Mesh.find(id).useful = true }
220
+ end
193
221
  end
194
222
 
195
- it 'should match headings at start of test' do
223
+ it 'should match headings at start of text' do
196
224
  text = 'Leukemia, lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pretium leo diam, quis adipiscing purus bibendum eu.'
197
225
  matches = MESH::Mesh.match_in_text(text)
198
226
  assert_equal 1, matches.length
199
227
  assert_equal MESH::Mesh.find('D007938'), matches[0][:heading]
200
228
  end
201
229
 
202
- it 'should match headings at end of test' do
230
+ it 'should match headings at end of text' do
203
231
  text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pretium leo diam, quis adipiscing purus bibendum eu leukemia'
204
232
  matches = MESH::Mesh.match_in_text(text)
205
233
  assert_equal 1, matches.length
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: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - mmmmmrob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-28 00:00:00.000000000 Z
11
+ date: 2014-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,6 +106,7 @@ files:
106
106
  - lib/MESH/mesh.rb
107
107
  - lib/MESH/translator.rb
108
108
  - lib/MESH/version.rb
109
+ - match.rb
109
110
  - test/mesh_test.rb
110
111
  - test/test_helper.rb
111
112
  - test/translator_test.rb