org.eclipse.rdf4j.query.GraphQueryResult Java Examples

The following examples show how to use org.eclipse.rdf4j.query.GraphQueryResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractLuceneSailSpinTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Reproduce #235 with following query: <code>
 * construct {
 *   ?pred a <urn:ontology/Phrase> . ?pred <urn:ontology/label> ?label2 .
 * ?pred <urn:ontology/score> ?score } where { bind(str("ornare") as ?query)
 * . (?query search:allMatches search:score) search:search (?pred ?score) .
 * ?pred rdfs:label ?label . bind(fn:upper-case(?label) as ?label2) , }
 * </code>
 *
 * @throws Exception
 */
@Test
@Ignore("Regression due to GH-1642 - no appetite pending deprecation of LuceneSpinSail")
public void test235Issue() throws Exception {
	StringBuilder buffer = new StringBuilder();
	buffer.append(" construct {\n");
	buffer.append("  ?pred a <urn:ontology/Phrase> .\n");
	buffer.append("  ?pred <urn:ontology/label> ?label2 .\n");
	buffer.append("  ?pred <urn:ontology/score> ?score .\n");
	buffer.append(" } where {\n");
	buffer.append("  bind(str(\"ornare\") as ?query) .\n");
	buffer.append("  (?query <" + ALL_MATCHES + "> <" + SCORE + ">) <" + SEARCH + "> (?pred ?score) . \n");
	buffer.append("  ?pred rdfs:label ?label .\n");
	buffer.append("  bind(fn:upper-case(?label) as ?label2)\n");
	buffer.append(" }");
	log.info("Request query: \n====================\n{}\n======================\n", buffer.toString());

	GraphQuery query = getConnection().prepareGraphQuery(QueryLanguage.SPARQL, buffer.toString());
	printGraphResult(query);
	try (GraphQueryResult res = query.evaluate()) {
		int cnt = countGraphResults(res);
		Assert.assertTrue(String.format("count triples: ", cnt), cnt > 2);
	}
}
 
Example #2
Source File: RepositoryModelSet.java    From semweb4j with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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);
	}
}
 
Example #3
Source File: RepositoryModel.java    From semweb4j with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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);
		}
	}
}
 
Example #4
Source File: ComplexSPARQLQueryTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testDescribeA() throws Exception {
	loadTestData("/testdata-query/dataset-describe.trig");
	StringBuilder query = new StringBuilder();
	query.append(getNamespaceDeclarations());
	query.append("DESCRIBE ex:a");

	GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString());

	ValueFactory f = conn.getValueFactory();
	IRI a = f.createIRI("http://example.org/a");
	IRI p = f.createIRI("http://example.org/p");
	try (GraphQueryResult evaluate = gq.evaluate();) {
		Model result = QueryResults.asModel(evaluate);
		Set<Value> objects = result.filter(a, p, null).objects();
		assertNotNull(objects);
		for (Value object : objects) {
			if (object instanceof BNode) {
				assertTrue(result.contains((Resource) object, null, null));
				assertEquals(2, result.filter((Resource) object, null, null).size());
			}
		}
	}
}
 
Example #5
Source File: ComplexSPARQLQueryTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testDescribeAWhere() throws Exception {
	loadTestData("/testdata-query/dataset-describe.trig");
	StringBuilder query = new StringBuilder();
	query.append(getNamespaceDeclarations());
	query.append("DESCRIBE ?x WHERE {?x rdfs:label \"a\". } ");

	GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString());

	ValueFactory f = conn.getValueFactory();
	IRI a = f.createIRI("http://example.org/a");
	IRI p = f.createIRI("http://example.org/p");
	try (GraphQueryResult evaluate = gq.evaluate();) {
		Model result = QueryResults.asModel(evaluate);
		Set<Value> objects = result.filter(a, p, null).objects();
		assertNotNull(objects);
		for (Value object : objects) {
			if (object instanceof BNode) {
				assertTrue(result.contains((Resource) object, null, null));
				assertEquals(2, result.filter((Resource) object, null, null).size());
			}
		}
	}
}
 
