mesh-medical-subject-headings 2.3.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  require_relative 'test_helper'
2
2
 
3
3
  module MESH
4
- class HeadingTest < TestBase
4
+ class EntryTest < TestBase
5
5
 
6
6
  # PRINT ENTRY = Acetamidophenol|T109|T121|NON|EQV|UNK (19XX)|771118|abbcdef
7
7
  # PRINT ENTRY = Hydroxyacetanilide|T109|T121|NON|EQV|UNK (19XX)|740329|abbcdef
@@ -24,43 +24,181 @@ module MESH
24
24
  # ENTRY = Anacin3
25
25
 
26
26
  def test_has_heading
27
- entry = Entry.new(@parent_heading, 'Anacin3')
27
+ entry = Entry.new(@parent_heading, 'Anacin3', :en_gb)
28
28
  assert_equal @parent_heading, entry.heading
29
29
  end
30
30
 
31
+ def test_has_locale
32
+ entry = Entry.new(@parent_heading, 'Anacin3', :en_gb)
33
+ assert_equal 1, entry.locales.length
34
+ assert_includes entry.locales, :en_gb
35
+ end
36
+
31
37
  def test_construct_from_plain_string
32
- entry = Entry.new(@parent_heading, 'Anacin3')
38
+ entry = Entry.new(@parent_heading, 'Anacin3', :en_gb)
33
39
  assert_equal 'Anacin3', entry.term
34
40
  assert_nil entry.semantic_relationship
35
41
  end
36
42
 
43
+ def test_has_match_key
44
+ entry = Entry.new(@parent_heading, 'Anacin3', :en_gb)
45
+ assert_equal 'ANACIN3', entry.loose_match_term
46
+ entry = Entry.new(@parent_heading, 'Anacin - 3', :en_gb)
47
+ assert_equal 'ANACIN 3', entry.loose_match_term
48
+ end
49
+
37
50
  def test_has_lexical_type
38
- entry = Entry.new(@parent_heading, 'Panadol|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef')
51
+ entry = Entry.new(@parent_heading, 'Panadol|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef', :en_gb)
39
52
  assert_equal 'Panadol', entry.term
40
53
  assert_equal :trade_name, entry.lexical_type
41
54
  end
42
55
 
43
56
  def test_has_semantic_relationship
44
- entry = Entry.new(@parent_heading, 'Panadol|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef')
57
+ entry = Entry.new(@parent_heading, 'Panadol|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef', :en_gb)
45
58
  assert_equal 'Panadol', entry.term
46
59
  assert_equal :narrower, entry.semantic_relationship
47
60
  end
48
61
 
49
62
  def test_has_semantic_types
50
- entry = Entry.new(@parent_heading, 'Panadol|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef')
63
+ entry = Entry.new(@parent_heading, 'Panadol|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef', :en_gb)
51
64
  assert_equal 'Panadol', entry.term
52
65
  assert_equal ['Organic Chemical', 'Pharmacologic Substance'], entry.semantic_types
53
66
  end
