Class: Mitie::NER
- Inherits:
-
Object
- Object
- Mitie::NER
- Defined in:
- lib/mitie/ner.rb
Instance Attribute Summary collapse
-
#pointer ⇒ Object
readonly
Returns the value of attribute pointer.
Instance Method Summary collapse
- #doc(text) ⇒ Object
- #entities(text) ⇒ Object
-
#initialize(path = nil, pointer: nil) ⇒ NER
constructor
A new instance of NER.
- #save_to_disk(filename) ⇒ Object
- #tags ⇒ Object
- #tokens(text) ⇒ Object
- #tokens_with_offset(text) ⇒ Object
Constructor Details
#initialize(path = nil, pointer: nil) ⇒ NER
Returns a new instance of NER.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/mitie/ner.rb', line 5 def initialize(path = nil, pointer: nil) if path # better error message raise ArgumentError, "File does not exist" unless File.exist?(path) @pointer = FFI.mitie_load_named_entity_extractor(+path) @pointer.free = FFI["mitie_free"] elsif pointer @pointer = pointer else raise ArgumentError, "Must pass either a path or a pointer" end end |
Instance Attribute Details
#pointer ⇒ Object (readonly)
Returns the value of attribute pointer.
3 4 5 |
# File 'lib/mitie/ner.rb', line 3 def pointer @pointer end |
Instance Method Details
#doc(text) ⇒ Object
24 25 26 |
# File 'lib/mitie/ner.rb', line 24 def doc(text) Document.new(self, text) end |
#entities(text) ⇒ Object
28 29 30 |
# File 'lib/mitie/ner.rb', line 28 def entities(text) doc(text).entities end |
#save_to_disk(filename) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/mitie/ner.rb', line 32 def save_to_disk(filename) if FFI.mitie_save_named_entity_extractor(+filename, pointer) != 0 raise Error, "Unable to save model" end nil end |
#tags ⇒ Object
18 19 20 21 22 |
# File 'lib/mitie/ner.rb', line 18 def FFI.(pointer).times.map do |i| FFI.(pointer, i).to_s end end |
#tokens(text) ⇒ Object
39 40 41 |
# File 'lib/mitie/ner.rb', line 39 def tokens(text) doc(text).tokens end |
#tokens_with_offset(text) ⇒ Object
43 44 45 |
# File 'lib/mitie/ner.rb', line 43 def tokens_with_offset(text) doc(text).tokens_with_offset end |