Example #6
Source File: ComplexSPARQLQueryTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testDescribeB() throws Exception {
	loadTestData("/testdata-query/dataset-describe.trig");
	StringBuilder query = new StringBuilder();
	query.append(getNamespaceDeclarations());
	query.append("DESCRIBE ex:b");

	GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString());

	ValueFactory f = conn.getValueFactory();
	IRI b = f.createIRI("http://example.org/b");
	IRI p = f.createIRI("http://example.org/p");
	try (GraphQueryResult evaluate = gq.evaluate();) {
		Model result = QueryResults.asModel(evaluate);
		Set<Resource> subjects = result.filter(null, p, b).subjects();
		assertNotNull(subjects);
		for (Value subject : subjects) {
			if (subject instanceof BNode) {
				assertTrue(result.contains(null, null, subject));
			}
		}
	}
}
 
Example #7
Source File: ComplexSPARQLQueryTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testSES2104ConstructBGPSameURI() throws Exception {
	final String queryStr = "PREFIX : <urn:> CONSTRUCT {:x :p :x } WHERE {} ";

	conn.add(new StringReader("@prefix : <urn:> . :a :p :b . "), "", RDFFormat.TURTLE);

	final IRI x = conn.getValueFactory().createIRI("urn:x");
	final IRI p = conn.getValueFactory().createIRI("urn:p");

	GraphQuery query = conn.prepareGraphQuery(QueryLanguage.SPARQL, queryStr);
	try (GraphQueryResult evaluate = query.evaluate();) {
		Model result = QueryResults.asModel(evaluate);

		assertNotNull(result);
		assertFalse(result.isEmpty());
		assertTrue(result.contains(x, p, x));
	}
}
 
Example #8
Source File: ComplexSPARQLQueryTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testDescribeMultipleA() throws Exception {
	String update = "insert data { <urn:1> <urn:p1> <urn:v> . [] <urn:blank> <urn:1> . <urn:2> <urn:p2> <urn:3> . } ";
	conn.prepareUpdate(QueryLanguage.SPARQL, update).execute();

	StringBuilder query = new StringBuilder();
	query.append(getNamespaceDeclarations());
	query.append("DESCRIBE <urn:1> <urn:2> ");

	GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString());

	ValueFactory vf = conn.getValueFactory();
	IRI urn1 = vf.createIRI("urn:1");
	IRI p1 = vf.createIRI("urn:p1");
	IRI p2 = vf.createIRI("urn:p2");
	IRI urn2 = vf.createIRI("urn:2");
	IRI blank = vf.createIRI("urn:blank");

	try (GraphQueryResult evaluate = gq.evaluate();) {
		Model result = QueryResults.asModel(evaluate);
		assertTrue(result.contains(urn1, p1, null));
		assertTrue(result.contains(null, blank, urn1));
		assertTrue(result.contains(urn2, p2, null));
	}
}
 
Example #9
Source File: ComplexSPARQLQueryTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testDescribeMultipleB() throws Exception {
	String update = "insert data { <urn:1> <urn:p1> <urn:v> . <urn:1> <urn:blank> [] . <urn:2> <urn:p2> <urn:3> . } ";
	conn.prepareUpdate(QueryLanguage.SPARQL, update).execute();

	StringBuilder query = new StringBuilder();
	query.append(getNamespaceDeclarations());
	query.append("DESCRIBE <urn:1> <urn:2> ");

	GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString());

	ValueFactory vf = conn.getValueFactory();
	IRI urn1 = vf.createIRI("urn:1");
	IRI p1 = vf.createIRI("urn:p1");
	IRI p2 = vf.createIRI("urn:p2");
	IRI urn2 = vf.createIRI("urn:2");
	IRI blank = vf.createIRI("urn:blank");
	try (GraphQueryResult evaluate = gq.evaluate();) {
		Model result = QueryResults.asModel(evaluate);

		assertTrue(result.contains(urn1, p1, null));
		assertTrue(result.contains(urn1, blank, null));
		assertTrue(result.contains(urn2, p2, null));
	}
}
 