54
-
67
+
68
+ def test_knows_own_case_sensitivity
69
+ entry = Entry.new(@parent_heading, 'Panadol|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef', :en_gb)
70
+ refute entry.case_sensitive
71
+ entry = Entry.new(@parent_heading, 'AND|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef', :en_gb)
72
+ assert entry.case_sensitive
73
+ entry = Entry.new(@parent_heading, 'A122|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef', :en_gb)
74
+ assert entry.case_sensitive
75
+ entry = Entry.new(@parent_heading, 'Panadol978|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef', :en_gb)
76
+ refute entry.case_sensitive
77
+ end
78
+
79
+ def test_has_correct_case_insensitive_regex
80
+ entry = Entry.new(@parent_heading, 'Panadol|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef', :en_gb)
81
+ assert_equal /(^|\W)Panadol(\W|$)/i, entry.regex
82
+ end
83
+
84
+ def test_has_correct_case_sensitive_regex
85
+ entry = Entry.new(@parent_heading, 'AND|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef', :en_gb)
86
+ assert_equal /(^|\W)AND(\W|$)/, entry.regex
87
+ end
88
+
89
+ def test_matches_empty_when_given_empty_with_nil
90
+ entry = Entry.new(@parent_heading, 'WBC|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef', :en_gb)
91
+ assert_empty entry.match_in_text(nil, nil)
92
+ assert_empty entry.match_in_text('', '')
93
+ assert_empty entry.match_in_text("", "")
94
+ end
95
+
96
+ def test_matches_empty_when_no_matches
97
+ entry = Entry.new(@parent_heading, 'WBC|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef', :en_gb)
98
+ text = 'text that does not include the term'
99
+ assert_empty entry.match_in_text(text, text.downcase)
100
+ end
101
+
102
+ def test_matches_itself_in_text_when_all_caps
103
+ entry = Entry.new(@parent_heading, 'WBC|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef', :en_gb)
104
+
105
+ expected_matches = [
106
+ {heading: entry.heading, matched: entry, index: [720, 725]},
107
+ {heading: entry.heading, matched: entry, index: [795, 800]},
108
+ {heading: entry.heading, matched: entry, index: [7854, 7859]}
109
+ ]
110
+
111
+ actual_matches = entry.match_in_text(@example_text, @example_text.downcase)
112
+
113
+ refute_nil actual_matches
114
+ assert_equal expected_matches, actual_matches
115
+ end
116
+
117
+ def test_matches_itself_in_text
118
+ entry = Entry.new(@parent_heading, 'Leukaemia', :en_gb)
119
+
120
+ expected_matches = [
121
+ {heading: @parent_heading, matched: entry, index: [0, 10]},
122
+ {heading: @parent_heading, matched: entry, index: [51, 62]},
123
+ {heading: @parent_heading, matched: entry, index: [97, 108]},
124
+ {heading: @parent_heading, matched: entry, index: [678, 689]},
125
+ {heading: @parent_heading, matched: entry, index: [703, 714]},
126
+ {heading: @parent_heading, matched: entry, index: [807, 818]},
127
+ {heading: @parent_heading, matched: entry, index: [972, 983]},
128
+ {heading: @parent_heading, matched: entry, index: [1002, 1013]},
129
+ {heading: @parent_heading, matched: entry, index: [1085, 1096]},
130
+ {heading: @parent_heading, matched: entry, index: [1109, 1120]},
131
+ {heading: @parent_heading, matched: entry, index: [1190, 1201]},
132
+ {heading: @parent_heading, matched: entry, index: [1223, 1234]},
133
+ {heading: @parent_heading, matched: entry, index: [1326, 1337]},
134
+ {heading: @parent_heading, matched: entry, index: [1383, 1394]},
135
+ {heading: @parent_heading, matched: entry, index: [1411, 1422]},
136
+ {heading: @parent_heading, matched: entry, index: [1441, 1452]},
137
+ {heading: @parent_heading, matched: entry, index: [1568, 1579]},
138
+ {heading: @parent_heading, matched: entry, index: [1598, 1609]},
139
+ {heading: @parent_heading, matched: entry, index: [1754, 1765]},
140
+ {heading: @parent_heading, matched: entry, index: [1941, 1952]},
141
+ {heading: @parent_heading, matched: entry, index: [1961, 1972]},
142
+ {heading: @parent_heading, matched: entry, index: [1981, 1992]},
143
+ {heading: @parent_heading, matched: entry, index: [2412, 2423]},
144
+ {heading: @parent_heading, matched: entry, index: [2451, 2462]},
145
+ {heading: @parent_heading, matched: entry, index: [2594, 2605]},
146
+ {heading: @parent_heading, matched: entry, index: [2922, 2933]},
147
+ {heading: @parent_heading, matched: entry, index: [3038, 3049]},
148
+ {heading: @parent_heading, matched: entry, index: [3433, 3444]},
149
+ {heading: @parent_heading, matched: entry, index: [3555, 3566]},
150
+ {heading: @parent_heading, matched: entry, index: [3686, 3697]},
151
+ {heading: @parent_heading, matched: entry, index: [3899, 3910]},
152
+ {heading: @parent_heading, matched: entry, index: [3980, 3991]},
153
+ {heading: @parent_heading, matched: entry, index: [4031, 4042]},
154
+ {heading: @parent_heading, matched: entry, index: [4499, 4510]},
155
+ {heading: @parent_heading, matched: entry, index: [4677, 4688]},
156
+ {heading: @parent_heading, matched: entry, index: [4762, 4773]},
157
+ {heading: @parent_heading, matched: entry, index: [4847, 4858]},
158
+ {heading: @parent_heading, matched: entry, index: [5569, 5580]},
159
+ {heading: @parent_heading, matched: entry, index: [5606, 5617]},
160
+ {heading: @parent_heading, matched: entry, index: [5707, 5718]},
161
+ {heading: @parent_heading, matched: entry, index: [5924, 5935]},
162
+ {heading: @parent_heading, matched: entry, index: [6347, 6358]},
163
+ {heading: @parent_heading, matched: entry, index: [7905, 7916]},
164
+ {heading: @parent_heading, matched: entry, index: [8065, 8076]},
165
+ {heading: @parent_heading, matched: entry, index: [8394, 8405]},
166
+ {heading: @parent_heading, matched: entry, index: [8416, 8427]},
167
+ {heading: @parent_heading, matched: entry, index: [8581, 8592]},
168
+ {heading: @parent_heading, matched: entry, index: [8603, 8614]},
169
+ {heading: @parent_heading, matched: entry, index: [9168, 9179]},
170
+ {heading: @parent_heading, matched: entry, index: [9246, 9257]},
171
+ {heading: @parent_heading, matched: entry, index: [10403, 10414]},
172
+ {heading: @parent_heading, matched: entry, index: [10958, 10969]},
173
+ {heading: @parent_heading, matched: entry, index: [11249, 11260]}
174
+ ]
175
+
176
+ actual_matches = entry.match_in_text(@example_text, @example_text.downcase)
177
+
178
+ refute_nil actual_matches
179
+ expected_indexes = expected_matches.map { |match| match[:index] }
180
+ actual_indexes = actual_matches.map { |match| match[:index] }
181
+ assert_equal expected_indexes, actual_indexes #to show index diffs more easily
182
+ assert_equal expected_matches, actual_matches
183
+ end
184
+
55
185
  def test_datril
56
186
  # ENTRY =
57
- entry = Entry.new(@parent_heading, 'Datril|T109|T121|NON|NRW|UNK (19XX)|861119|abbcdef')
187
+ entry = Entry.new(@parent_heading, 'Datril|T109|T121|NON|NRW|UNK (19XX)|861119|abbcdef', :en_gb)
58
188
  assert_equal 'Datril', entry.term
59
189
  assert_equal ['Organic Chemical', 'Pharmacologic Substance'], entry.semantic_types
60
190
  assert_nil entry.lexical_type
61
191
  assert_equal :narrower, entry.semantic_relationship
62
192
  end
63
193
 
194
+ def test_acetamidophenol
195
+ entry = Entry.new(@parent_heading, 'p-Acetamidophenol|T109|T121|NON|EQV|UNK (19XX)|800813|abbcdef', :en_gb)
196
+ assert_equal 'p-Acetamidophenol', entry.term
197
+ assert_equal ['Organic Chemical', 'Pharmacologic Substance'], entry.semantic_types
198
+ assert_nil entry.lexical_type
199
+ assert_equal :equivalent, entry.semantic_relationship
200
+ end
201
+
64
202
  # def test_semantic_relationship
65
203
  # skip
66
204
  # # ABB (Abbreviation)
@@ -84,7 +222,7 @@ module MESH
84
222
 
85
223
  def setup
86
224
  @mesh_tree = @@mesh_tree
87
- @parent_heading = @mesh_tree.find('D000234')
225
+ @parent_heading = @mesh_tree.find_heading_by_unique_id('D000234')
88
226
  end
89
227
 
90
228
  end
@@ -4,108 +4,107 @@ module MESH
4
4
  class HeadingTest < TestBase
5
5
 
6
6
  def test_have_the_correct_unique_id
7
- mh = @mesh_tree.find('D000001')
7
+ mh = @mesh_tree.find_heading_by_unique_id('D000001')
8
8
  assert_equal 'D000001', mh.unique_id
9
9
  end
10
10
 
11
11
  def test_have_the_correct_tree_number
12
- mh = @mesh_tree.find('D000001')
12
+ mh = @mesh_tree.find_heading_by_unique_id('D000001')
13
13
  assert_equal 1, mh.tree_numbers.length
14
14
  assert_includes mh.tree_numbers, 'D03.438.221.173'
15
15
  end
16
16
 
17
17
  def test_have_the_correct_tree_numbers
18
- mh = @mesh_tree.find('D000224')
18
+ mh = @mesh_tree.find_heading_by_unique_id('D000224')
19
19
  assert_equal 2, mh.tree_numbers.length
20
20
  assert_includes mh.tree_numbers, 'C19.053.500.263'
21
21
  assert_includes mh.tree_numbers, 'C20.111.163'
