本文整理汇总了Java中com.hp.hpl.jena.query.QuerySolution.varNames方法的典型用法代码示例。如果您正苦于以下问题:Java QuerySolution.varNames方法的具体用法?Java QuerySolution.varNames怎么用?Java QuerySolution.varNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.query.QuerySolution
的用法示例。
在下文中一共展示了QuerySolution.varNames方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: solutionToMap
import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
public static Map<String,RDFNode> solutionToMap(QuerySolution solution, List<String> variables) {
Map<String,RDFNode> result = new HashMap<String,RDFNode>();
Iterator<String> it = solution.varNames();
while (it.hasNext()) {
String variableName = it.next();
if (!variables.contains(variableName)) {
continue;
}
RDFNode value = solution.get(variableName);
int size = value.toString().length();
if (size>250) {
bigStringInResultLogger.debug("Big string (" + size + ") in resultBinding:\n" + value);
}
result.put(variableName,value);
}
return result;
}
示例2: executeQuerySelect
import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
public SelectQueryResponse executeQuerySelect(String query) throws QueryParseException {
//Query sparql = QueryFactory.create(query);
VirtuosoQueryExecution vqe = queryExecutionFactory.create(query, set);
ResultSet resultSet = vqe.execSelect();
SelectQueryResponse selectQueryResponse = new SelectQueryResponse();
Boolean named = false;
while (resultSet.hasNext()) {
QuerySolution querySolution = resultSet.next();
Iterator <String> varNames = querySolution.varNames();
for (int i = 0; varNames.hasNext(); i++) {
if (!named) {
String varName = varNames.next();
selectQueryResponse.addColumn(varName);
selectQueryResponse.addValue(i, querySolution.get(varName).toString());
}
else {
selectQueryResponse.addValue(i, querySolution.get(varNames.next()).toString());
}
}
named = true;
}
vqe.close();
return selectQueryResponse;
}
示例3: addSolution
import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
private void addSolution(QuerySolution solution) {
Map<String,RDFNode> map = new HashMap<String,RDFNode>();
Iterator<String> it = solution.varNames();
while (it.hasNext()) {
String variable = it.next();
RDFNode value = solution.get(variable);
map.put(variable, value);
}
this.results.add(map);
}
示例4: convertIntoTable
import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
private static StringMatrix convertIntoTable(
PrefixMapping prefixMap, ResultSet results) {
StringMatrix table = new StringMatrix();
int rowCount = 0;
while (results.hasNext()) {
rowCount++;
QuerySolution soln = results.nextSolution();
Iterator<String> varNames = soln.varNames();
while (varNames.hasNext()) {
String varName = varNames.next();
int colCount = -1;
if (table.hasColumn(varName)) {
colCount = table.getColumnNumber(varName);
} else {
colCount = table.getColumnCount() + 1;
table.setColumnName(colCount, varName);
}
RDFNode node = soln.get(varName);
if (node != null) {
if (node.isResource()) {
Resource resource = (Resource)node;
table.set(rowCount, colCount,
resource.getURI()
);
} else if (node.isLiteral()) {
Literal literal = (Literal)node;
table.set(rowCount, colCount, "" + literal.getValue());
}
}
}
}
return table;
}
示例5: query
import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
/**
* Executes the specified SPARQL query and returns the first variable
* not listed in varsToIgnore for each row (unless the row contains only
* one variable)
*/
public Collection<String> query(String queryString, Set<String> varsToIgnore) {
Collection<String> res = new LinkedList<String>();
try {
QueryExecution qexec = getQueryExec(queryString);
ResultSet results = qexec.execSelect();
for (; results.hasNext(); )
{
QuerySolution sol = results.nextSolution();
Iterator<String> varNames = sol.varNames();
while (varNames.hasNext()) {
String varName = varNames.next();
String val = null;
if (!varsToIgnore.contains(varName) || !varNames.hasNext()) {
RDFNode var = sol.get(varName);
if (var.isLiteral()) {
Literal l = (Literal)var;
val = l.getValue().toString();
} else if (var.isResource()) {
Resource r = (Resource)var;
val = r.getURI();
}
res.add(val);
break;
}
}
}
qexec.close();
} catch (Exception e) {
log.error("Failed to execute query \"" + queryString + "\":", e);
}
return res;
}
示例6: parseResult
import com.hp.hpl.jena.query.QuerySolution; //导入方法依赖的package包/类
/**
* Receives the resultset from the SPARQL query and adds the relevant result values to the DBPediaInfoObject
* @param result
* @return
*/
private static DBPediaInfoObject parseResult (ResultSet result){
DBPediaInfoObject info = new DBPediaInfoObject();
if (!result.hasNext()){
info= null;
}
else{
while (result.hasNext() ){
QuerySolution soln = result.nextSolution() ;
HashMap<String, String> properties = new HashMap<String, String>();
HashMap<String,String> wikiLinks = new HashMap<String,String>();
// Iterates through the variable names
for ( final Iterator<String> varNames = soln.varNames(); varNames.hasNext(); ) {
final String varName = varNames.next();
if (varName.matches("Country") || varName.matches("Leader1") || varName.matches("Leader2") ){
if (soln.getLiteral(varName).getValue().toString()!=""){
String values= soln.getLiteral(varName).getValue().toString();
String[] separateValues = values.split(",,");
// For every separate values of the types defined get the equivalent wikilinks and store them into the created object
for (int i=0; i<separateValues.length ; i++){
String label = getWikiLink(separateValues[i])[0];
String wikiLink = getWikiLink(separateValues[i])[1];
if (!wikiLinks.containsKey(label))
wikiLinks.put(label, wikiLink);
}
}
}
else if (soln.get(varName).isLiteral() && soln.getLiteral(varName).getValue().toString()!="")
properties.put(varName, soln.getLiteral(varName).getValue().toString());
else if (soln.get(varName).isResource() && soln.getResource(varName).toString()!="")
properties.put(varName, soln.getResource(varName).toString());
}
// Store the literal values and the map of wikilinks that connects resources to their wikis
info.setLiteralProperties(properties);
info.setWikiLinks(wikiLinks);
}
}
return info;
}