本文整理汇总了Java中org.eclipse.rdf4j.query.QueryLanguage类的典型用法代码示例。如果您正苦于以下问题:Java QueryLanguage类的具体用法?Java QueryLanguage怎么用?Java QueryLanguage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueryLanguage类属于org.eclipse.rdf4j.query包,在下文中一共展示了QueryLanguage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSPARQLQueryCloseWait
import org.eclipse.rdf4j.query.QueryLanguage; //导入依赖的package包/类
@Test
public void testSPARQLQueryCloseWait()
throws Exception {
try{
String queryString = "select ?s ?p ?o { ?s ?p ?o } limit 100";
MarkLogicTupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
for(int i=0; i<101; i++){
TupleQueryResult results = tupleQuery.evaluate(3,1);
// must close query result
results.close();
}
}
catch(Exception ex)
{
throw ex;
}
finally {
conn.close();
Thread.sleep(1000);
}
}
示例2: testSPARQLQueryWithRuleset
import org.eclipse.rdf4j.query.QueryLanguage; //导入依赖的package包/类
@Test
public void testSPARQLQueryWithRuleset()
throws Exception {
String queryString = "select ?s ?p ?o { ?s ?p ?o } limit 100 ";
MarkLogicTupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
tupleQuery.setRulesets(SPARQLRuleset.RDFS_FULL);
TupleQueryResult results = tupleQuery.evaluate();
Assert.assertEquals(results.getBindingNames().get(0), "s");
Assert.assertEquals(results.getBindingNames().get(1), "p");
Assert.assertEquals(results.getBindingNames().get(2), "o");
BindingSet bindingSet = results.next();
Value sV = bindingSet.getValue("s");
Value pV = bindingSet.getValue("p");
Value oV = bindingSet.getValue("o");
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#AttaliaGeodata", sV.stringValue());
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#altitude", pV.stringValue());
Assert.assertEquals("0", oV.stringValue());
results.close();
}
示例3: testSPARQLQueryWithMultipleRulesets
import org.eclipse.rdf4j.query.QueryLanguage; //导入依赖的package包/类
@Test
public void testSPARQLQueryWithMultipleRulesets()
throws Exception {
String queryString = "select ?s ?p ?o { ?s ?p ?o } limit 100 ";
MarkLogicTupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
tupleQuery.setRulesets(SPARQLRuleset.RDFS_FULL,SPARQLRuleset.DOMAIN);
TupleQueryResult results = tupleQuery.evaluate();
Assert.assertEquals(results.getBindingNames().get(0), "s");
Assert.assertEquals(results.getBindingNames().get(1), "p");
Assert.assertEquals(results.getBindingNames().get(2), "o");
BindingSet bindingSet = results.next();
Value sV = bindingSet.getValue("s");
Value pV = bindingSet.getValue("p");
Value oV = bindingSet.getValue("o");
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#AttaliaGeodata", sV.stringValue());
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#altitude", pV.stringValue());
Assert.assertEquals("0", oV.stringValue());
results.close();
}
示例4: select
import org.eclipse.rdf4j.query.QueryLanguage; //导入依赖的package包/类
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> select(Service service, Set<String> projectionVars, BindingSet bindings, String baseUri) throws QueryEvaluationException {
RepositoryConnection conn = endpoint.getConn();
try {
TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, service.getSelectQueryString(projectionVars), baseUri);
Iterator<Binding> bIter = bindings.iterator();
while (bIter.hasNext()) {
Binding b = bIter.next();
if (service.getServiceVars().contains(b.getName()))
query.setBinding(b.getName(), b.getValue());
}
TupleQueryResult qRes = query.evaluate();
return new InsertBindingsIteration(qRes, bindings);
} catch(Throwable e) {
throw new QueryEvaluationException(e);
} finally {
conn.close();
}
}
示例5: FedSumClassLookup
import org.eclipse.rdf4j.query.QueryLanguage; //导入依赖的package包/类
/**
* Index lookup for rdf:type and its its corresponding values
* @param p Predicate i.e. rdf:type
* @param o Predicate value
* @param stmt Statement Pattern
* @throws RepositoryException
* @throws MalformedQueryException
* @throws QueryEvaluationException
*/
public void FedSumClassLookup(StatementPattern stmt, String p, String o) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
String queryString = "Prefix ds:<http://aksw.org/fedsum/> "
+ "SELECT Distinct ?url "
+ " WHERE {?s ds:url ?url. "
+ " ?s ds:capability ?cap. "
+ " ?cap ds:predicate <" + p + ">."
+ "?cap ds:objAuthority <" + o + "> }" ;
TupleQuery tupleQuery = FedSumConfig.con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
TupleQueryResult result = tupleQuery.evaluate();
while(result.hasNext())
{
String endpoint = result.next().getValue("url").stringValue();
String id = "sparql_" + endpoint.replace("http://", "").replace("/", "_");
addSource(stmt, new StatementSource(id, StatementSourceType.REMOTE));
}
}
示例6: FedSumD_getMatchingSbjAuthorities
import org.eclipse.rdf4j.query.QueryLanguage; //导入依赖的package包/类
/**
* Get matching Subject authorities from a specific source for a triple pattern
* @param stmt Triple pattern
* @param src Capable source
* @return List of authorities
* @throws RepositoryException
* @throws MalformedQueryException
* @throws QueryEvaluationException
*/
public ArrayList<String> FedSumD_getMatchingSbjAuthorities(StatementPattern stmt, StatementSource src) throws RepositoryException, MalformedQueryException, QueryEvaluationException
{
String endPointUrl = "http://"+src.getEndpointID().replace("sparql_", "");
endPointUrl = endPointUrl.replace("_", "/");
ArrayList<String> sbjAuthorities = new ArrayList<String>();
String queryString = getFedSumSbjAuthLookupQuery(stmt, endPointUrl) ;
TupleQuery tupleQuery = FedSumConfig.con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
TupleQueryResult result = tupleQuery.evaluate();
while(result.hasNext())
sbjAuthorities.add(result.next().getValue("sbjAuth").stringValue());
return sbjAuthorities;
}
示例7: executeQuery
import org.eclipse.rdf4j.query.QueryLanguage; //导入依赖的package包/类
/**
* Execute query and return the number of results
* @param query SPARQL query
* @param bgpGroups BGPs
* @param stmtToSources Triple Pattern to sources
* @param repo repository
* @return Number of results
* @throws RepositoryException
* @throws MalformedQueryException
* @throws QueryEvaluationException
*/
public static int executeQuery(String query, HashMap<Integer, List<StatementPattern>> bgpGroups, Map<StatementPattern, List<StatementSource>> stmtToSources, SPARQLRepository repo) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
String newQuery = QueryRewriting.doQueryRewriting(query,bgpGroups,stmtToSources);
System.out.println(newQuery);
TupleQuery tupleQuery = repo.getConnection().prepareTupleQuery(QueryLanguage.SPARQL, newQuery);
int count = 0;
TupleQueryResult result = tupleQuery.evaluate();
while(result.hasNext())
{
//System.out.println(result.next());
result.next();
count++;
}
return count;
}
示例8: executeQuery
import org.eclipse.rdf4j.query.QueryLanguage; //导入依赖的package包/类
/**
* Execute query and return the number of results
* @param query SPARQL query
* @param bgpGroups BGPs
* @param stmtToSources Triple Pattern to sources
* @param repo repository
* @return Number of results
* @throws RepositoryException
* @throws MalformedQueryException
* @throws QueryEvaluationException
*/
public static int executeQuery(String query, HashMap<Integer, List<StatementPattern>> bgpGroups, Map<StatementPattern, List<StatementSource>> stmtToSources, SPARQLRepository repo) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
String newQuery = QueryRewriting.doQueryRewriting(query,bgpGroups,stmtToSources);
// System.out.println(newQuery);
TupleQuery tupleQuery = repo.getConnection().prepareTupleQuery(QueryLanguage.SPARQL, newQuery);
int count = 0;
TupleQueryResult result = tupleQuery.evaluate();
while(result.hasNext())
{
//System.out.println(result.next());
result.next();
count++;
}
return count;
}
示例9: buildPrefixes
import org.eclipse.rdf4j.query.QueryLanguage; //导入依赖的package包/类
void buildPrefixes(RepositoryConnection conn, String query, SortedMap<KeyTuple, ValueTuple> prefixMap, boolean isSbjPrefix) {
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
TupleQueryResult result = tupleQuery.evaluate();
while (result.hasNext())
{
BindingSet row = result.next();
String endpoint = row.getValue("url").stringValue();
String predicate = row.getValue("p").stringValue();
String prefix = row.getValue("prefix").stringValue();
long unique = Long.parseLong(row.getValue("unique").stringValue());
long card = Long.parseLong(row.getValue("card").stringValue());
//log.info(predicate + " : " + prefix + " : " + card);
String eid = getEID(endpoint);
KeyTuple kt = new KeyTuple(predicate, prefix);
updateMap(prefixMap, kt, eid);
KeyTuple kt0 = new KeyTuple(null, prefix);
updateMap(prefixMap, kt0, eid);
updateCapabilityPrefix(eid, predicate, prefix, unique, card, isSbjPrefix);
}
result.close();
}
示例10: getObj
import org.eclipse.rdf4j.query.QueryLanguage; //导入依赖的package包/类
/**
* Get total number of triple for a predicate
* @param pred Predicate
* @param m model
* @return triples
* @throws RepositoryException
* @throws MalformedQueryException
* @throws QueryEvaluationException
*/
public static double getObj(String pred, String endpoint) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
String strQuery = "SELECT (COUNT(DISTINCT ?o) AS ?objs) " + //
"WHERE " +
"{" +
"?s <"+pred+"> ?o " +
"} " ;
SPARQLRepository repo = createSPARQLRepository(endpoint);
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();
}
}
示例11: getSubjectsCount
import org.eclipse.rdf4j.query.QueryLanguage; //导入依赖的package包/类
/**
* Get total number of distinct subjects of a dataset
* @return count
*/
public static Long getSubjectsCount(String endpoint) {
String strQuery = "SELECT (COUNT(DISTINCT ?s) AS ?sbjts) " + //
"WHERE " +
"{" +
"?s ?p ?o " +
"} " ;
SPARQLRepository repo = createSPARQLRepository(endpoint);
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();
}
}
示例12: getTripleCount
import org.eclipse.rdf4j.query.QueryLanguage; //导入依赖的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) {
String strQuery = "SELECT (COUNT(*) AS ?triples) " + //
"WHERE " +
"{" +
"?s <"+pred+"> ?o " +
"} " ;
SPARQLRepository repo = createSPARQLRepository(endpoint);
RepositoryConnection conn = repo.getConnection();
try {
TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery);
TupleQueryResult rs = query.evaluate();
String v = rs.next().getValue("triples").stringValue();
rs.close();
return Long.parseLong(v);
} finally {
conn.close();
}
}
示例13: getDistinctSubjectCount
import org.eclipse.rdf4j.query.QueryLanguage; //导入依赖的package包/类
public static Long getDistinctSubjectCount(String endpoint) {
String strQuery = "SELECT (COUNT(distinct ?s) AS ?triples) " + //
"WHERE " +
"{" +
"?s ?p ?o " +
"} " ;
SPARQLRepository repo = createSPARQLRepository(endpoint);
RepositoryConnection conn = repo.getConnection();
try {
TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery);
TupleQueryResult rs = query.evaluate();
String v = rs.next().getValue("triples").stringValue();
rs.close();
return Long.parseLong(v);
} finally {
conn.close();
}
}
示例14: getDistinctObjectCount
import org.eclipse.rdf4j.query.QueryLanguage; //导入依赖的package包/类
public static Long getDistinctObjectCount(String endpoint) {
String strQuery = "SELECT (COUNT(distinct ?o) AS ?triples) " + //
"WHERE " +
"{" +
"?s ?p ?o " +
"FILTER isIRI(?o)" +
"} " ;
SPARQLRepository repo = createSPARQLRepository(endpoint);
RepositoryConnection conn = repo.getConnection();
try {
TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery);
TupleQueryResult rs = query.evaluate();
String v = rs.next().getValue("triples").stringValue();
rs.close();
return Long.parseLong(v);
} finally {
conn.close();
}
}
示例15: getPredicates
import org.eclipse.rdf4j.query.QueryLanguage; //导入依赖的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)
{
List<String> predLst = new ArrayList<String>();
String strQuery = getPredQury(graph);
SPARQLRepository repo = createSPARQLRepository(endPointUrl);
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);
}
res.close();
} finally {
conn.close();
}
return predLst;
}