22
22
  end
23
23
 
24
24
  def test_have_the_correct_root_letters
25
- mh = @mesh_tree.find('D000224')
25
+ mh = @mesh_tree.find_heading_by_unique_id('D000224')
26
26
  assert_equal ['C'], mh.roots
27
- mh = @mesh_tree.find('D064946')
27
+ mh = @mesh_tree.find_heading_by_unique_id('D064946')
28
28
  assert_equal ['H', 'N'], mh.roots
29
29
  end
30
30
 
31
31
  def test_have_the_correct_descriptor_class
32
- mh = @mesh_tree.find('D000224')
32
+ mh = @mesh_tree.find_heading_by_unique_id('D000224')
33
33
  assert_equal :topical_descriptor, mh.descriptor_class
34
- mh = @mesh_tree.find('D005260')
34
+ mh = @mesh_tree.find_heading_by_unique_id('D005260')
35
35
  assert_equal :check_tag, mh.descriptor_class
36
36
  end
37
37
 
38
38
  def test_have_the_correct_semantic_type
39
- mh = @mesh_tree.find('D000224')
39
+ mh = @mesh_tree.find_heading_by_unique_id('D000224')
40
40
  assert_equal ['Disease or Syndrome'], mh.semantic_types
41
- mh = @mesh_tree.find('D005260')
41
+ mh = @mesh_tree.find_heading_by_unique_id('D005260')
42
42
  assert_equal ['Organism Attribute'], mh.semantic_types
43
- mh = @mesh_tree.find('D014148')
43
+ mh = @mesh_tree.find_heading_by_unique_id('D014148')
44
44
  assert_equal ['Organic Chemical', 'Pharmacologic Substance'], mh.semantic_types
45
45
 
46
46
  end
47
47
 
48
48
  def test_have_the_correct_original_heading
49
- mh = @mesh_tree.find('D000224')
49
+ mh = @mesh_tree.find_heading_by_unique_id('D000224')
50
50
  assert_equal 'Addison Disease', mh.original_heading
51
- mh = @mesh_tree.find('D000014')
51
+ mh = @mesh_tree.find_heading_by_unique_id('D000014')
52
52
  assert_equal 'Abnormalities, Drug-Induced', mh.original_heading
53
53
  end
54
54
 
55
55
  def test_have_anglicised_original_heading
56
- mh = @mesh_tree.find('D001471')
56
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
57
57
  assert_equal 'Barrett Esophagus', mh.original_heading
58
58
  assert_equal 'Barrett Oesophagus', mh.original_heading(:en_gb)
59
59
  end
60
60
 
61
61
  def test_have_natural_language_name
62
- mh = @mesh_tree.find('D000224')
62
+ mh = @mesh_tree.find_heading_by_unique_id('D000224')
63
63
  assert_equal 'Addison Disease', mh.natural_language_name
64
- mh = @mesh_tree.find('D000014')
64
+ mh = @mesh_tree.find_heading_by_unique_id('D000014')
65
65
  assert_equal 'Drug-Induced Abnormalities', mh.natural_language_name
66
66
  end
67
67
 
68
68
  def test_have_anglicised_natural_language_name
69
- mh = @mesh_tree.find('D001471')
69
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
70
70
  assert_equal 'Barrett Esophagus', mh.natural_language_name
71
71
  assert_equal 'Barrett Oesophagus', mh.natural_language_name(:en_gb)
72
72
  end
73
73
 
74
74
  def test_have_the_correct_summary
75
- mh = @mesh_tree.find('D000238')
75
+ mh = @mesh_tree.find_heading_by_unique_id('D000238')
76
76
  assert_equal 'A benign tumor of the anterior pituitary in which the cells do not stain with acidic or basic dyes.', mh.summary
77
77
  end
78
78
 
79
79
  def test_have_anglicised_summary
80
- mh = @mesh_tree.find('D001471')
80
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
81
81
  assert_equal 'A condition with damage to the lining of the lower ESOPHAGUS resulting from chronic acid reflux (ESOPHAGITIS, REFLUX). Through the process of metaplasia, the squamous cells are replaced by a columnar epithelium with cells resembling those of the INTESTINE or the salmon-pink mucosa of the STOMACH. Barrett\'s columnar epithelium is a marker for severe reflux and precursor to ADENOCARCINOMA of the esophagus.', mh.summary
82
82
  assert_equal 'A condition with damage to the lining of the lower OESOPHAGUS resulting from chronic acid reflux (OESOPHAGITIS, REFLUX). Through the process of metaplasia, the squamous cells are replaced by a columnar epithelium with cells resembling those of the INTESTINE or the salmon-pink mucosa of the STOMACH. Barrett\'s columnar epithelium is a marker for severe reflux and precursor to ADENOCARCINOMA of the oesophagus.', mh.summary(:en_gb)
83
83
  end
84
84
 
85
85
  def test_linkify_summary
86
- mh = @mesh_tree.find('D001471')
86
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
87
87
  original_summary = 'A condition with damage to the lining of the lower ESOPHAGUS resulting from chronic acid reflux (ESOPHAGITIS, REFLUX). Through the process of metaplasia, the squamous cells are replaced by a columnar epithelium with cells resembling those of the INTESTINE or the salmon-pink mucosa of the STOMACH. Barrett\'s columnar epithelium is a marker for severe reflux and precursor to ADENOCARCINOMA of the esophagus.'
88
88
  assert_equal original_summary, mh.summary
89
89
 
90
90
  found = {
91
- 'ESOPHAGUS' => false,
92
- 'ESOPHAGITIS, REFLUX' => false,
93
- 'INTESTINE' => false,
94
- 'STOMACH' => false,
95
- 'ADENOCARCINOMA' => false
91
+ 'ESOPHAGUS' => false,
92
+ 'ESOPHAGITIS, REFLUX' => false,
93
+ 'INTESTINE' => false,
94
+ 'STOMACH' => false,
95
+ 'ADENOCARCINOMA' => false
96
96
  }
97
97
 
98
- linkified_summary = mh.linkify_summary do |text, heading|
99
- found[text] = true unless heading.nil?
98
+ linkified_summary = mh.linkify_summary do |text, entry|
99
+ found[text] = entry
100
100
  "<foo>#{text.downcase}</foo>"
101
101
  end
102
102
 
103
103
  assert_equal 5, found.length
104
- assert found['ESOPHAGUS']
105
- assert found['ESOPHAGITIS, REFLUX']
106
- assert found['INTESTINE']
107
- assert found['STOMACH']
108
- assert found['ADENOCARCINOMA']
104
+ found.each do |text, found_entry|
105
+ refute_nil found_entry, "Linkify found '#{text}' but entry was nil"
106
+ assert found_entry, "Linkify failed to find '#{text}'"
107
+ end
109
108
 
