Class: NerRuby::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/ner_ruby/entity.rb

Constant Summary collapse

LABELS =
i[PER LOC ORG MISC DATE TIME MONEY PERCENT QUANTITY].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, label:, start_offset: nil, end_offset: nil, score: 0.0) ⇒ Entity



9
10
11
12
13
14
15
# File 'lib/ner_ruby/entity.rb', line 9

def initialize(text:, label:, start_offset: nil, end_offset: nil, score: 0.0)
  @text = text
  @label = label.to_sym
  @start_offset = start_offset
  @end_offset = end_offset
  @score = score
end

Instance Attribute Details

#end_offsetObject (readonly)

Returns the value of attribute end_offset.



5
6
7
# File 'lib/ner_ruby/entity.rb', line 5

def end_offset
  @end_offset
end

#labelObject (readonly)

Returns the value of attribute label.



5
6
7
# File 'lib/ner_ruby/entity.rb', line 5

def label
  @label
end

#scoreObject (readonly)

Returns the value of attribute score.



5
6
7
# File 'lib/ner_ruby/entity.rb', line 5

def score
  @score
end

#start_offsetObject (readonly)

Returns the value of attribute start_offset.



5
6
7
# File 'lib/ner_ruby/entity.rb', line 5

def start_offset
  @start_offset
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/ner_ruby/entity.rb', line 5

def text
  @text
end

Instance Method Details

#location?Boolean



21
22
23
# File 'lib/ner_ruby/entity.rb', line 21

def location?
  label == :LOC
end

#organization?Boolean



25
26
27
# File 'lib/ner_ruby/entity.rb', line 25

def organization?
  label == :ORG
end

#person?Boolean



17
18
19
# File 'lib/ner_ruby/entity.rb', line 17

def person?
  label == :PER
end

#to_hObject



29
30
31
32
33
34
35
36
37
# File 'lib/ner_ruby/entity.rb', line 29

def to_h
  {
    text: @text,
    label: @label,
    start_offset: @start_offset,
    end_offset: @end_offset,
    score: @score
  }
end

#to_sObject



39
40
41
# File 'lib/ner_ruby/entity.rb', line 39

def to_s
  "#{@text} [#{@label}] (#{(@score * 100).round(1)}%)"
end