本文整理汇总了Java中org.apache.jena.sparql.engine.http.QueryEngineHTTP类的典型用法代码示例。如果您正苦于以下问题:Java QueryEngineHTTP类的具体用法?Java QueryEngineHTTP怎么用?Java QueryEngineHTTP使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueryEngineHTTP类属于org.apache.jena.sparql.engine.http包,在下文中一共展示了QueryEngineHTTP类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runSelectQuery
import org.apache.jena.sparql.engine.http.QueryEngineHTTP; //导入依赖的package包/类
static ResultSet runSelectQuery(String queryString, String service, String... defaultGraphs) throws Exception {
QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(service, queryString);
qExec.addDefaultGraph(Constants.DBPEDIA_URL);
if (defaultGraphs != null) {
for (String defaultGraph : defaultGraphs) {
qExec.addDefaultGraph(defaultGraph);
}
}
qExec.addParam("timeout", Constants.TIMEOUT_VALUE); //100 sec
ResultSet set = null;
try {
set = qExec.execSelect();
set = ResultSetFactory.copyResults(set);
} catch (Exception e) {
QGenLogger.severe("Exception in SELECT\n" + queryString + "\n" + e.getMessage());
} finally {
qExec.close();
}
return set;
}
示例2: createRemoteQueryExecution
import org.apache.jena.sparql.engine.http.QueryEngineHTTP; //导入依赖的package包/类
public QueryEngineHTTP createRemoteQueryExecution(
String service,
Query query,
List<String> defaultGraphURIs,
List<String> namedGraphURIs,
String user,
String password) {
HttpClient httpClient = buildHttpClient(service, user, password);
QueryEngineHTTP qexec = (QueryEngineHTTP) QueryExecutionFactoryFilter.get().sparqlService(service, query, httpClient);
if( defaultGraphURIs.size() > 0 ) {
qexec.setDefaultGraphURIs(defaultGraphURIs);
}
if( namedGraphURIs.size() > 0 ) {
qexec.setNamedGraphURIs(namedGraphURIs);
}
return qexec;
}
示例3: main
import org.apache.jena.sparql.engine.http.QueryEngineHTTP; //导入依赖的package包/类
static public void main(String...argv)
{
String queryStr = "select distinct ?Concept where {[] a ?Concept} LIMIT 10";
Query query = QueryFactory.create(queryStr);
// Remote execution.
try ( QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query) ) {
// Set the DBpedia specific timeout.
((QueryEngineHTTP)qexec).addParam("timeout", "10000") ;
// Execute.
ResultSet rs = qexec.execSelect();
ResultSetFormatter.out(System.out, rs, query);
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: sparql
import org.apache.jena.sparql.engine.http.QueryEngineHTTP; //导入依赖的package包/类
public String sparql(String subject) {
// First query takes the most specific class from a given resource.
String ontology_service = endpoint;
String endpointsSparql = "select ?label where {<" + subject
+ "> <http://www.w3.org/2000/01/rdf-schema#label> ?label FILTER (lang(?label) = 'en')} LIMIT 100";
Query sparqlQuery = QueryFactory.create(endpointsSparql, Syntax.syntaxARQ);
QueryEngineHTTP qexec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(ontology_service, sparqlQuery);
qexec.setModelContentType(WebContent.contentTypeRDFXML);
ResultSet results = qexec.execSelect();
String property = null;
while (results.hasNext()) {
QuerySolution qs = results.next();
property = qs.getLiteral("?label").getLexicalForm();
}
return property;
}
示例5: executeQuery
import org.apache.jena.sparql.engine.http.QueryEngineHTTP; //导入依赖的package包/类
public QueryExecution executeQuery(String queryString) {
logger.info("SPARQL Query is:\n" + queryString);
Query query = QueryFactory.create(queryString);
QueryEngineHTTP queryEngine = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(ENDPOINT, query);
queryEngine.addParam("timeout", String.valueOf(Constants.API_TIMEOUT));
return queryEngine;
}
示例6: ask
import org.apache.jena.sparql.engine.http.QueryEngineHTTP; //导入依赖的package包/类
/**
*
* @param sparql
* @return boolean True if ASK query passes
*/
private static boolean ask(String sparql) {
try {
LOGGER.debug(sparql);
Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
httpQuery = new QueryEngineHTTP(S_E, query);
boolean result = httpQuery.execAsk();
LOGGER.debug(result);
return result;
} catch (Exception e) {
LOGGER.error(e);
return false;
}
}
示例7: ask
import org.apache.jena.sparql.engine.http.QueryEngineHTTP; //导入依赖的package包/类
public boolean ask(String query)
{
StopWatch watch = StopWatches.INSTANCE.getWatch("sparql");
watch.start();
try(QueryEngineHTTP qe = new QueryEngineHTTP(endpoint, prefixes+query);)
{
defaultGraphs.forEach(qe::addDefaultGraph);
return qe.execAsk();
} catch(Exception e) {throw new RuntimeException("Error on SPARQL ASK on endpoint "+endpoint+" with query:\n"+query,e);}
finally {watch.stop();}
}
示例8: select
import org.apache.jena.sparql.engine.http.QueryEngineHTTP; //导入依赖的package包/类
public ResultSetRewindable select(String query)
{
StopWatch watch = StopWatches.INSTANCE.getWatch("sparql");
watch.start();
try(QueryEngineHTTP qe = new QueryEngineHTTP(endpoint, prefixes+query);)
{
qe.setDefaultGraphURIs(defaultGraphs);
return ResultSetFactory.copyResults(qe.execSelect());
} catch(Exception e) {throw new RuntimeException("Error on sparql select on endpoint "+endpoint+" with query:\n"+query,e);}
finally {watch.stop();}
}
示例9: test
import org.apache.jena.sparql.engine.http.QueryEngineHTTP; //导入依赖的package包/类
@Test public void test()
{
String query ="select (min(xsd:double(?d)) as ?min) "
+ "{?o a qb:Observation. ?o qb:dataSet <http://linkedspending.aksw.org/instance/finland-aid>.?o <http://linkedspending.aksw.org/ontology/finland-aid-aid-to-environment> ?d.} limit 1";
try(QueryEngineHTTP qe = new QueryEngineHTTP("http://linkedspending.aksw.org/sparql", query))
{
ResultSet rs = qe.execSelect();
QuerySolution qs = rs.nextSolution();
assertTrue(qs.get("min").asLiteral().getDouble()==0);
}
}
示例10: customizeRequest
import org.apache.jena.sparql.engine.http.QueryEngineHTTP; //导入依赖的package包/类
@Override
protected void customizeRequest(QueryExecution qe) {
super.customizeRequest(qe);
if (qe instanceof QueryEngineHTTP) {
QueryEngineHTTP remote = (QueryEngineHTTP) qe;
T options = this.getOptions();
remote.setSelectContentType(options.getResultsSelectFormat());
remote.setAskContentType(options.getResultsAskFormat());
remote.setModelContentType(options.getResultsGraphFormat());
remote.setAllowDeflate(options.getAllowCompression());
remote.setAllowGZip(options.getAllowCompression());
}
}
示例11: customizeRequest
import org.apache.jena.sparql.engine.http.QueryEngineHTTP; //导入依赖的package包/类
@Override
protected void customizeRequest(QueryExecution qe) {
super.customizeRequest(qe);
if (qe instanceof QueryEngineHTTP) {
QueryEngineHTTP remote = (QueryEngineHTTP) qe;
for (Entry<String, List<String>> nvp : this.nvps.entrySet()) {
for (String value : nvp.getValue()) {
remote.addParam(nvp.getKey(), value);
}
}
}
}
示例12: getNMostSpecificYAGOTypesForDepthRange
import org.apache.jena.sparql.engine.http.QueryEngineHTTP; //导入依赖的package包/类
static List<String> getNMostSpecificYAGOTypesForDepthRange(String resourceURI, int n, int depthLowerBound, int depthUpperBound) {
String queryString = Constants.PREFIX_RDFS;
String variableName = "type";
resourceURI = "<" + resourceURI + ">";
queryString += "SELECT ?" + variableName + " ?count WHERE {\n" +
"{\n" +
"SELECT DISTINCT ?" + variableName + " (COUNT(*) as ?count) WHERE {\n" +
" {\n" +
" select distinct ?" + variableName + " where {\n" +
resourceURI + " a ?" + variableName + " .\n" +
" filter (strstarts(str(?" + variableName + "), \"" + Constants.DBPEDIA_URL + "\"))\n" +
" filter (!strstarts(str(?" + variableName + "), \"" + Constants.DBPEDIA_CLASS_YAGO_WIKICAT + "\"))\n" +
" }\n" +
" }\n" +
" ?" + variableName + " rdfs:subClassOf* ?path .\n" +
"} group by ?" + variableName + " order by desc (?count)\n" +
"}\n";
if (n != -1) {
queryString += "filter (?count < " + depthUpperBound + " && ?count > " + depthLowerBound + ")\n";
}
queryString += "} limit " + n;
// ResultSet resultSet = null;
// try {
// resultSet = runSelectQuery(queryString, DBPEDIA_SPARQL_SERVICE);
// } catch (Exception e) {
// e.printStackTrace();
// }
QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(Constants.DBPEDIA_SPARQL_SERVICE, queryString);
qExec.addDefaultGraph("http://dbpedia.org");
ResultSet resultSet = null;
try {
resultSet = qExec.execSelect();
resultSet = ResultSetFactory.copyResults(resultSet);
} catch (Exception e) {
// Report exception
} finally {
qExec.close();
}
return QueryUtils.getResultSetAsStringList(resultSet, variableName, false);
}
示例13: getLinkSUMForResource
import org.apache.jena.sparql.engine.http.QueryEngineHTTP; //导入依赖的package包/类
static List<LinkSUMResultRow> getLinkSUMForResource(String resourceURI) {
resourceURI = "<" + resourceURI + ">";
String queryString = Constants.PREFIX_RDFS + Constants.PREFIX_VRANK + Constants.PREFIX_DBPEDIA_ONTOLOGY + Constants.PREFIX_DBPEDIA_PROPERTY +
"SELECT distinct (SAMPLE (?s) AS ?subject) (SAMPLE (?p) AS ?pred) (SAMPLE(?o) AS ?object) " +
"(SAMPLE(?slabel) AS ?sublabel) (SAMPLE (?plabel) AS ?predlabel) (SAMPLE(?olabel) AS ?oblabel) ?v \n" +
"FROM <" + Constants.DBPEDIA_URL + "> \n" +
"FROM <" + Constants.DBPEDIA_PAGE_RANK + "> \n" +
"WHERE {\n" +
"\t{\t" + resourceURI + " ?p ?o.\n" +
"\t\tFILTER regex(str(?o),\"http://dbpedia.org/resource\",\"i\").\n" +
"\t\tFILTER (?p != dbp-ont:wikiPageWikiLink && ?p != <http://purl.org/dc/terms/subject> " +
"&& ?p != dbp-prop:wikiPageUsesTemplate && ?p != rdfs:seeAlso && ?p != <http://www.w3.org/2002/07/owl#differentFrom> " +
"&& ?p != dbp-ont:wikiPageDisambiguates && ?p != dbp-ont:wikiPageRedirects && ?p != dbp-ont:wikiPageExternalLink).\n" +
"\t\tOPTIONAL {?o rdfs:label ?olabel. FILTER langmatches( lang(?olabel), \"EN\" ). }.\n" +
"\t\tOPTIONAL {?p rdfs:label ?plabel. FILTER langmatches( lang(?plabel), \"EN\" ).}.\n" +
"\t\tOPTIONAL {" + resourceURI + " rdfs:label ?slabel. FILTER langmatches( lang(?slabel), \"EN\" ).}.\n" +
"\t\tOPTIONAL {?o vrank:hasRank ?r. ?r vrank:rankValue ?v}.\n" +
"\t} \n" +
"UNION\n" +
"\t{\t?s ?p " + resourceURI + ".\n" +
"\t\tFILTER regex(str(?s),\"http://dbpedia.org/resource\",\"i\").\n" +
"\t\tFILTER (?p != dbp-ont:wikiPageWikiLink && ?p != <http://purl.org/dc/terms/subject> " +
"&& ?p != dbp-prop:wikiPageUsesTemplate && ?p != rdfs:seeAlso && ?p != <http://www.w3.org/2002/07/owl#differentFrom> " +
"&& ?p != dbp-ont:wikiPageDisambiguates && ?p != dbp-ont:wikiPageRedirects && ?p != dbp-ont:wikiPageExternalLink).\n" +
"\t\tOPTIONAL {?s rdfs:label ?slabel. FILTER langmatches( lang(?slabel), \"EN\" ). }.\n" +
"\t\tOPTIONAL {?p rdfs:label ?plabel. FILTER langmatches( lang(?plabel), \"EN\" ).}.\n" +
"\t\tOPTIONAL {" + resourceURI + " rdfs:label ?olabel. FILTER langmatches( lang(?olabel), \"EN\" ).}.\n" +
"\t\tOPTIONAL {?s vrank:hasRank ?r. ?r vrank:rankValue ?v}.\n" +
"\t}\n" +
"} group by ?v order by desc (?v)";
// ResultSet resultSet = null;
// try {
// resultSet = runSelectQuery(query, DBPEDIA_SPARQL_SERVICE);
// } catch (Exception e) {
// e.printStackTrace();
// }
// String DBPEDIA_SPARQL_SERVICE = "http://dbpedia.org/sparql/";
QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(Constants.DBPEDIA_SPARQL_SERVICE, queryString);
qExec.addDefaultGraph(Constants.DBPEDIA_URL);
ResultSet resultSet = null;
try {
resultSet = qExec.execSelect();
resultSet = ResultSetFactory.copyResults(resultSet);
} catch (Exception e) {
// Report exception
} finally {
qExec.close();
}
// if (resultSet != null) {
// while (resultSet.hasNext()) {
// QuerySolution result = resultSet.next();
// if (result != null) {
// System.out.println(result);
// }
// }
// }
return QueryUtils.getResultSetAsObjectList(resultSet);
}
示例14: Cixty_Query
import org.apache.jena.sparql.engine.http.QueryEngineHTTP; //导入依赖的package包/类
public String Cixty_Query(String city, String publisher, String output) {
String queryString ="PREFIX dul: <http://ontologydesignpatterns.org/ont/dul/DUL.owl#>\n" +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"+
"PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" +
"PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>\n"+
"PREFIX locationOnt: <http://data.linkedevents.org/def/location#>" +
"select * where { \n" +
" graph <http://3cixty.com/" + city + '/' + publisher + ">{?s a dul:Place}\n" +
" ?s rdfs:label ?label .\n" +
" ?s locationOnt:businessTypeTop ?category .\n" +
" ?s dc:identifier ?identifier .\n" +
" ?s dc:publisher ?publisher .\n" +
" ?s geo:location/geo:lat ?latitude .\n" +
" ?s geo:location/geo:long ?longitude .\n" +
" ?s dc:publisher ?publisher\n" +
"}";
try {
System.out.println(queryString);
Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
//send sparql to endpoint
QueryEngineHTTP httpQuery = QueryExecutionFactory.createServiceRequest(sparqlEndpoint,query);
ResultSet results = httpQuery.execSelect();
//output a result to a JSON file
File file = new File(output + '/' + city + '_' + publisher + ".cixtyjson");
FileOutputStream fout = new FileOutputStream(file);
ResultSetFormatter.outputAsJSON(fout, results);
fout.close();
httpQuery.close();
System.out.println(file.getName());
return (output + '/' + city + '_' + publisher + ".cixtyjson");
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}