110
109
  assert_equal original_summary, mh.summary
111
110
  assert_equal 'A condition with damage to the lining of the lower <foo>esophagus</foo> resulting from chronic acid reflux (<foo>esophagitis, reflux</foo>). Through the process of metaplasia, the squamous cells are replaced by a columnar epithelium with cells resembling those of the <foo>intestine</foo> or the salmon-pink mucosa of the <foo>stomach</foo>. Barrett\'s columnar epithelium is a marker for severe reflux and precursor to <foo>adenocarcinoma</foo> of the esophagus.', linkified_summary
@@ -113,9 +112,9 @@ module MESH
113
112
  end
114
113
 
115
114
  def test_linkifies_another_summary
116
- mh = @mesh_tree.find_by_original_heading('Diabetic Nephropathies')
117
- linkified_summary = mh.linkify_summary do |text, heading|
118
- "<linky href=\"#{heading.unique_id}\">#{text.downcase}</linky>"
115
+ mh = @mesh_tree.find_heading_by_main_heading('Diabetic Nephropathies')
116
+ linkified_summary = mh.linkify_summary do |text, entry|
117
+ "<linky href=\"#{entry.heading.unique_id}\">#{text.downcase}</linky>"
119
118
  end
120
119
 
121
120
  expected_summary = 'KIDNEY injuries associated with diabetes mellitus and affecting KIDNEY GLOMERULUS; ARTERIOLES; KIDNEY TUBULES; and the interstitium. Clinical signs include persistent PROTEINURIA, from microalbuminuria progressing to ALBUMINURIA of greater than 300 mg/24 h, leading to reduced GLOMERULAR FILTRATION RATE and END-STAGE RENAL DISEASE.'
@@ -128,72 +127,79 @@ module MESH
128
127
  end
129
128
 
130
129
  def test_to_s
131
- mh = @mesh_tree.find('D001471')
130
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
132
131
  assert_equal 'D001471, Barrett Esophagus, [C06.198.102,C06.405.117.102]', mh.to_s
133
132
  end
134
133
 
135
134
  def test_have_the_correct_entries
136
- expected_entries = ['Activity Cycles', 'Ultradian Cycles', 'Activity Cycle', 'Cycle, Activity', 'Cycle, Ultradian', 'Cycles, Activity', 'Cycles, Ultradian', 'Ultradian Cycle']
137
- expected_entries.sort!
138
- mh = @mesh_tree.find('D000204')
139
- assert_equal expected_entries, mh.entries
135
+ expected_terms = ['Activity Cycles', 'Ultradian Cycles', 'Activity Cycle', 'Cycle, Activity', 'Cycle, Ultradian',
136
+ 'Cycles, Activity', 'Cycles, Ultradian', 'Ultradian Cycle']
137
+ mh = @mesh_tree.find_heading_by_unique_id('D000204')
138
+ actual_terms = mh.structured_entries.map { |entry| entry.term }
139
+ assert_equal expected_terms.sort, actual_terms.sort
140
140
  end
141
141
 
142
142
  def test_have_anglicised_entries
143
- expected_entries = ['Barrett Esophagus', 'Barrett Syndrome', 'Esophagus, Barrett', 'Barrett Epithelium', 'Barrett Metaplasia', 'Barrett\'s Esophagus', 'Barrett\'s Syndrome', 'Barretts Esophagus', 'Barretts Syndrome', 'Epithelium, Barrett', 'Esophagus, Barrett\'s', 'Syndrome, Barrett', 'Syndrome, Barrett\'s']
144
- expected_entries_en = ['Barrett Oesophagus', 'Barrett Syndrome', 'Oesophagus, Barrett', 'Barrett Epithelium', 'Barrett Metaplasia', 'Barrett\'s Oesophagus', 'Barrett\'s Syndrome', 'Barretts Oesophagus', 'Barretts Syndrome', 'Epithelium, Barrett', 'Oesophagus, Barrett\'s', 'Syndrome, Barrett', 'Syndrome, Barrett\'s']
143
+ expected_entries = ["Barrett Epithelium", "Barrett Esophagus", "Barrett Metaplasia", "Barrett Oesophagus", "Barrett Syndrome",
144
+ "Barrett's Esophagus", "Barrett's Oesophagus", "Barrett's Syndrome", "Barretts Esophagus", "Barretts Oesophagus",
145
+ "Barretts Syndrome", "Epithelium, Barrett", "Esophagus, Barrett", "Esophagus, Barrett's", "Oesophagus, Barrett",
146
+ "Oesophagus, Barrett's", "Syndrome, Barrett", "Syndrome, Barrett's"]
147
+ expected_entries_en = ['Barrett Oesophagus', 'Barrett Syndrome', 'Oesophagus, Barrett', 'Barrett Epithelium',
148
+ 'Barrett Metaplasia', 'Barrett\'s Oesophagus', 'Barrett\'s Syndrome', 'Barretts Oesophagus',
149
+ 'Barretts Syndrome', 'Epithelium, Barrett', 'Oesophagus, Barrett\'s', 'Syndrome, Barrett',
150
+ 'Syndrome, Barrett\'s']
145
151
 
146
152
  expected_entries.sort!
147
153
  expected_entries_en.sort!
148
- mh = @mesh_tree.find('D001471')
149
- assert_equal expected_entries.sort, mh.entries
150
- assert_equal expected_entries_en.sort, mh.entries(:en_gb)
154
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
155
+ actual_entry_terms_all = mh.structured_entries.map { |entry| entry.term }
156
+ en_gb_entries = mh.structured_entries.select { |entry| entry.locales.include? :en_gb }
157
+ en_gb_terms = en_gb_entries.map { |entry| entry.term }
158
+ assert_equal expected_entries.sort, actual_entry_terms_all.sort
159
+ assert_equal expected_entries_en.sort, en_gb_terms.sort
151
160
  end
152
161
 
153
- def test_has_structured_entries
162
+ def test_structured_entries_have_duplicates_with_MH
163
+ skip
164
+ #todo for test_has_structured_entries
165
+ #ideally shouldn't have Acetominophen duplicated.
154
166
 
155
- mh = @mesh_tree.find_by_original_heading('Acetaminophen')
156
- assert_equal 19, mh.structured_entries.length
167
+ end
157
168
 
