Skip to content

Commit

Permalink
Merge branch 'version4' into feature/protege-refactoring-reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
fracorco committed Nov 5, 2021
2 parents eef330d + 59fdc95 commit 73acc7c
Show file tree
Hide file tree
Showing 255 changed files with 96,502 additions and 1,402 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.unibz.inf.ontop.owlapi;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.junit.*;

import java.util.Arrays;
Expand All @@ -18,7 +19,8 @@ public class LeftJoinProfTest extends AbstractOWLAPITest {
public static void setUp() throws Exception {
initOBDA("/test/redundant_join/redundant_join_fk_create.sql",
"/test/redundant_join/redundant_join_fk_test.obda",
"/test/redundant_join/redundant_join_fk_test.owl");
"/test/redundant_join/redundant_join_fk_test.owl",
"/test/redundant_join/redundant_join_fk_test.properties");

}

Expand Down Expand Up @@ -1242,6 +1244,35 @@ public void testNonOptimizableLJAndJoinMix() throws Exception {
assertTrue(sql.toUpperCase().contains("LEFT"));
}

@Test
public void testValuesNodeOntologyProperty() throws Exception {
String querySelect = "SELECT ?o WHERE {\n" +
"?s <http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#conductsLab> ?o\n" +
"}";

checkReturnedValues(querySelect, "o", ImmutableList.of(
// From the facts
"<http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#course/Algorithms>",
"<http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#course/DataIntegration>"));

}

@Test
public void testAggregationMappingProfStudentCountProperty() throws Exception {

String querySelect = "PREFIX : <http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#>\n" +
"\n" +
"SELECT ?v\n" +
"WHERE {\n" +
"?p a :Teacher ;\n" +
" :nbStudents ?v .\n" +
"}" +
"ORDER BY ?v\n" ;

ImmutableList<String> expectedValues = ImmutableList.of("\"12\"^^xsd:integer", "\"13\"^^xsd:integer", "\"21\"^^xsd:integer");
checkReturnedValues(querySelect, "v", expectedValues);
}

