Class: Tagger
- Inherits:
-
Object
- Object
- Tagger
- Defined in:
- lib/tagger.rb
Overview
Copyright 2015 The MITRE Corporation
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Direct Known Subclasses
DispenseQuantityTagger, DoseAmountTagger, DurationTagger, IndicationTagger, ListTagger, RefillTagger, StrengthTagger, StrengthUnitTagger, SubstitutionTagger, TimingTagger
Constant Summary collapse
- @@unit_search_global =
/(?:mg\.?(?:(?:\/|\s*per\s*)(one|five|1|5)?\s*(?:ml|cc|m2|meters? squared|m squared)\.?)? |units?|micrograms?|milligrams?|mg|grams?|millimoles?|milliequivalents?|percent |(?:au|pnu)(?:\/|per\s*)ml |\%|gr\.?|meq\.?|mmol\.?|ugm?s?|mcg)/ix
- @@number_word_search =
/(?:one|two|three|four|five|six|seven|eight|nine|ten|fifteen|twenty|thirty|sixty)/
- @@number_numeric_search =
/(?:\d+\/)?\d+(?:\.\d+)?/
- @@number_numeric_or_word_search =
/(?:(?:#{@@number_numeric_search})|(?:#{@@number_word_search}))/
- @@number_hundred_thousand_search =
/(?:\shundred|\sthousand)/
- @@number_complete_search =
search for number (word or numeric) with optional hundred or thousand modifier
/(?:#{@@number_numeric_or_word_search})(?:\s(?:#{@@number_hundred_thousand_search}))?/
Instance Method Summary collapse
- #normalize(text) ⇒ Object
- #parse_main(text) ⇒ Object
-
#parse_text(text, precondition, search, content_group = @content_group) ⇒ Object
@@numberSearch = /(?:#@@number_numeric_or_word_search) (?:shundred|sthousand)?(?:(?:-|s+tos+) (?:d+(?:.d+)?|one|two) (?:shundred|sthousand)?)?/i.
Instance Method Details
#normalize(text) ⇒ Object
86 87 88 89 |
# File 'lib/tagger.rb', line 86 def normalize(text) # placeholder for Tagger-subclass-specific normalization mappers, # e.g. "once a day" => :qd for the FrequencyTagger end |
#parse_main(text) ⇒ Object
82 83 84 |
# File 'lib/tagger.rb', line 82 def parse_main(text) = parse_text(text, @default_precondition, @default_search, @content_group) end |
#parse_text(text, precondition, search, content_group = @content_group) ⇒ Object
@@numberSearch =
/(?:#{@@number_numeric_or_word_search})
(?:\shundred|\sthousand)?(?:(?:-|\s+to\s+)
(?:\d+(?:\.\d+)?|one|two)
(?:\shundred|\sthousand)?)?/i
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/tagger.rb', line 49 def parse_text(text, precondition, search, content_group = @content_group) = [] if text =~ precondition #if there are multiple instances, this will find them all #and record them as separate tags, as well as preserving their #location in the text window = text.dup textlocation = 0 while window =~ search instance = search.match window beginning = textlocation + instance.begin(content_group) ending = textlocation + instance.end(content_group) textlocation = ending content = instance[content_group] window = window.slice instance.end(content_group)..window.length normalized = normalize content attributes = normalized ? {:normalized => normalized} : {} << Standoff::Tag.new(:content => content, :attributes => attributes, :name => @name, :start => beginning, :end => ending) end end return end |