Class: RoadForest::SourceRigor::Investigation

Inherits:
Object
  • Object
show all
Defined in:
lib/roadforest/source-rigor/investigation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInvestigation

Returns a new instance of Investigation.



7
8
9
# File 'lib/roadforest/source-rigor/investigation.rb', line 7

def initialize
  @results = []
end

Instance Attribute Details

#context_rolesObject

Returns the value of attribute context_roles.



5
6
7
# File 'lib/roadforest/source-rigor/investigation.rb', line 5

def context_roles
  @context_roles
end

#queryableObject

Returns the value of attribute queryable.



5
6
7
# File 'lib/roadforest/source-rigor/investigation.rb', line 5

def queryable
  @queryable
end

#resultsObject

Returns the value of attribute results.



5
6
7
# File 'lib/roadforest/source-rigor/investigation.rb', line 5

def results
  @results
end

#source_rigorObject

Returns the value of attribute source_rigor.



5
6
7
# File 'lib/roadforest/source-rigor/investigation.rb', line 5

def source_rigor
  @source_rigor
end

Instance Method Details

#context_metadata(context) ⇒ Object



69
70
71
72
73
74
# File 'lib/roadforest/source-rigor/investigation.rb', line 69

def (context)
  query = RDF::Query.new do |query|
    query.pattern [context, :property, :value]
  end
  query.execute(queryable.unnamed_graph).select(:property, :value)
end

#credence_policiesObject



23
24
25
# File 'lib/roadforest/source-rigor/investigation.rb', line 23

def credence_policies
  source_rigor.credence_policies
end

#empty_for_context(context) ⇒ Object

XXX Do we need the nil result if context_metadata is empty?



83
84
85
86
87
88
89
# File 'lib/roadforest/source-rigor/investigation.rb', line 83

def empty_for_context(context)
  if (context).empty? #We've never checked
    nil
  else
    empty_result
  end
end

#found_results?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/roadforest/source-rigor/investigation.rb', line 15

def found_results?
  !@results.nil?
end

#http_clientObject



11
12
13
# File 'lib/roadforest/source-rigor/investigation.rb', line 11

def http_client
  queryable.http_client
end

#insert_graph(context, graph) ⇒ Object



31
32
33
# File 'lib/roadforest/source-rigor/investigation.rb', line 31

def insert_graph(context, graph)
  queryable.insert_graph(context, graph)
end

#investigatorsObject



19
20
21
# File 'lib/roadforest/source-rigor/investigation.rb', line 19

def investigators
  source_rigor.investigators
end

#make_request(method, url, graph = nil) ⇒ Object



27
28
29
# File 'lib/roadforest/source-rigor/investigation.rb', line 27

def make_request(method, url, graph=nil)
  source_rigor.graph_transfer.make_request(method, url, graph)
end

#resultObject

Raises:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/roadforest/source-rigor/investigation.rb', line 35

def result
  investigators.each do |investigator|
    self.results = []
    yield(results)

    contexts = result_contexts

    catch :not_credible do
      credence_policies.each do |policy|
        contexts = policy.credible(contexts, self)
        if contexts.empty?
          throw :not_credible
        end
      end
      return results_for_context(contexts.first)
    end

    self.results = nil
    investigator.pursue(self)

    if found_results?
      return results
    end
  end
  raise NoCredibleResults
end

#result_contextsObject



62
63
64
65
66
67
# File 'lib/roadforest/source-rigor/investigation.rb', line 62

def result_contexts
  (results.map(&:context) +
   context_roles.values.find_all do |context|
    not (context).empty?
   end).uniq
end

#results_for_context(context) ⇒ Object



76
77
78
79
80
# File 'lib/roadforest/source-rigor/investigation.rb', line 76

def results_for_context(context)
  results.find_all do |item|
    item.context == context
  end
end