Class: Mitie::BinaryRelationDetector
- Inherits:
-
Object
- Object
- Mitie::BinaryRelationDetector
- Defined in:
- lib/mitie/binary_relation_detector.rb
Instance Method Summary collapse
-
#initialize(path = nil, pointer: nil) ⇒ BinaryRelationDetector
constructor
A new instance of BinaryRelationDetector.
- #name ⇒ Object
- #relations(doc) ⇒ Object
- #save_to_disk(filename) ⇒ Object
Constructor Details
#initialize(path = nil, pointer: nil) ⇒ BinaryRelationDetector
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/mitie/binary_relation_detector.rb', line 3 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_binary_relation_detector(+path) @pointer.free = FFI["mitie_free"] elsif pointer @pointer = pointer else raise ArgumentError, "Must pass either a path or a pointer" end end |
Instance Method Details
#name ⇒ Object
16 17 18 |
# File 'lib/mitie/binary_relation_detector.rb', line 16 def name FFI.mitie_binary_relation_detector_name_string(pointer).to_s end |
#relations(doc) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mitie/binary_relation_detector.rb', line 20 def relations(doc) raise ArgumentError, "Expected Mitie::Document, not #{doc.class.name}" unless doc.is_a?(Document) entities = doc.entities combinations = [] (entities.size - 1).times do |i| combinations << [entities[i], entities[i + 1]] combinations << [entities[i + 1], entities[i]] end relations = [] combinations.each do |entity1, entity2| relation = extract_relation(doc, entity1, entity2) relations << relation if relation end relations end |
#save_to_disk(filename) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/mitie/binary_relation_detector.rb', line 38 def save_to_disk(filename) if FFI.mitie_save_binary_relation_detector(+filename, pointer) != 0 raise Error, "Unable to save detector" end nil end |