本文整理汇总了Java中org.openrdf.query.GraphQuery类的典型用法代码示例。如果您正苦于以下问题:Java GraphQuery类的具体用法?Java GraphQuery怎么用?Java GraphQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GraphQuery类属于org.openrdf.query包,在下文中一共展示了GraphQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runSPARQL
import org.openrdf.query.GraphQuery; //导入依赖的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.query.GraphQuery; //导入依赖的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();
}
示例3: testGraphQueryWithBaseURIInline
import org.openrdf.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();
}
示例4: testGraphQueryWithBaseURIWithEmptyBaseURI
import org.openrdf.query.GraphQuery; //导入依赖的package包/类
@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();
}
示例5: testPrepareGraphQueryWithSingleResult
import org.openrdf.query.GraphQuery; //导入依赖的package包/类
@Test
public void testPrepareGraphQueryWithSingleResult() throws Exception
{
Resource context1 = conn.getValueFactory().createURI("http://marklogic.com/test/context1");
ValueFactory f= conn.getValueFactory();
URI alice = f.createURI("http://example.org/people/alice");
URI name = f.createURI("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);
}
示例6: queryConstruct
import org.openrdf.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.toOpenRDFQueryLanguage(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(OpenRDFException e) {
throw new ModelRuntimeException(e);
}
}
示例7: getQueryType
import org.openrdf.query.GraphQuery; //导入依赖的package包/类
@Override
public QueryType getQueryType(String query) {
SailRepositoryConnection connection;
try {
connection = sr.getConnection();
final Query prepareQuery = connection.prepareQuery(
QueryLanguage.SPARQL, query);
if (prepareQuery instanceof BooleanQuery)
return QueryType.BOOLEANQUERY;
if (prepareQuery instanceof GraphQuery)
return QueryType.CONSTRUCTQUERY;
if (prepareQuery instanceof TupleQuery)
return QueryType.TUPLEQUERY;
} catch (RepositoryException | MalformedQueryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return QueryType.DESCRIBEQUERY;
}
示例8: SPARQLGraphStreamingOutput
import org.openrdf.query.GraphQuery; //导入依赖的package包/类
/**
* Creates a new graph streaming output that executes a CONSTRUCT query
* and streams the result.
*
* @param query the CONSTRUCT query to execute
* @param writerFactory a RDF writer factory to use for serialisation
* @param conn the connection to use for query execution
*/
public SPARQLGraphStreamingOutput(
GraphQuery query,
RDFWriterFactory writerFactory,
RepositoryConnection conn) {
super(conn);
this.query = query;
this.factory = writerFactory;
}
示例9: testConstructQuery
import org.openrdf.query.GraphQuery; //导入依赖的package包/类
@Test
public void testConstructQuery()
throws Exception {
String queryString = "PREFIX nn: <http://semanticbible.org/ns/2006/NTNames#>\n" +
"PREFIX test: <http://marklogic.com#test>\n" +
"\n" +
"construct { ?s test:test \"0\"} 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());
Statement st2 = results.next();
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#Cain", st2.getSubject().stringValue());
results.close();
}
示例10: testGraphQueryWithBaseURI
import org.openrdf.query.GraphQuery; //导入依赖的package包/类
@Test
public void testGraphQueryWithBaseURI()
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, "http://marklogic.com/test/baseuri/");
GraphQueryResult results = graphQuery.evaluate();
Statement st1 = results.next();
Assert.assertEquals("http://marklogic.com/test/baseuri/relative", st1.getObject().stringValue());
Statement st2 = results.next();
Assert.assertEquals("http://marklogic.com/test/baseuri/relative", st2.getObject().stringValue());
results.close();
}
示例11: testDescribeQuery
import org.openrdf.query.GraphQuery; //导入依赖的package包/类
@Test
public void testDescribeQuery()
throws Exception {
String queryString = "DESCRIBE <http://semanticbible.org/ns/2006/NTNames#Shelah>";
GraphQuery graphQuery = conn.prepareGraphQuery(QueryLanguage.SPARQL, queryString);
GraphQueryResult results = graphQuery.evaluate();
Statement st1 = results.next();
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#Shelah", st1.getSubject().stringValue());
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#childOf", st1.getPredicate().stringValue());
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#CainanSonOfArphaxad", st1.getObject().stringValue());
results.close();
}
示例12: testPrepareGraphQueryWithNoResult
import org.openrdf.query.GraphQuery; //导入依赖的package包/类
@Test
public void testPrepareGraphQueryWithNoResult() throws Exception
{
String query = "DESCRIBE <http://example.org/nonexistant>";
GraphQuery queryObj = conn.prepareGraphQuery(query);
GraphQueryResult result = queryObj.evaluate();
Assert.assertTrue(result != null);
Assert.assertFalse(result.hasNext());
result.close();
}
示例13: testPrepareGraphQueryClose
import org.openrdf.query.GraphQuery; //导入依赖的package包/类
@Test
public void testPrepareGraphQueryClose() throws Exception
{
String query = "DESCRIBE <http://example.org/ontology/name>";
GraphQuery queryObj = conn.prepareGraphQuery(query);
GraphQueryResult result = queryObj.evaluate();
result.close();
}
示例14: executeQuery
import org.openrdf.query.GraphQuery; //导入依赖的package包/类
public GraphQueryResult executeQuery(String query) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
RepositoryConnection conn = cf.getConnection();
try {
GraphQuery graphQuery = conn.prepareGraphQuery(QueryLanguage.SPARQL, query);
return graphQuery.evaluate();
} finally {
// conn.close();
}
}
示例15: doQuery
import org.openrdf.query.GraphQuery; //导入依赖的package包/类
@Override
protected void doQuery(QueryDefinition query, WriterConfig config,
RepositoryConnection cxn, OutputStream os) throws Exception {
final GraphQuery sailGraphQuery = cxn
.prepareGraphQuery(query.getQueryLanguage(), query.getQuery(),
config.getBaseUri());
final RDFFormat format = RDFFormat.forMIMEType(config.getContentType(),
RDFFormat.RDFXML);
// final RDFFormat format = RDFWriterRegistry.getInstance()
// .getFileFormatForMIMEType(config.getFormat());
final RDFWriter w = RDFWriterRegistry.getInstance().get(format)
.getWriter(os);
applyConfig(w);
sailGraphQuery.evaluate(w);
}