Example #10
Source File: ComplexSPARQLQueryTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testDescribeMultipleC() throws Exception {
	String update = "insert data { <urn:1> <urn:p1> <urn:v> . [] <urn:blank> <urn:1>. <urn:1> <urn:blank> [] . <urn:2> <urn:p2> <urn:3> . } ";
	conn.prepareUpdate(QueryLanguage.SPARQL, update).execute();

	StringBuilder query = new StringBuilder();
	query.append(getNamespaceDeclarations());
	query.append("DESCRIBE <urn:1> <urn:2> ");

	GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString());

	ValueFactory vf = conn.getValueFactory();
	IRI urn1 = vf.createIRI("urn:1");
	IRI p1 = vf.createIRI("urn:p1");
	IRI p2 = vf.createIRI("urn:p2");
	IRI urn2 = vf.createIRI("urn:2");
	IRI blank = vf.createIRI("urn:blank");
	try (GraphQueryResult evaluate = gq.evaluate();) {
		Model result = QueryResults.asModel(evaluate);

		assertTrue(result.contains(urn1, p1, null));
		assertTrue(result.contains(urn1, blank, null));
		assertTrue(result.contains(null, blank, urn1));
		assertTrue(result.contains(urn2, p2, null));
	}
}
 
Example #11
Source File: HalyardExport.java    From Halyard with Apache License 2.0 6 votes vote down vote up
@Override
public void writeGraphQueryResult(GraphQueryResult queryResult) throws ExportException {
    try {
        writer.startRDF();
        for (Map.Entry<String, String> me : queryResult.getNamespaces().entrySet()) {
            writer.handleNamespace(me.getKey(), me.getValue());
        }
        while (queryResult.hasNext()) {
            writer.handleStatement(queryResult.next());
            tick();
        }
        writer.endRDF();
    } catch (QueryEvaluationException | RDFHandlerException e) {
        throw new ExportException(e);
    }
}
 
Example #12
Source File: GraphQueryResultTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testDescribeEmpty() throws Exception {
	GraphQueryResult result = con.prepareGraphQuery(QueryLanguage.SPARQL, emptyDescribeQuery).evaluate();
	assertFalse("Query result should be empty", result.hasNext());

	Model model = QueryResults.asModel(result);
	assertTrue("Query result should be empty", model.isEmpty());
}
 
Example #13
Source File: LuceneSailExample.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void graphQuery(String queryString, RepositoryConnection connection)
		throws RepositoryException, MalformedQueryException, QueryEvaluationException {
	System.out.println("Running query: \n" + queryString);
	GraphQuery query = connection.prepareGraphQuery(QueryLanguage.SPARQL, queryString);
	try (GraphQueryResult result = query.evaluate()) {
		// print the results
		while (result.hasNext()) {
			Statement stmt = result.next();
			System.out.println("found match: " + stmt.getSubject().stringValue() + "\t"
					+ stmt.getPredicate().stringValue() + "\t" + stmt.getObject().stringValue());
		}
	}

}
 
