當前位置: 首頁>>代碼示例>>Java>>正文


Java TupleQuery.evaluate方法代碼示例

本文整理匯總了Java中org.openrdf.query.TupleQuery.evaluate方法的典型用法代碼示例。如果您正苦於以下問題:Java TupleQuery.evaluate方法的具體用法?Java TupleQuery.evaluate怎麽用?Java TupleQuery.evaluate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.openrdf.query.TupleQuery的用法示例。


在下文中一共展示了TupleQuery.evaluate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDistinctObj

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
/**
 * Get total number of distinct objects for a predicate
 * @param pred Predicate
 * @param m model
 * @return triples
 */
public static long getDistinctObj(String pred, String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(DISTINCT ?o) AS ?objs) " + // 
			"WHERE " +
			"{" +
       		"?s <" + pred + "> ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("objs").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:25,代碼來源:SemagrowSummariesGenerator.java

示例2: getDistinctSbj

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
/**
 * Get total number of distinct objects for a predicate
 * @param pred Predicate
 * @param m model
 * @return triples
 */
public static long getDistinctSbj(String pred, String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(DISTINCT ?s) AS ?subjs) " + // 
			"WHERE " +
			"{" +
       		"?s <" + pred + "> ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("subjs").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:25,代碼來源:SemagrowSummariesGenerator.java

示例3: getSubjectCount

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
/**
 * Get total number of distinct subjects of a dataset
 * @return count 
 */
public static long getSubjectCount(String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(DISTINCT ?s) AS ?sbjts) " + // 
			"WHERE " +
			"{" +
       		"?s ?p ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("sbjts").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:23,代碼來源:SemagrowSummariesGenerator.java

示例4: getObjectCount

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
/**
 * Get total number of distinct objects of a dataset
 * @return count
 */
public static long getObjectCount(String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(DISTINCT ?o) AS ?objts) " + // 
			"WHERE " +
			"{" +
       		"?s ?p ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("objts").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:23,代碼來源:SemagrowSummariesGenerator.java

示例5: getTripleCount

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
/**
 * Get total number of triple for a predicate
 * @param pred Predicate
 * @param m model
 * @return triples
 */
public static Long getTripleCount(String pred, String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(?s) AS ?triples) " + // 
			"WHERE " +
			"{" +
       		"?s <"+pred+"> ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("triples").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:25,代碼來源:SemagrowSummariesGenerator.java

示例6: getPredicates

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
/**
 * Get Predicate List
 * @param endPointUrl SPARQL endPoint Url
 * @param graph Named graph
 * @return  predLst Predicates List
 */
private static List<String> getPredicates(String endPointUrl, String graph) throws Exception
{
	List<String>  predLst = new ArrayList<String>();
	String strQuery = getPredQuery(graph);
	SPARQLRepository repo = new SPARQLRepository(endPointUrl);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult res = query.evaluate();
		while (res.hasNext()) 
		{
			String pred = res.next().getValue("p").toString();
			predLst.add(pred);	  		
		}
	} finally {
		conn.close();
		repo.shutDown();
	}
	return predLst;
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:28,代碼來源:SemagrowSummariesGenerator.java

示例7: runSPARQL

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
/**
 * Execute a SELECT SPARQL query against the graph
 * 
 * @param qs
 *            SELECT SPARQL query
 * @return list of solutions, each containing a hashmap of bindings
 */
