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


Java QueryExecution.setTimeout方法代码示例

本文整理汇总了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
		}
       }

}
 
开发者ID:ALIADA,项目名称:aliada-tool,代码行数:27,代码来源:AliadaRDFStoreDAO.java

示例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;
}
 
开发者ID:ALIADA,项目名称:aliada-tool,代码行数:33,代码来源:RDFStoreDAO.java

示例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;
}
 
开发者ID:ALIADA,项目名称:aliada-tool,代码行数:27,代码来源:RDFStoreDAO.java

示例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;
  }
}
 
开发者ID:semiotproject,项目名称:semiot-platform,代码行数:31,代码来源:CSPARQL.java

示例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()]);
}
 
开发者ID:ALIADA,项目名称:aliada-tool,代码行数:47,代码来源:RDFStoreDAO.java

示例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()]);
}
 
开发者ID:ALIADA,项目名称:aliada-tool,代码行数:54,代码来源:RDFStoreDAO.java

示例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;
}
 
开发者ID:ALIADA,项目名称:aliada-tool,代码行数:41,代码来源:RDFStoreDAO.java

示例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);
	}
}
 
开发者ID:ALIADA,项目名称:aliada-tool,代码行数:43,代码来源:RDFStoreDAO.java

示例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()]);
}
 
开发者ID:ALIADA,项目名称:aliada-tool,代码行数:45,代码来源:RDFStoreDAO.java

示例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();
}
 
开发者ID:aitoralmeida,项目名称:c4a_data_repository,代码行数:77,代码来源:ResourceDescriptionServlet.java


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