Example #14
Source File: BasicTests.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testSingleSource_SetBinding() throws Exception {

	/* test a single source select query where we set a binding */
	prepareTest(Arrays.asList("/tests/basic/data01endpoint1.ttl", "/tests/basic/data01endpoint2.ttl"));

	try (RepositoryConnection conn = fedxRule.getRepository().getConnection()) {

		// SELECT query
		TupleQuery tq = conn
				.prepareTupleQuery("SELECT ?person WHERE { ?person <http://xmlns.com/foaf/0.1/name> ?name }");
		tq.setBinding("name", l("Alan"));
		TupleQueryResult tqr = tq.evaluate();
		List<BindingSet> res = Iterations.asList(tqr);
		assertContainsAll(res, "person", Sets.newHashSet(iri("http://example.org/", "a")));

		// CONSTRUCT query
		GraphQuery gq = conn.prepareGraphQuery(
				"CONSTRUCT { ?person <http://xmlns.com/foaf/0.1/name> ?name } WHERE { ?person <http://xmlns.com/foaf/0.1/name> ?name }");
		gq.setBinding("name", l("Alan"));
		GraphQueryResult gqr = gq.evaluate();
		List<Statement> stmts = Iterations.asList(gqr);
		Assertions.assertEquals(1, stmts.size());
		Assertions.assertEquals(iri("http://example.org/", "a"), stmts.get(0).getSubject());

		// BOOLEAN query
		BooleanQuery bq = conn.prepareBooleanQuery("ASK { ?person <http://xmlns.com/foaf/0.1/name> ?name }");
		bq.setBinding("name", l("non-existing-name"));
		Assertions.assertEquals(false, bq.evaluate());

	}

}
 
Example #15
Source File: RepositoryController.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static QueryResult<?> distinct(QueryResult<?> qr) {
	if (qr instanceof TupleQueryResult) {
		TupleQueryResult tqr = (TupleQueryResult) qr;
		return QueryResults.distinctResults(tqr);
	} else if (qr instanceof GraphQueryResult) {
		GraphQueryResult gqr = (GraphQueryResult) qr;
		return QueryResults.distinctResults(gqr);
	} else {
		return qr;
	}
}
 
Example #16
Source File: GraphQueryResultTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testDescribeMultiple() throws Exception {
	GraphQueryResult result = con.prepareGraphQuery(QueryLanguage.SPARQL, multipleDescribeQuery).evaluate();
	assertTrue("Query result should not be empty", result.hasNext());

	Model model = QueryResults.asModel(result);
	assertFalse("Query result should not be empty", model.isEmpty());
	assertEquals(4, model.size());
}
 
Example #17
Source File: ComplexSPARQLQueryTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testDescribeF() throws Exception {
	loadTestData("/testdata-query/dataset-describe.trig");
	StringBuilder query = new StringBuilder();
	query.append(getNamespaceDeclarations());
	query.append("DESCRIBE ex:f");

	GraphQuery gq = conn.prepareGraphQuery(QueryLanguage.SPARQL, query.toString());

	ValueFactory vf = conn.getValueFactory();
	IRI f = vf.createIRI("http://example.org/f");
	IRI p = vf.createIRI("http://example.org/p");
	try (GraphQueryResult evaluate = gq.evaluate();) {
		Model result = QueryResults.asModel(evaluate);

		assertNotNull(result);
		assertEquals(4, result.size());
		Set<Value> objects = result.filter(f, p, null).objects();
		assertNotNull(objects);
		for (Value object : objects) {
			if (object instanceof BNode) {
				Set<Value> childObjects = result.filter((BNode) object, null, null).objects();
				assertNotNull(childObjects);
				for (Value childObject : childObjects) {
					if (childObject instanceof BNode) {
						assertTrue(result.contains((BNode) childObject, null, null));
					}
				}
			}
		}
	}
}
 
Example #18
Source File: GraphQueryResultTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testConstructMultiple() throws Exception {
	GraphQueryResult result = con.prepareGraphQuery(QueryLanguage.SPARQL, multipleConstructQuery).evaluate();
	assertTrue("Query result should not be empty", result.hasNext());

	Model model = QueryResults.asModel(result);
	assertFalse("Query result should not be empty", model.isEmpty());
	assertEquals(4, model.size());
}
 
Example #19
Source File: GraphQueryResultTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testConstructSingle() throws Exception {
	GraphQueryResult result = con.prepareGraphQuery(QueryLanguage.SPARQL, singleConstructQuery).evaluate();
	assertTrue("Query result should not be empty", result.hasNext());

	Model model = QueryResults.asModel(result);
	assertFalse("Query result should not be empty", model.isEmpty());
	assertEquals(1, model.size());
}
 