158
- expected_terms = ['Acetamidophenol', 'Hydroxyacetanilide', 'Paracetamol', 'APAP', 'Acamol', 'Acephen', 'Acetaco', 'Acetominophen', 'Algotropyl', 'Anacin-3', 'Datril', 'N-(4-Hydroxyphenyl)acetanilide', 'N-Acetyl-p-aminophenol', 'Panadol', 'Tylenol', 'p-Acetamidophenol', 'p-Hydroxyacetanilide', 'Anacin 3', 'Anacin3']
169
+ def test_has_structured_entries
170
+ mh = @mesh_tree.find_heading_by_main_heading('Acetaminophen')
171
+ expected_terms = ['APAP', 'Acamol', 'Acephen', 'Acetaco', 'Acetamidophenol', 'Acetaminophen', 'Acetominophen',
172
+ 'Algotropyl', 'Anacin 3', 'Anacin-3', 'Anacin3', 'Datril', 'Hydroxyacetanilide',
173
+ 'N-(4-Hydroxyphenyl)acetanilide', 'N-Acetyl-p-aminophenol', 'Panadol', 'Paracetamol', 'Tylenol',
174
+ 'p-Acetamidophenol', 'p-Hydroxyacetanilide']
159
175
 
160
176
  actual_terms = mh.structured_entries.map { |tn| tn.term }
161
-
162
- assert_equal actual_terms, expected_terms
163
-
164
-
165
- # PRINT ENTRY = Acetamidophenol|T109|T121|NON|EQV|UNK (19XX)|771118|abbcdef
166
- # PRINT ENTRY = Hydroxyacetanilide|T109|T121|NON|EQV|UNK (19XX)|740329|abbcdef
167
- # PRINT ENTRY = Paracetamol|T109|T121|NON|EQV|BAN (19XX)|FDA SRS (2014)|INN (19XX)|740329|abbcdeeef
168
- # ENTRY = APAP|T109|T121|NON|EQV|BAN (19XX)|FDA SRS (2014)|020515|abbcdeef
169
- # ENTRY = Acamol|T109|T121|TRD|NRW|NLM (1995)|930902|abbcdef
170
- # ENTRY = Acephen|T109|T121|TRD|NRW|NLM (1991)|900509|abbcdef
171
- # ENTRY = Acetaco|T109|T121|TRD|REL|UNK (19XX)|861022|abbcdef
172
- # ENTRY = Acetominophen|T109|T121|NON|EQV|UNK (19XX)|810625|abbcdef
173
- # ENTRY = Algotropyl|T109|T121|TRD|REL|UNK (19XX)|800825|abbcdef
174
- # ENTRY = Anacin-3|T109|T121|TRD|NRW|UNK (19XX)|861119|abbcdef
175
- # ENTRY = Datril|T109|T121|NON|NRW|UNK (19XX)|861119|abbcdef
176
- # ENTRY = N-(4-Hydroxyphenyl)acetanilide|T109|T121|NON|EQV|NLM (1996)|950330|abbcdef
177
- # ENTRY = N-Acetyl-p-aminophenol|T109|T121|NON|EQV|UNK (19XX)|800813|abbcdef
178
- # ENTRY = Panadol|T109|T121|TRD|NRW|UNK (19XX)|830915|abbcdef
179
- # ENTRY = Tylenol|T109|T121|TRD|NRW|UNK (19XX)|830223|abbcdef
180
- # ENTRY = p-Acetamidophenol|T109|T121|NON|EQV|UNK (19XX)|800813|abbcdef
181
- # ENTRY = p-Hydroxyacetanilide|T109|T121|NON|EQV|UNK (19XX)|800801|abbcdef
182
- # ENTRY = Anacin 3
183
- # ENTRY = Anacin3
184
-
177
+ assert_equal expected_terms.sort, actual_terms.sort
178
+ end
179
+
180
+ def test_has_entries_by_term
181
+ mh = @mesh_tree.find_heading_by_main_heading('Acetaminophen')
182
+ expected_terms = ['Acetamidophenol', 'Hydroxyacetanilide', 'Paracetamol', 'APAP', 'Acamol', 'Acephen', 'Acetaco',
183
+ 'Acetominophen', 'Acetominophen', 'Algotropyl', 'Anacin-3', 'Datril', 'N-(4-Hydroxyphenyl)acetanilide',
184
+ 'N-Acetyl-p-aminophenol', 'Panadol', 'Tylenol', 'p-Acetamidophenol', 'p-Hydroxyacetanilide',
185
+ 'Anacin 3', 'Anacin3']
186
+ entries_by_term = mh.entries_by_term
187
+ assert_equal expected_terms.length, entries_by_term.length
188
+ expected_terms.each do |expected_term|
189
+ assert_equal expected_term, entries_by_term[expected_term].term
190
+ end
185
191
  end
186
192
 
187
193
  def test_have_a_single_wikipedia_link
188
194
 
189
195
  expected = {
190
- 'D000001' => 'http://en.wikipedia.org/wiki/A23187',
191
- 'D000005' => 'http://en.wikipedia.org/wiki/Abdomen',
192
- 'D000082' => 'http://en.wikipedia.org/wiki/Paracetamol'
196
+ 'D000001' => 'http://en.wikipedia.org/wiki/A23187',
197
+ 'D000005' => 'http://en.wikipedia.org/wiki/Abdomen',
198
+ 'D000082' => 'http://en.wikipedia.org/wiki/Paracetamol'
193
199
  }
194
200
 
195
201
  expected.each do |id, expected_link|
196
- mh = @mesh_tree.find(id)
202
+ mh = @mesh_tree.find_heading_by_unique_id(id)
197
203
  assert_equal 1, mh.wikipedia_links.length
198
204
  assert_equal expected_link, mh.wikipedia_links[0][:link]
199
205
  end
@@ -202,13 +208,13 @@ module MESH
202
208
 
203
209
  def test_have_a_single_wikipedia_score
204
210
  expected = {
205
- 'D000001' => 0.5,
206
- 'D000005' => 1.0,
207
- 'D000082' => 0.35
211
+ 'D000001' => 0.5,
212
+ 'D000005' => 1.0,
213
+ 'D000082' => 0.35
208
214
  }
209
215
 
210
216
  expected.each do |id, expected_score|
211
- mh = @mesh_tree.find(id)
217
+ mh = @mesh_tree.find_heading_by_unique_id(id)
212
218
  assert_equal 1, mh.wikipedia_links.length
213
219
  assert_equal expected_score, mh.wikipedia_links[0][:score]
214
220
  end
@@ -217,13 +223,13 @@ module MESH
217
223
 
218
224
  def test_have_a_single_wikipedia_image
