當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。