本文整理匯總了Java中com.hp.hpl.jena.query.ResultSet.getResultVars方法的典型用法代碼示例。如果您正苦於以下問題:Java ResultSet.getResultVars方法的具體用法?Java ResultSet.getResultVars怎麽用?Java ResultSet.getResultVars使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.query.ResultSet
的用法示例。
在下文中一共展示了ResultSet.getResultVars方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: subscribeTopics
import com.hp.hpl.jena.query.ResultSet; //導入方法依賴的package包/類
private boolean subscribeTopics(int query_id, boolean subsc) {
try {
String sparql = db.getQuery(query_id).getString("sparql");
QueryExecution sparqlService = QueryExecutionFactory.sparqlService(config.storeUrl(), sparql);
sparqlService.setTimeout(600000);
ResultSet execution = sparqlService.execSelect();
List<String> lst = execution.getResultVars();
if (lst.isEmpty() || lst.size() > 1) {
logger.debug("Sparql query is bad!");
return false;
}
String var = lst.get(0);
List<String> topics = new ArrayList<>();
while (execution.hasNext()) {
topics.add(execution.next().get(var).asLiteral().getString());
}
if (topics.isEmpty()) {
return false;
}
if (subsc) {
subscriber.subscribeTopics(topics, query_id);
} else {
subscriber.unsubscribeTopics(topics, query_id);
}
return true;
} catch (Throwable ex) {
logger.debug("Error in sparql query! Message: " + ex.getMessage());
return false;
}
}
示例2: start
import com.hp.hpl.jena.query.ResultSet; //導入方法依賴的package包/類
@Override
public void start(ResultSet rs) {
// start elements: document, root, header, results
try {
handler.startDocument();
// start root element
atts.clear();
handler.startElement(dfNamespace, dfRootTag, dfRootTag, atts);
// start header
atts.clear();
handler.startElement(dfNamespace, dfHead, dfHead, atts);
for (String varName : rs.getResultVars()) {
atts.clear();
atts.addAttribute(dfNamespace, dfAttrVarName, dfAttrVarName, "CDATA", varName);
handler.startElement(dfNamespace, dfVariable, dfVariable, atts);
handler.endElement(dfNamespace, dfVariable, dfVariable);
}
// end header
handler.endElement(dfNamespace, dfHead, dfHead);
// start results
atts.clear();
handler.startElement(dfNamespace, dfResults, dfResults, atts);
} catch (SAXException ex) {
}
}
示例3: renderResultSet
import com.hp.hpl.jena.query.ResultSet; //導入方法依賴的package包/類
public static SparqlResults renderResultSet(QueryResult queryResult) throws JsonProcessingException
{
ObjectMapper mapper = new ObjectMapper();
SparqlResults results = new SparqlResults();
results.setResults(new Results());
results.setHead(new Head());
results.getHead().setVars(new ArrayList<>());
// results.getHead().getVars().add("s");
// results.getHead().getVars().add("p");
// results.getHead().getVars().add("o");
// results.getHead().getVars().add("?");
results.getHead().setLinks(new HashMap<>());
results.getHead().getLinks().put("cursor", mapper.writeValueAsString(queryResult.getCursor()));
Set<String> vars = new HashSet<>();
for(ResultSet set : queryResult.getResultSets())
{
vars.addAll(set.getResultVars());
for(;set.hasNext();)
{
Map<String, Map<String, String>> binding = new HashMap<>();
QuerySolution sol = set.nextSolution();
for(String v : set.getResultVars())
{
binding.put(v, new HashMap<>());
if(sol.get(v).isLiteral())
{
binding.get(v).put("type", "literal");
binding.get(v).put("value", sol.get(v).asLiteral().getLexicalForm());
if(sol.get(v).asLiteral().getDatatypeURI() != null &&
!sol.get(v).asLiteral().getDatatypeURI().equals(""))
{
binding.get(v).put("datatype", sol.get(v).asLiteral().getDatatypeURI());
}
if(sol.get(v).asLiteral().getLanguage() != null &&
!sol.get(v).asLiteral().getLanguage().equals(""))
{
binding.get(v).put("xml:lang", sol.get(v).asLiteral().getLanguage());
}
}
else if(sol.get(v).isResource())
{
binding.get(v).put("type", "uri");
binding.get(v).put("value", sol.get(v).asResource().getURI());
}
}
results.getResults().getBindings().add(binding);
}
}
results.getHead().getVars().addAll(vars);
return results;
}