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


Java Query.setLimit方法代码示例

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


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

示例1: execute

import com.hp.hpl.jena.query.Query; //导入方法依赖的package包/类
/**
     * Creates and executes the SPARQL query according to the
     * criteria specified by the user.
     *
     * @param <T> type Type of the expected result.
     * @return the result set
     */
    public <T extends ResourceObject> List<T> execute(Class<T> type) throws ParseException, RepositoryException, MalformedQueryException, QueryEvaluationException {

        URI rootType = connection.getObjectFactory().getNameOf(type);
        if (rootType == null) {
            throw new IllegalArgumentException("Can't query for: " + type + " not found in name map. Is @Iri annotation set?");
        }

        Query sparql = EvalQuery.evaluate(queryServiceDTO, rootType);

        // LDPath allows distinct. May have bad performance.
        sparql.setDistinct(true);

        if (limit != null) {
            sparql.setLimit(limit);
        }

        if (offset != null) {
            sparql.setOffset(offset);
        }

        // Print with line numbers
//        sparql.serialize(new IndentedWriter(System.out, true));
//        System.out.println();

        String q = sparql.serialize();
        logger.debug("Initial query:\n" + queryOptimizer.prettyPrint(q));

        // Optimize the join order
        q = queryOptimizer.optimizeJoinOrder(q);
        logger.debug("Query after join order optimization:\n " + q);

        ObjectQuery query = connection.prepareObjectQuery(q);

        if (query.getDataset() != null) {
            logger.info("\nGRAPH CONTEXT = " + query.getDataset().getDefaultGraphs() + "\nFINAL QUERY :\n" + q);
        } else {
            logger.info("\nFINAL QUERY :\n" + q);
        }

        return (List<T>) query.evaluate().asList();
    }
 
开发者ID:anno4j,项目名称:anno4j,代码行数:49,代码来源:QueryService.java

示例2: graphBaseFind

import com.hp.hpl.jena.query.Query; //导入方法依赖的package包/类
@Override
	protected ExtendedIterator<Triple> graphBaseFind(TripleMatch m) {
		
		Node s = m.getMatchSubject() ;
		Var sVar = null ;
		if ( s == null )
		{
			sVar = Var.alloc("s") ;
			s = sVar ;
		}
		
		Node p = m.getMatchPredicate() ;
		Var pVar = null ;
		if ( p == null )
		{
			pVar = Var.alloc("p") ;
			p = pVar ;
		}
		
		Node o = m.getMatchObject() ;
		Var oVar = null ;
		if ( o == null )
		{
			oVar = Var.alloc("o") ;
			o = oVar ;
		}
		
		Triple triple = new Triple(s, p ,o) ;
		
		BasicPattern pattern = new BasicPattern() ;
		pattern.add(triple) ;
		ElementTriplesBlock element = new ElementTriplesBlock(pattern);
		Query query = new Query();
		query.setQuerySelectType(); 
		query.setQueryResultStar(true);
		query.setQueryPattern(element);
//		query.setDistinct(true);
		
		boolean resNotEmpty = true;
		query.setLimit(tripleSliceSize);
		long offsetCounter = 0;
		Set<Triple> triples = new HashSet<Triple>() ;
		while (resNotEmpty) {
			long offset = tripleSliceSize * offsetCounter++;
			query.setOffset(offset);
			QueryExecution qe = QueryExecutionFactory.sparqlService(serviceURI, query);
			logger.debug(query.serialize());
	
			ResultSet res = qe.execSelect();
			if (!res.hasNext()) resNotEmpty = false;
			
			while(res.hasNext()) {
				QuerySolution sol = res.nextSolution();
				Node subj;
				if (s.isVariable()) {
					subj = sol.get("s").asNode();
				} else {
					subj= s;
				}
				
				Node pred;
				if (p.isVariable()) {
					pred = sol.get("p").asNode();
				} else {
					pred = p;
				}
				
				Node obj;
				if (o.isVariable()) {
					obj = sol.get("o").asNode();
				} else {
					obj = o;
				}
				Triple resTriple = new Triple(subj, pred, obj);
				
				triples.add(resTriple);
			}
			qe.close();
		}
		return WrappedIterator.createNoRemove(triples.iterator()) ;
	}
 
开发者ID:SmartDataAnalytics,项目名称:R2RLint,代码行数:82,代码来源:SparqlGraph.java


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