Class: Model::Reasoner

Inherits:
Object
  • Object
show all
Defined in:
lib/services/reasoner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository) ⇒ Reasoner

Returns a new instance of Reasoner.



8
9
10
# File 'lib/services/reasoner.rb', line 8

def initialize(repository)
  @repository = repository
end

Instance Attribute Details

#repositoryObject (readonly)

Returns the value of attribute repository.



6
7
8
# File 'lib/services/reasoner.rb', line 6

def repository
  @repository
end

Instance Method Details

#check_condition(condition) ⇒ Object

makes sure that the graph with name condition is valid to do that, it creates a temporary graph (:helper_graph) and tries to imply condition => helper_graph it creates a new temp_reasoner object so as not to modify the current repository with the helper_graph



32
33
34
35
36
37
38
39
40
# File 'lib/services/reasoner.rb', line 32

def check_condition(condition)
  temp_repository = @repository.clone
  temp_repository << [ LV.condition, LV.was, LV.true, :helper_graph ]

  temp_reasoner = Reasoner.new temp_repository
  result = temp_reasoner.imply(condition, :helper_graph)

  result.query([ LV.condition, LV.was, LV.true ]).any?
end

#imply(precondition, postcondition) ⇒ Object

implication doesn’t work well when a blank node is used in the condition, e.g.: <…#type> _:vehicle . => … will always result in the postcondition, because of _:vehicle



16
17
18
19
20
21
22
23
24
25
# File 'lib/services/reasoner.rb', line 16

def imply(precondition, postcondition)
  eye_input = EyeSerializer.serialize_implication(
    repository.facts_only,
    repository.graph(precondition),
    repository.graph(postcondition)
  )

  eye_output = run_eye eye_input
  parse_eye_output eye_output
end

#load_and_process_n3(n3_input) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/services/reasoner.rb', line 42

def load_and_process_n3(n3_input)
  input = [
    n3_input,
    EyeSerializer.serialize_graph(repository.facts_only)
  ].join

  eye_output = run_eye input
  parse_eye_output eye_output, @repository
  @repository
end