forked from researchspace/researchspace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from swiss-art-research-net/feature/qlever
Add Qlever repo connector
- Loading branch information
Showing
7 changed files
with
202 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/org/researchspace/repository/sparql/qlever/QLeverRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/org/researchspace/repository/sparql/qlever/QLeverRepositoryConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/org/researchspace/repository/sparql/qlever/QLeverRepositoryConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/org/researchspace/repository/sparql/qlever/QLeverRepositoryFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/resources/org/researchspace/apps/default/config/repository-templates/qlever.ttl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
]. |