当前位置: 首页>>代码示例>>Java>>正文


Java QueryExecutionFactory.sparqlService方法代码示例

本文整理汇总了Java中com.hp.hpl.jena.query.QueryExecutionFactory.sparqlService方法的典型用法代码示例。如果您正苦于以下问题:Java QueryExecutionFactory.sparqlService方法的具体用法?Java QueryExecutionFactory.sparqlService怎么用?Java QueryExecutionFactory.sparqlService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.hp.hpl.jena.query.QueryExecutionFactory的用法示例。


在下文中一共展示了QueryExecutionFactory.sparqlService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTypesFromSPARQL

import com.hp.hpl.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
private Set<String> getTypesFromSPARQL(String sparqlQueryString) {

        Query query = QueryFactory.create(sparqlQueryString);
        QueryExecution qexec = QueryExecutionFactory.sparqlService(this.endpoint, query);
        Set<String> types = new HashSet<>();

        ResultSet results = qexec.execSelect();
        while(results.hasNext()) {
            QuerySolution qs = results.next();
            Resource type = qs.getResource("?type");
            types.add(type.getURI());
        }

        qexec.close();
        return types;
    }
 
开发者ID:freme-project,项目名称:freme-ner,代码行数:17,代码来源:SPARQLProcessor.java

示例2: main

import com.hp.hpl.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
public static void main(String[] args) {
	// populate SPARQL SELECT Query string
	StringBuilder sb = new StringBuilder();
	sb.append("PREFIX books:   <http://example.org/book/>").append(NEWLINE);
	sb.append("PREFIX dc:      <http://purl.org/dc/elements/1.1/>").append(NEWLINE);
	sb.append("SELECT ?book ?title").append(NEWLINE);
	sb.append("WHERE {").append(NEWLINE);
	sb.append("		?book dc:title ?title").append(NEWLINE);
	sb.append("}").append(NEWLINE);

	// query from remote service
	QueryExecution qexec = QueryExecutionFactory.sparqlService(SERVICE_URL, sb.toString());

	System.out.println("Plan to run remote SPARQL query: ");
	System.out.println(BOUNDARY);
	System.out.println(sb.toString());
	System.out.println(BOUNDARY);

	ResultSet rs = qexec.execSelect();

	// use result set formatter
	ResultSetFormatter.out(rs);

	qexec.close();
}
 
开发者ID:zhoujiagen,项目名称:Jena-Based-Semantic-Web-Tutorial,代码行数:26,代码来源:SelectQueryUsingRemoteService.java

示例3: queryRemote

import com.hp.hpl.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
/**
 * RDF Navigation using remote SPARQL Query
 * 
 * @param service
 *            the SAPRQL end point URL
 * @param query
 *            SPARQL Query String
 * @param queryField
 *            the placeholder of filed in parameter query(sample: ?name)
 */
public static void queryRemote(final String service, final String query, String... queryFields) {
	if (queryFields == null || queryFields.length == 0) {
		return;
	}

	QueryExecution qexec = QueryExecutionFactory.sparqlService(service, query);

	System.out.println("Plan to run remote SPARQL query: ");
	System.out.println(BOUNDARY);
	System.out.println(query);
	System.out.println(BOUNDARY);

	ResultSet rs = qexec.execSelect();
	rendererResultSet(rs, queryFields);

	System.out.println(BOUNDARY);

	qexec.close();
}
 
开发者ID:zhoujiagen,项目名称:Jena-Based-Semantic-Web-Tutorial,代码行数:30,代码来源:SPARQLUtils.java

示例4: poseInfoQuery

import com.hp.hpl.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
/**
 * Queries DBPedia dataset for info based on the name of the city of the current location
 * @param location
 * @return
 */
public static DBPediaInfoObject poseInfoQuery(Location location) { 
	String sQuery = "";
	try {
        java.net.URL url = Play.class.getResource("/dbpedia_sparql.txt");
        java.nio.file.Path resPath = java.nio.file.Paths.get(url.toURI());
        sQuery= new String(java.nio.file.Files.readAllBytes(resPath), "UTF8");

           sQuery = sQuery.replace("SIMPLE_NAME", location.getSimpleName());

           Query query = QueryFactory.create(sQuery);
           QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
           ResultSet results = qexec.execSelect();
           // Put result into a DBPediaInfoObject
           DBPediaInfoObject info = parseResult(results);
           qexec.close();

           return info;
	} catch (Exception e) {
		e.printStackTrace();
	}

       return null;
}
 