private static boolean containsMoreThanOneOccurrence(String query, String pattern) {
int firstOccurrenceIndex = query.indexOf(pattern);
if (firstOccurrenceIndex >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class RedundantJoinFKProfTest extends AbstractOWLAPITest {
public static void setUp() throws Exception {
initOBDA("/test/redundant_join/redundant_join_fk_create.sql",
"/test/redundant_join/redundant_join_fk_test.obda",
"/test/redundant_join/redundant_join_fk_test.owl");
"/test/redundant_join/redundant_join_fk_test.owl",
"/test/redundant_join/redundant_join_fk_test.properties");
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ mappingId MAPID-course
target :course/{course_id} a :Course ; :duration {duration} ; :nbStudents {nb_students} .
source SELECT * FROM course;

mappingId MAPID-prof-student-count
target :professor/{prof_id} :nbStudents {count} .
source SELECT t.prof_id, sum(c.nb_students) AS count FROM teaching t, course c WHERE t.course_id = c.course_id GROUP BY prof_id

]]

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
</owl:ObjectProperty>


<!-- http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#conductsLab -->

<owl:ObjectProperty rdf:about="http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#conductsLab">
<rdfs:domain rdf:resource="http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#Teacher"/>
<rdfs:range rdf:resource="http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#Course"/>
</owl:ObjectProperty>


<!--
///////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -123,6 +130,63 @@
<!-- http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#Teacher -->

<owl:Class rdf:about="http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#Teacher"/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Individuals
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#course/Algorithms -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#course/Algorithms"/>



<!-- http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#course/DataIntegration -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#course/DataIntegration"/>



<!-- http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#course/Programming -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#course/Programming"/>



<!-- http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#course/Mathematics -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#course/Mathematics"/>



<!-- http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#course/Painting -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#course/Painting"/>



<!-- http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#teacher/Jane -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#teacher/Jane">
<conductsLab rdf:resource="http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#course/Algorithms"/>
</owl:NamedIndividual>



<!-- http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#teacher/Joe -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#teacher/Joe">
<conductsLab rdf:resource="http://www.semanticweb.org/user/ontologies/2016/8/untitled-ontology-84#course/DataIntegration"/>
</owl:NamedIndividual>
</rdf:RDF>


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ontop.allowRetrievingBlackBoxViewMetadataFromDB = true
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import it.unibz.inf.ontop.answering.cache.HTTPCacheHeaders;
import it.unibz.inf.ontop.injection.OntopSystemConfiguration;
import it.unibz.inf.ontop.rdf4j.repository.impl.OntopVirtualRepository;
import org.eclipse.rdf4j.repository.RepositoryException;

/**
* Ontop RDF4J repository
Expand All @@ -11,6 +12,9 @@ public interface OntopRepository extends org.eclipse.rdf4j.repository.Repository

HTTPCacheHeaders getHttpCacheHeaders();

@Override
OntopRepositoryConnection getConnection() throws RepositoryException;

static OntopVirtualRepository defaultRepository(OntopSystemConfiguration configuration) {
return new OntopVirtualRepository(configuration);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package it.unibz.inf.ontop.rdf4j.repository;

import com.google.common.collect.ImmutableMultimap;
import org.eclipse.rdf4j.query.*;
import org.eclipse.rdf4j.repository.RepositoryException;

public interface OntopRepositoryConnection extends org.eclipse.rdf4j.repository.RepositoryConnection {

Query prepareQuery(QueryLanguage ql, String query, ImmutableMultimap<String, String> httpHeaders)
throws RepositoryException, MalformedQueryException;

Query prepareQuery(QueryLanguage ql, String queryString, String baseIRI,
ImmutableMultimap<String, String> httpHeaders)
throws RepositoryException, MalformedQueryException;

TupleQuery prepareTupleQuery(QueryLanguage ql, String queryString, String baseIRI,
ImmutableMultimap<String, String> httpHeaders)
throws RepositoryException, MalformedQueryException;

GraphQuery prepareGraphQuery(QueryLanguage ql, String queryString,
String baseIRI, ImmutableMultimap<String, String> httpHeaders)
throws RepositoryException, MalformedQueryException;

BooleanQuery prepareBooleanQuery(QueryLanguage ql, String queryString,
String baseIRI, ImmutableMultimap<String, String> httpHeaders)
throws RepositoryException, MalformedQueryException;

String reformulate(String sparql) throws RepositoryException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import it.unibz.inf.ontop.answering.reformulation.input.RDF4JInputQueryFactory;
import it.unibz.inf.ontop.answering.reformulation.input.SPARQLQuery;
import it.unibz.inf.ontop.exception.OntopConnectionException;
import it.unibz.inf.ontop.exception.OntopInvalidInputQueryException;
import it.unibz.inf.ontop.exception.OntopReformulationException;
import it.unibz.inf.ontop.injection.OntopSystemSettings;
import it.unibz.inf.ontop.rdf4j.query.impl.*;
import it.unibz.inf.ontop.rdf4j.repository.OntopRepository;
import it.unibz.inf.ontop.rdf4j.repository.OntopRepositoryConnection;
import org.eclipse.rdf4j.IsolationLevel;
import org.eclipse.rdf4j.IsolationLevels;
import org.eclipse.rdf4j.common.iteration.CloseableIteratorIteration;
Expand All @@ -33,10 +33,10 @@
import java.net.URL;
import java.util.*;

public class OntopRepositoryConnection implements org.eclipse.rdf4j.repository.RepositoryConnection {
public class OntopRepositoryConnectionImpl implements OntopRepositoryConnection {

private static final String READ_ONLY_MESSAGE = "Ontop is a read-only system";
private static Logger LOGGER = LoggerFactory.getLogger(OntopRepositoryConnection.class);
private static Logger LOGGER = LoggerFactory.getLogger(OntopRepositoryConnectionImpl.class);
private OntopRepository repository;
private OntopConnection ontopConnection;
private final RDF4JInputQueryFactory inputQueryFactory;
Expand All @@ -47,8 +47,8 @@ public class OntopRepositoryConnection implements org.eclipse.rdf4j.repository.R
private Map<String, String> namespaces;


OntopRepositoryConnection(OntopRepository rep, OntopConnection connection,
RDF4JInputQueryFactory inputQueryFactory, OntopSystemSettings settings) {
OntopRepositoryConnectionImpl(OntopRepository rep, OntopConnection connection,
RDF4JInputQueryFactory inputQueryFactory, OntopSystemSettings settings) {
this.repository = rep;
this.ontopConnection = connection;
this.inputQueryFactory = inputQueryFactory;
Expand Down Expand Up @@ -322,6 +322,7 @@ public BooleanQuery prepareBooleanQuery(QueryLanguage ql, String queryString,
return prepareBooleanQuery(ql, queryString, baseIRI, ImmutableMultimap.of());
}

@Override
public BooleanQuery prepareBooleanQuery(QueryLanguage ql, String queryString,
String baseIRI, ImmutableMultimap<String, String> httpHeaders) throws RepositoryException, MalformedQueryException {
//Prepares true/false queries.
Expand Down Expand Up @@ -351,6 +352,7 @@ public GraphQuery prepareGraphQuery(QueryLanguage ql, String queryString, String
return prepareGraphQuery(ql, queryString, baseIRI, ImmutableMultimap.of());
}

@Override
public GraphQuery prepareGraphQuery(QueryLanguage ql, String queryString,
String baseIRI, ImmutableMultimap<String, String> httpHeaders)
throws RepositoryException, MalformedQueryException {
Expand All @@ -376,6 +378,7 @@ public Query prepareQuery(QueryLanguage ql, String query)
return prepareTupleQuery(ql, query, null, ImmutableMultimap.of());
}

@Override
public Query prepareQuery(QueryLanguage ql, String query, ImmutableMultimap<String, String> httpHeaders)
throws RepositoryException, MalformedQueryException {
//Prepares a query for evaluation on this repository (optional operation).
Expand All @@ -390,6 +393,7 @@ public Query prepareQuery(QueryLanguage ql, String queryString, String baseIRI)
return prepareQuery(ql, queryString, baseIRI, ImmutableMultimap.of());
}

@Override
public Query prepareQuery(QueryLanguage ql, String queryString, String baseIRI,
ImmutableMultimap<String, String> httpHeaders)
throws RepositoryException, MalformedQueryException {
Expand Down Expand Up @@ -426,6 +430,7 @@ public TupleQuery prepareTupleQuery(QueryLanguage ql, String queryString, String
return prepareTupleQuery(ql, queryString, baseIRI, ImmutableMultimap.of());
}

@Override
public TupleQuery prepareTupleQuery(QueryLanguage ql, String queryString, String baseIRI,
ImmutableMultimap<String, String> httpHeaders)
throws RepositoryException, MalformedQueryException {
Expand Down Expand Up @@ -605,10 +610,15 @@ public <E extends Exception> void remove(
throw new UnsupportedOperationException(READ_ONLY_MESSAGE);
}

@Override
public String reformulate(String sparql)
throws OntopConnectionException, OntopInvalidInputQueryException, OntopReformulationException {
SPARQLQuery sparqlQuery = ontopConnection.getInputQueryFactory().createSPARQLQuery(sparql);
return ontopConnection.createStatement().getExecutableQuery(sparqlQuery).toString();
throws RepositoryException {
try {
SPARQLQuery sparqlQuery = ontopConnection.getInputQueryFactory().createSPARQLQuery(sparql);
return ontopConnection.createStatement().getExecutableQuery(sparqlQuery).toString();
} catch (OntopReformulationException | OntopConnectionException e) {
throw new RepositoryException(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import it.unibz.inf.ontop.injection.OntopSystemConfiguration;
import it.unibz.inf.ontop.injection.OntopSystemSettings;
import it.unibz.inf.ontop.rdf4j.repository.OntopRepository;
import it.unibz.inf.ontop.rdf4j.repository.OntopRepositoryConnection;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.eclipse.rdf4j.repository.RepositoryException;
Expand Down Expand Up @@ -53,7 +54,7 @@ public OntopRepositoryConnection getConnection() throws RepositoryException {
}

try {
return new OntopRepositoryConnection(this, getOntopConnection(), inputQueryFactory, settings);
return new OntopRepositoryConnectionImpl(this, getOntopConnection(), inputQueryFactory, settings);
} catch (Exception e) {
logger.error("Error creating repo connection: " + e.getMessage());
throw new RepositoryException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void testThreeOptionals() {
}

@Test
public void testThreeOptionalsWithLimit() {
public void testThreeOptionalsWithOrderBy() {
String query = "PREFIX ex: <http://example.org/>\n" +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import it.unibz.inf.ontop.injection.OntopSQLOWLAPIConfiguration;
import it.unibz.inf.ontop.rdf4j.repository.impl.OntopVirtualRepository;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.query.*;
import org.eclipse.rdf4j.query.impl.MapBindingSet;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -31,14 +31,14 @@ public class AbstractRDF4JTest {
private static final String PASSWORD = "";
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractRDF4JTest.class);
private static Connection SQL_CONNECTION;
private static RepositoryConnection REPO_CONNECTION;
private static OntopRepositoryConnection REPO_CONNECTION;

protected static void initOBDA(String dbScriptRelativePath, String obdaRelativePath) throws SQLException, IOException {
initOBDA(dbScriptRelativePath, obdaRelativePath, null);
}
protected static void initOBDA(String dbScriptRelativePath, String obdaRelativePath,
@Nullable String ontologyRelativePath) throws SQLException, IOException {
initOBDA(dbScriptRelativePath, obdaRelativePath, null, null);
initOBDA(dbScriptRelativePath, obdaRelativePath, ontologyRelativePath, null);
}

protected static void initOBDA(String dbScriptRelativePath, String obdaRelativePath,
Expand Down Expand Up @@ -95,14 +95,15 @@ protected static void initOBDA(String dbScriptRelativePath, String obdaRelativeP

OntopSQLOWLAPIConfiguration config = builder.build();

OntopRepository repo = OntopRepository.defaultRepository(config);
OntopVirtualRepository repo = OntopRepository.defaultRepository(config);
repo.init();
/*
* Prepare the data connection for querying.
*/
REPO_CONNECTION = repo.getConnection();
}


protected static void initR2RML(String dbScriptRelativePath, String r2rmlRelativePath) throws SQLException, IOException {
initR2RML(dbScriptRelativePath, r2rmlRelativePath, null, null);
}
Expand Down Expand Up @@ -149,7 +150,7 @@ protected static void initR2RML(String dbScriptRelativePath, String r2rmlRelativ

OntopSQLOWLAPIConfiguration config = builder.build();

OntopRepository repo = OntopRepository.defaultRepository(config);
OntopVirtualRepository repo = OntopRepository.defaultRepository(config);
repo.init();
/*
* Prepare the data connection for querying.
Expand Down Expand Up @@ -196,6 +197,10 @@ protected void runQueryAndCompare(String queryString, ImmutableList<String> expe
assertEquals(expectedVValues, vValues);
}

protected String reformulate(String queryString) {
return REPO_CONNECTION.reformulate(queryString);
}

protected ImmutableList<String> runQuery(String queryString) {
return runQuery(queryString, new MapBindingSet());
}
Expand Down
Loading

0 comments on commit 73acc7c

Please sign in to comment.