use of org.openrdf.queryrender.sparql.SPARQLQueryRenderer in project incubator-rya by apache.
the class PcjMetadataRenderer method render.
/**
* Pretty render the state of a PCJ.
*
* @param queryId - The ID of the query the metadata is from. (not null)
* @param metadata - Metadata about one of the PCJs. (not null)
* @return A pretty render of a PCJ's state.
* @throws Exception The SPARQL within the metadata could not be parsed or
* it could not be rendered.
*/
public String render(final String queryId, final PcjMetadata metadata) throws Exception {
checkNotNull(metadata);
// Pretty format the cardinality.
final String cardinality = NumberFormat.getInstance().format(metadata.getCardinality());
// Pretty format and split the SPARQL query into lines.
final SPARQLParser parser = new SPARQLParser();
final SPARQLQueryRenderer renderer = new SPARQLQueryRenderer();
final ParsedQuery pq = parser.parseQuery(metadata.getSparql(), null);
final String prettySparql = renderer.render(pq);
final String[] sparqlLines = StringUtils.split(prettySparql, '\n');
// Split the variable orders into lines.
final String[] varOrderLines = new String[metadata.getVarOrders().size()];
int i = 0;
for (final VariableOrder varOrder : metadata.getVarOrders()) {
varOrderLines[i++] = varOrder.toString();
}
// Create the report.
final Report.Builder builder = Report.builder();
builder.appendItem(new ReportItem("Query ID", queryId));
builder.appendItem(new ReportItem("Cardinality", cardinality));
builder.appendItem(new ReportItem("Export Variable Orders", varOrderLines));
builder.appendItem(new ReportItem("SPARQL", sparqlLines));
return builder.build().toString();
}
Aggregations