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
Returns a new instance of BinaryRelationDetector.
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# 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) elsif pointer @pointer = pointer else raise ArgumentError, "Must pass either a path or a pointer" end ObjectSpace.define_finalizer(self, self.class.finalize(pointer)) end |
Instance Method Details
#name ⇒ Object
17 18 19 |
# File 'lib/mitie/binary_relation_detector.rb', line 17 def name FFI.mitie_binary_relation_detector_name_string(pointer).to_s end |
#relations(doc) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mitie/binary_relation_detector.rb', line 21 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 |