Java Code Examples for org.eclipse.rdf4j.query.QueryLanguage#SPARQL

The following examples show how to use org.eclipse.rdf4j.query.QueryLanguage#SPARQL . 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: QueryStorage.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Save a query. UNSAFE from an injection point of view. It is the responsibility of the calling code to call
 * checkAccess() with the full credentials first.
 *
 * @param repository    the repository the query is associated with
 * @param queryName     the name for the query
 * @param userName      the user saving the query
 * @param shared        whether the query is to be shared with other users
 * @param queryLanguage the language, SeRQL or SPARQL, of the query
 * @param queryText     the actual query text
 * @param infer
 * @param rowsPerPage   rows to display per page, may be 0 (all), 10, 50, 100, or 200)
 * @throws RDF4JException
 */
public void saveQuery(final HTTPRepository repository, final String queryName, final String userName,
		final boolean shared, final QueryLanguage queryLanguage, final String queryText, final boolean infer,
		final int rowsPerPage) throws RDF4JException {
	if (QueryLanguage.SPARQL != queryLanguage && QueryLanguage.SERQL != queryLanguage) {
		throw new RepositoryException("May only save SPARQL or SeRQL queries, not" + queryLanguage.toString());
	}
	if (0 != rowsPerPage && 10 != rowsPerPage && 20 != rowsPerPage && 50 != rowsPerPage && 100 != rowsPerPage
			&& 200 != rowsPerPage) {
		throw new RepositoryException("Illegal value for rows per page: " + rowsPerPage);
	}
	this.checkQueryText(queryText);
	final QueryStringBuilder save = new QueryStringBuilder(SAVE);
	save.replaceURI(REPOSITORY, repository.getRepositoryURL());
	save.replaceURI(QUERY, "urn:uuid:" + UUID.randomUUID());
	save.replaceQuote(QUERY_NAME, queryName);
	this.replaceUpdateFields(save, userName, shared, queryLanguage, queryText, infer, rowsPerPage);
	updateQueryRepository(save.toString());
}
 
Example 2
Source File: PagedQuery.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private String modifyOffset(final QueryLanguage language, final int offset, final String query) {
	String rval = query;
	final String newOffsetClause = "offset " + offset;
	if (QueryLanguage.SPARQL == language) {
		if (offset > 0) {
			rval = ensureNewlineAndAppend(rval, newOffsetClause);
		}
	} else {
		/*
		 * SeRQL, add the clause before before the namespace section
		 */
		rval = insertAtMatchOnOwnLine(SERQL_NAMESPACE, rval, newOffsetClause);
	}
	return rval;
}
 
Example 3
Source File: PagedQuery.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static String modifyLimit(final QueryLanguage language, final String query, final int limitSubstitute) {
	String rval = query;

	/*
	 * In SPARQL, LIMIT and/or OFFSET can occur at the end, in either order. In SeRQL, LIMIT and/or OFFSET must be
	 * immediately prior to the *optional* namespace declaration section (which is itself last), and LIMIT must
	 * precede OFFSET. This code makes no attempt to correct if the user places them out of order in the query.
	 */
	if (QueryLanguage.SPARQL == language) {
		rval = ensureNewlineAndAppend(rval, "limit " + limitSubstitute);
	} else {
		rval = insertAtMatchOnOwnLine(SERQL_NAMESPACE, rval, "limit " + limitSubstitute);
	}
	return rval;
}
 
Example 4
Source File: ConversionUtil.java    From semweb4j with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static QueryLanguage toRDF4JQueryLanguage(String queryLanguage) {
	String queryLanguageLowerCase = queryLanguage.toLowerCase();

	switch (queryLanguageLowerCase) {
		case "sparql":
			return QueryLanguage.SPARQL;
		case "serql":
			return QueryLanguage.SERQL;
		default:
			throw new QueryLanguageNotSupportedException("Query language '"
					+ queryLanguageLowerCase
					+ "' not supported. Valid values are \"sparql\" and \"serql\".");
	}
}
 
Example 5
Source File: CustomGraphQueryInferencerRepositoryConnectionTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected Repository createRepository()
		throws MalformedQueryException, UnsupportedQueryLanguageException, SailException, IOException {
	return new SailRepository(new CustomGraphQueryInferencer(new MemoryStore(), QueryLanguage.SPARQL,
			ResourceUtil.getString("/custom-query-inferencing/rule.rq"),
			ResourceUtil.getString("/custom-query-inferencing/match.rq")));
}
 
Example 6
Source File: RepositoryQueryResultTable.java    From semweb4j with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public RepositoryQueryResultTable(String queryString, RepositoryConnection connection)
        throws ModelRuntimeException {
	this(queryString, QueryLanguage.SPARQL, connection);
}
 
Example 7
Source File: SPARQLParserFactory.java    From semagrow with Apache License 2.0 4 votes vote down vote up
@Override
public QueryLanguage getQueryLanguage() {
    return QueryLanguage.SPARQL;
}
 
Example 8
Source File: SPARQLQueryRenderer.java    From semagrow with Apache License 2.0 4 votes vote down vote up
/**
 * @inheritDoc
 */
public QueryLanguage getLanguage() {
    return QueryLanguage.SPARQL;
}
 
Example 9
Source File: SPARQLBooleanQuery.java    From semagrow with Apache License 2.0 4 votes vote down vote up
public SPARQLBooleanQuery(SparqlSession httpClient, String baseURI,
                          String queryString) {
    super(httpClient, QueryLanguage.SPARQL, queryString, baseURI);
}
 
Example 10
Source File: SPARQLParserFactory.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Returns {@link QueryLanguage#SPARQL}.
 */
@Override
public QueryLanguage getQueryLanguage() {
	return QueryLanguage.SPARQL;
}
 
Example 11
Source File: SPARQLQueryRenderer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
public QueryLanguage getLanguage() {
	return QueryLanguage.SPARQL;
}
 
Example 12
Source File: SPARQLUpdate.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public SPARQLUpdate(SPARQLProtocolSession httpClient, String baseURI, String queryString) {
	super(httpClient, QueryLanguage.SPARQL, queryString, baseURI);
}
 
Example 13
Source File: SPARQLTupleQuery.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public SPARQLTupleQuery(SPARQLProtocolSession httpClient, String baseUri, String queryString) {
	super(httpClient, QueryLanguage.SPARQL, queryString, baseUri);
}
 
Example 14
Source File: SPARQLGraphQuery.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public SPARQLGraphQuery(SPARQLProtocolSession httpClient, String baseURI, String queryString) {
	super(httpClient, QueryLanguage.SPARQL, queryString, baseURI);
}
 
Example 15
Source File: SPARQLBooleanQuery.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public SPARQLBooleanQuery(SPARQLProtocolSession httpClient, String baseURI, String queryString) {
	super(httpClient, QueryLanguage.SPARQL, queryString, baseURI);
}
 
Example 16
Source File: TestPagedQuery.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Check that inner query limits do not affect the paging parameters.
 *
 * @throws IOException
 */
@Test
public final void testSES2307regression() throws IOException {
	PagedQuery pagedQuery = new PagedQuery(ResourceUtil.getString("ses2307.rq"), QueryLanguage.SPARQL, 100, 0);
	assertThat(pagedQuery.getLimit()).isEqualTo(100);
}
 
Example 17
Source File: TestPagedQuery.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public final void testSES1895regression() {
	PagedQuery pagedQuery = new PagedQuery("select * {?s ?p ?o } LIMIT 10", QueryLanguage.SPARQL, 100, 0);
	assertThat(pagedQuery.toString().toLowerCase()).isEqualTo("select * {?s ?p ?o } limit 10");
}