Method: RDF::Query::Pattern#initialize!

Defined in:
lib/rdf/query/pattern.rb

#initialize!Object

Since:

  • 0.3.0



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rdf/query/pattern.rb', line 45

def initialize!
  @graph_name = Variable.new(@graph_name) if @graph_name.is_a?(Symbol)
  @subject    = Variable.new(@subject)    if @subject.is_a?(Symbol)
  @predicate  = Variable.new(@predicate)  if @predicate.is_a?(Symbol)
  @object     = Variable.new(@object)     if @object.is_a?(Symbol)

  # Estmate cost positionally, with variables being least expensive as objects, then predicates, then subjects, then graph_names.
  # XXX does not consider bound variables, which would need to be dynamically calculated.
  @cost = (@object.nil?     || @object.is_a?(Variable)      ? 8 : 0) +
          (@predicate.nil?  || @predicate.is_a?(Variable)   ? 4 : 0) +
          (@subject.nil?    || @subject.is_a?(Variable)     ? 2 : 0) +
          (@graph_name.is_a?(Variable)                      ? 1 : 0) +
          (@object.is_a?(Pattern)                           ? (@object.cost * 4) : 0) +
          (@subject.is_a?(Pattern)                          ? (@subject.cost * 2) : 0)
  super
end