1   package eu.fbk.rdfpro.util;
2   
3   import java.util.Map;
4   
5   import javax.annotation.Nullable;
6   
7   import org.openrdf.query.QueryLanguage;
8   import org.openrdf.query.parser.ParsedQuery;
9   import org.openrdf.queryrender.QueryRenderer;
10  
11  /**
12   * Implementation of {@link QueryRenderer} based on RDFpro rendering capabilities.
13   */
14  public class QueryRendererImpl implements QueryRenderer {
15  
16      @Nullable
17      private final Map<String, String> prefixes;
18  
19      private final boolean forceSelect;
20  
21      public QueryRendererImpl(@Nullable final Map<String, String> prefixes,
22              final boolean forceSelect) {
23          this.prefixes = prefixes;
24          this.forceSelect = forceSelect;
25      }
26  
27      @Override
28      public QueryLanguage getLanguage() {
29          return QueryLanguage.SPARQL;
30      }
31  
32      @Override
33      public String render(final ParsedQuery query) throws Exception {
34          return Algebra.renderQuery(query.getTupleExpr(), query.getDataset(), this.prefixes,
35                  this.forceSelect);
36      }
37  
38  }