本文整理匯總了Java中com.hp.hpl.jena.query.QueryExecution.setTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryExecution.setTimeout方法的具體用法?Java QueryExecution.setTimeout怎麽用?Java QueryExecution.setTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.query.QueryExecution
的用法示例。
在下文中一共展示了QueryExecution.setTimeout方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: crm2AliadaClass
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
public String crm2AliadaClass(final String crmClass) {
final Query query = QueryFactory.create(CRM_TO_ALIADA_CLASS_P1 + crmClass + CRM_TO_ALIADA_CLASS_P2);
ARQ.getContext().setTrue(ARQ.useSAX);
QueryExecution execution = null;
try {
execution = QueryExecutionFactory.sparqlService("http://172.25.5.15:8890/sparql", query);
execution.setTimeout(2000, 5000);
final ResultSet results = execution.execSelect();
//Iterating over the SPARQL Query results
while (results.hasNext()) {
QuerySolution soln = results.nextSolution();
//Printing DBpedia entries' abstract.
System.out.println(soln.get("?abstract"));
return soln.get("?abstract").asResource().getURI();
}
return "NULL";
} finally {
try {
execution.close();
} catch (Exception exception) {
// TODO: handle exception
}
}
}
示例2: getNumResources
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的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;
}
示例3: executeSelect
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的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;
}
示例4: subscribeTopics
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的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;
}
}
示例5: getDiscoveredLinks
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
/**
* It executes a SELECT SPARQL query on the SPARQL endpoint,
* to get the discovered links.
*
* @param sparqlEndpointURI the SPARQL endpoint URI.
* @param graphName the graphName, null in case of default graph.
* @param user the user name for the SPARQl endpoint.
* @param password the password for the SPARQl endpoint.
* @param offset causes the solutions generated to start after
* the specified number of solutions.
* @param limit upper bound on the number of solutions returned.
* @return a list of triples with the discovered links.
* @since 2.0
*/
public Triple[] getDiscoveredLinks(final String sparqlEndpointURI, final String graphName, final String user, final String password, final int offset, final int limit) {
final String query = "select * FROM <" + graphName + "> " +
"where {?source ?rel ?target }" +
" ORDER BY ?source ?target" +
" OFFSET " + offset + " LIMIT " + limit;
ArrayList<Triple> linksList = new ArrayList<Triple>();
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() ;
final Resource sourceResType = soln.getResource("source");
final Resource targetResType = soln.getResource("target");
final Resource relResType = soln.getResource("rel");
final Triple triple = new Triple(sourceResType.asNode(), relResType.asNode(), targetResType.asNode());
linksList.add(triple);
}
qexec.close() ;
} catch (Exception exception) {
LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query);
}
if (linksList.isEmpty()) {
return new Triple[0];
}
return (Triple[]) linksList.toArray(new Triple[linksList.size()]);
}
示例6: getAmbiguousDiscoveredLinks
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
/**
* It executes a SELECT SPARQL query on the SPARQL endpoint,
* to get the ambiguous discovered links.
*
* @param sparqlEndpointURI the SPARQL endpoint URI.
* @param graphName the graphName, null in case of default graph.
* @param user the user name for the SPARQl endpoint.
* @param password the password for the SPARQl endpoint.
* @param offset causes the solutions generated to start after
* the specified number of solutions.
* @param limit upper bound on the number of solutions returned.
* @return a list of {@link eu.aliada.shared.rdfstore.AmbiguousLink} with the ambiguous discovered links.
* @since 2.0
*/
public AmbiguousLink[] getAmbiguousDiscoveredLinks(final String sparqlEndpointURI, final String graphName, final String user, final String password, final int offset, final int limit) {
final String query = "SELECT ?localRes ?extResBegin (COUNT(?localRes) AS ?count) FROM <" + graphName + "> " +
" WHERE {?localRes ?rel ?extRes ." +
" BIND( str(?extRes) as ?extResStr )." +
" BIND( SUBSTR(?extResStr, 1,14) AS ?extResBegin)" +
" }" +
" GROUP BY ?localRes ?extResBegin" +
" HAVING (COUNT(?localRes) > 1)" +
" ORDER BY ?localRes" +
" OFFSET " + offset + " LIMIT " + limit;
ArrayList<AmbiguousLink> ambiguousLinksList = new ArrayList<AmbiguousLink>();
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() ;
final Resource localRes = soln.getResource("localRes");
final String extResBegin = soln.getLiteral("extResBegin").getString();
final AmbiguousLink ambiguousLink = new AmbiguousLink();
ambiguousLink.setSourceURI(localRes.getURI());
getSourceURIAmbiguousLinks(ambiguousLink, localRes, extResBegin, sparqlEndpointURI, graphName, user, password);
ambiguousLinksList.add(ambiguousLink);
}
qexec.close() ;
} catch (Exception exception) {
LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query);
}
if (ambiguousLinksList.isEmpty()) {
return new AmbiguousLink[0];
}
return (AmbiguousLink[]) ambiguousLinksList.toArray(new AmbiguousLink[ambiguousLinksList.size()]);
}
示例7: getNumAmbiguousDiscoveredLinks
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
/**
* It executes a SELECT SPARQL query on the SPARQL endpoint,
* to get the number of ambiguous discovered links.
*
* @param sparqlEndpointURI the SPARQL endpoint URI.
* @param graphName the graphName, null in case of default graph.
* @param user the user name for the SPARQl endpoint.
* @param password the password for the SPARQl endpoint.
* @return the number of the ambiguous discovered links.
* @since 2.0
*/
public int getNumAmbiguousDiscoveredLinks (final String sparqlEndpointURI, final String graphName, final String user, final String password) {
final String query = "SELECT (COUNT(?localRes) AS ?count) FROM <" + graphName + "> " +
" WHERE {?localRes ?rel ?extRes ." +
" BIND( str(?extRes) as ?extResStr )." +
" BIND( SUBSTR(?extResStr, 1,14) AS ?extResBegin)" +
" }" +
" GROUP BY ?localRes ?extResBegin" +
" HAVING (COUNT(?localRes) > 1)";
int numLinks = 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() ;
numLinks = numLinks + soln.getLiteral("count").getInt();
}
qexec.close() ;
} catch (Exception exception) {
LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query);
}
return numLinks;
}
示例8: getSourceURIAmbiguousLinks
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
/**
* It executes a SELECT SPARQL query on the SPARQL endpoint,
* to get the ambiguous discovered links of a source URI.
*
* @param ambiguousLink a {@link eu.aliada.shared.rdfstore.AmbiguousLink} that contains the source URI.
* @param localRes the source resource of the link.
* @param extResBegin the beginning string of the target link.
* @param sparqlEndpointURI the SPARQL endpoint URI.
* @param graphName the graphName, null in case of default graph.
* @param user the user name for the SPARQl endpoint.
* @param password the password for the SPARQl endpoint.
* @param offset causes the solutions generated to start after
* the specified number of solutions.
* @param limit upper bound on the number of solutions returned.
* @since 2.0
*/
public void getSourceURIAmbiguousLinks(final AmbiguousLink ambiguousLink, final Resource localRes, final String extResBegin, final String sparqlEndpointURI, final String graphName, final String user, final String password) {
final String query = "SELECT ?rel ?extRes FROM <" + graphName + "> " +
" WHERE {<" + ambiguousLink.getSourceURI() + "> ?rel ?extRes ." +
" FILTER regex(?extRes, \"^" + extResBegin + "\", \"i\")" +
" }";
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() ;
final Resource extRes = soln.getResource("extRes");
final Resource relResType = soln.getResource("rel");
final Triple triple = new Triple(localRes.asNode(), relResType.asNode(), extRes.asNode());
ambiguousLink.addLink(triple);
}
qexec.close() ;
} catch (Exception exception) {
LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query);
}
}
示例9: getResources
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
/**
* It executes a SELECT SPARQL query on the SPARQL endpoint,
* to get the resources specified in the query argument.
*
* @param query the query to execute to get the resources.
* @param sparqlEndpointURI the SPARQL endpoint URI.
* @param user the user name for the SPARQl endpoint.
* @param password the password for the SPARQl endpoint.
* @param offset causes the solutions generated to start after
* the specified number of solutions.
* @param limit upper bound on the number of solutions returned.
* @return a list of {@link eu.aliada.shared.rdfstore.RetrievedResource} with the resources.
* @since 2.0
*/
public RetrievedResource[] getResources(final String query, final String sparqlEndpointURI, final String user, final String password, final int offset, final int limit) {
final ArrayList<RetrievedResource> resList = new ArrayList<RetrievedResource>();
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() ;
final Resource res = soln.getResource("res");
String name = "";
if(soln.contains("name")) {
name = soln.getLiteral("name").getString();
}
final RetrievedResource retrievedRes = new RetrievedResource(res.getURI(), name);
resList.add(retrievedRes);
}
qexec.close() ;
} catch (Exception exception) {
LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query);
}
if (resList.isEmpty()) {
return new RetrievedResource[0];
}
return (RetrievedResource[]) resList.toArray(new RetrievedResource[resList.size()]);
}
示例10: doGet
import com.hp.hpl.jena.query.QueryExecution; //導入方法依賴的package包/類
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
D2RServer server = D2RServer.fromServletContext(getServletContext());
server.checkMappingFileChanged();
String relativeResourceURI = request.getRequestURI().substring(
request.getContextPath().length()
+ request.getServletPath().length());
// Some servlet containers keep the leading slash, some don't
if (!"".equals(relativeResourceURI)
&& "/".equals(relativeResourceURI.substring(0, 1))) {
relativeResourceURI = relativeResourceURI.substring(1);
}
if (request.getQueryString() != null) {
relativeResourceURI = relativeResourceURI + "?"
+ request.getQueryString();
}
/* Determine service stem, i.e. vocab/ in /[vocab/]data */
int servicePos;
if (-1 == (servicePos = request.getServletPath().indexOf(
"/" + D2RServer.getDataServiceName())))
throw new ServletException("Expected to find service path /"
+ D2RServer.getDataServiceName());
String serviceStem = request.getServletPath().substring(1,
servicePos + 1);
String resourceURI = RequestParamHandler
.removeOutputRequestParam(server.resourceBaseURI(serviceStem)
+ relativeResourceURI);
String documentURL = server.dataURL(serviceStem, relativeResourceURI);
String pageURL = server.pageURL(serviceStem, relativeResourceURI);
String sparqlQuery = "DESCRIBE <" + resourceURI + ">";
QueryExecution qe = QueryExecutionFactory.create(sparqlQuery,
server.dataset());
if (server.getConfig().getPageTimeout() > 0) {
qe.setTimeout(Math.round(server.getConfig().getPageTimeout() * 1000));
}
Model description = qe.execDescribe();
qe.close();
if (description.size() == 0) {
response.sendError(404);
}
if (description.qnameFor(FOAF.primaryTopic.getURI()) == null
&& description.getNsPrefixURI("foaf") == null) {
description.setNsPrefix("foaf", FOAF.NS);
}
Resource resource = description.getResource(resourceURI);
Resource document = description.getResource(documentURL);
document.addProperty(FOAF.primaryTopic, resource);
Statement label = resource.getProperty(RDFS.label);
if (label != null) {
document.addProperty(RDFS.label,
"RDF Description of " + label.getString());
}
server.addDocumentMetadata(description, document);
if (server.getConfig().serveMetadata()) {
// add document metadata from template
Model resourceMetadataTemplate = server.getConfig().getResourceMetadataTemplate(
server, getServletContext());
MetadataCreator resourceMetadataCreator = new MetadataCreator(
server, resourceMetadataTemplate);
description.add(resourceMetadataCreator.addMetadataFromTemplate(
resourceURI, documentURL, pageURL));
Map<String, String> descPrefixes = description.getNsPrefixMap();
descPrefixes.putAll(resourceMetadataTemplate.getNsPrefixMap());
description.setNsPrefixes(descPrefixes);
}
// TODO: Add a Content-Location header
new ModelResponse(description, request, response).serve();
}