class Mitier::Ner

Attributes

detections[RW]
extractor[RW]

Public Class Methods

new(extractor, text) click to toggle source
Calls superclass method
# File lib/mitier/ner.rb, line 5
def initialize(extractor, text)
  super text
  @extractor = extractor
end

Public Instance Methods

process() click to toggle source
# File lib/mitier/ner.rb, line 10
def process
  check_text { return self }
  tokens_ptr = tokenize
  detections_ptr = detect tokens_ptr
  process_token_elements tokens_ptr
  process_detections detections_ptr
  self
end

Private Instance Methods

check_text() { || ... } click to toggle source
# File lib/mitier/ner.rb, line 45
def check_text
  return unless text.empty?
  @tokens = @detections = []
  yield
end
detect(tokens_ptr) click to toggle source
# File lib/mitier/ner.rb, line 23
def detect(tokens_ptr)
  Wrapper.mitie_extract_entities extractor, tokens_ptr
end
detection_attrs(ptr, nr) click to toggle source
# File lib/mitier/ner.rb, line 32
def detection_attrs(ptr, nr)
  { tokens: detection_tokens(ptr, nr),
    tagstr: Wrapper.mitie_ner_get_detection_tagstr(ptr, nr),
    tag: Wrapper.mitie_ner_get_detection_tag(ptr, nr),
    score: Wrapper.mitie_ner_get_detection_score(ptr, nr) }
end
detection_tokens(ptr, nr) click to toggle source
# File lib/mitier/ner.rb, line 39
def detection_tokens(ptr, nr)
  pos = Wrapper.mitie_ner_get_detection_position ptr, nr
  len = Wrapper.mitie_ner_get_detection_length ptr, nr
  (pos...(pos + len)).map { |elem| tokens[elem] }
end
process_detections(ptr) click to toggle source
# File lib/mitier/ner.rb, line 27
def process_detections(ptr)
  num = Wrapper.mitie_ner_get_num_detections ptr
  @detections = (0...num).map { |elem| detection_attrs(ptr, elem) }
end