class Tagger

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.

Public Instance Methods

normalize(text) click to toggle source
# 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) click to toggle source
# File lib/tagger.rb, line 82
def parse_main(text)
  tags = parse_text(text, @default_precondition, @default_search, @content_group)
end
parse_text(text, precondition, search, content_group = @content_group) click to toggle source

@@numberSearch =

/(?:#{@@number_numeric_or_word_search})
    (?:\shundred|\sthousand)?(?:(?:-|\s+to\s+)
    (?:\d+(?:\.\d+)?|one|two)
    (?:\shundred|\sthousand)?)?/i
# File lib/tagger.rb, line 49
def parse_text(text, precondition, search, content_group = @content_group)
    tags = []
    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} : {}
          tags << Standoff::Tag.new(:content => content,
                                    :attributes => attributes,
                                    :name => @name,
                                    :start => beginning,
                                    :end => ending)
        end
    end
    
    return tags
end