Skip to content

Commit

Permalink
Additional API to support SPARQL queries for inlined resources. (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
jad-elkhoury authored Nov 11, 2021
1 parent 18ab62b commit 44f8430
Show file tree
Hide file tree
Showing 3 changed files with 222 additions and 126 deletions.
69 changes: 65 additions & 4 deletions store/store-core/src/main/java/org/eclipse/lyo/store/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import org.apache.jena.rdf.model.Model;
import org.apache.jena.arq.querybuilder.SelectBuilder;
import java.net.URISyntaxException;
import java.net.URI;
import java.util.Collection;
Expand Down Expand Up @@ -167,8 +168,58 @@ <T extends IResource> List<T> getResources(URI namedGraphUri, Class<T> clazz, in
* occurred when working with Jena model.
*/
<T extends IResource> List<T> getResources(URI namedGraphUri, Class<T> clazz,
String prefixes, String where, String searchTerms,
int limit, int offset) throws StoreAccessException, ModelUnmarshallingException;
String prefixes, String where, String searchTerms,
int limit, int offset) throws StoreAccessException, ModelUnmarshallingException;

/**
* Alternative to {@link Store#getResources(URI, Class, String, String, String, int, int)} with additional paramters for inlined resources.
*
* These paramters extend the default query from
*
* DESCRIBE ?s
* WHERE {
* ...
* SELECT distinct ?s
* WHERE {
* ?s ?p ?o .
* ?s rdf:type <http://...> .
* ...
* }
* }
*
* to
*
* DESCRIBE ?s ?a ?b
* WHERE {
* ...
* SELECT distinct ?s ?a ?b
* WHERE {
* ?s ?p ?o .
* ?s rdf:type <http://...> .
* ?s <http://...#prp1> ?a .
* ?a <http://prp2> ?b
* }
* }
*
* hence allowing ?a and ?b to be described, as well as ?a
*
* Corresponding paramters to acheive this:
* List<String> additionalDistinctVars = new ArrayList<String>();
* additionalDistinctVars.add("a");
* additionalDistinctVars.add("b");
*
* SelectBuilder additionalQueryFilter = new SelectBuilder();
* additionalQueryFilter
* .addWhere( "?s", new ResourceImpl("http://...#" + "prp1"), "?a")
* .addWhere( "?a", new ResourceImpl(http://...# + "prp2"), "?b");
* @param additionalDistinctVars
* @param additionalQueryFilter
*/
<T extends IResource> List<T> getResources(URI namedGraphUri, Class<T> clazz,
String prefixes, String where, String searchTerms,
int limit, int offset,
List<String> additionalDistinctVars, SelectBuilder additionalQueryFilter) throws StoreAccessException, ModelUnmarshallingException;

/**
* Retrieve a Jena model that satisfies the given where parameter as defined in the OSLC Query language (https://tools.oasis-open.org/version-control/svn/oslc-core/trunk/specs/oslc-query.html)
Expand All @@ -184,7 +235,7 @@ <T extends IResource> List<T> getResources(URI namedGraphUri, Class<T> clazz,
* @return list of resources, size is less or equal to 'limit'
*
*/
Model getResources(URI namedGraph, String prefixes, String where, int limit, int offset);
Model getResources(URI namedGraph, String prefixes, String where, int limit, int offset);

/**
* Retrieve a Jena model that satisfies the given where parameter as defined in the OSLC Query language (https://tools.oasis-open.org/version-control/svn/oslc-core/trunk/specs/oslc-query.html)
Expand All @@ -201,7 +252,17 @@ <T extends IResource> List<T> getResources(URI namedGraphUri, Class<T> clazz,
* @return list of resources, size is less or equal to 'limit'
*
*/
Model getResources(URI namedGraph, String prefixes, String where, String searchTerms, int limit, int offset);
Model getResources(URI namedGraph, String prefixes, String where, String searchTerms, int limit, int offset);


/**
* Alternative to {@link Store#getResources(URI, String, String, String, int, int)} with additional paramters for inlined resources.
*
* See {@link Store#getResources(URI, Class, String, String, String, int, int, List<String>, SelectBuilder)} for an explanation of these additional paramters.
*/
Model getResources(URI namedGraph, String prefixes, String where, String searchTerms, int limit, int offset,
List<String> additionalDistinctVars, SelectBuilder additionalQueryFilter);

/**
* Retrieve a single {@link IResource} instance specified by the concrete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import com.google.common.collect.Sets;
import java.util.HashSet;

import org.apache.jena.arq.querybuilder.SelectBuilder;
import org.apache.jena.query.Dataset;
import org.apache.jena.query.ReadWrite;
import org.apache.jena.rdf.model.Model;
Expand Down Expand Up @@ -163,23 +165,35 @@ public <T extends IResource> List<T> getResources(final URI namedGraph,
return resources.subList(offset, Math.min(resources.size(), offset + limit));
}

@Override
public <T extends IResource> List<T> getResources(URI namedGraphUri, Class<T> clazz, String prefixes, String where,
String searchTerms, int limit, int offset) throws StoreAccessException, ModelUnmarshallingException {
throw new UnsupportedOperationException();
}
@Override
public <T extends IResource> List<T> getResources(URI namedGraphUri, Class<T> clazz, String prefixes, String where,
String searchTerms, int limit, int offset) throws StoreAccessException, ModelUnmarshallingException {
throw new UnsupportedOperationException();
}

@Override
public <T extends IResource> List<T> getResources(URI namedGraphUri, Class<T> clazz, String prefixes, String where,
String searchTerms, int limit, int offset, List<String> additionalDistinctVars, SelectBuilder additionalQueryFilter) throws StoreAccessException, ModelUnmarshallingException {
throw new UnsupportedOperationException();
}

@Override
public Model getResources(URI namedGraph, String prefixes, String where, int limit,
int offset) {
throw new UnsupportedOperationException();
}

@Override
public Model getResources(URI namedGraph, String prefixes, String where, int limit,
int offset) {
@Override
public Model getResources(URI namedGraph, String prefixes, String where, String searchTerms, int limit,
int offset) {
throw new UnsupportedOperationException();
}
}

@Override
public Model getResources(URI namedGraph, String prefixes, String where, String searchTerms, int limit,
int offset) {
@Override
public Model getResources(URI namedGraph, String prefixes, String where, String searchTerms, int limit,
int offset, List<String> additionalDistinctVars, SelectBuilder additionalQueryFilter) {
throw new UnsupportedOperationException();
}
}

@Override
public Set<String> keySet() {
Expand Down
Loading

0 comments on commit 44f8430

Please sign in to comment.