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


Java QuerySolution.get方法代碼示例

本文整理匯總了Java中com.hp.hpl.jena.query.QuerySolution.get方法的典型用法代碼示例。如果您正苦於以下問題:Java QuerySolution.get方法的具體用法?Java QuerySolution.get怎麽用?Java QuerySolution.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.hp.hpl.jena.query.QuerySolution的用法示例。


在下文中一共展示了QuerySolution.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: rendererResultSet

import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
private static void rendererResultSet(ResultSet rs, String... queryFields) {
	System.out.println("Result:");
	int queryFieldSize = queryFields.length;
	for (int i = 0; i < queryFieldSize; i++) {
		System.out.print(queryFields[i] + TAB);
	}
	System.out.println();

	while (rs.hasNext()) {
		QuerySolution qs = rs.nextSolution();
		for (int i = 0; i < queryFieldSize; i++) {
			RDFNode name = qs.get(queryFields[i]);
			if (name != null) {
				System.out.print(name + TAB);
			} else {
				System.out.print("NULL" + TAB);
			}
		}
		System.out.println();
	}
}
 
開發者ID:zhoujiagen,項目名稱:Jena-Based-Semantic-Web-Tutorial,代碼行數:22,代碼來源:SPARQLUtils.java

示例3: sparql

import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
/**
 * RDF Navigation using SPARQL Query
 * 
 * @param model
 *            the RDF model
 * @param query
 *            SPARQL Query String
 * @param field
 *            the placeholder of filed in parameter query
 */
private static void sparql(Model model, String query, String field) {
	Query q = QueryFactory.create(query);
	QueryExecution qexec = QueryExecutionFactory.create(q, model);
	System.out.println("Plan to run SPARQL query: ");
	System.out.println(BOUNDARY);
	System.out.println(query);
	System.out.println(BOUNDARY);
	ResultSet rs = qexec.execSelect();
	while (rs.hasNext()) {
		QuerySolution qs = rs.nextSolution();
		RDFNode name = qs.get(field);// using RDFNode currently
		if (name != null) {
			System.out.println("Hello to " + name);
		} else {
			System.out.println("No friends found!");
		}
	}
	qexec.close();
}
 
開發者ID:zhoujiagen,項目名稱:Jena-Based-Semantic-Web-Tutorial,代碼行數:30,代碼來源:HelloSemanticWeb.java

示例4: queryLabels

import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
private Set<String> queryLabels(QueryExecutionFactory qef, String query) throws IOException {
	QueryExecution exec = qef.createQueryExecution(query);
	ResultSet resultSet = null;
	try {
		resultSet = exec.execSelect();
	} catch (Exception e) {
		throw new IOException("Couldn't query labels.", e);
	}
	Set<String> labels = new HashSet<String>();
	QuerySolution result = null;
	RDFNode predicate, object;
	while (resultSet.hasNext()) {
		result = resultSet.next();
		predicate = result.get(PREDICATE);
		if ((predicate != null) && (LABEL_PROPERTIES.contains(predicate.toString()))) {
			object = result.get(OBJECT);
			if (object != null) {
				labels.add(object.toString());
			}
		}
	}
	return labels;
}
 
開發者ID:dice-group,項目名稱:Tapioca,代碼行數:24,代碼來源:SPARQLEndpointLabelExtractor.java

示例5: getWholeCount

import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
private long getWholeCount(SparqlifyDataset dataset) {
	long count = 0;
	Query query = QueryFactory.create("SELECT (count(*) AS ?count) { ?s ?p ?o }");
	QueryExecution qe;
	if (dataset.isSparqlService() && dataset.getSparqlServiceUri() != null) {
		qe = QueryExecutionFactory.sparqlService(dataset.getSparqlServiceUri(), query);
	} else {
		qe = QueryExecutionFactory.create(query, dataset);
	}
	ResultSet res = qe.execSelect();
	
	while(res.hasNext())
	{
		QuerySolution solution = res.nextSolution();
		RDFNode solNode = solution.get("count");
		count += solNode.asLiteral().getLong();
	}
	qe.close(); 
	
	return count;
}
 
開發者ID:SmartDataAnalytics,項目名稱:R2RLint,代碼行數:22,代碼來源:ExternalSameAsLinks.java

示例6: getDataEntryFromRS

import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
public DataEntry getDataEntryFromRS(ResultSet rs) {
	DataEntry dataEntry = new DataEntry();
	QuerySolution soln = rs.nextSolution();
	String colName, value;
	boolean useColumnNumbers = this.isUsingColumnNumbers();
	/* for each column get the colName and colValue and add to the data entry */
	for (int i = 0; i < rs.getResultVars().size(); i++) {
		colName = rs.getResultVars().get(i);
		RDFNode node = soln.get(colName) ;  			
		if (node.isLiteral()) {
			value = convertRSToString(soln, colName);
		} else {
			value = soln.getResource(colName).getURI();
		}			
		dataEntry.addValue(useColumnNumbers ? Integer.toString(i + 1) : 
			colName, new ParamValue(value));
	}
	return dataEntry;
}
 