public List runSPARQL(String qs) {
	try {
		RepositoryConnection con = therepository.getConnection();
		try {
			TupleQuery query = con.prepareTupleQuery(org.openrdf.query.QueryLanguage.SPARQL, qs);
			TupleQueryResult qres = query.evaluate();
			ArrayList reslist = new ArrayList();
			while (qres.hasNext()) {
				BindingSet b = qres.next();
				Set names = b.getBindingNames();
				HashMap hm = new HashMap();
				for (Object n : names) {
					hm.put((String) n, b.getValue((String) n));
				}
				reslist.add(hm);
			}
			return reslist;
		} finally {
			con.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:dvcama,項目名稱:resource-to-sparqlresult,代碼行數:33,代碼來源:SimpleGraph.java

示例8: doTupleQuery

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
public static List<HashMap<String, Value>> doTupleQuery(RepositoryConnection con, String query) {

		List<HashMap<String, Value>> results = new ArrayList<HashMap<String, Value>>();
		try {
			TupleQuery resultsTable = con.prepareTupleQuery(QueryLanguage.SPARQL, query);
			TupleQueryResult bindings = resultsTable.evaluate();
			for (@SuppressWarnings("unused")
			int row = 0; bindings.hasNext(); row++) {
				HashMap<String, Value> riga = new HashMap<String, Value>();
				BindingSet pairs = bindings.next();
				List<String> names = bindings.getBindingNames();
				for (int i = 0; i < names.size(); i++) {
					String name = names.get(i);
					Value value = pairs.getValue(name);
					
					riga.put(name, value != null && value.stringValue().equals("") ? null : value);
				}
				results.add(riga);
			}
 		} catch (Exception e) {
			e.printStackTrace();
		}
		return results;
	}
 
開發者ID:regestaexe,項目名稱:bygle-ldp,代碼行數:25,代碼來源:QueryRDF.java

示例9: testEvaluate

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
public void testEvaluate() throws Exception {
    RepositoryConnection conn = repository.getConnection();
    URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
    URI uri1 = vf.createURI(litdupsNS, "uri1");
    conn.add(cpu, loadPerc, uri1);
    conn.commit();

    String query = "select * where {" +
            "?x <" + loadPerc.stringValue() + "> ?o1." +
            "}";
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    CountTupleHandler cth = new CountTupleHandler();
    tupleQuery.evaluate(cth);
    assertEquals(cth.getCount(), 1);
    conn.close();
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:17,代碼來源:RdfCloudTripleStoreConnectionTest.java

示例10: testPOPredRange

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
public void testPOPredRange() throws Exception {
    RepositoryConnection conn = repository.getConnection();
    URI loadPerc = vf.createURI(litdupsNS, "loadPerc1");
    URI loadPerc2 = vf.createURI(litdupsNS, "loadPerc2");
    URI loadPerc3 = vf.createURI(litdupsNS, "loadPerc3");
    URI loadPerc4 = vf.createURI(litdupsNS, "loadPerc4");
    Literal six = vf.createLiteral("6");
    Literal sev = vf.createLiteral("7");
    Literal ten = vf.createLiteral("10");
    conn.add(cpu, loadPerc, six);
    conn.add(cpu, loadPerc2, sev);
    conn.add(cpu, loadPerc4, ten);
    conn.commit();

    String query = "PREFIX org.apache: <" + NAMESPACE + ">\n" +
            "select * where {" +
            "?x ?p ?o.\n" +
            "FILTER(org.apache:range(?p, <" + loadPerc.stringValue() + ">, <" + loadPerc3.stringValue() + ">))." +
            "}";
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    CountTupleHandler cth = new CountTupleHandler();
    tupleQuery.evaluate(cth);
    conn.close();
    assertEquals(cth.getCount(), 2);
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:26,代碼來源:RdfCloudTripleStoreConnectionTest.java

示例11: testSPOSubjRange

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
public void testSPOSubjRange() throws Exception {
    RepositoryConnection conn = repository.getConnection();
    URI cpu2 = vf.createURI(litdupsNS, "cpu2");
    URI cpu3 = vf.createURI(litdupsNS, "cpu3");
    URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
    Literal six = vf.createLiteral("6");
    Literal sev = vf.createLiteral("7");
    Literal ten = vf.createLiteral("10");
    conn.add(cpu, loadPerc, six);
    conn.add(cpu2, loadPerc, sev);
    conn.add(cpu3, loadPerc, ten);
    conn.commit();

    String query = "PREFIX org.apache: <" + NAMESPACE + ">\n" +
            "select * where {" +
            "?s ?p ?o.\n" +
            "FILTER(org.apache:range(?s, <" + cpu.stringValue() + ">, <" + cpu2.stringValue() + ">))." +
            "}";
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    CountTupleHandler cth = new CountTupleHandler();
    tupleQuery.evaluate(cth);
    conn.close();
    assertEquals(cth.getCount(), 2);
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:25,代碼來源:RdfCloudTripleStoreConnectionTest.java

示例12: runQuery

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
public Collection<? extends SesameMatch> runQuery(final RailwayQuery query, final String queryDefinition)
		throws RepositoryException, MalformedQueryException, QueryEvaluationException {
	final Collection<SesameMatch> results = new ArrayList<>();

	final TupleQuery tupleQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL, queryDefinition);
	final TupleQueryResult queryResults = tupleQuery.evaluate();
	try {
		while (queryResults.hasNext()) {
			final BindingSet bs = queryResults.next();
			final SesameMatch match = SesameMatch.createMatch(query, bs);
			results.add(match);
		}
	} finally {
		queryResults.close();
	}

	return results;
}
 
開發者ID:FTSRG,項目名稱:trainbenchmark,代碼行數:19,代碼來源:SesameDriver.java

示例13: evaluate

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
public List<List<Object>> evaluate(String queries) throws Exception {
	List<List<Object>> report = new ArrayList<List<Object>>();
			
	List<String> qnames = Arrays.asList(queries.split(" "));
	for (String curQueryName : qnames)
	{
		List<Object> reportRow = new ArrayList<Object>();
		report.add(reportRow);
		String curQuery = qp.getQuery(curQueryName);
		reportRow.add(curQueryName);
		
		long startTime = System.currentTimeMillis();
		//ParsedOperation pO = QueryParserUtil.parseOperation(QueryLanguage.SPARQL, curQuery, null);
		RepositoryConnection repCon = this.repository.getConnection();
		try {
			Query tempq = repCon.prepareQuery(QueryLanguage.SPARQL, curQuery);
			TupleQuery q = (TupleQuery)tempq;
			
			SyncTupleQueryResultHandler rhandler = new SyncTupleQueryResultHandler();
            q.evaluate(rhandler);
            		
		    long runTime = System.currentTimeMillis() - startTime;
		    reportRow.add((Long)rhandler.resultCount); reportRow.add((Long)runTime);

		    log.info(curQueryName + ": Query exection time (msec): "+ runTime + ", Total Number of Records: " + rhandler.resultCount);
		} catch (Exception e) {
			reportRow.add(null); reportRow.add(null);
		} finally {
			repCon.close();
        }
	}
	return report;
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:34,代碼來源:QueryEvaluation.java

示例14: getSelect

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
public static final <T> T getSelect( QueryExecutor<T> query,
		RepositoryConnection rc, boolean dobindings ) throws RepositoryException,
		MalformedQueryException, QueryEvaluationException {

	String sparql = processNamespaces( dobindings ? query.getSparql()
			: query.bindAndGetSparql(), query.getNamespaces() );

	ValueFactory vfac = new ValueFactoryImpl();
	TupleQuery tq = rc.prepareTupleQuery( QueryLanguage.SPARQL, sparql );

	if ( null != query.getContext() ) {
		DatasetImpl dataset = new DatasetImpl();
		dataset.addDefaultGraph( query.getContext() );
		tq.setDataset( dataset );
	}

	if ( dobindings ) {
		tq.setIncludeInferred( query.usesInferred() );
		query.setBindings( tq, vfac );
	}

	TupleQueryResult rslt = tq.evaluate();
	query.start( rslt.getBindingNames() );
	while ( rslt.hasNext() ) {
		query.handleTuple( rslt.next(), vfac );
	}
	query.done();
	rslt.close();
	return query.getResults();
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:31,代碼來源:AbstractSesameEngine.java

示例15: findUnresolvedTarget

import org.openrdf.query.TupleQuery; //導入方法依賴的package包/類
private TupleQueryResult findUnresolvedTarget(int limit)
		throws OpenRDFException {
	String qry = TARGET_WITHOUT_DATE + "\nLIMIT " + limit;
	ObjectConnection con = getObjectConnection();
	TupleQuery query = con.prepareTupleQuery(qry);
	query.setBinding("this", getResource());
	return query.evaluate();
}
 
開發者ID:mowjoothfm,項目名稱:persistenturls,代碼行數:9,代碼來源:ValidatingDomainSupport.java


注:本文中的org.openrdf.query.TupleQuery.evaluate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。