本文整理汇总了Java中org.eclipse.rdf4j.query.GraphQuery类的典型用法代码示例。如果您正苦于以下问题:Java GraphQuery类的具体用法?Java GraphQuery怎么用?Java GraphQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GraphQuery类属于org.eclipse.rdf4j.query包,在下文中一共展示了GraphQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluate_SetsBindings
import org.eclipse.rdf4j.query.GraphQuery; //导入依赖的package包/类
@Test
public void evaluate_SetsBindings() {
// Arrange
GraphQuery query = mock(GraphQuery.class);
GraphQueryResult queryResult = mock(GraphQueryResult.class);
when(repositoryConnection.prepareQuery(QueryLanguage.SPARQL, GRAPH_QUERY)).thenReturn(query);
when(query.evaluate()).thenReturn(queryResult);
ImmutableMap<String, Value> bindings = ImmutableMap.of("dateOfFoundation",
DBEERPEDIA.BROUWTOREN_DATE_OF_FOUNDATION, "fte", DBEERPEDIA.BROUWTOREN_FTE);
// Act
Object result = queryEvaluator.evaluate(repositoryConnection, GRAPH_QUERY, bindings);
// Assert
assertThat(result, instanceOf(GraphQueryResult.class));
verify(query).setBinding("dateOfFoundation", DBEERPEDIA.BROUWTOREN_DATE_OF_FOUNDATION);
verify(query).setBinding("fte", DBEERPEDIA.BROUWTOREN_FTE);
}
示例2: testGraphQueryWithBaseURIInline
import org.eclipse.rdf4j.query.GraphQuery; //导入依赖的package包/类
@Test
public void testGraphQueryWithBaseURIInline()
throws Exception {
String queryString ="BASE <http://marklogic.com/test/baseuri>\n" +
"PREFIX nn: <http://semanticbible.org/ns/2006/NTNames#>\n" +
"PREFIX test: <http://marklogic.com#test>\n" +
"construct { ?s test:test <relative>} WHERE {?s nn:childOf nn:Eve . }";
GraphQuery graphQuery = conn.prepareGraphQuery(QueryLanguage.SPARQL, queryString);
GraphQueryResult results = graphQuery.evaluate();
Statement st1 = results.next();
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#Abel", st1.getSubject().stringValue());
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#Abel", st1.getSubject().stringValue());
Statement st2 = results.next();
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#Cain", st2.getSubject().stringValue());
results.close();
}
示例3: testGraphQueryWithBaseURIWithEmptyBaseURI
import org.eclipse.rdf4j.query.GraphQuery; //导入依赖的package包/类
@Ignore
@Test
public void testGraphQueryWithBaseURIWithEmptyBaseURI()
throws Exception {
String queryString =
"PREFIX nn: <http://semanticbible.org/ns/2006/NTNames#>\n" +
"PREFIX test: <http://marklogic.com#test>\n" +
"construct { ?s test:test <relative>} WHERE {?s nn:childOf nn:Eve . }";
GraphQuery graphQuery = conn.prepareGraphQuery(queryString, "");
exception.expect(QueryEvaluationException.class);
GraphQueryResult results = graphQuery.evaluate();
Statement st1 = results.next();
Assert.assertEquals("http://relative", st1.getObject().stringValue());
@SuppressWarnings("unused")
Statement st2 = results.next();
Assert.assertEquals("http://relative", st1.getObject().stringValue());
results.close();
}
示例4: testPrepareGraphQueryWithSingleResult
import org.eclipse.rdf4j.query.GraphQuery; //导入依赖的package包/类
@Test
public void testPrepareGraphQueryWithSingleResult() throws Exception
{
Resource context1 = conn.getValueFactory().createIRI("http://marklogic.com/test/context1");
ValueFactory f= conn.getValueFactory();
IRI alice = f.createIRI("http://example.org/people/alice");
IRI name = f.createIRI("http://example.org/ontology/name");
Literal alicesName = f.createLiteral("Alice1");
Statement st1 = f.createStatement(alice, name, alicesName);
conn.add(st1,context1);
String query = " DESCRIBE <http://example.org/people/alice> ";
GraphQuery queryObj = conn.prepareGraphQuery(query);
GraphQueryResult result = queryObj.evaluate();
Assert.assertTrue(result != null);
Assert.assertTrue(result.hasNext());
@SuppressWarnings("unused")
Statement st = result.next();
Assert.assertFalse(result.hasNext());
result.close();
conn.clear(context1);
}
示例5: run
import org.eclipse.rdf4j.query.GraphQuery; //导入依赖的package包/类
void run(Configuration configuration) throws ExportException {
try {
SailRepository rep = new SailRepository(new HBaseSail(configuration, htableName, false, 0, true, 0, elasticIndexURL, null));
rep.initialize();
try {
writer.initTimer();
log.logStatus("Query execution started");
Query q = rep.getConnection().prepareQuery(QueryLanguage.SPARQL, sparqlQuery);
if (q instanceof TupleQuery) {
writer.writeTupleQueryResult(((TupleQuery)q).evaluate());
} else if (q instanceof GraphQuery) {
writer.writeGraphQueryResult(((GraphQuery)q).evaluate());
} else {
throw new ExportException("Only SPARQL Tuple and Graph query types are supported.");
}
log.logStatus("Export finished");
} finally {
rep.shutDown();
}
} catch (RepositoryException | MalformedQueryException | QueryEvaluationException e) {
throw new ExportException(e);
} finally {
writer.close();
}
}
示例6: queryConstruct
import org.eclipse.rdf4j.query.GraphQuery; //导入依赖的package包/类
@Override
public ClosableIterable<Statement> queryConstruct(String query, String querylanguage)
throws QueryLanguageNotSupportedException {
assertModel();
if (querylanguage.equalsIgnoreCase("SPARQL"))
return sparqlConstruct(query);
else {
QueryLanguage ql = QueryLanguage.valueOf(querylanguage);
if (ql == null) {
throw new QueryLanguageNotSupportedException("Unsupported query language: '"
+ querylanguage + "'");
}
try {
GraphQuery prepared = this.connection.prepareGraphQuery(ql, query);
GraphQueryResult graphQueryResult = prepared.evaluate();
return new GraphIterable(graphQueryResult, this);
} catch (MalformedQueryException | RepositoryException |
UnsupportedQueryLanguageException | QueryEvaluationException e) {
throw new ModelRuntimeException(e);
}
}
}
示例7: queryConstruct
import org.eclipse.rdf4j.query.GraphQuery; //导入依赖的package包/类
@Override
public ClosableIterable<Statement> queryConstruct(String queryString, String queryLanguage)
throws QueryLanguageNotSupportedException, ModelRuntimeException {
this.assertModel();
// resolve the query language String to a QueryLanguage
QueryLanguage language = ConversionUtil.toRDF4JQueryLanguage(queryLanguage);
try {
// determine query result
GraphQuery query = this.connection.prepareGraphQuery(language, queryString);
GraphQueryResult queryResult = query.evaluate();
// wrap it in a GraphIterable
return new GraphIterable(queryResult, null);
} catch(RDF4JException e) {
throw new ModelRuntimeException(e);
}
}
示例8: getQueryForResources
import org.eclipse.rdf4j.query.GraphQuery; //导入依赖的package包/类
@Override
protected GraphQuery getQueryForResources(RepositoryConnection conn) {
String query = "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . ?s a ?type . }";
GraphQuery graphQuery = conn.prepareGraphQuery(query);
graphQuery.setBinding("type", ELMO.SITE);
return graphQuery;
}
示例9: getQueryForResources
import org.eclipse.rdf4j.query.GraphQuery; //导入依赖的package包/类
@Override
protected GraphQuery getQueryForResources(RepositoryConnection conn) {
String query = "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . ?s a ?type . }";
GraphQuery graphQuery = conn.prepareGraphQuery(query);
graphQuery.setBinding("type", ELMO.STAGE);
return graphQuery;
}
示例10: getQueryForResources
import org.eclipse.rdf4j.query.GraphQuery; //导入依赖的package包/类
@Override
protected GraphQuery getQueryForResources(RepositoryConnection conn) {
String query = "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o. ?rep ?parametermapper ?s. }";
GraphQuery graphQuery = conn.prepareGraphQuery(query);
graphQuery.setBinding("parametermapper", ELMO.PARAMETER_MAPPER_PROP);
return graphQuery;
}
示例11: getQueryForResources
import org.eclipse.rdf4j.query.GraphQuery; //导入依赖的package包/类
@Override
protected GraphQuery getQueryForResources(RepositoryConnection conn) {
String query = "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . ?s a ?type . }";
GraphQuery graphQuery = conn.prepareGraphQuery(query);
graphQuery.setBinding("type", ELMO.REDIRECTION);
return graphQuery;
}
示例12: getQueryForResources
import org.eclipse.rdf4j.query.GraphQuery; //导入依赖的package包/类
@Override
protected GraphQuery getQueryForResources(RepositoryConnection conn) {
final String query = "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . ?s a ?type . }";
final GraphQuery graphQuery = conn.prepareGraphQuery(query);
graphQuery.setBinding("type", ELMO.REPRESENTATION);
return graphQuery;
}
示例13: getQueryForResources
import org.eclipse.rdf4j.query.GraphQuery; //导入依赖的package包/类
@Override
protected GraphQuery getQueryForResources(@NonNull RepositoryConnection conn) {
String query = "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o. ?rep ?appearance ?s. }";
GraphQuery graphQuery = conn.prepareGraphQuery(query);
graphQuery.setBinding("appearance", ELMO.APPEARANCE_PROP);
return graphQuery;
}
示例14: evaluate_GivesGraphQueryResult_WithGraphQuery
import org.eclipse.rdf4j.query.GraphQuery; //导入依赖的package包/类
@Test
public void evaluate_GivesGraphQueryResult_WithGraphQuery() {
// Arrange
GraphQuery query = mock(GraphQuery.class);
GraphQueryResult queryResult = mock(GraphQueryResult.class);
when(repositoryConnection.prepareQuery(QueryLanguage.SPARQL, GRAPH_QUERY)).thenReturn(query);
when(query.evaluate()).thenReturn(queryResult);
// Act
Object result = queryEvaluator.evaluate(repositoryConnection, GRAPH_QUERY, ImmutableMap.of());
// Assert
assertThat(result, instanceOf(GraphQueryResult.class));
}
示例15: evaluate_ThrowsException_WithGraphEvalutationError
import org.eclipse.rdf4j.query.GraphQuery; //导入依赖的package包/类
@Test
public void evaluate_ThrowsException_WithGraphEvalutationError() {
// Arrange
GraphQuery query = mock(GraphQuery.class);
when(repositoryConnection.prepareQuery(QueryLanguage.SPARQL, GRAPH_QUERY)).thenReturn(query);
when(query.evaluate()).thenThrow(QueryEvaluationException.class);
// Assert
thrown.expect(BackendException.class);
thrown.expectMessage(String.format("Query could not be evaluated: %s", GRAPH_QUERY));
// Act
queryEvaluator.evaluate(repositoryConnection, GRAPH_QUERY, ImmutableMap.of());
}