開發者ID:wso2,項目名稱:carbon-data,代碼行數:20,代碼來源:SparqlQueryBase.java

示例7: getCountResult

import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
private int getCountResult(String queryStr, SparqlifyDataset dataset) {
	int count = 0;
	Query query = QueryFactory.create(queryStr);
	QueryExecution qe;
	if (dataset.isSparqlService() && dataset.getSparqlServiceUri() != null) {
		qe = QueryExecutionFactory.sparqlService(dataset.getSparqlServiceUri(), query);
	} else {
		qe = QueryExecutionFactory.create(query, dataset);
	}
	ResultSet res = qe.execSelect();
	
	while(res.hasNext())
	{
		QuerySolution solution = res.nextSolution();
		RDFNode solNode = solution.get("count");
		count += solNode.asLiteral().getInt();
	}
	qe.close(); 
	
	return count;
}
 
開發者ID:SmartDataAnalytics,項目名稱:R2RLint,代碼行數:22,代碼來源:InterlinkingCompleteness.java

示例8: 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

示例9: 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

示例10: main

import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
public static void main(String[] args) {
	ParameterizedSparqlString qs = new ParameterizedSparqlString(""
			+ "prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#>\n"
			+ "prefix dbpedia-owl: <http://dbpedia.org/ontology/>\n"
			+ "prefix dbpprop: <http://dbpedia.org/property/>\n"
			+ "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
			+
			"SELECT DISTINCT * \n" + "WHERE { \n"
			+ " ?resource  rdfs:label ?label ;\n"
			+ " dbpedia-owl:abstract ?abstract .\n"
			+ "FILTER ( lang(?abstract) = 'en' ) \n" + "}");

	Literal london = ResourceFactory.createLangLiteral("London", "en");
	qs.setParam("label", london);

	System.out.println(qs);

	QueryExecution exec = QueryExecutionFactory.sparqlService(
			"http://dbpedia.org/sparql", qs.asQuery());
	ResultSet results = ResultSetFactory.copyResults(exec.execSelect());

	while (results.hasNext()) {
		QuerySolution sol = (QuerySolution) results.next();
		RDFNode node = sol.get("resource");
		System.out.println(sol.get("?abstract"));
		System.out.println(node);
	}
	// A simpler way of printing the results.
	ResultSetFormatter.out(results);
}
 
開發者ID:nikolamilosevic86,項目名稱:Marvin,代碼行數:31,代碼來源:DBPediaQuery.java

示例11: mostrarTodo

import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
public static List<String> mostrarTodo(){
	
	
	String queryString = 
			"PREFIX vcard: <" + VCARD.getURI() + "> " +
			"SELECT ?Subject ?title "+
			"WHERE { ?Subject vcard:TITLE ?title. } ";
	Query query = QueryFactory.create(queryString);
	QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
	ResultSet results = qexec.execSelect() ;
	
	
	ArrayList<String> resultadoConsulta = new ArrayList<String>();
	
	while (results.hasNext())
	{
		QuerySolution binding = results.nextSolution();
		Resource subj = (Resource) binding.get("Subject");
		String categoria=subj.getProperty(VCARD.CATEGORIES).getLiteral().toString(); 
		if(categoria.length()>22)
			categoria=categoria.substring(23);
		else 
			categoria="actividad";
		resultadoConsulta.add("Evento: "+subj.getProperty(VCARD.TITLE).getLiteral()+"\n Fecha: "+subj.getProperty(VCARD.Other).getLiteral()+"  Categoría: "+categoria+"\n Biblioteca: "+subj.getProperty(VCARD.Locality).getLiteral());
	}
	
	return resultadoConsulta;
	
}
 
開發者ID:FacultadInformatica-LinkedData,項目名稱:Curso2014-2015,代碼行數:30,代碼來源:Consultas.java

示例12: ckeckLeadingZeros

import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
private void ckeckLeadingZeros(SparqlifyDataset dataset)
		throws NotImplementedException, SQLException {
	// http://www.w3.org/TR/2003/WD-rdf-syntax-grammar-20030123/#rdf-ns-uri
	
	String queryStr =
		"Prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
		"SELECT * { " +
			"?s ?p ?o . " +
			"FILTER(regex(str(?p), \"^http://www.w3.org/1999/02/22-rdf-syntax-ns#_0\")) " +
		"}";
	
	Query query = QueryFactory.create(queryStr);
	
	QueryExecution qe;
	if (dataset.isSparqlService() && dataset.getSparqlServiceUri()!=null) {
		qe = QueryExecutionFactory.createServiceRequest(
				dataset.getSparqlServiceUri(), query);
	} else {
		qe = QueryExecutionFactory.create(query, dataset);
	}
	ResultSet res = qe.execSelect();
	
	List<Triple> leadingZeroTriples = new ArrayList<Triple>();
	while(res.hasNext())
	{
		QuerySolution solution = res.nextSolution();
		Resource subj = solution.getResource("s");
		Resource pred = solution.getResource("p");
		RDFNode obj = solution.get("o");
		Triple leadingzeroTriple = new Triple(subj.asNode(), pred.asNode(), obj.asNode());
		leadingZeroTriples.add(leadingzeroTriple);
	}
	qe.close(); 
	
	for (Triple triple : leadingZeroTriples) {
		Set<ViewQuad<ViewDefinition>> viewQuads = pinpointer.getViewCandidates(triple);
		writeTripleMeasureToSink(leadingZeroVal, triple, viewQuads);
	}
}
 
