Class: ActiveRDF::Query2SPARQL

Inherits:
Object
  • Object
show all
Defined in:
lib/active_rdf/queryengine/query2sparql.rb

Constant Summary collapse

Engines_With_Keyword =
[:yars2, :virtuoso]

Class Method Summary collapse

Class Method Details

.translate(query, engine = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_rdf/queryengine/query2sparql.rb', line 10

def Query2SPARQL.translate(query, engine=nil)
  str = ""
  if query.select?
    distinct = query.distinct? ? "DISTINCT " : ""
    select_clauses = query.select_clauses.collect{|s| construct_clause(s)}

    str << "SELECT #{distinct}#{select_clauses.join(' ')} "
    str << "WHERE { #{where_clauses(query)} #{filter_clauses(query)}} "
    str << "ORDER BY #{order_clauses(query)} " if query.sort_clauses.size > 0
    str << "LIMIT #{query.limits} " if query.limits
    str << "OFFSET #{query.offsets} " if query.offsets
  elsif query.ask?
    str << "ASK { #{where_clauses(query)} } "
  end

  return str
end