當前位置: 首頁>>代碼示例>>Java>>正文


Java QuerySolution.varNames方法代碼示例

本文整理匯總了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;
}
 
開發者ID:aitoralmeida,項目名稱:c4a_data_repository,代碼行數:18,代碼來源:QueryLanguageTestFramework.java

示例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;
    }
 
開發者ID:conwetlab,項目名稱:Repository-RI,代碼行數:26,代碼來源:VirtuosoResourceDAO.java

示例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);
}
 
開發者ID:aitoralmeida,項目名稱:c4a_data_repository,代碼行數:11,代碼來源:QueryLanguageTestFramework.java

示例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;
}
 
開發者ID:wikipathways,項目名稱:GPML2RDF,代碼行數:34,代碼來源:SPARQLHelper.java

示例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;
}
 
開發者ID:johannessimon,項目名稱:pal,代碼行數:39,代碼來源:KnowledgeBaseConnector.java

示例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;

}
 
開發者ID:Localizr,項目名稱:Localizr,代碼行數:56,代碼來源:DBPedia.java


注:本文中的com.hp.hpl.jena.query.QuerySolution.varNames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。