Example #20
Source File: SPARQLStoreConnectionTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void testSimpleGraphQuery() throws Exception {
	testCon.add(alice, name, nameAlice, context2);
	testCon.add(alice, mbox, mboxAlice, context2);
	testCon.add(context2, publisher, nameAlice);

	testCon.add(bob, name, nameBob, context1);
	testCon.add(bob, mbox, mboxBob, context1);
	testCon.add(context1, publisher, nameBob);

	StringBuilder queryBuilder = new StringBuilder();
	queryBuilder.append(" PREFIX foaf: <" + FOAF_NS + ">");
	queryBuilder.append(" CONSTRUCT ");
	queryBuilder.append(" WHERE { [] foaf:name ?name; ");
	queryBuilder.append("            foaf:mbox ?mbox. }");

	try (GraphQueryResult result = testCon.prepareGraphQuery(QueryLanguage.SPARQL, queryBuilder.toString())
			.evaluate()) {
		assertTrue(result != null);
		assertTrue(result.hasNext());

		while (result.hasNext()) {
			Statement st = result.next();
			if (name.equals(st.getPredicate())) {
				assertTrue(nameAlice.equals(st.getObject()) || nameBob.equals(st.getObject()));
			} else {
				assertTrue(mbox.equals(st.getPredicate()));
				assertTrue(mboxAlice.equals(st.getObject()) || mboxBob.equals(st.getObject()));
			}
		}
	}
}
 
Example #21
Source File: QueryResultIO.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Writes a graph query result document in a specific RDF format to an output stream.
 *
 * @param gqr    The query result to write.
 * @param format The file format of the document to write.
 * @param out    An OutputStream to write the document to.
 * @throws IOException                  If an I/O error occurred while writing the query result document to the
 *                                      stream.
 * @throws RDFHandlerException          If such an exception is thrown by the used RDF writer.
 * @throws QueryEvaluationException
 * @throws UnsupportedRDFormatException If an unsupported query result file format was specified.
 */
public static void writeGraph(GraphQueryResult gqr, RDFFormat format, OutputStream out)
		throws IOException, RDFHandlerException, UnsupportedRDFormatException, QueryEvaluationException {
	RDFWriter writer = Rio.createWriter(format, out);
	try {
		QueryResults.report(gqr, writer);
	} catch (RDFHandlerException e) {
		if (e.getCause() instanceof IOException) {
			throw (IOException) e.getCause();
		} else {
			throw e;
		}
	}
}
 
Example #22
Source File: SPARQLGraphQuery.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public GraphQueryResult evaluate() throws QueryEvaluationException {
	SPARQLProtocolSession client = getHttpClient();
	try {
		// TODO getQueryString() already inserts bindings, use emptybindingset
		// as last argument?
		return client.sendGraphQuery(queryLanguage, getQueryString(), baseURI, dataset, getIncludeInferred(),
				getMaxExecutionTime(), getBindingsArray());
	} catch (IOException | RepositoryException | MalformedQueryException e) {
		throw new QueryEvaluationException(e.getMessage(), e);
	}
}
 
Example #23
Source File: SPARQLConnection.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private RepositoryResult<Statement> getStatementGeneral(Resource subj, IRI pred, Value obj, boolean includeInferred,
		Resource... contexts) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
	GraphQueryResult gRes = null;
	RepositoryResult<Statement> result = null;

	boolean allGood = false;
	try {
		GraphQuery query = prepareGraphQuery(SPARQL, EVERYTHING, "");
		query.setIncludeInferred(includeInferred);
		setBindings(query, subj, pred, obj, contexts);
		gRes = query.evaluate();
		result = new RepositoryResult<>(
				new ExceptionConvertingIteration<Statement, RepositoryException>(gRes) {

					@Override
					protected RepositoryException convert(Exception e) {
						return new RepositoryException(e);
					}
				});
		allGood = true;
		return result;
	} finally {
		if (!allGood) {
			try {
				if (result != null) {
					result.close();
				}
			} finally {
				if (gRes != null) {
					gRes.close();
				}
			}
		}
	}
}
 
