Class: NerRuby::Entity
- Inherits:
-
Object
- Object
- NerRuby::Entity
- 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
-
#end_offset ⇒ Object
readonly
Returns the value of attribute end_offset.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#start_offset ⇒ Object
readonly
Returns the value of attribute start_offset.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text:, label:, start_offset: nil, end_offset: nil, score: 0.0) ⇒ Entity
constructor
A new instance of Entity.
- #location? ⇒ Boolean
- #organization? ⇒ Boolean
- #person? ⇒ Boolean
- #to_h ⇒ Object
- #to_s ⇒ Object
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_offset ⇒ Object (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 |
#label ⇒ Object (readonly)
Returns the value of attribute label.
5 6 7 |
# File 'lib/ner_ruby/entity.rb', line 5 def label @label end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
5 6 7 |
# File 'lib/ner_ruby/entity.rb', line 5 def score @score end |
#start_offset ⇒ Object (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 |
#text ⇒ Object (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_h ⇒ Object
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_s ⇒ Object
39 40 41 |
# File 'lib/ner_ruby/entity.rb', line 39 def to_s "#{@text} [#{@label}] (#{(@score * 100).round(1)}%)" end |