当前位置: 首页>>代码示例>>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;未经允许,请勿转载。