mesh-medical-subject-headings 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/lib/MESH/heading.rb +10 -6
- data/lib/MESH/tree.rb +23 -2
- data/lib/MESH/version.rb +1 -1
- data/test/mesh_core_test.rb +47 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1779cff991e94c43a9adf2429b4ec0c487c2d0b4
|
4
|
+
data.tar.gz: 4ef7e94c5f20c098648bcb1a1a8874e1c4905b8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cf3b2a10bec165bf2652cd0d8ece4ab04900c8743c052ed9174e05526ccbb35cce6e68ac66e9703060e726aaa3c3e7aac77e360e80f57b5f3b235648f4efaaa
|
7
|
+
data.tar.gz: d8a2662c49f5235c8a0aa0165fe1188b2ab6a9a347f66b23dfd99f1cee40d7b1b91a2f6e3b48dc002d73e566db7ab9fc9fa7033956dcc78f2e6f316c187e87d5
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/MESH/heading.rb
CHANGED
@@ -3,6 +3,7 @@ module MESH
|
|
3
3
|
|
4
4
|
include Comparable
|
5
5
|
attr_accessor :unique_id, :tree_numbers, :roots, :parents, :children, :useful, :descriptor_class, :default_locale
|
6
|
+
attr_reader :linkified_summary
|
6
7
|
|
7
8
|
def <=> other
|
8
9
|
self.unique_id <=> other.unique_id
|
@@ -21,13 +22,16 @@ module MESH
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def linkify_summary
|
24
|
-
|
25
|
-
linkified_summary
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
return if summary.nil?
|
26
|
+
@linkified_summary = summary.dup
|
27
|
+
@linkified_summary.scan(/[A-Z]+[A-Z,\s]+[A-Z]+/).each do |text|
|
28
|
+
heading = @tree.find_by_entry(text)
|
29
|
+
if heading
|
30
|
+
replacement_text = yield text, heading
|
31
|
+
@linkified_summary.sub!(text, replacement_text)
|
32
|
+
end
|
29
33
|
end
|
30
|
-
linkified_summary
|
34
|
+
@linkified_summary
|
31
35
|
end
|
32
36
|
|
33
37
|
def entries(locale = default_locale)
|
data/lib/MESH/tree.rb
CHANGED
@@ -11,6 +11,7 @@ module MESH
|
|
11
11
|
@by_unique_id = {}
|
12
12
|
@by_tree_number = {}
|
13
13
|
@by_original_heading = {}
|
14
|
+
@by_entry = {}
|
14
15
|
@locales = [@@default_locale]
|
15
16
|
|
16
17
|
filename = File.expand_path('../../../data/mesh_data_2014/d2014.bin.gz', __FILE__)
|
@@ -30,8 +31,14 @@ module MESH
|
|
30
31
|
@by_unique_id[current_heading.unique_id] = current_heading
|
31
32
|
@by_original_heading[current_heading.original_heading] = current_heading
|
32
33
|
current_heading.tree_numbers.each do |tree_number|
|
34
|
+
raise if @by_tree_number[tree_number]
|
33
35
|
@by_tree_number[tree_number] = current_heading
|
34
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
|
35
42
|
end
|
36
43
|
current_heading = MESH::Heading.new(self)
|
37
44
|
current_heading.default_locale = @@default_locale
|
@@ -52,14 +59,14 @@ module MESH
|
|
52
59
|
when matches = line.match(/^MH = (.*)/)
|
53
60
|
mh = matches[1]
|
54
61
|
current_heading.set_original_heading(mh)
|
55
|
-
current_heading.entries << mh
|
62
|
+
current_heading.entries << mh unless current_heading.entries.include? mh
|
56
63
|
librarian_parts = mh.match(/(.*), (.*)/)
|
57
64
|
nln = librarian_parts.nil? ? mh : "#{librarian_parts[2]} #{librarian_parts[1]}"
|
58
65
|
current_heading.set_natural_language_name(nln)
|
59
66
|
|
60
67
|
when matches = line.match(/^(?:PRINT )?ENTRY = ([^|]+)/)
|
61
68
|
entry = matches[1].chomp
|
62
|
-
current_heading.entries << entry
|
69
|
+
current_heading.entries << entry unless current_heading.entries.include? entry
|
63
70
|
|
64
71
|
end
|
65
72
|
|
@@ -81,6 +88,10 @@ module MESH
|
|
81
88
|
|
82
89
|
end
|
83
90
|
|
91
|
+
def entry_match_key(e)
|
92
|
+
e.strip.upcase
|
93
|
+
end
|
94
|
+
|
84
95
|
def load_translation(locale)
|
85
96
|
return if @locales.include? locale
|
86
97
|
filename = File.expand_path("../../../data/mesh_data_2014/d2014.#{locale}.bin.gz", __FILE__)
|
@@ -136,6 +147,12 @@ module MESH
|
|
136
147
|
@locales << locale
|
137
148
|
end
|
138
149
|
|
150
|
+
def linkify_summaries &block
|
151
|
+
@headings.each do |h|
|
152
|
+
h.linkify_summary &block
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
139
156
|
# NO LONGER COVERED BY TESTS
|
140
157
|
# def translate(locale, tr)
|
141
158
|
# return if @locales.include? locale
|
@@ -162,6 +179,10 @@ module MESH
|
|
162
179
|
return @by_original_heading[heading]
|
163
180
|
end
|
164
181
|
|
182
|
+
def find_by_entry(entry)
|
183
|
+
return @by_entry[entry_match_key(entry)]
|
184
|
+
end
|
185
|
+
|
165
186
|
def where(conditions)
|
166
187
|
matches = []
|
167
188
|
@headings.each do |heading|
|
data/lib/MESH/version.rb
CHANGED
data/test/mesh_core_test.rb
CHANGED
@@ -40,6 +40,39 @@ module MESH
|
|
40
40
|
assert_nil mh
|
41
41
|
end
|
42
42
|
|
43
|
+
def test_find_by_entry
|
44
|
+
|
45
|
+
expected_entries = [
|
46
|
+
'Adult Reye Syndrome',
|
47
|
+
'Adult Reye\'s Syndrome',
|
48
|
+
'Fatty Liver with Encephalopathy',
|
49
|
+
'Reye Johnson Syndrome',
|
50
|
+
'Reye Like Syndrome',
|
51
|
+
'Reye Syndrome',
|
52
|
+
'Reye Syndrome, Adult',
|
53
|
+
'Reye\'s Like Syndrome',
|
54
|
+
'Reye\'s Syndrome',
|
55
|
+
'Reye\'s Syndrome, Adult',
|
56
|
+
'Reye\'s-Like Syndrome',
|
57
|
+
'Reye-Johnson Syndrome',
|
58
|
+
'Reye-Like Syndrome'
|
59
|
+
]
|
60
|
+
|
61
|
+
entries_to_test = expected_entries.flat_map do |e|
|
62
|
+
[e, e.upcase, e.downcase, " #{e.downcase} ", "\n\n\t #{e.downcase}\t "]
|
63
|
+
end
|
64
|
+
|
65
|
+
entries_to_test.each do |entry|
|
66
|
+
refute_nil mh = @mesh_tree.find_by_entry(entry), "Failed to find heading by entry '#{entry}'"
|
67
|
+
assert_equal 'D012202', mh.unique_id, "Found wrong heading by entry '#{entry}'"
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_find_by_entry_doesnt_match
|
73
|
+
assert_nil @mesh_tree.find_by_entry('foo')
|
74
|
+
end
|
75
|
+
|
43
76
|
def test_have_the_correct_unique_id
|
44
77
|
mh = @mesh_tree.find('D000001')
|
45
78
|
assert_equal 'D000001', mh.unique_id
|
@@ -121,10 +154,15 @@ module MESH
|
|
121
154
|
'ADENOCARCINOMA' => false
|
122
155
|
}
|
123
156
|
|
157
|
+
# start = Time.now
|
124
158
|
linkified_summary = mh.linkify_summary do |text, heading|
|
125
159
|
found[text] = true unless heading.nil?
|
126
160
|
"<foo>#{text.downcase}</foo>"
|
127
161
|
end
|
162
|
+
# finish = Time.now
|
163
|
+
# puts start
|
164
|
+
# puts finish
|
165
|
+
# puts finish - start
|
128
166
|
|
129
167
|
assert_equal 5, found.length
|
130
168
|
assert found['ESOPHAGUS']
|
@@ -137,6 +175,15 @@ module MESH
|
|
137
175
|
|
138
176
|
end
|
139
177
|
|
178
|
+
def test_linkifies_all_summaries
|
179
|
+
mesh = MESH::Tree.new
|
180
|
+
mesh.linkify_summaries do |text, heading|
|
181
|
+
"<bar>#{text.downcase}</bar>"
|
182
|
+
end
|
183
|
+
mh = mesh.find('D001471')
|
184
|
+
assert_equal 'A condition with damage to the lining of the lower <bar>esophagus</bar> resulting from chronic acid reflux (<bar>esophagitis, reflux</bar>). Through the process of metaplasia, the squamous cells are replaced by a columnar epithelium with cells resembling those of the <bar>intestine</bar> or the salmon-pink mucosa of the <bar>stomach</bar>. Barrett\'s columnar epithelium is a marker for severe reflux and precursor to <bar>adenocarcinoma</bar> of the esophagus.', mh.linkified_summary
|
185
|
+
end
|
186
|
+
|
140
187
|
def test_to_s
|
141
188
|
mh = @mesh_tree.find('D001471')
|
142
189
|
assert_equal 'D001471, Barrett Esophagus, [C06.198.102,C06.405.117.102]', mh.to_s
|