Class: Mitie::NERTrainingInstance
- Inherits:
-
Object
- Object
- Mitie::NERTrainingInstance
- Defined in:
- lib/mitie/ner_training_instance.rb
Instance Attribute Summary collapse
-
#pointer ⇒ Object
readonly
Returns the value of attribute pointer.
Instance Method Summary collapse
- #add_entity(range, label) ⇒ Object
-
#initialize(tokens) ⇒ NERTrainingInstance
constructor
A new instance of NERTrainingInstance.
- #num_entities ⇒ Object
- #num_tokens ⇒ Object
- #overlaps_any_entity?(range) ⇒ Boolean
Constructor Details
#initialize(tokens) ⇒ NERTrainingInstance
Returns a new instance of NERTrainingInstance.
5 6 7 8 9 10 11 |
# File 'lib/mitie/ner_training_instance.rb', line 5 def initialize(tokens) tokens_pointer = Utils.array_to_pointer(tokens) @pointer = FFI.mitie_create_ner_training_instance(tokens_pointer) raise Error, "Unable to create training instance. Probably ran out of RAM." if @pointer.null? @pointer.free = FFI["mitie_free"] end |
Instance Attribute Details
#pointer ⇒ Object (readonly)
Returns the value of attribute pointer.
3 4 5 |
# File 'lib/mitie/ner_training_instance.rb', line 3 def pointer @pointer end |
Instance Method Details
#add_entity(range, label) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mitie/ner_training_instance.rb', line 13 def add_entity(range, label) Utils.check_range(range, num_tokens) raise ArgumentError, "Range overlaps existing entity" if overlaps_any_entity?(range) unless FFI.mitie_add_ner_training_entity(@pointer, range.begin, range.size, +label).zero? raise Error, "Unable to add entity to training instance. Probably ran out of RAM." end nil end |
#num_entities ⇒ Object
25 26 27 |
# File 'lib/mitie/ner_training_instance.rb', line 25 def num_entities FFI.mitie_ner_training_instance_num_entities(@pointer) end |
#num_tokens ⇒ Object
29 30 31 |
# File 'lib/mitie/ner_training_instance.rb', line 29 def num_tokens FFI.mitie_ner_training_instance_num_tokens(@pointer) end |
#overlaps_any_entity?(range) ⇒ Boolean
33 34 35 36 37 |
# File 'lib/mitie/ner_training_instance.rb', line 33 def overlaps_any_entity?(range) Utils.check_range(range, num_tokens) FFI.mitie_overlaps_any_entity(@pointer, range.begin, range.size) == 1 end |