本文整理汇总了Java中org.openrdf.repository.RepositoryConnection.prepareTupleQuery方法的典型用法代码示例。如果您正苦于以下问题:Java RepositoryConnection.prepareTupleQuery方法的具体用法?Java RepositoryConnection.prepareTupleQuery怎么用?Java RepositoryConnection.prepareTupleQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openrdf.repository.RepositoryConnection
的用法示例。
在下文中一共展示了RepositoryConnection.prepareTupleQuery方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDistinctObj
import org.openrdf.repository.RepositoryConnection; //导入方法依赖的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();
}
}
示例2: getDistinctSbj
import org.openrdf.repository.RepositoryConnection; //导入方法依赖的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();
}
}
示例3: getSubjectCount
import org.openrdf.repository.RepositoryConnection; //导入方法依赖的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();
}
}
示例4: getObjectCount
import org.openrdf.repository.RepositoryConnection; //导入方法依赖的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();
}
}
示例5: getTripleCount
import org.openrdf.repository.RepositoryConnection; //导入方法依赖的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();
}
}
示例6: getPredicates
import org.openrdf.repository.RepositoryConnection; //导入方法依赖的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;
}
示例7: runSPARQL
import org.openrdf.repository.RepositoryConnection; //导入方法依赖的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;
}
示例8: getSelect
import org.openrdf.repository.RepositoryConnection; //导入方法依赖的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();
}