219
225
  expected = {
220
- 'D000001' => 'http://upload.wikimedia.org/wikipedia/commons/thumb/1/17/A23187.png/220px-A23187.png',
221
- 'D000005' => 'http://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Abdomen_%28PSF%29.jpg/250px-Abdomen_%28PSF%29.jpg',
222
- 'D000082' => 'http://upload.wikimedia.org/wikipedia/commons/thumb/2/29/Paracetamol-skeletal.svg/150px-Paracetamol-skeletal.svg.png'
226
+ 'D000001' => 'http://upload.wikimedia.org/wikipedia/commons/thumb/1/17/A23187.png/220px-A23187.png',
227
+ 'D000005' => 'http://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Abdomen_%28PSF%29.jpg/250px-Abdomen_%28PSF%29.jpg',
228
+ 'D000082' => 'http://upload.wikimedia.org/wikipedia/commons/thumb/2/29/Paracetamol-skeletal.svg/150px-Paracetamol-skeletal.svg.png'
223
229
  }
224
230
 
225
231
  expected.each do |id, expected_image|
226
- mh = @mesh_tree.find(id)
232
+ mh = @mesh_tree.find_heading_by_unique_id(id)
227
233
  assert_equal 1, mh.wikipedia_links.length
228
234
  assert_equal expected_image, mh.wikipedia_links[0][:image]
229
235
  end
@@ -231,20 +237,20 @@ module MESH
231
237
 
232
238
  def test_have_a_single_wikipedia_abstract
233
239
  expected = {
234
- 'D000001' => '| CAS_number = 52665-69-7',
235
- 'D000005' => 'The abdomen (less formally called the belly, stomach, or tummy), in vertebrates such as mammals, constitutes the part of the body between the thorax (chest) and pelvis. The region enclosed by the abdomen is termed the abdominal cavity.',
236
- 'D000082' => '| MedlinePlus = a681004'
240
+ 'D000001' => '| CAS_number = 52665-69-7',
241
+ 'D000005' => 'The abdomen (less formally called the belly, stomach, or tummy), in vertebrates such as mammals, constitutes the part of the body between the thorax (chest) and pelvis. The region enclosed by the abdomen is termed the abdominal cavity.',
242
+ 'D000082' => '| MedlinePlus = a681004'
237
243
  }
238
244
 
239
245
  expected.each do |id, expected_abstract|
240
- mh = @mesh_tree.find(id)
246
+ mh = @mesh_tree.find_heading_by_unique_id(id)
241
247
  assert_equal 1, mh.wikipedia_links.length
242
248
  assert_equal expected_abstract, mh.wikipedia_links[0][:abstract]
243
249
  end
244
250
  end
245
251
 
246
252
  def test_have_more_than_one_wikipedia_link