Example #24
Source File: HTTPGraphQuery.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public GraphQueryResult evaluate() throws QueryEvaluationException {
	SPARQLProtocolSession client = getHttpClient();
	try {
		conn.flushTransactionState(Protocol.Action.QUERY);
		return client.sendGraphQuery(queryLanguage, queryString, baseURI, dataset, getIncludeInferred(),
				getMaxExecutionTime(), getBindingsArray());
	} catch (IOException | RepositoryException | MalformedQueryException e) {
		throw new HTTPQueryEvaluationException(e.getMessage(), e);
	}
}
 
Example #25
Source File: SPARQLProtocolSession.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public GraphQueryResult sendGraphQuery(QueryLanguage ql, String query, String baseURI, Dataset dataset,
		boolean includeInferred, int maxQueryTime, Binding... bindings) throws IOException, RepositoryException,
		MalformedQueryException, UnauthorizedException, QueryInterruptedException {
	try {
		HttpUriRequest method = getQueryMethod(ql, query, baseURI, dataset, includeInferred, maxQueryTime,
				bindings);
		return getRDFBackground(method, false);
	} catch (RDFHandlerException e) {
		// Found a bug in TupleQueryResultBuilder?
		throw new RepositoryException(e);
	}
}
 
Example #26
Source File: HalyardExport.java    From Halyard with Apache License 2.0 5 votes vote down vote up
@Override
public void writeGraphQueryResult(GraphQueryResult queryResult) throws ExportException {
    try {
        while (queryResult.hasNext()) {
            queryResult.next();
            tick();
        }
    } catch (QueryEvaluationException e) {
        throw new ExportException(e);
    }
}
 
Example #27
Source File: RepositoryModel.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public ClosableIterable<Statement> sparqlDescribe(String query) throws ModelRuntimeException {
	assertModel();
	try {
		GraphQuery prepared = this.connection.prepareGraphQuery(QueryLanguage.SPARQL, query);
		GraphQueryResult graphQueryResult = prepared.evaluate();
		return new GraphIterable(graphQueryResult, this);
	} catch (MalformedQueryException | RepositoryException |
			UnsupportedQueryLanguageException | QueryEvaluationException e) {
		throw new ModelRuntimeException(e);
	}
}
 
Example #28
Source File: RepositoryModel.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public ClosableIterable<Statement> sparqlConstruct(String query) throws ModelRuntimeException {
	assertModel();
	try {
		GraphQuery prepared = this.connection.prepareGraphQuery(QueryLanguage.SPARQL, query);
		GraphQueryResult graphQueryResult = prepared.evaluate();
		return new GraphIterable(graphQueryResult, this);
	} catch (MalformedQueryException | RepositoryException |
			UnsupportedQueryLanguageException | QueryEvaluationException e) {
		throw new ModelRuntimeException(e);
	}
}
 
Example #29
Source File: RepositoryModelSet.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public ClosableIterable<Statement> sparqlConstruct(String queryString)
        throws ModelRuntimeException {
	this.assertModel();
	GraphQuery query;
	try {
		query = this.connection.prepareGraphQuery(QueryLanguage.SPARQL, queryString);
		GraphQueryResult graphQueryResult = query.evaluate();
		return new StatementIterable(graphQueryResult, null);
	} catch(RDF4JException e) {
		throw new ModelRuntimeException(e);
	}
}
 
Example #30
Source File: RepositoryModelSet.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public ClosableIterable<Statement> sparqlDescribe(String queryString)
        throws ModelRuntimeException {
	this.assertModel();
	GraphQuery query;
	try {
		query = this.connection.prepareGraphQuery(QueryLanguage.SPARQL, queryString);
		GraphQueryResult graphQueryResult = query.evaluate();
		return new StatementIterable(graphQueryResult, null);
	} catch(RDF4JException e) {
		throw new ModelRuntimeException(e);
	}
}