medattrib 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tagger.rb +1 -1
- data/lib/taggers/#duration_tagger.rb# +31 -0
- data/lib/taggers/dose_amount_tagger.rb +34 -2
- data/lib/taggers/duration_tagger.rb +5 -2
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 227bec7d4279a4fd39a16399199ff8799b736b12
|
|
4
|
+
data.tar.gz: 34c4d46a42970f5e5f8130d1e22677bb740cd006
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e38309aa298ba3e1a9e4340d8b9e78f3c6ec99b546859fdd49b791ee2f9300f4f7e17a7949488cc3ab8d0a42511e621a16bde6f5ed75e0ae32678f3764efbab8
|
|
7
|
+
data.tar.gz: 5b8cfb0ac7781d96d5449a68c3f11c44f84548b6dacf3debe6c0a3d327b6b8a0088c98961c2b2fa4f749b04a5ff3c8cab315e705d935834e596b456c86b5affa
|
data/lib/tagger.rb
CHANGED
|
@@ -17,7 +17,7 @@ limitations under the License.
|
|
|
17
17
|
class Tagger
|
|
18
18
|
|
|
19
19
|
@@unit_search_global =
|
|
20
|
-
/(?:mg\.?(?:(?:\/|\s*per\s*)(one|five|1|5)?\s*(?:ml|cc|m2|meters? squared|m squared)
|
|
20
|
+
/(?:mg\.?(?:(?:\/|\s*per\s*)(one|five|1|5)?\s*(?:ml|cc|m2|meters? squared|m squared))?
|
|
21
21
|
|units?|micrograms?|milligrams?|mg|grams?|millimoles?|milliequivalents?|percent
|
|
22
22
|
|(?:au|pnu)(?:\/|per\s*)ml
|
|
23
23
|
|\%|gr\.?|meq\.?|mmol\.?|ugm?s?|mcg)/ix
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
Copyright 2015 The MITRE Corporation
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
=end
|
|
16
|
+
|
|
17
|
+
class DurationTagger < Tagger
|
|
18
|
+
def initialize
|
|
19
|
+
@shared_search = /(?x)(?:\d+(?:\-\d)?|one|two|three|four|five|six|seven|
|
|
20
|
+
eight|nine|ten|fifteen|twenty|thirty|sixty)\s*
|
|
21
|
+
(?:days?|weeks?|wks|months?|cycles?|courses?|d\b)/i
|
|
22
|
+
@cycles_courses_only_search = /(?x)(?:\d+(?:\-\d)?|one|two|three|four|five|six|seven|
|
|
23
|
+
eight|nine|ten|fifteen|twenty|thirty|sixty)\s*
|
|
24
|
+
(?:|cycles?|courses?|d\b)/i
|
|
25
|
+
@default_precondition = /#{@shared_search}/i
|
|
26
|
+
@default_search = /(?x)((?:for|x)\s?(?:a\stotal\sof\s+)?(?:up\s+to\s+)?
|
|
27
|
+
(?:the\snext\s+)?)(#{@shared_search})|(?:@cycles_courses_only_search)i/
|
|
28
|
+
@content_group = 2
|
|
29
|
+
@name = 'duration'
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -37,12 +37,44 @@ class DoseAmountTagger < Tagger
|
|
|
37
37
|
local_search = /(?x)((?:(?:\d\s+)?(?:\d(?:\/|-))?(?:\d+(?:\.\d+)?
|
|
38
38
|
(?:\s?(?:-|\/)\s?\d+)?)|one|two))(\s+
|
|
39
39
|
(?:(?:#{@shared_search})|<route))/i
|
|
40
|
-
|
|
40
|
+
|
|
41
|
+
# AnnotatedString::to_s interpolates standoff tags into inline XML.
|
|
42
|
+
# This is necessary because the regexes rely on other tag adjacency for search context.
|
|
43
|
+
# This is kludgy, and should at some point be replaced by using the standoff annotation directly so we can leave the signal text alone.
|
|
41
44
|
new_tags += parse_text as.to_s, local_precondition, local_search
|
|
42
|
-
|
|
45
|
+
|
|
46
|
+
# Because of the conversion from standoff to inline tags (above), match positions will be wrong.
|
|
47
|
+
# The following line is a necessary workaround to map the start and end positions from the xml-augmented strings back to the signal text.
|
|
48
|
+
new_tags2 = map_annotation_from_inline_to_clean as.to_s, as.tags, new_tags
|
|
49
|
+
|
|
50
|
+
as.tags += new_tags2
|
|
43
51
|
return as
|
|
44
52
|
end
|
|
45
53
|
|
|
54
|
+
def map_annotation_from_inline_to_clean(string_with_annots, existing_annotations, new_annotations)
|
|
55
|
+
clean_string = ""
|
|
56
|
+
annots_re = /<[^>]+>/
|
|
57
|
+
first_original = 0
|
|
58
|
+
last_original = string_with_annots.length
|
|
59
|
+
|
|
60
|
+
#re_result = str.scan(annots_re)
|
|
61
|
+
re_results = string_with_annots.to_enum(:scan, annots_re).map { Regexp.last_match }
|
|
62
|
+
|
|
63
|
+
map_dirty_to_clean_annot = lambda do |dirty_annot,re_results|
|
|
64
|
+
clean_annot = dirty_annot.dup
|
|
65
|
+
#correction = re_results.map{ |item| item.offset(0)[1] <= dirty_annot.start ? item.offset(0)[1] - item.offset(0)[0] : 0}.reduce(0, :+)
|
|
66
|
+
prior_lengths = re_results.map{ |item| item.offset(0)[1] <= dirty_annot.start ? item.offset(0)[1] - item.offset(0)[0] : 0}
|
|
67
|
+
correction = prior_lengths.reduce(0, :+)
|
|
68
|
+
clean_annot.start = clean_annot.start - correction
|
|
69
|
+
clean_annot.end = clean_annot.end - correction
|
|
70
|
+
clean_annot
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
clean_annots = new_annotations.map{|old_entry| map_dirty_to_clean_annot[old_entry, re_results] }
|
|
74
|
+
|
|
75
|
+
clean_annots
|
|
76
|
+
end
|
|
77
|
+
|
|
46
78
|
def normalize(dose)
|
|
47
79
|
re = {:int => /^\d+$/,
|
|
48
80
|
:decimal => /^(\d+)?\.\d+$/,
|
|
@@ -18,10 +18,13 @@ class DurationTagger < Tagger
|
|
|
18
18
|
def initialize
|
|
19
19
|
@shared_search = /(?x)(?:\d+(?:\-\d)?|one|two|three|four|five|six|seven|
|
|
20
20
|
eight|nine|ten|fifteen|twenty|thirty|sixty)\s*
|
|
21
|
-
(?:days?|weeks?|wks|months?|cycles?|d\b)/i
|
|
21
|
+
(?:days?|weeks?|wks|months?|cycles?|courses?|d\b)/i
|
|
22
|
+
@cycles_courses_only_search = /(?x)(?:\d+(?:\-\d)?|one|two|three|four|five|six|seven|
|
|
23
|
+
eight|nine|ten|fifteen|twenty|thirty|sixty)\s*
|
|
24
|
+
(?:|cycles?|courses?|d\b)/i
|
|
22
25
|
@default_precondition = /#{@shared_search}/i
|
|
23
26
|
@default_search = /(?x)((?:for|x)\s?(?:a\stotal\sof\s+)?(?:up\s+to\s+)?
|
|
24
|
-
(?:the\snext\s+)?)(#{@shared_search})/i
|
|
27
|
+
(?:the\snext\s+)?)(#{@shared_search})|(?:@cycles_courses_only_search)/i
|
|
25
28
|
@content_group = 2
|
|
26
29
|
@name = 'duration'
|
|
27
30
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: medattrib
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cheryl Clark
|
|
@@ -49,6 +49,7 @@ files:
|
|
|
49
49
|
- lib/medattrib.rb
|
|
50
50
|
- lib/run_medattrib.rb
|
|
51
51
|
- lib/tagger.rb
|
|
52
|
+
- lib/taggers/#duration_tagger.rb#
|
|
52
53
|
- lib/taggers/dispense_quantity_tagger.rb
|
|
53
54
|
- lib/taggers/dose_amount_tagger.rb
|
|
54
55
|
- lib/taggers/duration_tagger.rb
|