247
- mh = @mesh_tree.find('D000100')
253
+ mh = @mesh_tree.find_heading_by_unique_id('D000100')
248
254
  expected = %w(
249
255
  http://en.wikipedia.org/wiki/Sodium_acetrizoate
250
256
  http://en.wikipedia.org/wiki/Acetrizoic_acid
@@ -253,13 +259,13 @@ module MESH
253
259
  end
254
260
 
255
261
  def test_have_more_than_one_wikipedia_score
256
- mh = @mesh_tree.find('D000100')
262
+ mh = @mesh_tree.find_heading_by_unique_id('D000100')
257
263
  expected = [0.09, 0.09]
258
264
  assert_equal expected, mh.wikipedia_links.map { |l| l[:score] }
259
265
  end
260
266
 
261
267
  def test_have_more_than_one_wikipedia_image
262
- mh = @mesh_tree.find('D000100')
268
+ mh = @mesh_tree.find_heading_by_unique_id('D000100')
263
269
  expected = %w(
264
270
  http://upload.wikimedia.org/wikipedia/commons/thumb/4/4d/Sodium_acetrizoate.svg/150px-Sodium_acetrizoate.svg.png
265
271
  http://upload.wikimedia.org/wikipedia/commons/thumb/2/26/Acetrizoic_acid.png/220px-Acetrizoic_acid.png
@@ -268,39 +274,39 @@ module MESH
268
274
  end
269
275
 
270
276
  def test_have_more_than_one_wikipedia_abstract
271
- mh = @mesh_tree.find('D000100')
277
+ mh = @mesh_tree.find_heading_by_unique_id('D000100')
272
278
  expected = ['| CAS_number = 129-63-5', '| CAS_number = 85-36-9']
273
279
  assert_equal expected, mh.wikipedia_links.map { |l| l[:abstract] }
274
280
  end
275
281
 
276
282
  def test_have_the_correct_parent
277
- mh = @mesh_tree.find('D000001')
283
+ mh = @mesh_tree.find_heading_by_unique_id('D000001')
278
284
  assert_equal 1, mh.parents.length
279
285
  assert_equal 'D001583', mh.parents[0].unique_id
280
286
  end
281
287
 
282
288
  def test_have_the_correct_parents
283
- mh = @mesh_tree.find('D000224')
284
- p1 = @mesh_tree.find('D000309')
285
- p2 = @mesh_tree.find('D001327')
289
+ mh = @mesh_tree.find_heading_by_unique_id('D000224')
290
+ p1 = @mesh_tree.find_heading_by_unique_id('D000309')
291
+ p2 = @mesh_tree.find_heading_by_unique_id('D001327')
286
292
  assert_equal 2, mh.parents.length
287
293
  assert_includes mh.parents, p1
288
294
  assert_includes mh.parents, p2
289
295
  end
290
296
 
291
297
  def test_have_the_correct_parents_again
292
- child = @mesh_tree.find_by_original_heading('Questionnaires')
298
+ child = @mesh_tree.find_heading_by_main_heading('Questionnaires')
293
299
  assert_equal 1, child.parents.length
294
- expected_parent = @mesh_tree.find_by_original_heading('Data Collection')
300
+ expected_parent = @mesh_tree.find_heading_by_main_heading('Data Collection')
295
301
  assert_includes child.parents, expected_parent
296
302
  end
297
303
 
298
304
  def test_have_the_correct_children
299
- parent = @mesh_tree.find_by_tree_number('C19.053.500')
300
- child1 = @mesh_tree.find_by_tree_number('C19.053.500.263')
301
- child2 = @mesh_tree.find_by_tree_number('C19.053.500.270')
302
- child3 = @mesh_tree.find_by_tree_number('C19.053.500.480')
303
- child4 = @mesh_tree.find_by_tree_number('C19.053.500.740')
305
+ parent = @mesh_tree.find_heading_by_tree_number('C19.053.500')
306
+ child1 = @mesh_tree.find_heading_by_tree_number('C19.053.500.263')
307
+ child2 = @mesh_tree.find_heading_by_tree_number('C19.053.500.270')
308
+ child3 = @mesh_tree.find_heading_by_tree_number('C19.053.500.480')
309
+ child4 = @mesh_tree.find_heading_by_tree_number('C19.053.500.740')
304
310
 
305
311
  assert_equal 4, parent.children.length
306
312
  assert_includes parent.children, child1
@@ -310,24 +316,24 @@ module MESH
310
316
  end
311
317
 
312
318
  def test_have_the_correct_children_again
313
- parent = @mesh_tree.find_by_original_heading('Data Collection')
319
+ parent = @mesh_tree.find_heading_by_main_heading('Data Collection')
314
320
 
315
321
  expected_children = [
316
- 'Health Surveys',
317
- 'Interviews as Topic',
318
- 'Questionnaires',
319
- 'Records as Topic',
320
- 'Registries',
321
- 'Vital Statistics',
322
- 'Geriatric Assessment',
323
- 'Nutrition Assessment',
324
- 'Health Care Surveys',
325
- 'Narration',
326
- 'Lot Quality Assurance Sampling',
327
- 'Checklist',
328
- 'Health Impact Assessment',
329
- 'Crowdsourcing'
330
- ].map { |oh| @mesh_tree.find_by_original_heading(oh) }
322
+ 'Health Surveys',
323
+ 'Interviews as Topic',
324
+ 'Questionnaires',
325
+ 'Records as Topic',
326
+ 'Registries',
327
+ 'Vital Statistics',
328
+ 'Geriatric Assessment',
329
+ 'Nutrition Assessment',
330
+ 'Health Care Surveys',
331
+ 'Narration',
332
+ 'Lot Quality Assurance Sampling',
333
+ 'Checklist',
334
+ 'Health Impact Assessment',
335
+ 'Crowdsourcing'
336
+ ].map { |oh| @mesh_tree.find_heading_by_main_heading(oh) }
331
337
 
332
338
 
333
339
  assert_equal expected_children.length, parent.children.length
@@ -337,19 +343,19 @@ module MESH
337
343
  end
338
344
 
339
345
  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')
346
+ mh = @mesh_tree.find_heading_by_main_heading('Abdominal Muscles')
347
+ fx = @mesh_tree.find_heading_by_main_heading('Abdominal Wall')
342
348
  assert_equal [fx], mh.forward_references
343
349
  end
344
350
 
345
351
  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')
352
+ mh = @mesh_tree.find_heading_by_main_heading('Acquired Immunodeficiency Syndrome')
353
+ fx1 = @mesh_tree.find_heading_by_main_heading('AIDS Arteritis, Central Nervous System')
354
+ fx2 = @mesh_tree.find_heading_by_main_heading('AIDS Dementia Complex')
355
+ fx3 = @mesh_tree.find_heading_by_main_heading('AIDS Serodiagnosis')
356
+ fx4 = @mesh_tree.find_heading_by_main_heading('HIV Seropositivity')
357
+ fx5 = @mesh_tree.find_heading_by_main_heading('HIV Seroprevalence')
358
+ fx6 = @mesh_tree.find_heading_by_main_heading('Lymphoma, AIDS-Related')
353
359
 
354
360
  assert_equal [fx1, fx2, fx3, fx4, fx5, fx6], mh.forward_references
355
361
  end
@@ -359,36 +365,36 @@ module MESH
359
365
  end
360
366
 
361
367
  def test_match_on_conditions_for_original_heading
362
- mh = @mesh_tree.find('D001471')
368
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
363
369
  assert mh.matches(original_heading: /^Barrett Esophagus$/)
364
370
  end
365
371
 
366
372
  def test_not_match_on_incorrect_condition_for_original_heading
367
- mh = @mesh_tree.find('D001471')
373
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
368
374
  refute mh.matches(original_heading: /^Foo$/)
369
375
  end
370
376
 
371
377
  def test_match_on_conditions_for_entries
372
- mh = @mesh_tree.find('D001471')
378
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
373
379
  assert mh.matches(entries: /Metaplasia/)
374
380
  end
375
381
 
376
382
  def test_not_match_on_incorrect_conditions_for_entries
377
- mh = @mesh_tree.find('D001471')
383
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
378
384
  refute mh.matches(entries: /Foo/)
379
385
  end
380
386
 
381
387
  def test_match_on_descriptor_class
382
- mh = @mesh_tree.find('D000224')
388
+ mh = @mesh_tree.find_heading_by_unique_id('D000224')
383
389
  assert mh.matches(descriptor_class: :topical_descriptor)
384
390
  refute mh.matches(descriptor_class: :check_tag)
385
- mh = @mesh_tree.find('D005260')
391
+ mh = @mesh_tree.find_heading_by_unique_id('D005260')
386
392
  assert mh.matches(descriptor_class: :check_tag)
387
393
  refute mh.matches(descriptor_class: :topical_descriptor)
388
394
  end
389
395
 
390
396
  def test_match_on_conditions_for_tree_numbers
391
- mh = @mesh_tree.find('D001471')
397
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
392
398
  assert mh.matches(tree_numbers: /C06\.198\.102/)
393
399
  assert mh.matches(tree_numbers: /^C06\.198\.102$/)
394
400
  assert mh.matches(tree_numbers: /^C06/)
@@ -397,22 +403,22 @@ module MESH
397
403
  end
398
404
 
399
405
  def test_not_match_on_incorrect_conditions_for_tree_numbers
400
- mh = @mesh_tree.find('D001471')
406
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
401
407
  refute mh.matches(tree_numbers: /Foo/)
402
408
  end
403
409
 
404
410
  def test_match_on_conditions_for_summary
405
- mh = @mesh_tree.find('D001471')
411
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
406
412
  assert mh.matches(summary: /the lower ESOPHAGUS resulting from chronic acid reflux \(ESOPHAGITIS, REFLUX\)\./)
407
413
  end
408
414
 
409
415
  def test_not_match_on_incorrect_conditions_for_summary
410
- mh = @mesh_tree.find('D001471')
416
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
411
417
  refute mh.matches(summary: /Foo/)
412
418
  end
413
419
 
414
420
  def test_match_on_conditions_for_useful
415
- mh = @mesh_tree.find('D001471')
421
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
416
422
  begin
417
423
  mh.useful = true
418
424
  assert mh.matches(useful: true)
@@ -426,18 +432,18 @@ module MESH
426
432
  end
427
433
 
428
434
  def test_match_on_multiple_conditions
429
- mh = @mesh_tree.find('D001471')
435
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
430
436
  assert mh.matches(original_heading: /^Barrett Esophagus$/, summary: /the lower ESOPHAGUS/)
431
437
  end
432
438
 
433
439
  def test_not_match_on_incorrect_multiple_conditions
434
- mh = @mesh_tree.find('D001471')
440
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
435
441
  refute mh.matches(original_heading: /^Barrett Esophagus$/, summary: /Foo/)
436
442
  refute mh.matches(original_heading: /^Foo/, summary: /the lower ESOPHAGUS/)
437
443
  end
438
444
 
439
445
  def test_allow_headings_to_be_marked_as_not_useful
440
- mh = @mesh_tree.find('D055550')
446
+ mh = @mesh_tree.find_heading_by_unique_id('D055550')
441
447
  mh.useful = true
442
448
  assert mh.useful
443
449
  mh.useful = false
@@ -448,26 +454,26 @@ module MESH
448
454
 
449
455
  def test_know_its_deepest_position_in_the_tree
450
456
  #single tree numbers
451
- assert_equal 1, @mesh_tree.find('D002319').deepest_position
452
- assert_equal 2, @mesh_tree.find('D001808').deepest_position
453
- assert_equal 3, @mesh_tree.find('D001158').deepest_position
454
- assert_equal 4, @mesh_tree.find('D001981').deepest_position
457
+ assert_equal 1, @mesh_tree.find_heading_by_unique_id('D002319').deepest_position
458
+ assert_equal 2, @mesh_tree.find_heading_by_unique_id('D001808').deepest_position
459
+ assert_equal 3, @mesh_tree.find_heading_by_unique_id('D001158').deepest_position
460
+ assert_equal 4, @mesh_tree.find_heading_by_unique_id('D001981').deepest_position
455
461
  end
456
462
 
457
463
  def test_know_its_shallowest_position_in_the_tree
458
464
  #single tree numbers
459
- assert_equal 1, @mesh_tree.find('D002319').shallowest_position
460
- assert_equal 2, @mesh_tree.find('D001808').shallowest_position
461
- assert_equal 3, @mesh_tree.find('D001158').shallowest_position
462
- assert_equal 4, @mesh_tree.find('D001981').shallowest_position
465
+ assert_equal 1, @mesh_tree.find_heading_by_unique_id('D002319').shallowest_position
466
+ assert_equal 2, @mesh_tree.find_heading_by_unique_id('D001808').shallowest_position
467
+ assert_equal 3, @mesh_tree.find_heading_by_unique_id('D001158').shallowest_position
468
+ assert_equal 4, @mesh_tree.find_heading_by_unique_id('D001981').shallowest_position
463
469
  end
464
470
 
465
471
  def test_know_if_one_heading_is_the_descendant_of_another
466
- parent = @mesh_tree.find('D002319')
467
- child = @mesh_tree.find('D001808')
468
- grandchild = @mesh_tree.find('D001158')
469
- great_grandchild = @mesh_tree.find('D001981')
470
- unrelated = @mesh_tree.find('D008091')
472
+ parent = @mesh_tree.find_heading_by_unique_id('D002319')
473
+ child = @mesh_tree.find_heading_by_unique_id('D001808')
474
+ grandchild = @mesh_tree.find_heading_by_unique_id('D001158')
475
+ great_grandchild = @mesh_tree.find_heading_by_unique_id('D001981')
476
+ unrelated = @mesh_tree.find_heading_by_unique_id('D008091')
471
477
 
472
478
  refute parent.has_descendant(parent), 'should not consider itself a desecendant'
473
479
  assert parent.has_descendant(child), "should consider child #{child.inspect} a descendant of #{parent.inspect} in #{parent.children}"
@@ -477,11 +483,11 @@ module MESH
477
483
  end
478
484
 
479
485
  def test_know_if_one_heading_is_the_ancestor_of_another
480
- child = @mesh_tree.find('D001981')
481
- parent = @mesh_tree.find('D001158')
482
- grandparent = @mesh_tree.find('D001808')
483
- great_grandparent = @mesh_tree.find('D002319')
484
- unrelated = @mesh_tree.find('D008091')
486
+ child = @mesh_tree.find_heading_by_unique_id('D001981')
487
+ parent = @mesh_tree.find_heading_by_unique_id('D001158')
488
+ grandparent = @mesh_tree.find_heading_by_unique_id('D001808')
489
+ great_grandparent = @mesh_tree.find_heading_by_unique_id('D002319')
490
+ unrelated = @mesh_tree.find_heading_by_unique_id('D008091')
485
491
 
486
492
  refute child.has_ancestor(child), 'should not consider itself an ancestor'
487
493
  assert child.has_ancestor(parent), "should consider parent #{parent.inspect} an ancestor of #{child.inspect} in #{child.parents}"
@@ -491,12 +497,12 @@ module MESH
491
497
  end
492
498
 
493
499
  def test_know_if_headings_are_siblings_at_the_same_level_below_a_common_parent
494
- parent = @mesh_tree.find_by_tree_number('C19.053.500')
495
- child1 = @mesh_tree.find_by_tree_number('C19.053.500.263')
496
- child2 = @mesh_tree.find_by_tree_number('C19.053.500.270')
497
- child3 = @mesh_tree.find_by_tree_number('C19.053.500.480')
498
- child4 = @mesh_tree.find_by_tree_number('C19.053.500.740')
499
- unrelated = @mesh_tree.find('D008091')
500
+ parent = @mesh_tree.find_heading_by_tree_number('C19.053.500')
501
+ child1 = @mesh_tree.find_heading_by_tree_number('C19.053.500.263')
502
+ child2 = @mesh_tree.find_heading_by_tree_number('C19.053.500.270')
503
+ child3 = @mesh_tree.find_heading_by_tree_number('C19.053.500.480')
504
+ child4 = @mesh_tree.find_heading_by_tree_number('C19.053.500.740')
505
+ unrelated = @mesh_tree.find_heading_by_unique_id('D008091')
500
506
  children = [child1, child2, child3, child4]
501
507
 
502
508
  children.each { |c| refute parent.sibling?(c) }
@@ -510,7 +516,7 @@ module MESH
510
516
  end
511
517
 
512
518
  def test_override_inspect_to_prevent_issues_in_test_diagnostics
513
- mh = @mesh_tree.find('D001471')
519
+ mh = @mesh_tree.find_heading_by_unique_id('D001471')
514
520
  expected = "#{mh.unique_id}, #{mh.original_heading}, [#{mh.tree_numbers.join(',')}]"
515
521
  assert_equal expected, mh.inspect
516
522
  end