Search in sources :

Example 1 with TupleQueryResult

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);
}
Also used : StringWriter(java.io.StringWriter) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) TupleQuery(org.eclipse.rdf4j.query.TupleQuery) IOException(java.io.IOException) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) SparqlConjunctiveQueryWriter(fr.lirmm.graphik.graal.io.sparql.SparqlConjunctiveQueryWriter)

Example 2 with TupleQueryResult

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);
}
Also used : ListBindingSet(org.eclipse.rdf4j.query.impl.ListBindingSet) IteratingTupleQueryResult(org.eclipse.rdf4j.query.impl.IteratingTupleQueryResult) IteratingTupleQueryResult(org.eclipse.rdf4j.query.impl.IteratingTupleQueryResult) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with TupleQueryResult

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();
}
Also used : TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult) Test(org.junit.Test) WebIntegrationBaseTest(org.nextprot.api.web.dbunit.base.mvc.WebIntegrationBaseTest)

Example 4 with TupleQueryResult

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;
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) TupleQuery(org.eclipse.rdf4j.query.TupleQuery) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult)

Example 5 with TupleQueryResult

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());
        }
    }
}
Also used : QueryResultFormat(org.eclipse.rdf4j.query.resultio.QueryResultFormat) BooleanQueryResultFormat(org.eclipse.rdf4j.query.resultio.BooleanQueryResultFormat) TupleQueryResultFormat(org.eclipse.rdf4j.query.resultio.TupleQueryResultFormat) TupleQueryResultParser(org.eclipse.rdf4j.query.resultio.TupleQueryResultParser) HttpResponse(org.apache.http.HttpResponse) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult)

Aggregations

TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)15 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)10 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)9 IOException (java.io.IOException)7 TupleQuery (org.eclipse.rdf4j.query.TupleQuery)7 BindingSet (org.eclipse.rdf4j.query.BindingSet)6 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)5 Value (org.eclipse.rdf4j.model.Value)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)2 ExceptionConvertingIteration (org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration)2 RDF4JProtocolSession (org.eclipse.rdf4j.http.client.RDF4JProtocolSession)2 Resource (org.eclipse.rdf4j.model.Resource)2 UnsupportedQueryLanguageException (org.eclipse.rdf4j.query.UnsupportedQueryLanguageException)2 UpdateExecutionException (org.eclipse.rdf4j.query.UpdateExecutionException)2 IteratingTupleQueryResult (org.eclipse.rdf4j.query.impl.IteratingTupleQueryResult)2 ListBindingSet (org.eclipse.rdf4j.query.impl.ListBindingSet)2 UnknownTransactionStateException (org.eclipse.rdf4j.repository.UnknownTransactionStateException)2 SPARQLTupleQuery (org.eclipse.rdf4j.repository.sparql.query.SPARQLTupleQuery)2