Class: Mitie::NERTrainer

Inherits:
Object
  • Object
show all
Defined in:
lib/mitie/ner_trainer.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ NERTrainer

Returns a new instance of NERTrainer.

Raises:

  • (ArgumentError)


3
4
5
6
7
# File 'lib/mitie/ner_trainer.rb', line 3

def initialize(filename)
  raise ArgumentError, "File does not exist" unless File.exist?(filename)
  @pointer = FFI.mitie_create_ner_trainer(+filename)
  @pointer.free = FFI["mitie_free"]
end

Instance Method Details

#add(instance) ⇒ Object



9
10
11
# File 'lib/mitie/ner_trainer.rb', line 9

def add(instance)
  FFI.mitie_add_ner_training_instance(@pointer, instance.pointer)
end

#betaObject



13
14
15
# File 'lib/mitie/ner_trainer.rb', line 13

def beta
  FFI.mitie_ner_trainer_get_beta(@pointer)
end

#beta=(value) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
# File 'lib/mitie/ner_trainer.rb', line 17

def beta=(value)
  raise ArgumentError, "beta must be greater than or equal to zero" unless value >= 0

  FFI.mitie_ner_trainer_set_beta(@pointer, value)
end

#num_threadsObject



23
24
25
# File 'lib/mitie/ner_trainer.rb', line 23

def num_threads
  FFI.mitie_ner_trainer_get_num_threads(@pointer)
end

#num_threads=(value) ⇒ Object



27
28
29
# File 'lib/mitie/ner_trainer.rb', line 27

def num_threads=(value)
  FFI.mitie_ner_trainer_set_num_threads(@pointer, value)
end

#sizeObject



31
32
33
# File 'lib/mitie/ner_trainer.rb', line 31

def size
  FFI.mitie_ner_trainer_size(@pointer)
end

#trainObject

Raises:



35
36
37
38
39
40
41
42
43
# File 'lib/mitie/ner_trainer.rb', line 35

def train
  raise Error, "You can't call train() on an empty trainer" if size.zero?

  extractor = FFI.mitie_train_named_entity_extractor(@pointer)

  raise Error, "Unable to create named entity extractor. Probably ran out of RAM." if extractor.null?

  Mitie::NER.new(pointer: extractor)
end