Class: Query2SPARQL
- Inherits:
-
Object
- Object
- Query2SPARQL
- Defined in:
- lib/active_rdf/queryengine/query2sparql.rb
Overview
Translates abstract query into SPARQL that can be executed on SPARQL-compliant data source.
Constant Summary collapse
- Engines_With_Keyword =
[:yars2, :virtuoso]
Class Method Summary collapse
-
.filter_clauses(query) ⇒ Object
concatenate filters in query.
- .translate(query, engine = nil) ⇒ Object
Class Method Details
.filter_clauses(query) ⇒ Object
concatenate filters in query
27 28 29 |
# File 'lib/active_rdf/queryengine/query2sparql.rb', line 27 def self.filter_clauses(query) "FILTER (#{query.filter_clauses.join(" && ")})" unless query.filter_clauses.empty? end |
.translate(query, engine = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_rdf/queryengine/query2sparql.rb', line 9 def self.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 << "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 |