本文整理汇总了Java中org.openrdf.repository.RepositoryConnection.prepareGraphQuery方法的典型用法代码示例。如果您正苦于以下问题:Java RepositoryConnection.prepareGraphQuery方法的具体用法?Java RepositoryConnection.prepareGraphQuery怎么用?Java RepositoryConnection.prepareGraphQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openrdf.repository.RepositoryConnection
的用法示例。
在下文中一共展示了RepositoryConnection.prepareGraphQuery方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runSPARQL
import org.openrdf.repository.RepositoryConnection; //导入方法依赖的package包/类
/**
* Execute a CONSTRUCT/DESCRIBE SPARQL query against the graph
*
* @param qs
* CONSTRUCT or DESCRIBE SPARQL query
* @param format
* the serialization format for the returned graph
* @return serialized graph of results
*/
public String runSPARQL(String qs, RDFFormat format) {
try {
RepositoryConnection con = therepository.getConnection();
try {
GraphQuery query = con.prepareGraphQuery(org.openrdf.query.QueryLanguage.SPARQL, qs);
StringWriter stringout = new StringWriter();
RDFWriter w = Rio.createWriter(format, stringout);
query.evaluate(w);
return stringout.toString();
} finally {
con.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例2: getConstruct
import org.openrdf.repository.RepositoryConnection; //导入方法依赖的package包/类
public static Model getConstruct( QueryExecutor<Model> query,
RepositoryConnection rc, boolean dobindings )
throws RepositoryException, MalformedQueryException, QueryEvaluationException {
String sparql = processNamespaces( dobindings ? query.getSparql()
: query.bindAndGetSparql(), query.getNamespaces() );
GraphQuery tq = rc.prepareGraphQuery( QueryLanguage.SPARQL, sparql );
tq.setIncludeInferred( query.usesInferred() );
if ( dobindings ) {
query.setBindings( tq, rc.getValueFactory() );
}
GraphQueryResult gqr = tq.evaluate();
while ( gqr.hasNext() ) {
query.getResults().add( gqr.next() );
}
gqr.close();
return query.getResults();
}