开发者ID:Localizr,项目名称:Localizr,代码行数:29,代码来源:DBPedia.java

示例5: getGeoLocation

import com.hp.hpl.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
/**
  * Gets and returns the geolocation of a POI
  * @param resource
  * @return
  */
 private static Literal getGeoLocation(String resource){
 	
 	Literal geoLocation;
 	
 	String sparqlquery= "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#> \n"			
				+ "select distinct ?geolocation where {" 
				+ "<"+resource+"> geo:geometry ?geolocation.}\n"
				+ "LIMIT 1 ";
 	Query query = QueryFactory.create(sparqlquery);
  QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
  ResultSet results = qexec.execSelect();
  if (results.hasNext() ){ 				
QuerySolution soln = results.nextSolution();
geoLocation = soln.getLiteral("geolocation");
   qexec.close();
   return geoLocation;
  }
  else {
   qexec.close();
  	return null;
  }
 }
 
开发者ID:Localizr,项目名称:Localizr,代码行数:28,代码来源:GeoNamesRecommendation.java

示例6: retrieveHierarchyTwo

import com.hp.hpl.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
/**
 * Queries for the supertypes of the given resource
 * @param resource
 * @return
 */
private static List<Resource> retrieveHierarchyTwo(String resource){
	
	String sparqlquery= "PREFIX dbpedia-owl:<http://dbpedia.org/ontology/> \n"
+ "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#> \n"
+ "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> \n"
+ "PREFIX foaf:<http://xmlns.com/foaf/0.1/> \n"
+ "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#> \n"
+ "select distinct ?super ?subclass where {" 
+ "<"+resource+"> a ?super.\n"
+ "<"+resource+">  a ?subclass.\n"
+ "?subclass rdfs:subClassOf ?super.\n"
+ "FILTER (?subclass!=?super)}";
	
	Query query = QueryFactory.create(sparqlquery);
 QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
 ResultSet results = qexec.execSelect();
 
 // Parse the result to avoid transitivity and thus repetition of types
 List<Resource> hierarchy_two = parseResult(results);
 qexec.close();
 
 return hierarchy_two;

}
 
开发者ID:Localizr,项目名称:Localizr,代码行数:30,代码来源:GeoNamesRecommendation.java

示例7: fetch

import com.hp.hpl.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
private ArrayList<QuerySolution> fetch(String pageQueryString) {
	ArrayList<QuerySolution> result = new ArrayList<QuerySolution>();
	Query q = QueryFactory.create(pageQueryString);
	QueryExecution qexec =QueryExecutionFactory.sparqlService(endPoint, q);
	ResultSet results;
	try {
		results = qexec.execSelect();		
		for (; results.hasNext();) {
			QuerySolution soln = results.nextSolution();
			result.add(soln);				
		}
	}
	catch(Exception e){
		e.printStackTrace();
		return null;
	}		
	finally {
		qexec.close();
	}		
	return result;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:22,代码来源:SparqlQueryPager.java

示例8: getNumResources

import com.hp.hpl.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
/**
 * It executes a SELECT SPARQL query on the SPARQL endpoint, 
 * to get the number of resources specified in the query argument.
 *
 * @param query					the query to execute to get the number of resources.  
 * @param sparqlEndpointURI		the SPARQL endpoint URI.  
 * @param user					the user name for the SPARQl endpoint.
 * @param password				the password for the SPARQl endpoint.
 * @return the number of resources.
 * @since 2.0
 */
public int getNumResources(final String query, final String sparqlEndpointURI, final String user, final String password) {
	int numRes = 0;
	try {
        // Execute the query and obtain results
        final QueryExecution qexec = QueryExecutionFactory.sparqlService(
        		sparqlEndpointURI, 
        		QueryFactory.create(query), 
				auth(sparqlEndpointURI, user, password));
        qexec.setTimeout(2000, 5000);
           final ResultSet results = qexec.execSelect() ;
           while (results.hasNext())
           {
           	final QuerySolution soln = results.nextSolution() ;
           	numRes = soln.getLiteral("count").getInt();
           }
        qexec.close() ;
      } catch (Exception exception) {
		LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query);
	}
	return numRes;
}
 
