use of org.eclipse.rdf4j.query.TupleQueryResult in project graal by graphik-team.
the class RDF4jStore method match.
@Override
public CloseableIterator<Atom> match(Atom atom) throws AtomSetException {
ConjunctiveQuery query = DefaultConjunctiveQueryFactory.instance().create(atom);
StringWriter s = new StringWriter();
SparqlConjunctiveQueryWriter w = new SparqlConjunctiveQueryWriter(s, this.utils.getURIzer());
try {
w.write(query);
w.close();
} catch (IOException e1) {
throw new AtomSetException("Error while converting to SPARQL " + atom, e1);
}
TupleQuery sparqlQuery = this.connection.prepareTupleQuery(s.toString());
TupleQueryResult result = sparqlQuery.evaluate();
return new TupleQueryResultAtomIterator(result, atom, utils);
}
use of org.eclipse.rdf4j.query.TupleQueryResult in project rdf4j by eclipse.
the class SPARQLTSVCustomTest method testSES2126QuotedLiteralIntegerAsStringExplicitType.
/**
* Only Literals with the XML Schema numeric types should be simplified.
* <p>
* NOTE: This will fail when using RDF-1.1, as the datatype {@link XMLSchema#STRING} is implied and hence
* is not generally represented.
*
* @throws Exception
*/
@Ignore("This test does not work with RDF-1.1")
@Test
public void testSES2126QuotedLiteralIntegerAsStringExplicitType() throws Exception {
List<String> bindingNames = Arrays.asList("test");
TupleQueryResult tqr = new IteratingTupleQueryResult(bindingNames, Arrays.asList(new ListBindingSet(bindingNames, SimpleValueFactory.getInstance().createLiteral("1", XMLSchema.STRING))));
String result = writeTupleResult(tqr);
assertEquals("?test\n\"1\"^^<http://www.w3.org/2001/XMLSchema#string>\n", result);
}
use of org.eclipse.rdf4j.query.TupleQueryResult in project nextprot-api by calipho-sib.
the class PhenotypicTTLIntegrationTest method shouldReturnCorrectTTLAndBeAbleToPerformAnRDFQuery.
@Test
public void shouldReturnCorrectTTLAndBeAbleToPerformAnRDFQuery() throws Exception {
// String sparqlQuery = sparqlDictionary.getSparqlOnly("NXQ_00147");
// //For phenotypic
String sparqlQuery = "SELECT (COUNT(*) AS ?no) where { ?s ?p ?o }";
TupleQueryResult result = doTupleQuery(sparqlQuery);
// System.err.println(result.getBindingNames().iterator().next());
long numberOfTriples = Long.valueOf(result.next().getBinding("no").getValue().stringValue());
Assert.assertTrue(numberOfTriples > 1000);
result.close();
}
use of org.eclipse.rdf4j.query.TupleQueryResult in project nextprot-api by calipho-sib.
the class PhenotypicTTLIntegrationTest method doTupleQuery.
private TupleQueryResult doTupleQuery(String sparqlQuery) throws RepositoryException, QueryEvaluationException, MalformedQueryException {
RepositoryConnection conn = testRepo.getConnection();
TupleQuery query = (TupleQuery) conn.prepareQuery(QueryLanguage.SPARQL, sparqlQuery);
TupleQueryResult result = query.evaluate();
return result;
}
use of org.eclipse.rdf4j.query.TupleQueryResult in project rdf4j by eclipse.
the class SPARQLProtocolSession method getBackgroundTupleQueryResult.
/*------------------*
* Response parsing *
*------------------*/
/**
* Parse the response in a background thread. HTTP connections are dealt with in the
* {@link BackgroundTupleResult} or (in the error-case) in this method.
*/
protected TupleQueryResult getBackgroundTupleQueryResult(HttpUriRequest method) throws RepositoryException, QueryInterruptedException, MalformedQueryException, IOException {
boolean submitted = false;
// Specify which formats we support
Set<QueryResultFormat> tqrFormats = TupleQueryResultParserRegistry.getInstance().getKeys();
if (tqrFormats.isEmpty()) {
throw new RepositoryException("No tuple query result parsers have been registered");
}
TupleQueryResult tRes = null;
// send the tuple query
HttpResponse response = sendTupleQueryViaHttp(method, tqrFormats);
try {
// if we get here, HTTP code is 200
String mimeType = getResponseMIMEType(response);
QueryResultFormat format = TupleQueryResultFormat.matchMIMEType(mimeType, tqrFormats).orElseThrow(() -> new RepositoryException("Server responded with an unsupported file format: " + mimeType));
TupleQueryResultParser parser = QueryResultIO.createTupleParser(format, getValueFactory());
tRes = background.parse(parser, response.getEntity().getContent());
submitted = true;
return tRes;
} finally {
if (!submitted) {
EntityUtils.consumeQuietly(response.getEntity());
}
}
}
Aggregations