Skip to content

Commit

Permalink
Merge pull request #62 from swiss-art-research-net/feature/qlever
Browse files Browse the repository at this point in the history
Add Qlever repo connector
  • Loading branch information
fkraeutli authored Oct 9, 2024
2 parents e0ec20b + ca1453a commit 0d433ed
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public CustomSPARQLConnection(SPARQLRepository repository, SPARQLProtocolSession
this.enableSilentMode(isSilentMode);
}

public CustomSPARQLConnection(SPARQLRepository repository, SPARQLProtocolSession client) {
super(repository, client);
public CustomSPARQLConnection(SPARQLRepository repository, SPARQLProtocolSession client, boolean quadMode) {
super(repository, client, quadMode);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* ResearchSpace
* Copyright (C) 2024, PHAROS: The International Consortium of Photo Archives
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.researchspace.repository.sparql.qlever;

import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryException;
import org.researchspace.repository.sparql.CustomSPARQLRepository;

/**
* Repository imlementation for QLever SPARQL endpoint.
*
* @see https://github.com/ad-freiburg/qlever
* @see QLeverRepositoryConnection
* @author Artem Kozlov
*/
public class QLeverRepository extends CustomSPARQLRepository {
public QLeverRepository(String endpointUrl) {
super(endpointUrl);
}

@Override
public RepositoryConnection getConnection() throws RepositoryException {
// qlever doesn't support quads, for now
return new QLeverRepositoryConnection(this, createHTTPClient(), false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* ResearchSpace
* Copyright (C) 2024, PHAROS: The International Consortium of Photo Archives
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.researchspace.repository.sparql.qlever;

import org.researchspace.repository.sparql.MpSPARQLRepositoryConfig;

/**
* Implementation config for {@link QLeverRepository}.
*
* @author Artem Kozlov
*/
public class QLeverRepositoryConfig extends MpSPARQLRepositoryConfig {

public QLeverRepositoryConfig() {
super();
setType(QLeverRepositoryFactory.REPOSITORY_TYPE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* ResearchSpace
* Copyright (C) 2024, PHAROS: The International Consortium of Photo Archives
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.researchspace.repository.sparql.qlever;

import org.eclipse.rdf4j.http.client.SPARQLProtocolSession;
import org.eclipse.rdf4j.query.BooleanQuery;
import org.eclipse.rdf4j.query.MalformedQueryException;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.repository.RepositoryException;
import org.eclipse.rdf4j.repository.sparql.SPARQLRepository;
import org.researchspace.api.sparql.SparqlUtil;
import org.researchspace.repository.sparql.CustomSPARQLConnection;
import org.researchspace.repository.sparql.virtuoso.VirtuosoWrapperBooleanQuery;

/**
* A wrapper connection for a QLever SPARQL repository.
*
* Supports ASK queries, by transforming them into equivalent SELECT * {} LIMIT 1
*
* @author Artem Kozlov
*/
public class QLeverRepositoryConnection extends CustomSPARQLConnection {
public QLeverRepositoryConnection(SPARQLRepository repository, SPARQLProtocolSession client, boolean quadMode) {
super(repository, client, quadMode);
}

@Override
public BooleanQuery prepareBooleanQuery(QueryLanguage ql, String query, String base)
throws RepositoryException, MalformedQueryException {
String selectQueryString = SparqlUtil.transformAskToSelect(query);
TupleQuery tupleQuery = prepareTupleQuery(selectQueryString);
VirtuosoWrapperBooleanQuery wrapperQuery = new VirtuosoWrapperBooleanQuery(query, tupleQuery);
return wrapperQuery;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* ResearchSpace
* Copyright (C) 2024, PHAROS: The International Consortium of Photo Archives
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.researchspace.repository.sparql.qlever;

import org.eclipse.rdf4j.repository.config.RepositoryConfigException;
import org.eclipse.rdf4j.repository.config.RepositoryFactory;
import org.eclipse.rdf4j.repository.config.RepositoryImplConfig;
import org.eclipse.rdf4j.repository.sparql.config.SPARQLRepositoryConfig;
import org.researchspace.repository.sparql.AbstractMpSPARQLRepositoryFactory;
import org.researchspace.repository.sparql.MpSPARQLRepositoryConfig;

/**
* A {@link RepositoryFactory} implementation for a QLever repository.
*
* @author Artem Kozlov
*/
public class QLeverRepositoryFactory extends AbstractMpSPARQLRepositoryFactory {

public static final String REPOSITORY_TYPE = "researchspace:QLeverRepository";

@Override
public String getRepositoryType() {
return REPOSITORY_TYPE;
}

@Override
public RepositoryImplConfig getConfig() {
return new QLeverRepositoryConfig();
}

@Override
public QLeverRepository getRepositoryInternal(MpSPARQLRepositoryConfig config) throws RepositoryConfigException {
if (config instanceof SPARQLRepositoryConfig) {
SPARQLRepositoryConfig httpConfig = config;
QLeverRepository result = new QLeverRepository(httpConfig.getQueryEndpointUrl());
result.setWritable(config.isWritable());
return result;
} else {
throw new RepositoryConfigException("Invalid configuration class: " + config.getClass());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ org.researchspace.federation.repository.MpFederationSailRepositoryFactory
org.researchspace.repository.memory.MpMemoryRepositoryFactory
org.researchspace.repository.sparql.virtuoso.VirtuosoWrapperRepositoryFactory
org.researchspace.repository.sparql.bearertoken.SPARQLBearerTokenAuthRepositoryFactory
org.researchspace.repository.sparql.qlever.QLeverRepositoryFactory
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# platform configuration template for a QLever SPARQL repository
#
@prefix rep: <http://www.openrdf.org/config/repository#> .
@prefix sail: <http://www.openrdf.org/config/sail#> .
@prefix sr: <http://www.openrdf.org/config/repository/sail#> .
@prefix sparqlr: <http://www.openrdf.org/config/repository/sparql#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix mph: <http://www.researchspace.org/resource/system/repository#> .


[] a rep:Repository ;
rep:repositoryID "my-qlever-repo" ; # Replace with your repository ID or leave default if this is the main repository
rdfs:label "QLever SPARQL repository" ; # Replace with a meaningful description for this repository
rep:repositoryImpl [
rep:repositoryType "researchspace:QLeverRepository" ;
sparqlr:query-endpoint <http://example.org/query> # Replace with the URL of the SPARQL endpoint to submit queries to
].

0 comments on commit 0d433ed

Please sign in to comment.