开发者ID:ALIADA,项目名称:aliada-tool,代码行数:33,代码来源:RDFStoreDAO.java

示例9: executeSelect

import com.hp.hpl.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
/**
 * It executes a SELECT SPARQL query on the SPARQL endpoint.
 *
 * @param sparqlEndpointURI		the SPARQL endpoint URI.  
 * @param user					the user name for the SPARQl endpoint.
 * @param password				the password for the SPARQl endpoint.
 * @param query					the query to use to look for the resources.
 * @return the {@link com.hp.hpl.jena.query.ResultSet} of the SELECT SPARQL query.
 * @since 2.0
 */
public ResultSet executeSelect(final String sparqlEndpointURI, final String user, final String password, final String query) {
	ResultSet results = null;
 	try {
        // Execute the query and obtain results
        final QueryExecution qexec = QueryExecutionFactory.sparqlService(
        		sparqlEndpointURI, 
        		QueryFactory.create(query), 
				auth(sparqlEndpointURI, user, password));
        qexec.setTimeout(2000, 5000);
           results = qexec.execSelect() ;
        qexec.close() ;
      } catch (Exception exception) {
		LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query);
	}
 	return results;
}
 
开发者ID:ALIADA,项目名称:aliada-tool,代码行数:27,代码来源:RDFStoreDAO.java

示例10: size

import com.hp.hpl.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
@Override
public long size() {
	if (sparqlWrapping) {
		if (size < 0 || !cachingEnabled) {
			Query query = QueryFactory.create(
					"SELECT DISTINCT (count(*) AS ?count) {?s ?p ?o}");
			QueryExecution qe = QueryExecutionFactory.sparqlService(
					((SparqlGraph) getGraph()).getServiceUri(),
					query);
			ResultSet res = qe.execSelect();
			RDFNode count = null;
			while(res.hasNext())
			{
				QuerySolution sol = res.nextSolution();
				count = sol.get("count").asLiteral();
			}
			qe.close();
			
			return count.asLiteral().getLong();
		} else {
			return size;
		}
	} else {
		return super.size();
	}
}
 
开发者ID:SmartDataAnalytics,项目名称:R2RLint,代码行数:27,代码来源:SparqlifyDataset.java

示例11: getWholeCount

import com.hp.hpl.jena.query.QueryExecutionFactory; //导入方法依赖的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

示例12: getCountResult

import com.hp.hpl.jena.query.QueryExecutionFactory; //导入方法依赖的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,代码行数:23,代码来源:PopulationCompleteness.java

示例13: getCountResult

import com.hp.hpl.jena.query.QueryExecutionFactory; //导入方法依赖的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

示例14: queryClassPartitionStatistics

import com.hp.hpl.jena.query.QueryExecutionFactory; //导入方法依赖的package包/类
private void queryClassPartitionStatistics() {
	Query query = QueryFactory.create(classPartitionStatisticsQuery);
	QueryExecution qexec = QueryExecutionFactory.sparqlService(
			this.sparqlEndPoint.toString(), query);

	try {
		ResultSet results = qexec.execSelect();
		for (; results.hasNext();) {
			QuerySolution soln = results.nextSolution();
			OntResource clazz = soln.getResource("class").as(
					OntResource.class);
			Integer entities = (soln.getLiteral("count") != null) ? soln
					.getLiteral("count").getInt() : null;
			partitions.addClassPartition(clazz, entities);
		}
	} catch (Exception e) {
		Log.debug(
				Dataset.class,
				"Unable to connect to SPARQLEndpoint to execute classPartitionStatisticsQuery: "
						+ this.sparqlEndPoint.toString());
	} finally {
		qexec.close();
	}
}
 
开发者ID:peterjohnlawrence,项目名称:com.inova8.remediator,代码行数:25,代码来源:Dataset.java

示例15: subscribeTopics

import com.hp.hpl.jena.query.QueryExecutionFactory; //导入方法依赖的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;
  }
}
 
开发者ID:semiotproject,项目名称:semiot-platform,代码行数:31,代码来源:CSPARQL.java


注:本文中的com.hp.hpl.jena.query.QueryExecutionFactory.sparqlService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。