Class: StrengthUnitTagger

Inherits:
Tagger
  • Object
show all
Defined in:
lib/taggers/strength_unit_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.

Instance Method Summary collapse

Methods inherited from Tagger

#normalize, #parse_main

Constructor Details

#initializeStrengthUnitTagger

Returns a new instance of StrengthUnitTagger.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/taggers/strength_unit_tagger.rb', line 18

def initialize
    @numberSearch2 =
         /(?:(?:(?:\d+\/)?\d+(?:\.\d+)?)?|one|two)
            (?:\shundred|\sthousand)?(?:(?:-|\s+to\s+)
            (?:\d+(?:\.\d+)?|one|two)
            (?:\shundred|\sthousand)?)?/i
    @numberSearch3 =
         /(?:(?:\d+))/
    @default_precondition = /\s(#{@@number_complete_search})\s+#{@@unit_search_global || (raise Exception.new("unit search regex not found"))}/i
    @default_search = /(#{@@unit_search_global})/i
    @content_group = 1
    @name = 'strength_unit'
end

Instance Method Details

#parse_text(text, precondition, search, content_group) ⇒ Object



31
32
33
34
35
36
# File 'lib/taggers/strength_unit_tagger.rb', line 31

def parse_text(text, precondition, search, content_group)
    tags = []
    local_precondition = /#{@shared_search}/i
    tags += super text, local_precondition, @default_search
    return tags
end