開發者ID:SmartDataAnalytics,項目名稱:R2RLint,代碼行數:40,代碼來源:CorrectContainerUse.java

示例13: retrieveClassesInUse

import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
/**
 * @see KnowledgeBaseConnector#classesInUse
 */
private void retrieveClassesInUse() {
	classesInUseSet = new HashSet<String>();
	classesInUse = new HashMap<String, Integer>();
	String query = "SELECT ?t (COUNT(?t) as ?count)  WHERE { ?s a ?t } GROUP BY ?t ORDER BY DESC(?count) LIMIT 10000";
	log.debug("Retrieving classes in use for endpoint " + sparqlEndpoint);
	try {
		QueryExecution qexec = getQueryExec(query);
		ResultSet results = qexec.execSelect();
		while (results.hasNext()) {
			QuerySolution sol = results.next();
			RDFNode t = sol.get("?t");
			if (t.isResource()) {
				String classResourceUri = t.asResource().getURI();
				int count = sol.getLiteral("?count").getInt();
				classesInUse.put(classResourceUri, count);
				classesInUseSet.add(classResourceUri);
			} else {
				log.warn("Query \"" + query + "\" for endpoint " + sparqlEndpoint + " returned a non-resource ?t: " + t);
			}
		}
		log.info("Found " + classesInUseSet.size() + " classes in use for endpoint " + sparqlEndpoint);
		qexec.close();
	} catch (Exception e) {
		log.error("Failed to retrieve classes in use for endpoint " + sparqlEndpoint + ": ", e);
	}
}
 
開發者ID:johannessimon,項目名稱:pal,代碼行數:30,代碼來源:KnowledgeBaseConnector.java

示例14: query

import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
/**
 * Executes the specified SPARQL query and returns the result(s) with
 * respect to the focus variable
 */
public Collection<String> query(String queryString, String focusVariable) {
	Collection<String> res = new LinkedList<String>();
	
	// Invalid query check
	if (queryString == null || queryString.contains("<null>")) {
		return res;
	}
	

	final int RESULT_LIMIT = 1000;
	if (!queryString.contains("LIMIT")) {
		queryString += " LIMIT " + RESULT_LIMIT;
	}
	
	try {
		QueryExecution qexec = getQueryExec(queryString);
		ResultSet results = qexec.execSelect();
		for (; results.hasNext(); )
		{
			QuerySolution soln = results.nextSolution();
			RDFNode var = soln.get(focusVariable);
			if (var != null) {
				String varString = null;
				if (var.isResource()) {
					Resource r = var.asResource();
					varString = URLDecoder.decode(r.getURI(), "UTF-8");
				} if (var.isLiteral()) {
					Literal l = var.asLiteral();
					varString = l.getValue().toString();
				}
				res.add(varString);
			}
		}
		qexec.close();
	} catch (Exception e) {
		log.error("Failed to execute query \"" + queryString + "\":", e);
	}
	return res;
}
 
開發者ID:johannessimon,項目名稱:pal,代碼行數:44,代碼來源:KnowledgeBaseConnector.java

示例15: findForSubject

import com.hp.hpl.jena.query.QuerySolution; //導入方法依賴的package包/類
public CSet findForSubject(RDFNode s) {
	System.out.println("searching for predicates for " + s.asResource().getLocalName());
	
	Query query = QueryFactory.create(getSetQuery(s)) ;
	List<Triplet> triplets = new ArrayList<Triplet>();
	  QueryExecution qexec = null;
	  try {
		  qexec  = QueryExecutionFactory.sparqlService(endpoint, query, graph);
	  }
	  catch(Error e) {
		  System.err.println("Error on creating query: "+query+" .... error: "+e.getMessage());
		  return null;
	  }
	    ResultSet results = qexec.execSelect() ;
	    for ( ; results.hasNext() ; )
	    {
	      QuerySolution soln = results.nextSolution() ;
	      RDFNode predicate = soln.get("?p") ;       // Get a result variable by name.
		  RDFNode objType = soln.get("?otyped");
		  if(objType != null)
		  {
			  triplets.add(new Triplet(s, predicate, objType));
		      System.out.println("found predicate ... " + predicate.asResource().getNameSpace()+ " : "+ 
		    		  predicate.asResource().getLocalName());
		  }
	      
	    }
	  return new CSet(triplets);		 
}
 
開發者ID:marek-dudas,項目名稱:LODSight,代碼行數:30,代碼來源:CSetFinder.java


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