diff --git a/jopa-integration-tests-jena/pom.xml b/jopa-integration-tests-jena/pom.xml index 486e8001c..83f80531b 100644 --- a/jopa-integration-tests-jena/pom.xml +++ b/jopa-integration-tests-jena/pom.xml @@ -13,11 +13,6 @@ JOPA Integration Tests for Jena Integration tests of JOPA and Jena OntoDriver implementation - - 1.8.5 - 2.3.0 - - cz.cvut.kbss.jopa diff --git a/jopa-integration-tests-owlapi/pom.xml b/jopa-integration-tests-owlapi/pom.xml index 122b11bb7..e74c9af56 100644 --- a/jopa-integration-tests-owlapi/pom.xml +++ b/jopa-integration-tests-owlapi/pom.xml @@ -14,7 +14,6 @@ Integration tests of JOPA and OWLAPI OntoDriver implementation - 1.8.5 2.4.0-SNAPSHOT diff --git a/jopa-integration-tests-sesame/pom.xml b/jopa-integration-tests-sesame/pom.xml index 12bc73616..fdb5ff9fc 100644 --- a/jopa-integration-tests-sesame/pom.xml +++ b/jopa-integration-tests-sesame/pom.xml @@ -13,10 +13,6 @@ JOPA Integration Tests for Sesame Integration tests of JOPA and Sesame OntoDriver implementation - - 1.8.5 - - diff --git a/jopa-integration-tests-sesame/src/test/java/cz/cvut/kbss/jopa/test/environment/SesameDataPersist.java b/jopa-integration-tests-sesame/src/test/java/cz/cvut/kbss/jopa/test/environment/SesameDataPersist.java index 0b1702b8f..c3856c4e5 100644 --- a/jopa-integration-tests-sesame/src/test/java/cz/cvut/kbss/jopa/test/environment/SesameDataPersist.java +++ b/jopa-integration-tests-sesame/src/test/java/cz/cvut/kbss/jopa/test/environment/SesameDataPersist.java @@ -16,9 +16,9 @@ import cz.cvut.kbss.jopa.model.EntityManager; import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; -import org.openrdf.model.ValueFactory; -import org.openrdf.repository.Repository; -import org.openrdf.repository.RepositoryConnection; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.repository.Repository; +import org.eclipse.rdf4j.repository.RepositoryConnection; import java.net.URI; import java.util.Collection; @@ -33,10 +33,10 @@ public void persistTestData(Collection data, EntityManager em) throws Ex connection.begin(); for (Triple t : data) { if (t.getValue() instanceof URI) { - connection.add(vf.createURI(t.getSubject().toString()), vf.createURI(t.getProperty().toString()), - vf.createURI(t.getValue().toString())); + connection.add(vf.createIRI(t.getSubject().toString()), vf.createIRI(t.getProperty().toString()), + vf.createIRI(t.getValue().toString())); } else { - connection.add(vf.createURI(t.getSubject().toString()), vf.createURI(t.getProperty().toString()), + connection.add(vf.createIRI(t.getSubject().toString()), vf.createIRI(t.getProperty().toString()), SesameUtils.createDataPropertyLiteral(t.getValue(), "en", vf)); } diff --git a/jopa-integration-tests-sesame/src/test/java/cz/cvut/kbss/jopa/test/integration/sesame/MiscellaneousTest.java b/jopa-integration-tests-sesame/src/test/java/cz/cvut/kbss/jopa/test/integration/sesame/MiscellaneousTest.java index 3cc1a9159..eacb2ac26 100644 --- a/jopa-integration-tests-sesame/src/test/java/cz/cvut/kbss/jopa/test/integration/sesame/MiscellaneousTest.java +++ b/jopa-integration-tests-sesame/src/test/java/cz/cvut/kbss/jopa/test/integration/sesame/MiscellaneousTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -16,8 +16,8 @@ import cz.cvut.kbss.jopa.model.EntityManager; import cz.cvut.kbss.jopa.test.environment.SesamePersistenceFactory; +import org.eclipse.rdf4j.repository.Repository; import org.junit.Test; -import org.openrdf.repository.Repository; import java.util.Collections; diff --git a/jopa-integration-tests/pom.xml b/jopa-integration-tests/pom.xml index bcb640bd9..b2672891b 100644 --- a/jopa-integration-tests/pom.xml +++ b/jopa-integration-tests/pom.xml @@ -15,7 +15,6 @@ Integration tests of JOPA and its OntoDriver implementations - 2.3.0 1.1.6 diff --git a/jopa-owl2java/pom.xml b/jopa-owl2java/pom.xml index 9cfc14902..4db06573b 100644 --- a/jopa-owl2java/pom.xml +++ b/jopa-owl2java/pom.xml @@ -61,6 +61,37 @@ + + + release + + + + + com.google.code.maven-replacer-plugin + replacer + 1.5.3 + + + prepare-package + + replace + + + + + false + ${project.basedir}/src/main/java/cz/cvut/kbss/jopa/owl2java/Constants.java + false + $VERSION$ + ${project.parent.version} + + + + + + + @@ -96,28 +127,6 @@ - - - - com.google.code.maven-replacer-plugin - replacer - 1.5.3 - - - prepare-package - - replace - - - - - false - ${project.basedir}/src/main/java/cz/cvut/kbss/jopa/owl2java/Constants.java - false - $VERSION$ - ${project.parent.version} - - diff --git a/ontodriver-sesame/pom.xml b/ontodriver-sesame/pom.xml index 6be026074..66954ceb6 100644 --- a/ontodriver-sesame/pom.xml +++ b/ontodriver-sesame/pom.xml @@ -13,7 +13,7 @@ - 2.8.9 + 2.2 @@ -24,14 +24,14 @@ compile - org.openrdf.sesame - sesame-runtime - ${openrdf.sesame.version} + org.eclipse.rdf4j + rdf4j-runtime + ${rdf4j.version} - org.openrdf.sesame - sesame-sail-nativerdf - ${openrdf.sesame.version} + org.eclipse.rdf4j + rdf4j-sail-nativerdf + ${rdf4j.version} diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/AbstractSesameIterator.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/AbstractSesameIterator.java index af4b49f68..1386a2c6f 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/AbstractSesameIterator.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/AbstractSesameIterator.java @@ -14,49 +14,43 @@ */ package cz.cvut.kbss.ontodriver.sesame; -import java.util.Collection; -import java.util.HashSet; - -import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; - +import cz.cvut.kbss.ontodriver.descriptor.ListDescriptor; import cz.cvut.kbss.ontodriver.exception.IntegrityConstraintViolatedException; +import cz.cvut.kbss.ontodriver.model.*; import cz.cvut.kbss.ontodriver.sesame.connector.Connector; -import cz.cvut.kbss.ontodriver.descriptor.ListDescriptor; -import cz.cvut.kbss.ontodriver.model.Assertion; -import cz.cvut.kbss.ontodriver.model.Axiom; -import cz.cvut.kbss.ontodriver.model.AxiomImpl; -import cz.cvut.kbss.ontodriver.model.NamedResource; -import cz.cvut.kbss.ontodriver.model.Value; +import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.ValueFactory; + +import java.util.Collection; +import java.util.HashSet; abstract class AbstractSesameIterator implements SesameIterator { protected final Resource listOwner; - protected final URI hasListProperty; - protected final URI hasNextProperty; - protected final URI context; + protected final IRI hasListProperty; + protected final IRI hasNextProperty; + protected final IRI context; protected final boolean includeInferred; protected final Connector connector; protected final ValueFactory vf; - public AbstractSesameIterator(ListDescriptor listDescriptor, Connector connector, - ValueFactory vf) { - this.listOwner = SesameUtils.toSesameUri(listDescriptor.getListOwner().getIdentifier(), vf); - this.hasListProperty = SesameUtils.toSesameUri(listDescriptor.getListProperty() + public AbstractSesameIterator(ListDescriptor listDescriptor, Connector connector, ValueFactory vf) { + this.listOwner = SesameUtils.toSesameIri(listDescriptor.getListOwner().getIdentifier(), vf); + this.hasListProperty = SesameUtils.toSesameIri(listDescriptor.getListProperty() .getIdentifier(), vf); - this.hasNextProperty = SesameUtils.toSesameUri( + this.hasNextProperty = SesameUtils.toSesameIri( listDescriptor.getNextNode().getIdentifier(), vf); - this.context = SesameUtils.toSesameUri(listDescriptor.getContext(), vf); + this.context = SesameUtils.toSesameIri(listDescriptor.getContext(), vf); this.includeInferred = listDescriptor.getListProperty().isInferred(); this.connector = connector; this.vf = vf; } - protected void checkSuccessorMax(Collection stmts, URI property) { + protected void checkSuccessorMax(Collection stmts, IRI property) { // We don't mind the same statement multiple times, it could have been added during transaction if (new HashSet<>(stmts).size() > 1) { throw new IntegrityConstraintViolatedException( diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/AxiomLoader.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/AxiomLoader.java index cfb57f383..5ebea03b5 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/AxiomLoader.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/AxiomLoader.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -22,10 +22,10 @@ import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; import cz.cvut.kbss.ontodriver.sesame.util.AxiomBuilder; import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.ValueFactory; import java.util.*; import java.util.stream.Collectors; @@ -35,9 +35,9 @@ class AxiomLoader { private final Connector connector; private final ValueFactory valueFactory; - private Map propertyToAssertion; - private Map explicitAssertions; - private Map inferredAssertions; + private Map propertyToAssertion; + private Map explicitAssertions; + private Map inferredAssertions; AxiomLoader(Connector connector, ValueFactory valueFactory) { this.connector = connector; @@ -51,7 +51,7 @@ Collection> loadAxioms(AxiomDescriptor axiomDescriptor) throws SesameDr private Collection> findStatements(AxiomDescriptor descriptor) throws SesameDriverException { final Collection> result = new HashSet<>(); - final Resource subject = SesameUtils.toSesameUri(descriptor.getSubject().getIdentifier(), valueFactory); + final Resource subject = SesameUtils.toSesameIri(descriptor.getSubject().getIdentifier(), valueFactory); final Assertion unspecified = processAssertions(descriptor); final AxiomBuilder axiomBuilder = new AxiomBuilder(descriptor.getSubject(), propertyToAssertion, unspecified); final StatementLoader statementLoader = new StatementLoader(descriptor, connector, subject, axiomBuilder); @@ -77,7 +77,7 @@ private Assertion processAssertions(AxiomDescriptor descriptor) { this.inferredAssertions = new HashMap<>(descriptor.getAssertions().size()); Assertion unspecified = null; for (Assertion a : descriptor.getAssertions()) { - final URI property = SesameUtils.toSesameUri(a.getIdentifier(), valueFactory); + final IRI property = SesameUtils.toSesameIri(a.getIdentifier(), valueFactory); propertyToAssertion.put(property, a); if (a.equals(Assertion.createUnspecifiedPropertyAssertion(a.isInferred()))) { unspecified = a; @@ -91,10 +91,10 @@ private Assertion processAssertions(AxiomDescriptor descriptor) { return unspecified; } - public Collection> loadAxioms(NamedResource individual, boolean includeInferred, java.net.URI context) + Collection> loadAxioms(NamedResource individual, boolean includeInferred, java.net.URI context) throws SesameDriverException { - final URI sesameContext = SesameUtils.toSesameUri(context, valueFactory); - final URI subject = SesameUtils.toSesameUri(individual.getIdentifier(), valueFactory); + final IRI sesameContext = SesameUtils.toSesameIri(context, valueFactory); + final IRI subject = SesameUtils.toSesameIri(individual.getIdentifier(), valueFactory); final AxiomBuilder axiomBuilder = new AxiomBuilder(individual, Collections.emptyMap(), Assertion.createUnspecifiedPropertyAssertion(includeInferred)); final Collection statements; diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/AxiomSaver.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/AxiomSaver.java index bfb9c4cae..71318c87f 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/AxiomSaver.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/AxiomSaver.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -14,16 +14,16 @@ */ package cz.cvut.kbss.ontodriver.sesame; -import cz.cvut.kbss.ontodriver.sesame.connector.Connector; -import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; import cz.cvut.kbss.ontodriver.descriptor.AxiomValueDescriptor; import cz.cvut.kbss.ontodriver.model.Assertion; import cz.cvut.kbss.ontodriver.model.NamedResource; import cz.cvut.kbss.ontodriver.model.Value; +import cz.cvut.kbss.ontodriver.sesame.connector.Connector; +import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.ValueFactory; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.ValueFactory; import java.net.URI; import java.util.*; @@ -52,7 +52,8 @@ void persistAxioms(AxiomValueDescriptor axiomDescriptor) throws SesameDriverExce } } - void persistAxioms(NamedResource subject, Map>> values, URI context) throws SesameDriverException { + void persistAxioms(NamedResource subject, Map>> values, URI context) + throws SesameDriverException { final List statements = new ArrayList<>(); for (Map.Entry>> entry : values.entrySet()) { statements.addAll(createSesameStatements(subject, entry.getKey(), entry.getValue(), context)); @@ -63,28 +64,29 @@ void persistAxioms(NamedResource subject, Map>> values, } private Collection createSesameStatements(NamedResource subject, - Assertion assertion, Collection> assertionValues, URI assertionContext) + Assertion assertion, + Collection> assertionValues, + URI assertionContext) throws SesameDriverException { final List statements = new ArrayList<>(assertionValues.size()); - final org.openrdf.model.Resource subjectUri = SesameUtils.toSesameUri( - subject.getIdentifier(), valueFactory); - final org.openrdf.model.URI property = SesameUtils.toSesameUri(assertion.getIdentifier(), + final Resource subjectUri = SesameUtils.toSesameIri(subject.getIdentifier(), valueFactory); + final org.eclipse.rdf4j.model.IRI property = SesameUtils.toSesameIri(assertion.getIdentifier(), valueFactory); - final org.openrdf.model.URI context = assertionContext != null ? SesameUtils.toSesameUri( - assertionContext, valueFactory) : null; + final org.eclipse.rdf4j.model.IRI context = + assertionContext != null ? SesameUtils.toSesameIri(assertionContext, valueFactory) : null; for (Value val : assertionValues) { if (val == Value.nullValue()) { continue; } - org.openrdf.model.Value value = valueConverter.toSesameValue(assertion, val); + org.eclipse.rdf4j.model.Value value = valueConverter.toSesameValue(assertion, val); statements.add(createStatement(subjectUri, property, value, context)); } return statements; } - private Statement createStatement(Resource subject, org.openrdf.model.URI property, - org.openrdf.model.Value value, org.openrdf.model.URI context) { + private Statement createStatement(Resource subject, org.eclipse.rdf4j.model.IRI property, + org.eclipse.rdf4j.model.Value value, org.eclipse.rdf4j.model.IRI context) { if (context != null) { return valueFactory.createStatement(subject, property, value, context); } else { diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/EpistemicAxiomRemover.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/EpistemicAxiomRemover.java index 94ab7593e..18e7b1645 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/EpistemicAxiomRemover.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/EpistemicAxiomRemover.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -14,23 +14,22 @@ */ package cz.cvut.kbss.ontodriver.sesame; -import cz.cvut.kbss.ontodriver.sesame.connector.Connector; -import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; import cz.cvut.kbss.ontodriver.descriptor.AxiomDescriptor; import cz.cvut.kbss.ontodriver.model.Assertion; import cz.cvut.kbss.ontodriver.model.NamedResource; import cz.cvut.kbss.ontodriver.model.Value; +import cz.cvut.kbss.ontodriver.sesame.connector.Connector; +import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.ValueFactory; import java.util.*; /** - * This class performs an epistemic remove of axioms described by the axiom - * descriptor.

+ * This class performs an epistemic remove of axioms described by the axiom descriptor. *

* Epistemic remove means that only information known to the application is * deleted. The assertions in the descriptor represent this information. Thus, @@ -52,20 +51,19 @@ class EpistemicAxiomRemover { } void remove(AxiomDescriptor axiomDescriptor) throws SesameDriverException { - final Resource individual = SesameUtils.toSesameUri(axiomDescriptor.getSubject() - .getIdentifier(), valueFactory); + final Resource individual = SesameUtils.toSesameIri(axiomDescriptor.getSubject().getIdentifier(), valueFactory); final Collection toRemove = new HashSet<>(); for (Assertion a : axiomDescriptor.getAssertions()) { if (a.isInferred()) { continue; } - final URI contextUri = SesameUtils.toSesameUri(axiomDescriptor.getAssertionContext(a), valueFactory); + final IRI contextUri = SesameUtils.toSesameIri(axiomDescriptor.getAssertionContext(a), valueFactory); if (contextUri != null) { toRemove.addAll(connector.findStatements(individual, - SesameUtils.toSesameUri(a.getIdentifier(), valueFactory), null, a.isInferred(), contextUri)); + SesameUtils.toSesameIri(a.getIdentifier(), valueFactory), null, a.isInferred(), contextUri)); } else { toRemove.addAll(connector.findStatements(individual, - SesameUtils.toSesameUri(a.getIdentifier(), valueFactory), null, a.isInferred())); + SesameUtils.toSesameIri(a.getIdentifier(), valueFactory), null, a.isInferred())); } } connector.removeStatements(toRemove); @@ -73,14 +71,14 @@ void remove(AxiomDescriptor axiomDescriptor) throws SesameDriverException { void remove(NamedResource individual, Map>> values, java.net.URI context) throws SesameDriverException { - final URI sesameContext = SesameUtils.toSesameUri(context, valueFactory); - final Resource subject = SesameUtils.toSesameUri(individual.getIdentifier(), valueFactory); + final IRI sesameContext = SesameUtils.toSesameIri(context, valueFactory); + final Resource subject = SesameUtils.toSesameIri(individual.getIdentifier(), valueFactory); final Collection toRemove = new ArrayList<>(); final SesameValueConverter valueConverter = new SesameValueConverter(valueFactory, language); for (Map.Entry>> entry : values.entrySet()) { - final URI property = SesameUtils.toSesameUri(entry.getKey().getIdentifier(), valueFactory); + final IRI property = SesameUtils.toSesameIri(entry.getKey().getIdentifier(), valueFactory); for (Value val : entry.getValue()) { - final org.openrdf.model.Value sesameValue = valueConverter.toSesameValue(entry.getKey(), val); + final org.eclipse.rdf4j.model.Value sesameValue = valueConverter.toSesameValue(entry.getKey(), val); if (sesameContext != null) { toRemove.add(valueFactory.createStatement(subject, property, sesameValue, sesameContext)); } else { diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/ListHandler.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/ListHandler.java index dab069383..1db3deab0 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/ListHandler.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/ListHandler.java @@ -20,11 +20,6 @@ import cz.cvut.kbss.ontodriver.model.NamedResource; import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; import cz.cvut.kbss.ontodriver.exception.IntegrityConstraintViolatedException; import cz.cvut.kbss.ontodriver.sesame.connector.Connector; @@ -36,6 +31,7 @@ import cz.cvut.kbss.ontodriver.descriptor.SimpleListDescriptor; import cz.cvut.kbss.ontodriver.descriptor.SimpleListValueDescriptor; import cz.cvut.kbss.ontodriver.model.Axiom; +import org.eclipse.rdf4j.model.*; /** * Base class for list handlers. @@ -87,14 +83,14 @@ void persistList(V listValueDescriptor) throws SesameDriverException { } final Collection statements = new ArrayList<>(listValueDescriptor.getValues() .size()); - final URI head = createListHead(listValueDescriptor, statements); + final IRI head = createListHead(listValueDescriptor, statements); statements.addAll(createListRest(head, listValueDescriptor)); connector.addStatements(statements); } - abstract URI createListHead(V valueDescriptor, Collection listStatements) throws SesameDriverException; + abstract IRI createListHead(V valueDescriptor, Collection listStatements) throws SesameDriverException; - abstract List createListRest(URI head, V valueDescriptor) throws SesameDriverException; + abstract List createListRest(IRI head, V valueDescriptor) throws SesameDriverException; /** * Updates list with values specified by the descriptor. @@ -113,8 +109,8 @@ void updateList(V listValueDescriptor) throws SesameDriverException { } } - private boolean isOldListEmpty(Resource owner, URI hasListProperty, boolean includeInferred, - URI context) throws SesameDriverException { + private boolean isOldListEmpty(Resource owner, IRI hasListProperty, boolean includeInferred, + IRI context) throws SesameDriverException { final Collection stmts = connector.findStatements(owner, hasListProperty, null, includeInferred, context); return stmts.isEmpty(); @@ -139,19 +135,19 @@ private void mergeList(V listDescriptor) throws SesameDriverException { abstract void appendNewNodes(V listDescriptor, MergeResult mergeResult) throws SesameDriverException; - void removeObsoletes(SesameIterator it) throws SesameDriverException { + private void removeObsoletes(SesameIterator it) throws SesameDriverException { while (it.hasNext()) { it.nextNode(); it.remove(); } } - Resource extractListNode(Collection stmts, URI nodeAssertion) + Resource extractListNode(Collection stmts, IRI nodeAssertion) throws SesameDriverException { if (stmts.size() > 1) { throw new IntegrityConstraintViolatedException( - "Invalid number of values found for assertion " + nodeAssertion - + ". Expected 1, got " + stmts.size()); + "Invalid number of values found for assertion " + nodeAssertion + ". Expected 1, got " + + stmts.size()); } final Value val = stmts.iterator().next().getObject(); if (!(val instanceof Resource)) { @@ -161,24 +157,24 @@ Resource extractListNode(Collection stmts, URI nodeAssertion) return (Resource) val; } - URI context(ListDescriptor listDescriptor) { - return sesameUri(listDescriptor.getContext()); + IRI context(ListDescriptor listDescriptor) { + return sesameIri(listDescriptor.getContext()); } - URI owner(ListDescriptor listDescriptor) { - return sesameUri(listDescriptor.getListOwner().getIdentifier()); + IRI owner(ListDescriptor listDescriptor) { + return sesameIri(listDescriptor.getListOwner().getIdentifier()); } - URI hasList(ListDescriptor listDescriptor) { - return sesameUri(listDescriptor.getListProperty().getIdentifier()); + IRI hasList(ListDescriptor listDescriptor) { + return sesameIri(listDescriptor.getListProperty().getIdentifier()); } - URI hasNext(ListDescriptor listDescriptor) { - return sesameUri(listDescriptor.getNextNode().getIdentifier()); + IRI hasNext(ListDescriptor listDescriptor) { + return sesameIri(listDescriptor.getNextNode().getIdentifier()); } - URI sesameUri(java.net.URI uri) { - return SesameUtils.toSesameUri(uri, vf); + IRI sesameIri(java.net.URI uri) { + return SesameUtils.toSesameIri(uri, vf); } /** @@ -213,9 +209,9 @@ static ListHandler crea static final class MergeResult { protected int i; - protected Resource previous; + Resource previous; - protected MergeResult(int i, Resource node) { + MergeResult(int i, Resource node) { this.i = i; this.previous = node; } diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/ReferencedListHandler.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/ReferencedListHandler.java index 39c4a9625..fd2cfcefa 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/ReferencedListHandler.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/ReferencedListHandler.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -19,10 +19,10 @@ import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptor; import cz.cvut.kbss.ontodriver.descriptor.ReferencedListValueDescriptor; import cz.cvut.kbss.ontodriver.model.NamedResource; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.ValueFactory; import java.util.ArrayList; import java.util.Collection; @@ -30,137 +30,137 @@ import java.util.List; public class ReferencedListHandler extends - ListHandler { + ListHandler { - private int sequenceCounter = 0; + private int sequenceCounter = 0; - ReferencedListHandler(Connector connector, ValueFactory vf) { - super(connector, vf); - } + ReferencedListHandler(Connector connector, ValueFactory vf) { + super(connector, vf); + } - @Override - SesameIterator createIterator(ReferencedListDescriptor listDescriptor) throws SesameDriverException { - return new ReferencedListIterator(listDescriptor, connector, vf); - } + @Override + SesameIterator createIterator(ReferencedListDescriptor listDescriptor) throws SesameDriverException { + return new ReferencedListIterator(listDescriptor, connector, vf); + } - URI createListHead(ReferencedListValueDescriptor listValueDescriptor, - Collection statements) throws SesameDriverException { - final URI owner = owner(listValueDescriptor); - final URI hasList = hasList(listValueDescriptor); - final URI hasContent = hasContent(listValueDescriptor); - final URI context = context(listValueDescriptor); - final URI nodeUri = generateSequenceNode(owner, context); - statements.add(vf.createStatement(owner, hasList, nodeUri, context)); - final URI nodeContent = sesameUri(listValueDescriptor.getValues().get(0).getIdentifier()); - statements.add(vf.createStatement(nodeUri, hasContent, nodeContent, context)); - return nodeUri; - } + IRI createListHead(ReferencedListValueDescriptor listValueDescriptor, + Collection statements) throws SesameDriverException { + final IRI owner = owner(listValueDescriptor); + final IRI hasList = hasList(listValueDescriptor); + final IRI hasContent = hasContent(listValueDescriptor); + final IRI context = context(listValueDescriptor); + final IRI nodeUri = generateSequenceNode(owner, context); + statements.add(vf.createStatement(owner, hasList, nodeUri, context)); + final IRI nodeContent = sesameIri(listValueDescriptor.getValues().get(0).getIdentifier()); + statements.add(vf.createStatement(nodeUri, hasContent, nodeContent, context)); + return nodeUri; + } - private URI hasContent(ReferencedListDescriptor listDescriptor) { - return sesameUri(listDescriptor.getNodeContent().getIdentifier()); - } + private IRI hasContent(ReferencedListDescriptor listDescriptor) { + return sesameIri(listDescriptor.getNodeContent().getIdentifier()); + } - private URI generateSequenceNode(URI owner, URI context) throws SesameDriverException { - final String uriBase = owner.stringValue(); - boolean unique; - URI node; - do { - node = vf.createURI(uriBase + "-SEQ_" + sequenceCounter++); - final Collection stmts = connector.findStatements(node, null, null, false, - context); - unique = stmts.isEmpty(); - } while (!unique); - return node; - } + private IRI generateSequenceNode(IRI owner, IRI context) throws SesameDriverException { + final String uriBase = owner.stringValue(); + boolean unique; + IRI node; + do { + node = vf.createIRI(uriBase + "-SEQ_" + sequenceCounter++); + final Collection stmts = connector.findStatements(node, null, null, false, + context); + unique = stmts.isEmpty(); + } while (!unique); + return node; + } - List createListRest(URI headNode, - ReferencedListValueDescriptor listValueDescriptor) throws SesameDriverException { - final URI owner = owner(listValueDescriptor); - final URI hasNext = hasNext(listValueDescriptor); - final URI hasContent = hasContent(listValueDescriptor); - final URI context = context(listValueDescriptor); - URI previous = headNode; - final List statements = new ArrayList<>( - listValueDescriptor.getValues().size() * 2); - final Iterator it = listValueDescriptor.getValues().iterator(); - // Skip the first element, it is already in the head - it.next(); - while (it.hasNext()) { - final URI content = sesameUri(it.next().getIdentifier()); - previous = createListNode(owner, hasNext, hasContent, content, context, previous, statements); - } - return statements; - } + List createListRest(IRI headNode, ReferencedListValueDescriptor listValueDescriptor) + throws SesameDriverException { + final IRI owner = owner(listValueDescriptor); + final IRI hasNext = hasNext(listValueDescriptor); + final IRI hasContent = hasContent(listValueDescriptor); + final IRI context = context(listValueDescriptor); + IRI previous = headNode; + final List statements = new ArrayList<>( + listValueDescriptor.getValues().size() * 2); + final Iterator it = listValueDescriptor.getValues().iterator(); + // Skip the first element, it is already in the head + it.next(); + while (it.hasNext()) { + final IRI content = sesameIri(it.next().getIdentifier()); + previous = createListNode(owner, hasNext, hasContent, content, context, previous, statements); + } + return statements; + } - private URI createListNode(URI owner, URI hasNext, URI hasContent, URI content, URI context, Resource previous, Collection statements) throws SesameDriverException { - final URI node = generateSequenceNode(owner, context); - statements.add(vf.createStatement(previous, hasNext, node, context)); - statements.add(vf.createStatement(node, hasContent, content, context)); - return node; - } + private IRI createListNode(IRI owner, IRI hasNext, IRI hasContent, IRI content, IRI context, Resource previous, + Collection statements) throws SesameDriverException { + final IRI node = generateSequenceNode(owner, context); + statements.add(vf.createStatement(previous, hasNext, node, context)); + statements.add(vf.createStatement(node, hasContent, content, context)); + return node; + } - @Override - void clearList(ReferencedListValueDescriptor listDescriptor) throws SesameDriverException { - final URI hasNext = hasNext(listDescriptor); - final URI hasContent = hasContent(listDescriptor); - final boolean includeInferred = listDescriptor.getListProperty().isInferred(); - final URI context = context(listDescriptor); - Resource previous = owner(listDescriptor); - URI currentProperty = hasList(listDescriptor); - final Collection toRemove = new ArrayList<>(); - Collection next; - do { - next = connector.findStatements(previous, currentProperty, null, includeInferred, - context); - if (!next.isEmpty()) { - final Resource node = extractListNode(next, currentProperty); - toRemove.addAll(next); - toRemove.addAll(connector.findStatements(node, hasContent, null, includeInferred, - context)); - previous = node; - } - currentProperty = hasNext; - } while (!next.isEmpty()); - connector.removeStatements(toRemove); - } + @Override + void clearList(ReferencedListValueDescriptor listDescriptor) throws SesameDriverException { + final IRI hasNext = hasNext(listDescriptor); + final IRI hasContent = hasContent(listDescriptor); + final boolean includeInferred = listDescriptor.getListProperty().isInferred(); + final IRI context = context(listDescriptor); + Resource previous = owner(listDescriptor); + IRI currentProperty = hasList(listDescriptor); + final Collection toRemove = new ArrayList<>(); + Collection next; + do { + next = connector.findStatements(previous, currentProperty, null, includeInferred, context); + if (!next.isEmpty()) { + final Resource node = extractListNode(next, currentProperty); + toRemove.addAll(next); + toRemove.addAll(connector.findStatements(node, hasContent, null, includeInferred, context)); + previous = node; + } + currentProperty = hasNext; + } while (!next.isEmpty()); + connector.removeStatements(toRemove); + } - @Override - SesameIterator iterator(ReferencedListValueDescriptor listDescriptor) throws SesameDriverException { - return new ReferencedListIterator(listDescriptor, connector, vf); - } + @Override + SesameIterator iterator(ReferencedListValueDescriptor listDescriptor) throws SesameDriverException { + return new ReferencedListIterator(listDescriptor, connector, vf); + } - @Override - MergeResult mergeWithOriginalList(ReferencedListValueDescriptor listDescriptor, SesameIterator it) throws SesameDriverException { - int i = 0; - Resource node = null; - while (it.hasNext() && i < listDescriptor.getValues().size()) { - node = it.nextNode(); - final Resource content = it.currentContent(); - final NamedResource newNode = listDescriptor.getValues().get(i); - if (!content.stringValue().equals(newNode.getIdentifier().toString())) { - it.replaceCurrentWith(newNode); - } - i++; - } - return new MergeResult(i, node); - } + @Override + MergeResult mergeWithOriginalList(ReferencedListValueDescriptor listDescriptor, SesameIterator it) + throws SesameDriverException { + int i = 0; + Resource node = null; + while (it.hasNext() && i < listDescriptor.getValues().size()) { + node = it.nextNode(); + final Resource content = it.currentContent(); + final NamedResource newNode = listDescriptor.getValues().get(i); + if (!content.stringValue().equals(newNode.getIdentifier().toString())) { + it.replaceCurrentWith(newNode); + } + i++; + } + return new MergeResult(i, node); + } - @Override - void appendNewNodes(ReferencedListValueDescriptor listDescriptor, MergeResult mergeResult) throws SesameDriverException { - int i = mergeResult.i; - Resource previous = mergeResult.previous; - final URI owner = owner(listDescriptor); - final URI hasNext = hasNext(listDescriptor); - final URI hasContent = hasContent(listDescriptor); - final URI context = context(listDescriptor); - assert i > 0; - final Collection toAdd = new ArrayList<>( - (listDescriptor.getValues().size() - i) * 2); - while (i < listDescriptor.getValues().size()) { - final URI content = sesameUri(listDescriptor.getValues().get(i).getIdentifier()); - previous = createListNode(owner, hasNext, hasContent, content, context, previous, toAdd); - i++; - } - connector.addStatements(toAdd); - } + @Override + void appendNewNodes(ReferencedListValueDescriptor listDescriptor, MergeResult mergeResult) + throws SesameDriverException { + int i = mergeResult.i; + Resource previous = mergeResult.previous; + final IRI owner = owner(listDescriptor); + final IRI hasNext = hasNext(listDescriptor); + final IRI hasContent = hasContent(listDescriptor); + final IRI context = context(listDescriptor); + assert i > 0; + final Collection toAdd = new ArrayList<>((listDescriptor.getValues().size() - i) * 2); + while (i < listDescriptor.getValues().size()) { + final IRI content = sesameIri(listDescriptor.getValues().get(i).getIdentifier()); + previous = createListNode(owner, hasNext, hasContent, content, context, previous, toAdd); + i++; + } + connector.addStatements(toAdd); + } } diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/ReferencedListIterator.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/ReferencedListIterator.java index 5c065de46..58c08fd46 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/ReferencedListIterator.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/ReferencedListIterator.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -19,10 +19,6 @@ import java.util.Collections; import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; import cz.cvut.kbss.ontodriver.exception.IntegrityConstraintViolatedException; import cz.cvut.kbss.ontodriver.sesame.connector.Connector; @@ -30,118 +26,121 @@ import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptor; import cz.cvut.kbss.ontodriver.model.Axiom; import cz.cvut.kbss.ontodriver.model.NamedResource; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.ValueFactory; class ReferencedListIterator extends AbstractSesameIterator { - private final ReferencedListDescriptor listDescriptor; - - private final URI hasContentProperty; - - private URI currentProperty; - - private Statement currentNode; - private Statement currentContent; - private Collection next; - - public ReferencedListIterator(ReferencedListDescriptor listDescriptor, Connector connector, - ValueFactory vf) throws SesameDriverException { - super(listDescriptor, connector, vf); - this.listDescriptor = listDescriptor; - this.hasContentProperty = SesameUtils.toSesameUri(listDescriptor.getNodeContent() - .getIdentifier(), vf); - this.currentProperty = hasListProperty; - init(); - } - - private void init() throws SesameDriverException { - this.next = connector.findStatements(listOwner, hasListProperty, null, includeInferred, - context); - } - - @Override - public boolean hasNext() throws SesameDriverException { - return (!next.isEmpty()); - } - - @Override - public Resource nextNode() throws SesameDriverException { - nextInternal(); - return (Resource) currentNode.getObject(); - } - - private void nextInternal() throws SesameDriverException { - if (!hasNext()) { - throw new IllegalStateException(); - } - checkSuccessorMax(next, currentProperty); - this.currentNode = next.iterator().next(); - this.currentProperty = currentNode.getPredicate(); - checkNodeIsResource(currentNode); - final Resource elem = (Resource) currentNode.getObject(); - this.currentContent = getNodeContent(elem); - this.next = connector.findStatements(elem, hasNextProperty, null, includeInferred, context); - } - - private Statement getNodeContent(Resource node) throws SesameDriverException { - final Collection elems = connector.findStatements(node, hasContentProperty, - null, includeInferred, context); - checkSuccessorMax(elems, hasContentProperty); - if (elems.isEmpty()) { - throw new IntegrityConstraintViolatedException("Node " + node + " has no content."); - } - final Statement elem = elems.iterator().next(); - checkNodeIsResource(elem); - return elem; - } - - @Override - public Resource currentContent() throws SesameDriverException { - assert currentContent.getObject() instanceof Resource; - return (Resource) currentContent.getObject(); - } - - @Override - public Axiom nextAxiom() throws SesameDriverException { - nextInternal(); - assert currentContent.getObject() instanceof Resource; - - return createAxiom(currentContent.getSubject(), listDescriptor.getNodeContent(), - (Resource) currentContent.getObject()); - } - - @Override - public void remove() throws SesameDriverException { - assert currentNode.getObject() instanceof Resource; - final Collection toRemove = new ArrayList<>(); - toRemove.add(currentNode); - toRemove.add(currentContent); - if (!next.isEmpty()) { - toRemove.addAll(next); - final Statement stmt = next.iterator().next(); - checkNodeIsResource(stmt); - final Resource nextNode = (Resource) stmt.getObject(); - final Statement connectNext = vf.createStatement(currentNode.getSubject(), - currentProperty, nextNode, context); - this.next = Collections.singleton(connectNext); - - this.currentNode = null; - this.currentContent = null; - connector.addStatements(next); - } else { - next = Collections.emptyList(); - } - connector.removeStatements(toRemove); - } - - @Override - public void replaceCurrentWith(NamedResource newContent) throws SesameDriverException { - assert currentNode.getObject() instanceof Resource; - // We just replace the original content statement with new one - connector.removeStatements(Collections.singleton(currentContent)); - final Resource node = (Resource) currentNode.getObject(); - final Statement stmt = vf.createStatement(node, hasContentProperty, - SesameUtils.toSesameUri(newContent.getIdentifier(), vf), context); - connector.addStatements(Collections.singleton(stmt)); - } + private final ReferencedListDescriptor listDescriptor; + + private final IRI hasContentProperty; + + private IRI currentProperty; + + private Statement currentNode; + private Statement currentContent; + private Collection next; + + public ReferencedListIterator(ReferencedListDescriptor listDescriptor, Connector connector, ValueFactory vf) + throws SesameDriverException { + super(listDescriptor, connector, vf); + this.listDescriptor = listDescriptor; + this.hasContentProperty = SesameUtils.toSesameIri(listDescriptor.getNodeContent().getIdentifier(), vf); + this.currentProperty = hasListProperty; + init(); + } + + private void init() throws SesameDriverException { + this.next = connector.findStatements(listOwner, hasListProperty, null, includeInferred, context); + } + + @Override + public boolean hasNext() throws SesameDriverException { + return (!next.isEmpty()); + } + + @Override + public Resource nextNode() throws SesameDriverException { + nextInternal(); + return (Resource) currentNode.getObject(); + } + + private void nextInternal() throws SesameDriverException { + if (!hasNext()) { + throw new IllegalStateException(); + } + checkSuccessorMax(next, currentProperty); + this.currentNode = next.iterator().next(); + this.currentProperty = currentNode.getPredicate(); + checkNodeIsResource(currentNode); + final Resource elem = (Resource) currentNode.getObject(); + this.currentContent = getNodeContent(elem); + this.next = connector.findStatements(elem, hasNextProperty, null, includeInferred, context); + } + + private Statement getNodeContent(Resource node) throws SesameDriverException { + final Collection elems = connector.findStatements(node, hasContentProperty, + null, includeInferred, context); + checkSuccessorMax(elems, hasContentProperty); + if (elems.isEmpty()) { + throw new IntegrityConstraintViolatedException("Node " + node + " has no content."); + } + final Statement elem = elems.iterator().next(); + checkNodeIsResource(elem); + return elem; + } + + @Override + public Resource currentContent() throws SesameDriverException { + assert currentContent.getObject() instanceof Resource; + return (Resource) currentContent.getObject(); + } + + @Override + public Axiom nextAxiom() throws SesameDriverException { + nextInternal(); + assert currentContent.getObject() instanceof Resource; + + return createAxiom(currentContent.getSubject(), listDescriptor.getNodeContent(), + (Resource) currentContent.getObject()); + } + + @Override + public void remove() throws SesameDriverException { + assert currentNode.getObject() instanceof Resource; + final Collection toRemove = new ArrayList<>(); + toRemove.add(currentNode); + toRemove.add(currentContent); + if (!next.isEmpty()) { + toRemove.addAll(next); + final Statement stmt = next.iterator().next(); + checkNodeIsResource(stmt); + final Resource nextNode = (Resource) stmt.getObject(); + final Statement connectNext = vf + .createStatement(currentNode.getSubject(), currentProperty, nextNode, context); + this.next = Collections.singleton(connectNext); + + this.currentNode = null; + this.currentContent = null; + connector.addStatements(next); + } else { + next = Collections.emptyList(); + } + connector.removeStatements(toRemove); + } + + @Override + public void replaceCurrentWith(NamedResource newContent) throws SesameDriverException { + assert currentNode.getObject() instanceof Resource; + // We just replace the original content statement with new one + connector.removeStatements(Collections.singleton(currentContent)); + final Resource node = (Resource) currentNode.getObject(); + final Statement stmt = vf + .createStatement(node, hasContentProperty, SesameUtils.toSesameIri(newContent.getIdentifier(), vf), + context); + connector.addStatements(Collections.singleton(stmt)); + } } diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameAdapter.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameAdapter.java index 62b962945..4b4ba6a83 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameAdapter.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameAdapter.java @@ -27,11 +27,11 @@ import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; import cz.cvut.kbss.ontodriver.util.IdentifierUtils; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.vocabulary.RDF; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.Value; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.vocabulary.RDF; import java.net.URI; import java.util.ArrayList; @@ -150,8 +150,8 @@ private void startTransactionIfNotActive() throws SesameDriverException { private boolean isIdentifierUnique(URI identifier, URI classUri) throws SesameDriverException { final Collection stmts = connector.findStatements( - SesameUtils.toSesameUri(identifier, valueFactory), RDF.TYPE, - SesameUtils.toSesameUri(classUri, valueFactory), true); + SesameUtils.toSesameIri(identifier, valueFactory), RDF.TYPE, + SesameUtils.toSesameIri(classUri, valueFactory), true); return stmts.isEmpty(); } @@ -159,20 +159,20 @@ boolean contains(Axiom axiom, URI context) throws SesameDriverException { startTransactionIfNotActive(); Value value; if (SesameUtils.isResourceIdentifier(axiom.getValue().getValue())) { - value = valueFactory.createURI(axiom.getValue().stringValue()); + value = valueFactory.createIRI(axiom.getValue().stringValue()); } else { value = SesameUtils.createDataPropertyLiteral(axiom.getValue().getValue(), language, valueFactory); } - final org.openrdf.model.URI sesameContext = SesameUtils.toSesameUri(context, valueFactory); + final org.eclipse.rdf4j.model.IRI sesameContext = SesameUtils.toSesameIri(context, valueFactory); return !findStatements( - SesameUtils.toSesameUri(axiom.getSubject().getIdentifier(), valueFactory), - SesameUtils.toSesameUri(axiom.getAssertion().getIdentifier(), valueFactory), value, + SesameUtils.toSesameIri(axiom.getSubject().getIdentifier(), valueFactory), + SesameUtils.toSesameIri(axiom.getAssertion().getIdentifier(), valueFactory), value, axiom.getAssertion().isInferred(), sesameContext).isEmpty(); } - private Collection findStatements(Resource subject, org.openrdf.model.URI property, Value value, - boolean includeInferred, org.openrdf.model.URI context) + private Collection findStatements(Resource subject, org.eclipse.rdf4j.model.IRI property, Value value, + boolean includeInferred, org.eclipse.rdf4j.model.IRI context) throws SesameDriverException { if (context != null) { return connector.findStatements(subject, property, value, includeInferred, context); diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameIterator.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameIterator.java index 0ed261a4a..e09728634 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameIterator.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameIterator.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -14,23 +14,22 @@ */ package cz.cvut.kbss.ontodriver.sesame; -import org.openrdf.model.Resource; - -import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; import cz.cvut.kbss.ontodriver.model.Axiom; import cz.cvut.kbss.ontodriver.model.NamedResource; +import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; +import org.eclipse.rdf4j.model.Resource; interface SesameIterator { - boolean hasNext() throws SesameDriverException; + boolean hasNext() throws SesameDriverException; - Resource nextNode() throws SesameDriverException; + Resource nextNode() throws SesameDriverException; - Resource currentContent() throws SesameDriverException; + Resource currentContent() throws SesameDriverException; - Axiom nextAxiom() throws SesameDriverException; + Axiom nextAxiom() throws SesameDriverException; - void remove() throws SesameDriverException; + void remove() throws SesameDriverException; - void replaceCurrentWith(NamedResource newNode) throws SesameDriverException; + void replaceCurrentWith(NamedResource newNode) throws SesameDriverException; } diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameProperties.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameProperties.java index 51a3ff3eb..c3c6f9757 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameProperties.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameProperties.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -22,7 +22,7 @@ import cz.cvut.kbss.ontodriver.model.Value; import cz.cvut.kbss.ontodriver.sesame.connector.Connector; import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; -import org.openrdf.model.ValueFactory; +import org.eclipse.rdf4j.model.ValueFactory; import java.net.URI; import java.util.Collection; diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameValueConverter.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameValueConverter.java index 332426599..b177021e8 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameValueConverter.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SesameValueConverter.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -14,11 +14,11 @@ */ package cz.cvut.kbss.ontodriver.sesame; -import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; import cz.cvut.kbss.ontodriver.model.Assertion; +import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; +import org.eclipse.rdf4j.model.Value; +import org.eclipse.rdf4j.model.ValueFactory; class SesameValueConverter { @@ -47,18 +47,18 @@ Value toSesameValue(Assertion assertion, cz.cvut.kbss.ontodriver.model.Value } } - private org.openrdf.model.URI getValueAsSesameUri(cz.cvut.kbss.ontodriver.model.Value val) + private org.eclipse.rdf4j.model.IRI getValueAsSesameUri(cz.cvut.kbss.ontodriver.model.Value val) throws SesameDriverException { try { - return vf.createURI(val.getValue().toString()); + return vf.createIRI(val.getValue().toString()); } catch (IllegalArgumentException e) { throw new SesameDriverException(e); } } - private org.openrdf.model.Value resolvePropertyValue(cz.cvut.kbss.ontodriver.model.Value val) { + private org.eclipse.rdf4j.model.Value resolvePropertyValue(cz.cvut.kbss.ontodriver.model.Value val) { if (SesameUtils.isResourceIdentifier(val.getValue())) { - return vf.createURI(val.getValue().toString()); + return vf.createIRI(val.getValue().toString()); } else { return SesameUtils.createDataPropertyLiteral(val.getValue(), language, vf); } diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SimpleListHandler.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SimpleListHandler.java index aa4cc3c36..7f7afb8a8 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SimpleListHandler.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SimpleListHandler.java @@ -19,10 +19,10 @@ import cz.cvut.kbss.ontodriver.descriptor.SimpleListDescriptor; import cz.cvut.kbss.ontodriver.descriptor.SimpleListValueDescriptor; import cz.cvut.kbss.ontodriver.model.NamedResource; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.ValueFactory; import java.util.ArrayList; import java.util.Collection; @@ -40,22 +40,22 @@ SesameIterator createIterator(SimpleListDescriptor listDescriptor) throws Sesame return new SimpleListIterator(listDescriptor, connector, vf); } - URI createListHead(SimpleListValueDescriptor listValueDescriptor, Collection listStatements) { - final URI firstNode = sesameUri(listValueDescriptor.getValues().get(0).getIdentifier()); + IRI createListHead(SimpleListValueDescriptor listValueDescriptor, Collection listStatements) { + final IRI firstNode = sesameIri(listValueDescriptor.getValues().get(0).getIdentifier()); listStatements.add(vf.createStatement(owner(listValueDescriptor), hasList(listValueDescriptor), firstNode, context(listValueDescriptor))); return firstNode; } - List createListRest(URI head, SimpleListValueDescriptor listValueDescriptor) { + List createListRest(IRI head, SimpleListValueDescriptor listValueDescriptor) { final List statements = new ArrayList<>(listValueDescriptor.getValues().size()); - URI previous = head; - final URI nextNodeProp = hasNext(listValueDescriptor); - final URI context = context(listValueDescriptor); + IRI previous = head; + final IRI nextNodeProp = hasNext(listValueDescriptor); + final IRI context = context(listValueDescriptor); final Iterator it = listValueDescriptor.getValues().iterator(); it.next(); while (it.hasNext()) { - final URI object = sesameUri(it.next().getIdentifier()); + final IRI object = sesameIri(it.next().getIdentifier()); statements.add(vf.createStatement(previous, nextNodeProp, object, context)); previous = object; } @@ -69,16 +69,15 @@ List createListRest(URI head, SimpleListValueDescriptor listValueDesc */ @Override void clearList(SimpleListValueDescriptor listValueDescriptor) throws SesameDriverException { - final URI context = context(listValueDescriptor); + final IRI context = context(listValueDescriptor); final Collection toRemove = new ArrayList<>(); - URI currentProperty = hasList(listValueDescriptor); - final URI hasNext = hasNext(listValueDescriptor); + IRI currentProperty = hasList(listValueDescriptor); + final IRI hasNext = hasNext(listValueDescriptor); final boolean includeInferred = listValueDescriptor.getNextNode().isInferred(); Collection stmts; Resource subject = owner(listValueDescriptor); do { - stmts = connector.findStatements(subject, currentProperty, null, includeInferred, - context); + stmts = connector.findStatements(subject, currentProperty, null, includeInferred, context); if (!stmts.isEmpty()) { subject = extractListNode(stmts, hasNext); toRemove.addAll(stmts); @@ -96,7 +95,7 @@ MergeResult mergeWithOriginalList(SimpleListValueDescriptor listDescriptor, Sesa node = it.nextNode(); final NamedResource newNode = listDescriptor.getValues().get(i); if (!node.stringValue().equals(newNode.getIdentifier().toString())) { - node = sesameUri(newNode.getIdentifier()); + node = sesameIri(newNode.getIdentifier()); it.replaceCurrentWith(newNode); } i++; @@ -109,12 +108,11 @@ void appendNewNodes(SimpleListValueDescriptor listDescriptor, MergeResult mergeR int i = mergeResult.i; final Collection toAdd = new ArrayList<>(listDescriptor.getValues().size() - i); Resource previous = mergeResult.previous; - final URI nextNode = sesameUri(listDescriptor.getNextNode().getIdentifier()); - final URI context = context(listDescriptor); + final IRI nextNode = sesameIri(listDescriptor.getNextNode().getIdentifier()); + final IRI context = context(listDescriptor); while (i < listDescriptor.getValues().size()) { - final Resource newNode = sesameUri(listDescriptor.getValues().get(i).getIdentifier()); - final Statement stmt = vf.createStatement(previous, - nextNode, newNode, context); + final Resource newNode = sesameIri(listDescriptor.getValues().get(i).getIdentifier()); + final Statement stmt = vf.createStatement(previous, nextNode, newNode, context); toAdd.add(stmt); previous = newNode; i++; diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SimpleListIterator.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SimpleListIterator.java index 625d680bb..e5ced52c3 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SimpleListIterator.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/SimpleListIterator.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -14,142 +14,140 @@ */ package cz.cvut.kbss.ontodriver.sesame; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; - -import cz.cvut.kbss.ontodriver.sesame.connector.Connector; -import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; import cz.cvut.kbss.ontodriver.descriptor.SimpleListDescriptor; import cz.cvut.kbss.ontodriver.model.Assertion; import cz.cvut.kbss.ontodriver.model.Axiom; import cz.cvut.kbss.ontodriver.model.NamedResource; +import cz.cvut.kbss.ontodriver.sesame.connector.Connector; +import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.ValueFactory; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; class SimpleListIterator extends AbstractSesameIterator { - private final SimpleListDescriptor listDescriptor; - - private URI currentProperty; - - private Statement current; - private Collection next; - - public SimpleListIterator(SimpleListDescriptor listDescriptor, Connector connector, - ValueFactory vf) throws SesameDriverException { - super(listDescriptor, connector, vf); - this.listDescriptor = listDescriptor; - this.currentProperty = hasListProperty; - init(); - } - - private void init() throws SesameDriverException { - this.next = connector.findStatements(listOwner, hasListProperty, null, includeInferred, - context); - } - - @Override - public boolean hasNext() { - return (!next.isEmpty()); - } - - @Override - public Resource nextNode() throws SesameDriverException { - nextInternal(); - assert current.getObject() instanceof Resource; - - return (Resource) current.getObject(); - } - - private void nextInternal() throws SesameDriverException { - if (!hasNext()) { - throw new IllegalStateException(); - } - checkSuccessorMax(next, currentProperty); - this.current = next.iterator().next(); - this.currentProperty = current.getPredicate(); - checkNodeIsResource(current); - final Resource elem = (Resource) current.getObject(); - this.next = connector.findStatements(elem, hasNextProperty, null, includeInferred, context); - } - - @Override - public Resource currentContent() throws SesameDriverException { - assert current.getObject() instanceof Resource; - - return (Resource) current.getObject(); - } - - @Override - public Axiom nextAxiom() throws SesameDriverException { - nextInternal(); - assert current.getObject() instanceof Resource; - - final Assertion assertion = current.getPredicate() == hasListProperty ? listDescriptor - .getListProperty() : listDescriptor.getNextNode(); - return createAxiom(current.getSubject(), assertion, (Resource) current.getObject()); - } - - @Override - public void replaceCurrentWith(NamedResource newNode) throws SesameDriverException { - assert current.getObject() instanceof Resource; - final Resource newNodeSesame = vf.createURI(newNode.getIdentifier().toString()); - final List toAdd = new ArrayList<>(2); - final List toRemove = new ArrayList<>(2); - toRemove.add(current); - final Statement newCurrent = vf.createStatement(current.getSubject(), currentProperty, - newNodeSesame, context); - // From the current subject to the new node - toAdd.add(newCurrent); - if (hasNext()) { - toRemove.addAll(next); - final Statement stmt = next.iterator().next(); - checkNodeIsResource(stmt); - final Resource nextNode = (Resource) stmt.getObject(); - if (!newNodeSesame.equals(nextNode)) { - // From the new node to the next node - final Statement newNext = vf.createStatement(newNodeSesame, hasNextProperty, - nextNode, context); - toAdd.add(newNext); - this.next = Collections.singletonList(newNext); - } else { - this.next = connector.findStatements(newNodeSesame, hasNextProperty, null, - includeInferred, context); - } - } else { - this.next = Collections.emptyList(); - } - this.current = null; - connector.removeStatements(toRemove); - connector.addStatements(toAdd); - } - - @Override - public void remove() throws SesameDriverException { - assert current.getObject() instanceof Resource; - final Collection toRemove = new ArrayList<>(next.size() + 1); - toRemove.add(current); - if (hasNext()) { - toRemove.addAll(next); - final Statement stmt = next.iterator().next(); - checkNodeIsResource(stmt); - final Resource nextNode = (Resource) stmt.getObject(); - // Here we use the current property, so that it can also be the - // hasList property - final Statement toAdd = vf.createStatement(current.getSubject(), currentProperty, - nextNode, context); - this.next = Collections.singletonList(toAdd); - this.current = null; - - connector.addStatements(next); - } else { - this.next = Collections.emptyList(); - } - connector.removeStatements(toRemove); - } + private final SimpleListDescriptor listDescriptor; + + private IRI currentProperty; + + private Statement current; + private Collection next; + + public SimpleListIterator(SimpleListDescriptor listDescriptor, Connector connector, ValueFactory vf) + throws SesameDriverException { + super(listDescriptor, connector, vf); + this.listDescriptor = listDescriptor; + this.currentProperty = hasListProperty; + init(); + } + + private void init() throws SesameDriverException { + this.next = connector.findStatements(listOwner, hasListProperty, null, includeInferred, context); + } + + @Override + public boolean hasNext() { + return (!next.isEmpty()); + } + + @Override + public Resource nextNode() throws SesameDriverException { + nextInternal(); + assert current.getObject() instanceof Resource; + + return (Resource) current.getObject(); + } + + private void nextInternal() throws SesameDriverException { + if (!hasNext()) { + throw new IllegalStateException(); + } + checkSuccessorMax(next, currentProperty); + this.current = next.iterator().next(); + this.currentProperty = current.getPredicate(); + checkNodeIsResource(current); + final Resource elem = (Resource) current.getObject(); + this.next = connector.findStatements(elem, hasNextProperty, null, includeInferred, context); + } + + @Override + public Resource currentContent() throws SesameDriverException { + assert current.getObject() instanceof Resource; + + return (Resource) current.getObject(); + } + + @Override + public Axiom nextAxiom() throws SesameDriverException { + nextInternal(); + assert current.getObject() instanceof Resource; + + final Assertion assertion = current.getPredicate() == hasListProperty ? listDescriptor + .getListProperty() : listDescriptor.getNextNode(); + return createAxiom(current.getSubject(), assertion, (Resource) current.getObject()); + } + + @Override + public void replaceCurrentWith(NamedResource newNode) throws SesameDriverException { + assert current.getObject() instanceof Resource; + final Resource newNodeSesame = vf.createIRI(newNode.getIdentifier().toString()); + final List toAdd = new ArrayList<>(2); + final List toRemove = new ArrayList<>(2); + toRemove.add(current); + final Statement newCurrent = vf.createStatement(current.getSubject(), currentProperty, + newNodeSesame, context); + // From the current subject to the new node + toAdd.add(newCurrent); + if (hasNext()) { + toRemove.addAll(next); + final Statement stmt = next.iterator().next(); + checkNodeIsResource(stmt); + final Resource nextNode = (Resource) stmt.getObject(); + if (!newNodeSesame.equals(nextNode)) { + // From the new node to the next node + final Statement newNext = vf.createStatement(newNodeSesame, hasNextProperty, + nextNode, context); + toAdd.add(newNext); + this.next = Collections.singletonList(newNext); + } else { + this.next = connector.findStatements(newNodeSesame, hasNextProperty, null, + includeInferred, context); + } + } else { + this.next = Collections.emptyList(); + } + this.current = null; + connector.removeStatements(toRemove); + connector.addStatements(toAdd); + } + + @Override + public void remove() throws SesameDriverException { + assert current.getObject() instanceof Resource; + final Collection toRemove = new ArrayList<>(next.size() + 1); + toRemove.add(current); + if (hasNext()) { + toRemove.addAll(next); + final Statement stmt = next.iterator().next(); + checkNodeIsResource(stmt); + final Resource nextNode = (Resource) stmt.getObject(); + // Here we use the current property, so that it can also be the + // hasList property + final Statement toAdd = vf.createStatement(current.getSubject(), currentProperty, + nextNode, context); + this.next = Collections.singletonList(toAdd); + this.current = null; + + connector.addStatements(next); + } else { + this.next = Collections.emptyList(); + } + connector.removeStatements(toRemove); + } } diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/StatementLoader.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/StatementLoader.java index b9ae81b17..503b42df8 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/StatementLoader.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/StatementLoader.java @@ -22,10 +22,7 @@ import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; import cz.cvut.kbss.ontodriver.sesame.util.AxiomBuilder; import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; +import org.eclipse.rdf4j.model.*; import java.util.Collection; import java.util.HashSet; @@ -54,7 +51,7 @@ void setIncludeInferred(boolean includeInferred) { this.includeInferred = includeInferred; } - Collection> loadAxioms(Map properties) + Collection> loadAxioms(Map properties) throws SesameDriverException { this.loadAll = properties.values().contains(Assertion.createUnspecifiedPropertyAssertion(includeInferred)); if (properties.size() < Constants.DEFAULT_LOAD_ALL_THRESHOLD && !loadAll) { @@ -67,8 +64,8 @@ Collection> loadAxioms(Map properties) private Collection> loadOneByOne(Collection assertions) throws SesameDriverException { final Collection> result = new HashSet<>(); for (Assertion a : assertions) { - final URI context = SesameUtils.toSesameUri(descriptor.getAssertionContext(a), vf); - final URI property = SesameUtils.toSesameUri(a.getIdentifier(), vf); + final IRI context = SesameUtils.toSesameIri(descriptor.getAssertionContext(a), vf); + final IRI property = SesameUtils.toSesameIri(a.getIdentifier(), vf); final Collection statements; if (context != null) { @@ -86,7 +83,7 @@ private Collection> loadOneByOne(Collection assertions) thro return result; } - private Collection> loadAll(Map properties) throws SesameDriverException { + private Collection> loadAll(Map properties) throws SesameDriverException { final Collection statements = connector.findStatements(subject, null, null, includeInferred); final Collection> result = new HashSet<>(statements.size()); final Assertion unspecified = Assertion.createUnspecifiedPropertyAssertion(includeInferred); @@ -106,7 +103,7 @@ private Collection> loadAll(Map properties) throws Sesa return result; } - private Assertion getAssertion(Map properties, Statement s) { + private Assertion getAssertion(Map properties, Statement s) { if (properties.containsKey(s.getPredicate())) { return properties.get(s.getPredicate()); } diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/TypesHandler.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/TypesHandler.java index 373277ed0..3e4234407 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/TypesHandler.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/TypesHandler.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -14,14 +14,14 @@ */ package cz.cvut.kbss.ontodriver.sesame; +import cz.cvut.kbss.ontodriver.model.*; import cz.cvut.kbss.ontodriver.sesame.connector.Connector; import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; -import cz.cvut.kbss.ontodriver.model.*; import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.vocabulary.RDF; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.vocabulary.RDF; import java.net.URI; import java.util.*; @@ -36,7 +36,8 @@ class TypesHandler { this.valueFactory = valueFactory; } - Set> getTypes(NamedResource individual, URI context, boolean includeInferred) throws SesameDriverException { + Set> getTypes(NamedResource individual, URI context, boolean includeInferred) + throws SesameDriverException { final Collection statements = getTypesStatements(individual, context, includeInferred); if (statements.isEmpty()) { return Collections.emptySet(); @@ -44,13 +45,15 @@ Set> getTypes(NamedResource individual, URI context, boolean includeI return resolveTypes(individual, includeInferred, statements); } - private Collection getTypesStatements(NamedResource individual, URI context, boolean includeInferred) throws SesameDriverException { - final Resource subject = SesameUtils.toSesameUri(individual.getIdentifier(), valueFactory); - final org.openrdf.model.URI contextUri = SesameUtils.toSesameUri(context, valueFactory); + private Collection getTypesStatements(NamedResource individual, URI context, boolean includeInferred) + throws SesameDriverException { + final Resource subject = SesameUtils.toSesameIri(individual.getIdentifier(), valueFactory); + final org.eclipse.rdf4j.model.IRI contextUri = SesameUtils.toSesameIri(context, valueFactory); return connector.findStatements(subject, RDF.TYPE, null, includeInferred, contextUri); } - private Set> resolveTypes(NamedResource individual, boolean includeInferred, Collection statements) { + private Set> resolveTypes(NamedResource individual, boolean includeInferred, + Collection statements) { final Set> types = new HashSet<>(statements.size()); final Assertion clsAssertion = Assertion.createClassAssertion(includeInferred); for (Statement stmt : statements) { @@ -71,11 +74,12 @@ void addTypes(NamedResource individual, URI context, Set types) throws Sesa } private Collection prepareSesameStatements(NamedResource individual, URI context, Set types) { - final org.openrdf.model.URI subject = SesameUtils.toSesameUri(individual.getIdentifier(), valueFactory); - final org.openrdf.model.URI contextUri = SesameUtils.toSesameUri(context, valueFactory); + final org.eclipse.rdf4j.model.IRI subject = SesameUtils.toSesameIri(individual.getIdentifier(), valueFactory); + final org.eclipse.rdf4j.model.IRI contextUri = SesameUtils.toSesameIri(context, valueFactory); final Collection statements = new ArrayList<>(types.size()); for (URI type : types) { - statements.add(valueFactory.createStatement(subject, RDF.TYPE, valueFactory.createURI(type.toString()), contextUri)); + statements.add(valueFactory + .createStatement(subject, RDF.TYPE, valueFactory.createIRI(type.toString()), contextUri)); } return statements; } diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/ConnectionStatementExecutor.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/ConnectionStatementExecutor.java index 7f5db9901..3e44b086e 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/ConnectionStatementExecutor.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/ConnectionStatementExecutor.java @@ -16,9 +16,9 @@ import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; -import org.openrdf.query.*; -import org.openrdf.repository.RepositoryConnection; -import org.openrdf.repository.RepositoryException; +import org.eclipse.rdf4j.query.*; +import org.eclipse.rdf4j.repository.RepositoryConnection; +import org.eclipse.rdf4j.repository.RepositoryException; /** * Actual implementation of statement processing. diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/Connector.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/Connector.java index a3b91fe20..ca489e59a 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/Connector.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/Connector.java @@ -14,18 +14,13 @@ */ package cz.cvut.kbss.ontodriver.sesame.connector; -import java.util.Collection; -import java.util.List; - -import cz.cvut.kbss.ontodriver.Wrapper; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; - import cz.cvut.kbss.ontodriver.Closeable; +import cz.cvut.kbss.ontodriver.Wrapper; import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; +import org.eclipse.rdf4j.model.*; + +import java.util.Collection; +import java.util.List; public interface Connector extends Closeable, StatementExecutor, Wrapper { @@ -81,8 +76,8 @@ public interface Connector extends Closeable, StatementExecutor, Wrapper { * @return Collection of matching statements * @throws SesameDriverException If a repository access error occurs */ - Collection findStatements(Resource subject, URI property, Value value, - boolean includeInferred, URI... contexts) throws SesameDriverException; + Collection findStatements(Resource subject, IRI property, Value value, + boolean includeInferred, IRI... contexts) throws SesameDriverException; /** * Adds the specified statements to the underlying repository. diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/LocalModel.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/LocalModel.java index 85d559a26..66cc315b8 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/LocalModel.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/LocalModel.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -14,51 +14,48 @@ */ package cz.cvut.kbss.ontodriver.sesame.connector; -import org.openrdf.model.*; -import org.openrdf.model.impl.LinkedHashModel; +import org.eclipse.rdf4j.model.*; +import org.eclipse.rdf4j.model.impl.LinkedHashModel; import java.util.Collection; /** * Caches local transactional changes to the Sesame repository model. - * - * @author ledvima1 - * */ class LocalModel { - private final Model addedStatements; - private final Model removedStatements; - - LocalModel() { - this.addedStatements = new LinkedHashModel(); - this.removedStatements = new LinkedHashModel(); - } - - void enhanceStatements(Collection statements, Resource subject, URI property, - Value object, URI... contexts) { - final URI[] ctxs = contexts != null ? contexts : new URI[0]; - final Collection added = addedStatements.filter(subject, property, object, ctxs); - statements.addAll(added); - final Collection removed = removedStatements.filter(subject, property, object, ctxs); - statements.removeAll(removed); - } - - void addStatements(Collection statements) { - removedStatements.removeAll(statements); - addedStatements.addAll(statements); - } - - void removeStatements(Collection statements) { - addedStatements.removeAll(statements); - removedStatements.addAll(statements); - } - - Collection getAddedStatements() { - return addedStatements; - } - - Collection getRemovedStatements() { - return removedStatements; - } + private final Model addedStatements; + private final Model removedStatements; + + LocalModel() { + this.addedStatements = new LinkedHashModel(); + this.removedStatements = new LinkedHashModel(); + } + + void enhanceStatements(Collection statements, Resource subject, IRI property, + Value object, IRI... contexts) { + final IRI[] ctxs = contexts != null ? contexts : new IRI[0]; + final Collection added = addedStatements.filter(subject, property, object, ctxs); + statements.addAll(added); + final Collection removed = removedStatements.filter(subject, property, object, ctxs); + statements.removeAll(removed); + } + + void addStatements(Collection statements) { + removedStatements.removeAll(statements); + addedStatements.addAll(statements); + } + + void removeStatements(Collection statements) { + addedStatements.removeAll(statements); + removedStatements.addAll(statements); + } + + Collection getAddedStatements() { + return addedStatements; + } + + Collection getRemovedStatements() { + return removedStatements; + } } diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/PoolingStorageConnector.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/PoolingStorageConnector.java index 8e71901ee..34c6f7fae 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/PoolingStorageConnector.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/PoolingStorageConnector.java @@ -16,11 +16,11 @@ import cz.cvut.kbss.ontodriver.exception.OntoDriverException; import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; -import info.aduna.iteration.Iterations; -import org.openrdf.model.*; -import org.openrdf.query.TupleQueryResult; -import org.openrdf.repository.RepositoryConnection; -import org.openrdf.repository.RepositoryException; +import org.eclipse.rdf4j.common.iteration.Iterations; +import org.eclipse.rdf4j.model.*; +import org.eclipse.rdf4j.query.TupleQueryResult; +import org.eclipse.rdf4j.repository.RepositoryConnection; +import org.eclipse.rdf4j.repository.RepositoryException; import java.util.Collection; import java.util.List; @@ -161,8 +161,8 @@ public void removeStatements(Collection statements) throws SesameDriv } @Override - public Collection findStatements(Resource subject, URI property, Value value, - boolean includeInferred, URI... contexts) throws SesameDriverException { + public Collection findStatements(Resource subject, IRI property, Value value, + boolean includeInferred, IRI... contexts) throws SesameDriverException { verifyTransactionActive(); try { final Collection statements = Iterations diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/QueryResult.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/QueryResult.java index 2e24d0f7e..cbdd99f12 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/QueryResult.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/QueryResult.java @@ -14,20 +14,18 @@ */ package cz.cvut.kbss.ontodriver.sesame.connector; -import java.util.List; +import org.eclipse.rdf4j.query.BindingSet; +import org.eclipse.rdf4j.query.QueryEvaluationException; +import org.eclipse.rdf4j.query.TupleQueryResult; +import org.eclipse.rdf4j.repository.RepositoryConnection; +import org.eclipse.rdf4j.repository.RepositoryException; -import org.openrdf.query.BindingSet; -import org.openrdf.query.QueryEvaluationException; -import org.openrdf.query.TupleQueryResult; -import org.openrdf.repository.RepositoryConnection; -import org.openrdf.repository.RepositoryException; +import java.util.List; /** * This class wraps the Sesame TupleQueryResult returned by QueryExecutor to be * able to close the repository connection once the result is closed. * - * @author ledvima1 - * */ class QueryResult implements TupleQueryResult { diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/StatementExecutor.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/StatementExecutor.java index cdc6d9714..c05d8ca14 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/StatementExecutor.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/StatementExecutor.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -14,9 +14,8 @@ */ package cz.cvut.kbss.ontodriver.sesame.connector; -import org.openrdf.query.TupleQueryResult; - import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; +import org.eclipse.rdf4j.query.TupleQueryResult; public interface StatementExecutor { diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/StorageConnector.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/StorageConnector.java index 737435e40..5377827ef 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/StorageConnector.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/StorageConnector.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -20,27 +20,27 @@ import cz.cvut.kbss.ontodriver.sesame.exceptions.RepositoryCreationException; import cz.cvut.kbss.ontodriver.sesame.exceptions.RepositoryNotFoundException; import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; -import info.aduna.iteration.Iterations; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.query.TupleQueryResult; -import org.openrdf.repository.Repository; -import org.openrdf.repository.RepositoryConnection; -import org.openrdf.repository.RepositoryException; -import org.openrdf.repository.RepositoryResult; -import org.openrdf.repository.config.RepositoryConfig; -import org.openrdf.repository.config.RepositoryConfigException; -import org.openrdf.repository.manager.RepositoryManager; -import org.openrdf.repository.manager.RepositoryProvider; -import org.openrdf.repository.sail.SailRepository; -import org.openrdf.repository.sail.config.SailRepositoryConfig; -import org.openrdf.sail.config.SailImplConfig; -import org.openrdf.sail.inferencer.fc.ForwardChainingRDFSInferencer; -import org.openrdf.sail.inferencer.fc.config.ForwardChainingRDFSInferencerConfig; -import org.openrdf.sail.memory.MemoryStore; -import org.openrdf.sail.nativerdf.config.NativeStoreConfig; +import org.eclipse.rdf4j.common.iteration.Iterations; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.Value; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.query.TupleQueryResult; +import org.eclipse.rdf4j.repository.Repository; +import org.eclipse.rdf4j.repository.RepositoryConnection; +import org.eclipse.rdf4j.repository.RepositoryException; +import org.eclipse.rdf4j.repository.RepositoryResult; +import org.eclipse.rdf4j.repository.config.RepositoryConfig; +import org.eclipse.rdf4j.repository.config.RepositoryConfigException; +import org.eclipse.rdf4j.repository.manager.RepositoryManager; +import org.eclipse.rdf4j.repository.manager.RepositoryProvider; +import org.eclipse.rdf4j.repository.sail.SailRepository; +import org.eclipse.rdf4j.repository.sail.config.SailRepositoryConfig; +import org.eclipse.rdf4j.sail.config.SailImplConfig; +import org.eclipse.rdf4j.sail.inferencer.fc.ForwardChainingRDFSInferencer; +import org.eclipse.rdf4j.sail.inferencer.fc.config.ForwardChainingRDFSInferencerConfig; +import org.eclipse.rdf4j.sail.memory.MemoryStore; +import org.eclipse.rdf4j.sail.nativerdf.config.NativeStoreConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -327,8 +327,9 @@ public void removeStatements(Collection statements) throws SesameDriv } @Override - public Collection findStatements(Resource subject, org.openrdf.model.URI property, - Value value, boolean includeInferred, org.openrdf.model.URI... contexts) + public Collection findStatements(Resource subject, org.eclipse.rdf4j.model.IRI property, + Value value, boolean includeInferred, + org.eclipse.rdf4j.model.IRI... contexts) throws SesameDriverException { RepositoryConnection connection = null; try { diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/TransactionalRepositoryConnection.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/TransactionalRepositoryConnection.java index aca6df759..0c88705de 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/TransactionalRepositoryConnection.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/connector/TransactionalRepositoryConnection.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -14,12 +14,16 @@ */ package cz.cvut.kbss.ontodriver.sesame.connector; -import info.aduna.iteration.Iteration; -import org.openrdf.IsolationLevel; -import org.openrdf.model.*; -import org.openrdf.query.*; -import org.openrdf.repository.*; -import org.openrdf.rio.*; + +import org.eclipse.rdf4j.IsolationLevel; +import org.eclipse.rdf4j.common.iteration.Iteration; +import org.eclipse.rdf4j.model.*; +import org.eclipse.rdf4j.query.*; +import org.eclipse.rdf4j.repository.Repository; +import org.eclipse.rdf4j.repository.RepositoryConnection; +import org.eclipse.rdf4j.repository.RepositoryException; +import org.eclipse.rdf4j.repository.RepositoryResult; +import org.eclipse.rdf4j.rio.*; import java.io.File; import java.io.IOException; @@ -136,13 +140,13 @@ public RepositoryResult getContextIDs() throws RepositoryException { } @Override - public RepositoryResult getStatements(Resource subj, URI pred, Value obj, boolean includeInferred, + public RepositoryResult getStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) throws RepositoryException { return wrappedConnection.getStatements(subj, pred, obj, includeInferred, contexts); } @Override - public boolean hasStatement(Resource subj, URI pred, Value obj, boolean includeInferred, Resource... contexts) + public boolean hasStatement(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) throws RepositoryException { return wrappedConnection.hasStatement(subj, pred, obj, includeInferred, contexts); } @@ -154,7 +158,7 @@ public boolean hasStatement(Statement st, boolean includeInferred, Resource... c } @Override - public void exportStatements(Resource subj, URI pred, Value obj, boolean includeInferred, RDFHandler handler, + public void exportStatements(Resource subj, IRI pred, Value obj, boolean includeInferred, RDFHandler handler, Resource... contexts) throws RepositoryException, RDFHandlerException { wrappedConnection.exportStatements(subj, pred, obj, includeInferred, handler, contexts); } @@ -185,7 +189,7 @@ public boolean isAutoCommit() throws RepositoryException { } @Override - public boolean isActive() throws UnknownTransactionStateException, RepositoryException { + public boolean isActive() throws RepositoryException { return wrappedConnection.isActive(); } @@ -244,7 +248,7 @@ public void add(File file, String baseURI, RDFFormat dataFormat, Resource... con } @Override - public void add(Resource subject, URI predicate, Value object, Resource... contexts) throws RepositoryException { + public void add(Resource subject, IRI predicate, Value object, Resource... contexts) throws RepositoryException { wrappedConnection.add(subject, predicate, object, contexts); } @@ -265,7 +269,7 @@ public void add(Iteration statemen } @Override - public void remove(Resource subject, URI predicate, Value object, Resource... contexts) throws RepositoryException { + public void remove(Resource subject, IRI predicate, Value object, Resource... contexts) throws RepositoryException { wrappedConnection.remove(subject, predicate, object, contexts); } diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/query/SelectResultSet.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/query/SelectResultSet.java index e72455c4d..fb5de19bd 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/query/SelectResultSet.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/query/SelectResultSet.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -18,12 +18,13 @@ import cz.cvut.kbss.ontodriver.exception.OntoDriverException; import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; -import org.openrdf.model.Literal; -import org.openrdf.model.URI; -import org.openrdf.model.Value; -import org.openrdf.query.BindingSet; -import org.openrdf.query.QueryEvaluationException; -import org.openrdf.query.TupleQueryResult; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Literal; +import org.eclipse.rdf4j.model.URI; +import org.eclipse.rdf4j.model.Value; +import org.eclipse.rdf4j.query.BindingSet; +import org.eclipse.rdf4j.query.QueryEvaluationException; +import org.eclipse.rdf4j.query.TupleQueryResult; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -216,8 +217,8 @@ private Object toObject(Value val) { } if (val instanceof Literal) { return SesameUtils.getDataPropertyValue((Literal) val); - } else if (val instanceof URI) { - return SesameUtils.toJavaUri((URI) val); + } else if (val instanceof IRI) { + return SesameUtils.toJavaUri((IRI) val); } else { return val.toString(); } @@ -245,8 +246,8 @@ private T toObject(Value val, Class cls) throws OntoDriverException { Object ob = null; if (val instanceof Literal) { ob = SesameUtils.getDataPropertyValue((Literal) val); - } else if (val instanceof URI) { - ob = SesameUtils.toJavaUri((URI) val); + } else if (val instanceof IRI) { + ob = SesameUtils.toJavaUri((IRI) val); } if (ob != null && cls.isAssignableFrom(ob.getClass())) { return cls.cast(ob); @@ -290,11 +291,9 @@ private T instantiateUsingConstructor(Class cls, Value val, Object ob) } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - throw new SesameDriverException("Unable to create instance of type " + cls - + " with value " + val, e); + throw new SesameDriverException("Unable to create instance of type " + cls + " with value " + val, e); } - throw new SesameDriverException("No suitable constructor for value " + val - + " found in type " + cls); + throw new SesameDriverException("No suitable constructor for value " + val + " found in type " + cls); } @Override diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/query/SesameStatement.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/query/SesameStatement.java index 14fb12996..7fa5d2b81 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/query/SesameStatement.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/query/SesameStatement.java @@ -19,8 +19,8 @@ import cz.cvut.kbss.ontodriver.exception.OntoDriverException; import cz.cvut.kbss.ontodriver.sesame.connector.StatementExecutor; import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; -import org.openrdf.query.QueryEvaluationException; -import org.openrdf.query.TupleQueryResult; +import org.eclipse.rdf4j.query.QueryEvaluationException; +import org.eclipse.rdf4j.query.TupleQueryResult; import java.net.URI; import java.util.Objects; diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/util/AxiomBuilder.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/util/AxiomBuilder.java index 4078036eb..0e78a3be0 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/util/AxiomBuilder.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/util/AxiomBuilder.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -15,56 +15,46 @@ package cz.cvut.kbss.ontodriver.sesame.util; import cz.cvut.kbss.ontodriver.model.*; -import org.openrdf.model.Literal; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Literal; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; import java.util.Map; +import java.util.Optional; public class AxiomBuilder { private final NamedResource subject; - private final Map propertyToAssertion; + private final Map propertyToAssertion; private final Assertion unspecifiedProperty; - public AxiomBuilder(NamedResource subject, Map propertyToAssertion, Assertion unspecifiedProperty) { + public AxiomBuilder(NamedResource subject, Map propertyToAssertion, Assertion unspecifiedProperty) { this.subject = subject; this.propertyToAssertion = propertyToAssertion; this.unspecifiedProperty = unspecifiedProperty; } public Axiom statementToAxiom(Statement statement) { - Assertion assertion = resolveAssertion(statement.getPredicate()); + final Assertion assertion = resolveAssertion(statement.getPredicate()); - final Value val = resolveValue(statement, assertion); - if (val == null) { - return null; - } - return new AxiomImpl<>(subject, assertion, val); + return statementToAxiom(statement, assertion); } - private Value resolveValue(Statement stmt, Assertion assertion) { + private Optional> resolveValue(Statement stmt, Assertion assertion) { if (assertion == null || SesameUtils.isBlankNode(stmt.getObject())) { - return null; - } - Value val = createValue(assertion.getType(), stmt.getObject()); - if (val == null) { - return null; + return Optional.empty(); } - return val; + return createValue(assertion.getType(), stmt.getObject()); } public Axiom statementToAxiom(Statement statement, Assertion assertion) { - final Value val = resolveValue(statement, assertion); - if (val == null) { - return null; - } - return new AxiomImpl<>(subject, assertion, val); + final Optional> val = resolveValue(statement, assertion); + return val.map(v -> new AxiomImpl<>(subject, assertion, v)).orElse(null); } - private Assertion resolveAssertion(URI predicate) { + private Assertion resolveAssertion(IRI predicate) { Assertion assertion = propertyToAssertion.get(predicate); if (assertion == null) { if (unspecifiedProperty != null) { @@ -80,31 +70,31 @@ private Assertion resolveAssertion(URI predicate) { return assertion; } - private Value createValue(Assertion.AssertionType assertionType, org.openrdf.model.Value value) { + private Optional> createValue(Assertion.AssertionType assertionType, org.eclipse.rdf4j.model.Value value) { switch (assertionType) { case DATA_PROPERTY: if (!(value instanceof Literal)) { - return null; + return Optional.empty(); } - return new Value<>(SesameUtils.getDataPropertyValue((Literal) value)); + return Optional.of(new Value<>(SesameUtils.getDataPropertyValue((Literal) value))); case CLASS: if (!(value instanceof Resource)) { - return null; + return Optional.empty(); } - return new Value<>(SesameUtils.toJavaUri((Resource) value)); + return Optional.of(new Value<>(SesameUtils.toJavaUri((Resource) value))); case OBJECT_PROPERTY: if (!(value instanceof Resource)) { - return null; + return Optional.empty(); } - return new Value<>(NamedResource.create(value.stringValue())); + return Optional.of(new Value<>(NamedResource.create(value.stringValue()))); case ANNOTATION_PROPERTY: // Intentional fall-through case PROPERTY: - return resolveValue(value); + return Optional.of(resolveValue(value)); } - return null; + return Optional.empty(); } - private Value resolveValue(org.openrdf.model.Value object) { + private Value resolveValue(org.eclipse.rdf4j.model.Value object) { if (object instanceof Literal) { return new Value<>(SesameUtils.getDataPropertyValue((Literal) object)); } else { diff --git a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/util/SesameUtils.java b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/util/SesameUtils.java index 2187f4b72..6e750551f 100644 --- a/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/util/SesameUtils.java +++ b/ontodriver-sesame/src/main/java/cz/cvut/kbss/ontodriver/sesame/util/SesameUtils.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -15,13 +15,12 @@ package cz.cvut.kbss.ontodriver.sesame.util; import cz.cvut.kbss.ontodriver.model.NamedResource; -import org.openrdf.model.*; -import org.openrdf.model.URI; -import org.openrdf.model.vocabulary.RDF; -import org.openrdf.model.vocabulary.XMLSchema; +import org.eclipse.rdf4j.model.*; +import org.eclipse.rdf4j.model.vocabulary.RDF; +import org.eclipse.rdf4j.model.vocabulary.XMLSchema; import org.slf4j.LoggerFactory; -import java.net.*; +import java.net.URL; import java.util.Date; /** @@ -46,7 +45,7 @@ private SesameUtils() { public static Object getDataPropertyValue(Literal literal) { assert literal != null; - final URI datatype = literal.getDatatype(); + final IRI datatype = literal.getDatatype(); if (datatype == null || datatype.equals(XMLSchema.STRING) || datatype.equals(XMLSchema.NORMALIZEDSTRING) || datatype.equals(RDF.LANGSTRING)) { return literal.stringValue(); @@ -151,10 +150,10 @@ public static boolean isResourceIdentifier(Object value) { * * @param javaUri The uri to convert * @param factory ValueFactory used for the conversion - * @return Sesame URI + * @return Sesame IRI */ - public static URI toSesameUri(java.net.URI javaUri, ValueFactory factory) { - return (javaUri != null ? factory.createURI(javaUri.toString()) : null); + public static IRI toSesameIri(java.net.URI javaUri, ValueFactory factory) { + return (javaUri != null ? factory.createIRI(javaUri.toString()) : null); } public static java.net.URI toJavaUri(Resource resource) { diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/AxiomLoaderTest.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/AxiomLoaderTest.java index 140a253e7..77409d890 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/AxiomLoaderTest.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/AxiomLoaderTest.java @@ -22,11 +22,10 @@ import cz.cvut.kbss.ontodriver.sesame.connector.Connector; import cz.cvut.kbss.ontodriver.sesame.environment.Generator; import cz.cvut.kbss.ontodriver.sesame.environment.TestRepositoryProvider; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.repository.Repository; +import org.eclipse.rdf4j.repository.RepositoryConnection; import org.junit.*; -import org.openrdf.model.ValueFactory; -import org.openrdf.repository.Repository; -import org.openrdf.repository.RepositoryConnection; - import java.net.URI; import java.util.*; @@ -165,13 +164,13 @@ private Object saveValueIntoContext(String individual, Assertion property, Strin final Object value; if (property.getType() == Assertion.AssertionType.DATA_PROPERTY) { value = new Date(); - conn.add(vf.createURI(individual), vf.createURI(property.getIdentifier().toString()), - vf.createLiteral((Date) value), vf.createURI(context)); + conn.add(vf.createIRI(individual), vf.createIRI(property.getIdentifier().toString()), + vf.createLiteral((Date) value), vf.createIRI(context)); } else { value = NamedResource.create("http://krizik.felk.cvut.cz/individualInContext" + Generator.randomInt()); - conn.add(vf.createURI(individual), vf.createURI(property.getIdentifier().toString()), - vf.createURI(value.toString()), vf.createURI(context)); + conn.add(vf.createIRI(individual), vf.createIRI(property.getIdentifier().toString()), + vf.createIRI(value.toString()), vf.createIRI(context)); } conn.commit(); conn.close(); @@ -265,7 +264,7 @@ public void loadAxiomsSkipsPropertyValueOfInvalidType_OP() throws Exception { .createObjectPropertyAssertion(URI.create("http://krizik.felk.cvut.cz/objectProperty"), false); final RepositoryConnection conn = connector.unwrap(Repository.class).getConnection(); conn.begin(); - conn.add(vf.createURI(individual), vf.createURI(a.getIdentifier().toString()), vf.createLiteral(false)); + conn.add(vf.createIRI(individual), vf.createIRI(a.getIdentifier().toString()), vf.createLiteral(false)); conn.commit(); conn.close(); @@ -285,8 +284,8 @@ public void loadAxiomsSkipsPropertyValueOfInvalidType_DP() throws Exception { .createDataPropertyAssertion(URI.create("http://krizik.felk.cvut.cz/dataProperty"), false); final RepositoryConnection conn = connector.unwrap(Repository.class).getConnection(); conn.begin(); - conn.add(vf.createURI(individual), vf.createURI(a.getIdentifier().toString()), - vf.createURI("http://krizik.felk.cvut.cz/individual")); + conn.add(vf.createIRI(individual), vf.createIRI(a.getIdentifier().toString()), + vf.createIRI("http://krizik.felk.cvut.cz/individual")); conn.commit(); conn.close(); diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/EpistemicAxiomRemoverTest.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/EpistemicAxiomRemoverTest.java index 37c2217de..bf9fda34a 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/EpistemicAxiomRemoverTest.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/EpistemicAxiomRemoverTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -18,13 +18,13 @@ import cz.cvut.kbss.ontodriver.model.Assertion; import cz.cvut.kbss.ontodriver.model.NamedResource; import cz.cvut.kbss.ontodriver.sesame.connector.Connector; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.openrdf.model.Statement; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.ValueFactoryImpl; import java.net.URI; @@ -51,7 +51,7 @@ public class EpistemicAxiomRemoverTest { @Before public void setUp() { MockitoAnnotations.initMocks(this); - this.vf = new ValueFactoryImpl(); + this.vf = SimpleValueFactory.getInstance(); this.descriptor = new AxiomDescriptor(SUBJECT); this.axiomRemover = new EpistemicAxiomRemover(connectorMock, vf, "en"); @@ -64,9 +64,9 @@ public void removeSkipsInferredAssertions() throws Exception { axiomRemover.remove(descriptor); verify(connectorMock, never()) - .findStatements(eq(vf.createURI(SUBJECT.toString())), eq(vf.createURI(PROPERTY)), any(), anyBoolean()); + .findStatements(eq(vf.createIRI(SUBJECT.toString())), eq(vf.createIRI(PROPERTY)), any(), anyBoolean()); verify(connectorMock, never()) - .findStatements(eq(vf.createURI(SUBJECT.toString())), eq(vf.createURI(PROPERTY)), any(), anyBoolean(), + .findStatements(eq(vf.createIRI(SUBJECT.toString())), eq(vf.createIRI(PROPERTY)), any(), anyBoolean(), anyVararg()); } @@ -79,8 +79,8 @@ public void removeWithAssertionContextSearchesInContext() throws Exception { axiomRemover.remove(descriptor); - verify(connectorMock).findStatements(vf.createURI(SUBJECT.toString()), vf.createURI(PROPERTY), null, false, - vf.createURI(context)); + verify(connectorMock).findStatements(vf.createIRI(SUBJECT.toString()), vf.createIRI(PROPERTY), null, false, + vf.createIRI(context)); verify(connectorMock).removeStatements(anyCollectionOf(Statement.class)); } @@ -91,7 +91,7 @@ public void removeCallsFindStatementsWithoutContextsWhenItIsNotSpecifiedForAsser axiomRemover.remove(descriptor); - verify(connectorMock).findStatements(vf.createURI(SUBJECT.toString()), vf.createURI(PROPERTY), null, false); + verify(connectorMock).findStatements(vf.createIRI(SUBJECT.toString()), vf.createIRI(PROPERTY), null, false); verify(connectorMock).removeStatements(anyCollectionOf(Statement.class)); } } diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/ListHandlerTestBase.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/ListHandlerTestBase.java index a52a1715c..7c50c6d65 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/ListHandlerTestBase.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/ListHandlerTestBase.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -15,46 +15,35 @@ package cz.cvut.kbss.ontodriver.sesame; import cz.cvut.kbss.ontodriver.model.NamedResource; -import org.openrdf.model.Resource; -import org.openrdf.model.ValueFactory; -import org.openrdf.repository.Repository; -import org.openrdf.repository.RepositoryException; -import org.openrdf.repository.sail.SailRepository; -import org.openrdf.sail.memory.MemoryStore; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import java.util.ArrayList; import java.util.List; class ListHandlerTestBase { - protected static final NamedResource OWNER = NamedResource - .create("http://krizik.felk.cvut.cz/ontologies/jopa/entityC"); + protected static final NamedResource OWNER = NamedResource + .create("http://krizik.felk.cvut.cz/ontologies/jopa/entityC"); - protected static final String LIST_PROPERTY = "http://krizik.felk.cvut.cz/ontologies/jopa/attributes#C-hasSequence"; - protected static final String NEXT_NODE_PROPERTY = "http://krizik.felk.cvut.cz/ontologies/jopa/attributes#C-hasNext"; + protected static final String LIST_PROPERTY = "http://krizik.felk.cvut.cz/ontologies/jopa/attributes#C-hasSequence"; + protected static final String NEXT_NODE_PROPERTY = "http://krizik.felk.cvut.cz/ontologies/jopa/attributes#C-hasNext"; - protected static ValueFactory vf; - protected static Repository repo; - protected static Resource owner; + protected static ValueFactory vf; + protected static Resource owner; - protected static void init() throws Exception { - final MemoryStore mStore = new MemoryStore(); - repo = new SailRepository(mStore); - repo.initialize(); - vf = repo.getValueFactory(); - owner = vf.createURI(OWNER.toString()); - } + protected static void init() throws Exception { + vf = SimpleValueFactory.getInstance(); + owner = vf.createIRI(OWNER.toString()); + } - protected static void close() throws RepositoryException { - repo.shutDown(); - } - - protected List initList() { - final List lst = new ArrayList<>(); - for (int i = 0; i < 5; i++) { - lst.add(NamedResource.create("http://krizik.felk.cvut.cz/ontologies/jopa/elem" + i)); - } - return lst; - } + protected List initList() { + final List lst = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + lst.add(NamedResource.create("http://krizik.felk.cvut.cz/ontologies/jopa/elem" + i)); + } + return lst; + } } diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/ReferencedListHandlerTest.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/ReferencedListHandlerTest.java index 5897d2b5d..24194d5cb 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/ReferencedListHandlerTest.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/ReferencedListHandlerTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -22,17 +22,16 @@ import cz.cvut.kbss.ontodriver.model.Axiom; import cz.cvut.kbss.ontodriver.model.NamedResource; import cz.cvut.kbss.ontodriver.sesame.connector.Connector; -import org.junit.AfterClass; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.Value; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.Value; import java.util.*; @@ -45,11 +44,11 @@ @SuppressWarnings({"unchecked", "rawtypes"}) public class ReferencedListHandlerTest extends ListHandlerTestBase { - protected static final String NODE_CONTENT_PROPERTY = "http://krizik.felk.cvut.cz/ontologies/2008/6/sequences.owl#hasContents"; + private static final String NODE_CONTENT_PROPERTY = "http://krizik.felk.cvut.cz/ontologies/2008/6/sequences.owl#hasContents"; - private static URI hasListProperty; - private static URI nextNodeProperty; - private static URI nodeContentProperty; + private static IRI hasListProperty; + private static IRI nextNodeProperty; + private static IRI nodeContentProperty; private ReferencedListDescriptor listDescriptor; private ReferencedListValueDescriptor valueDescriptor; @@ -65,14 +64,9 @@ public class ReferencedListHandlerTest extends ListHandlerTestBase { @BeforeClass public static void setUpBeforeClass() throws Exception { init(); - hasListProperty = vf.createURI(LIST_PROPERTY); - nextNodeProperty = vf.createURI(NEXT_NODE_PROPERTY); - nodeContentProperty = vf.createURI(NODE_CONTENT_PROPERTY); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - close(); + hasListProperty = vf.createIRI(LIST_PROPERTY); + nextNodeProperty = vf.createIRI(NEXT_NODE_PROPERTY); + nodeContentProperty = vf.createIRI(NODE_CONTENT_PROPERTY); } @Before @@ -111,13 +105,13 @@ public void staticFactoryMethodForReferencedLists() throws Exception { @Test public void loadsEmptyListAndReturnsEmptyCollection() throws Exception { - when(connector.findStatements(owner, hasListProperty, null, false, (URI[]) null)) - .thenReturn(Collections.emptyList()); + when(connector.findStatements(owner, hasListProperty, null, false, (IRI[]) null)) + .thenReturn(Collections.emptyList()); final Collection> res = handler.loadList(listDescriptor); assertNotNull(res); assertTrue(res.isEmpty()); verify(connector, never()).findStatements(any(Resource.class), eq(nextNodeProperty), - any(Value.class), any(Boolean.class), eq((URI[]) null)); + any(Value.class), any(Boolean.class), eq(null)); } @Test @@ -146,27 +140,27 @@ private List initStatementsForList(List nodes, Resource prev = owner; final List stmts = new ArrayList<>(); for (java.net.URI item : nodes) { - final URI itemUri = vf.createURI(item.toString()); + final IRI itemUri = vf.createIRI(item.toString()); Statement node; if (i == 0) { node = vf.createStatement(prev, hasListProperty, itemUri); when( - connector.findStatements(eq(prev), eq(hasListProperty), eq((Value) null), - anyBoolean(), eq((URI[]) null))).thenReturn( + connector.findStatements(eq(prev), eq(hasListProperty), eq(null), + anyBoolean(), eq(null))).thenReturn( Collections.singleton(node)); } else { node = vf.createStatement(prev, nextNodeProperty, itemUri); when( - connector.findStatements(eq(prev), eq(nextNodeProperty), eq((Value) null), - anyBoolean(), eq((URI[]) null))).thenReturn( + connector.findStatements(eq(prev), eq(nextNodeProperty), eq(null), + anyBoolean(), eq(null))).thenReturn( Collections.singleton(node)); } stmts.add(node); final Statement content = vf.createStatement(itemUri, nodeContentProperty, - vf.createURI(values.get(i).toString())); + vf.createIRI(values.get(i).toString())); when( connector.findStatements(eq(itemUri), eq(nodeContentProperty), - eq((Value) null), anyBoolean(), eq((URI[]) null))).thenReturn( + eq((Value) null), anyBoolean(), eq(null))).thenReturn( Collections.singleton(content)); stmts.add(content); prev = itemUri; @@ -177,22 +171,21 @@ private List initStatementsForList(List nodes, @Test(expected = IntegrityConstraintViolatedException.class) public void throwsICViolationWhenThereIsNoContentInHeadNode() throws Exception { - final URI headNode = vf.createURI("http://krizik.felk.cvut.cz/ontologies/jopa/SEQ0"); + final IRI headNode = vf.createIRI("http://krizik.felk.cvut.cz/ontologies/jopa/SEQ0"); when( - connector.findStatements(eq(owner), eq(hasListProperty), eq((Value) null), - anyBoolean(), eq((URI[]) null))).thenReturn( + connector.findStatements(eq(owner), eq(hasListProperty), eq(null), + anyBoolean(), eq(null))).thenReturn( Collections.singleton(vf.createStatement(owner, hasListProperty, headNode))); when( - connector.findStatements(eq(headNode), eq(nodeContentProperty), eq((Value) null), - anyBoolean(), eq((URI[]) null))).thenReturn( - Collections.emptyList()); + connector.findStatements(eq(headNode), eq(nodeContentProperty), eq(null), + anyBoolean(), eq(null))).thenReturn(Collections.emptyList()); try { final Collection> res = handler.loadList(listDescriptor); assert res == null; fail("This line should not have been reached."); } finally { verify(connector, never()).findStatements(any(Resource.class), eq(nextNodeProperty), - any(Value.class), anyBoolean(), any(URI[].class)); + any(Value.class), anyBoolean(), any(IRI[].class)); } } @@ -203,9 +196,8 @@ public void throwsICViolationWhenThereIsNoContentInSomeListNode() throws Excepti initStatementsForList(listNodes, refList); final Resource elem = selectRandomNode(listNodes); when( - connector.findStatements(eq(elem), eq(nodeContentProperty), eq((Value) null), - anyBoolean(), eq((URI[]) null))).thenReturn( - Collections.emptyList()); + connector.findStatements(eq(elem), eq(nodeContentProperty), eq(null), + anyBoolean(), eq(null))).thenReturn(Collections.emptyList()); final Collection> res = handler.loadList(listDescriptor); assert res == null; } @@ -214,35 +206,29 @@ private Resource selectRandomNode(List nodes) { // Select a random index, but it shouldn't be 0 (it would be the head), // so add 1 final int rand = new Random().nextInt(nodes.size() - 1) + 1; - return vf.createURI(nodes.get(rand).toString()); + return vf.createIRI(nodes.get(rand).toString()); } @Test(expected = IntegrityConstraintViolatedException.class) - public void throwsICViolationWhenThereAreMutlipleSuccessorsForNode() throws Exception { + public void throwsICViolationWhenThereAreMultipleSuccessorsForNode() throws Exception { + runIcViolationTest(nextNodeProperty); + } + + private void runIcViolationTest(IRI property) throws Exception { final List refList = initList(); final List listNodes = initListNodes(refList); initStatementsForList(listNodes, refList); final Resource node = selectRandomNode(listNodes); final List stmts = Arrays.asList(mock(Statement.class), mock(Statement.class)); when( - connector.findStatements(eq(node), eq(nextNodeProperty), eq((Value) null), - anyBoolean(), eq((URI[]) null))).thenReturn(stmts); - final Collection> res = handler.loadList(listDescriptor); - assert res == null; + connector.findStatements(eq(node), eq(property), eq(null), + anyBoolean(), eq(null))).thenReturn(stmts); + handler.loadList(listDescriptor); } @Test(expected = IntegrityConstraintViolatedException.class) public void throwsICViolationWhenThereAreMultipleReferencesInNode() throws Exception { - final List refList = initList(); - final List listNodes = initListNodes(refList); - initStatementsForList(listNodes, refList); - final Resource node = selectRandomNode(listNodes); - final List stmts = Arrays.asList(mock(Statement.class), mock(Statement.class)); - when( - connector.findStatements(eq(node), eq(nodeContentProperty), eq((Value) null), - anyBoolean(), eq((URI[]) null))).thenReturn(stmts); - final Collection> res = handler.loadList(listDescriptor); - assert res == null; + runIcViolationTest(nodeContentProperty); } @Test @@ -311,9 +297,8 @@ public void insertsListOnUpdateWhenThereWereNoValuesBefore() throws Exception { final ReferencedListValueDescriptor descriptor = initValues(5); when( connector.findStatements(owner, hasListProperty, null, descriptor.getListProperty() - .isInferred(), (URI[]) null)) - .thenReturn( - Collections.emptyList()); + .isInferred(), (IRI[]) null)) + .thenReturn(Collections.emptyList()); handler.updateList(descriptor); verify(connector, never()).removeStatements(any(Collection.class)); diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameAdapterTest.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameAdapterTest.java index 9dd3a89d2..95fd8938e 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameAdapterTest.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameAdapterTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -23,17 +23,17 @@ import cz.cvut.kbss.ontodriver.model.*; import cz.cvut.kbss.ontodriver.sesame.connector.Connector; import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.model.vocabulary.RDF; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.ValueFactoryImpl; -import org.openrdf.model.vocabulary.RDF; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -53,8 +53,8 @@ public class SesameAdapterTest { private static final NamedResource SUBJECT = NamedResource .create("http://krizik.felk.cvut.cz/ontologies/jopa/entityX"); - private static ValueFactory vf = new ValueFactoryImpl(); - private static org.openrdf.model.URI subjectUri; + private static ValueFactory vf = SimpleValueFactory.getInstance(); + private static org.eclipse.rdf4j.model.IRI subjectIri; @Mock private Connector connectorMock; @@ -63,7 +63,7 @@ public class SesameAdapterTest { @BeforeClass public static void setUpBeforeClass() throws Exception { - subjectUri = vf.createURI(SUBJECT.getIdentifier().toString()); + subjectIri = vf.createIRI(SUBJECT.getIdentifier().toString()); } @Before @@ -93,7 +93,7 @@ public void testSesameAdapter() throws Exception { public void testGetContexts() throws Exception { final List contexts = new ArrayList<>(); for (int i = 0; i < 5; i++) { - contexts.add(vf.createURI("http://krizik.felk.cvut.cz/ontologies/context" + i)); + contexts.add(vf.createIRI("http://krizik.felk.cvut.cz/ontologies/context" + i)); } when(connectorMock.getContexts()).thenReturn(contexts); final List res = adapter.getContexts(); @@ -112,7 +112,7 @@ public void testGetContextsWithBNodes() throws Exception { contexts.add(vf.createBNode()); bnodes++; } else { - contexts.add(vf.createURI("http://krizik.felk.cvut.cz/ontologies/context" + i)); + contexts.add(vf.createIRI("http://krizik.felk.cvut.cz/ontologies/context" + i)); } } when(connectorMock.getContexts()).thenReturn(contexts); @@ -156,15 +156,13 @@ private boolean statementsCorrespondToAxiomDescriptor(AxiomValueDescriptor ad, if (stmt.getPredicate().stringValue().equals(strIdentifier) && stmt.getObject().stringValue().equals(val.getValue().toString())) { valueFound = true; - assertEquals(ad.getSubject().getIdentifier().toString(), stmt.getSubject() - .stringValue()); + assertEquals(ad.getSubject().getIdentifier().toString(), stmt.getSubject().stringValue()); if (ad.getAssertionContext(as) == null) { assertNull(stmt.getContext()); } else if (stmt.getContext() == null) { assertNull(ad.getAssertionContext(as)); } else { - assertEquals(ad.getAssertionContext(as).toString(), stmt.getContext() - .stringValue()); + assertEquals(ad.getAssertionContext(as).toString(), stmt.getContext().stringValue()); } break; } @@ -296,14 +294,14 @@ public void testFindEntityWithDataProperty() throws Exception { desc.addAssertion(Assertion.createDataPropertyAssertion(URI.create(property), false)); final Map statements = initStatementsForDescriptor(desc); for (Assertion as : statements.keySet()) { - final org.openrdf.model.URI predicate = vf.createURI(as.getIdentifier().toString()); + final org.eclipse.rdf4j.model.IRI predicate = vf.createIRI(as.getIdentifier().toString()); when( - connectorMock.findStatements(subjectUri, predicate, null, as.isInferred())).thenReturn( + connectorMock.findStatements(subjectIri, predicate, null, as.isInferred())).thenReturn( Collections.singletonList(statements.get(as))); } final Collection> res = adapter.find(desc); verify(connectorMock, times(2)).findStatements(any(Resource.class), - any(org.openrdf.model.URI.class), any(org.openrdf.model.Value.class), anyBoolean()); + any(org.eclipse.rdf4j.model.IRI.class), any(org.eclipse.rdf4j.model.Value.class), anyBoolean()); assertEquals(statements.size(), res.size()); for (Axiom ax : res) { assertTrue(statements.containsKey(ax.getAssertion())); @@ -317,10 +315,10 @@ private Map initStatementsForDescriptor(AxiomDescriptor de int dpCounter = 0; int apCounter = 0; final Map lst = new HashMap<>(); - final Resource subject = vf.createURI(desc.getSubject().getIdentifier().toString()); + final Resource subject = vf.createIRI(desc.getSubject().getIdentifier().toString()); for (Assertion as : desc.getAssertions()) { - final org.openrdf.model.URI property = vf.createURI(as.getIdentifier().toString()); - org.openrdf.model.Value val = null; + final org.eclipse.rdf4j.model.IRI property = vf.createIRI(as.getIdentifier().toString()); + org.eclipse.rdf4j.model.Value val = null; switch (as.getType()) { case ANNOTATION_PROPERTY: val = vf.createLiteral( @@ -328,14 +326,14 @@ private Map initStatementsForDescriptor(AxiomDescriptor de + apCounter++); break; case CLASS: - val = vf.createURI("http://krizik.felk.cvut.cz/ontologies/jopa/entities#OWLClassA"); + val = vf.createIRI("http://krizik.felk.cvut.cz/ontologies/jopa/entities#OWLClassA"); break; case DATA_PROPERTY: val = vf.createLiteral("http://krizik.felk.cvut.cz/ontologies/jopa/attributes#dataPropertyValue" + dpCounter++); break; case OBJECT_PROPERTY: - val = vf.createURI("http://krizik.felk.cvut.cz/ontologies/jopa/entities#entityValue" + val = vf.createIRI("http://krizik.felk.cvut.cz/ontologies/jopa/entities#entityValue" + opCounter++); break; default: @@ -356,16 +354,16 @@ public void testFindEntityWithObjectPropertyAndInferredAnnotationProperty() thro desc.addAssertion(Assertion.createObjectPropertyAssertion(URI.create(obProperty), false)); final Map statements = initStatementsForDescriptor(desc); for (Assertion as : statements.keySet()) { - final org.openrdf.model.URI predicate = vf.createURI(as.getIdentifier().toString()); + final org.eclipse.rdf4j.model.IRI predicate = vf.createIRI(as.getIdentifier().toString()); when( - connectorMock.findStatements(subjectUri, predicate, null, as.isInferred())).thenReturn( + connectorMock.findStatements(subjectIri, predicate, null, as.isInferred())).thenReturn( Collections.singletonList(statements.get(as))); } final Collection> res = adapter.find(desc); verify(connectorMock, times(3)).findStatements(any(Resource.class), - any(org.openrdf.model.URI.class), any(org.openrdf.model.Value.class), anyBoolean()); - verify(connectorMock, times(1)).findStatements(eq(subjectUri), - eq(vf.createURI(anProperty)), eq(null), eq(true)); + any(org.eclipse.rdf4j.model.IRI.class), any(org.eclipse.rdf4j.model.Value.class), anyBoolean()); + verify(connectorMock, times(1)).findStatements(eq(subjectIri), + eq(vf.createIRI(anProperty)), eq(null), eq(true)); assertEquals(statements.size(), res.size()); for (Axiom ax : res) { assertTrue(statements.containsKey(ax.getAssertion())); @@ -381,19 +379,19 @@ public void testFindEntityWithTypesAndSubjectContext() throws Exception { desc.addAssertion(Assertion.createClassAssertion(false)); desc.setSubjectContext(subjectCtx); final List statements = new ArrayList<>(); - final org.openrdf.model.URI typeProperty = vf.createURI(Assertion + final org.eclipse.rdf4j.model.IRI typeProperty = vf.createIRI(Assertion .createClassAssertion(false).getIdentifier().toString()); final int count = 10; final Set types = new HashSet<>(); for (int i = 0; i < count; i++) { - final org.openrdf.model.URI type = vf - .createURI("http://krizik.felk.cvut.cz/ontologies/jopa/types#Type" + i); - statements.add(vf.createStatement(subjectUri, typeProperty, type)); + final org.eclipse.rdf4j.model.IRI type = vf + .createIRI("http://krizik.felk.cvut.cz/ontologies/jopa/types#Type" + i); + statements.add(vf.createStatement(subjectIri, typeProperty, type)); types.add(type.stringValue()); } when( - connectorMock.findStatements(subjectUri, typeProperty, null, false, - vf.createURI(subjectCtx.toString()))).thenReturn(statements); + connectorMock.findStatements(subjectIri, typeProperty, null, false, + vf.createIRI(subjectCtx.toString()))).thenReturn(statements); final Collection> res = adapter.find(desc); assertEquals(statements.size(), res.size()); for (Axiom ax : res) { @@ -418,16 +416,16 @@ public void testFindEntityWithProperties() throws Exception { stmts.addAll(statements.get(a)); } when( - connectorMock.findStatements(subjectUri, null, null, false)).thenReturn(stmts); - when(connectorMock.findStatements(subjectUri, vf.createURI(propertyOne), null, false)) + connectorMock.findStatements(subjectIri, null, null, false)).thenReturn(stmts); + when(connectorMock.findStatements(subjectIri, vf.createIRI(propertyOne), null, false)) .thenReturn(statements.get(asOne)); - when(connectorMock.findStatements(subjectUri, vf.createURI(propertyTwo), null, false)) + when(connectorMock.findStatements(subjectIri, vf.createIRI(propertyTwo), null, false)) .thenReturn(statements.get(asTwo)); final Collection> res = adapter.find(desc); - verify(connectorMock).findStatements(subjectUri, null, null, false); - verify(connectorMock, never()).findStatements(eq(subjectUri), eq(vf.createURI(propertyOne)), - any(org.openrdf.model.Value.class), anyBoolean()); + verify(connectorMock).findStatements(subjectIri, null, null, false); + verify(connectorMock, never()).findStatements(eq(subjectIri), eq(vf.createIRI(propertyOne)), + any(org.eclipse.rdf4j.model.Value.class), anyBoolean()); verifyReturnedAxioms(stmts, res); } @@ -436,12 +434,12 @@ private List createStatementsForProperty(String property, boolean obj int cnt = 3; if (objectProperty) { for (int i = 0; i < cnt; i++) { - res.add(vf.createStatement(subjectUri, vf.createURI(property), - vf.createURI("http://krizik.felk.cvut.cz/jopa#entity" + i))); + res.add(vf.createStatement(subjectIri, vf.createIRI(property), + vf.createIRI("http://krizik.felk.cvut.cz/jopa#entity" + i))); } } else { for (int i = 0; i < cnt; i++) { - res.add(vf.createStatement(subjectUri, vf.createURI(property), vf.createLiteral(i))); + res.add(vf.createStatement(subjectIri, vf.createIRI(property), vf.createLiteral(i))); } } return res; @@ -480,20 +478,20 @@ public void testFindEntityWithPropertiesAndInferredDataProperty() throws Excepti stmts.addAll(statements.get(a)); } final Collection inferred = new ArrayList<>(); - inferred.add(vf.createStatement(subjectUri, vf.createURI(propertyTwo), vf.createLiteral(true))); + inferred.add(vf.createStatement(subjectIri, vf.createIRI(propertyTwo), vf.createLiteral(true))); statements.get(asTwo).addAll(inferred); when( - connectorMock.findStatements(subjectUri, null, null, false)).thenReturn(stmts); - when(connectorMock.findStatements(subjectUri, vf.createURI(propertyOne), null, false)) + connectorMock.findStatements(subjectIri, null, null, false)).thenReturn(stmts); + when(connectorMock.findStatements(subjectIri, vf.createIRI(propertyOne), null, false)) .thenReturn(statements.get(asOne)); - when(connectorMock.findStatements(subjectUri, vf.createURI(propertyTwo), null, true)) + when(connectorMock.findStatements(subjectIri, vf.createIRI(propertyTwo), null, true)) .thenReturn(statements.get(asTwo)); final Collection> res = adapter.find(desc); - verify(connectorMock).findStatements(subjectUri, null, null, false); - verify(connectorMock).findStatements(subjectUri, vf.createURI(propertyTwo), null, true); - verify(connectorMock, never()).findStatements(eq(subjectUri), eq(vf.createURI(propertyOne)), - any(org.openrdf.model.Value.class), anyBoolean()); + verify(connectorMock).findStatements(subjectIri, null, null, false); + verify(connectorMock).findStatements(subjectIri, vf.createIRI(propertyTwo), null, true); + verify(connectorMock, never()).findStatements(eq(subjectIri), eq(vf.createIRI(propertyOne)), + any(org.eclipse.rdf4j.model.Value.class), anyBoolean()); final Collection allStatements = new ArrayList<>(stmts); allStatements.addAll(inferred); verifyReturnedAxioms(allStatements, res); @@ -508,13 +506,13 @@ public void testFindEntityReturnDataPropertyValueForObjectProperty() throws Exce false); desc.addAssertion(asOne); final String expected = "http://krizik.felk.cvut.cz/ontologies/jopa#entityOne"; - statements.add(vf.createStatement(subjectUri, vf.createURI(propertyOne), - vf.createURI(expected))); + statements.add(vf.createStatement(subjectIri, vf.createIRI(propertyOne), + vf.createIRI(expected))); // This statement should be filtered out by the adapter - statements.add(vf.createStatement(subjectUri, vf.createURI(propertyOne), + statements.add(vf.createStatement(subjectIri, vf.createIRI(propertyOne), vf.createLiteral("someNonUriValue"))); when( - connectorMock.findStatements(subjectUri, vf.createURI(propertyOne), null, false)) + connectorMock.findStatements(subjectIri, vf.createIRI(propertyOne), null, false)) .thenReturn(statements); final Collection> res = adapter.find(desc); assertEquals(1, res.size()); @@ -530,11 +528,11 @@ public void testFindEntityReturnObjectPropertyValueForDataProperty() throws Exce false); desc.addAssertion(asOne); // This statement should be filtered out - statements.add(vf.createStatement(subjectUri, vf.createURI(propertyOne), - vf.createURI("http://krizik.felk.cvut.cz/ontologies/jopa#entityOne"))); + statements.add(vf.createStatement(subjectIri, vf.createIRI(propertyOne), + vf.createIRI("http://krizik.felk.cvut.cz/ontologies/jopa#entityOne"))); when( - connectorMock.findStatements(subjectUri, vf.createURI(propertyOne), null, false, - (org.openrdf.model.URI) null)).thenReturn(statements); + connectorMock.findStatements(subjectIri, vf.createIRI(propertyOne), null, false, + (org.eclipse.rdf4j.model.IRI) null)).thenReturn(statements); final Collection> res = adapter.find(desc); assertTrue(res.isEmpty()); } @@ -544,8 +542,8 @@ public void findWithObjectPropertyAndPropertiesReturnsAxiomForObjectProperty() t final AxiomDescriptor desc = new AxiomDescriptor(SUBJECT); final String propertyOne = "http://krizik.felk.cvut.cz/ontologies/jopa/properties#objectProperty"; final List statements = new ArrayList<>(); - statements.add(vf.createStatement(subjectUri, vf.createURI(propertyOne), - vf.createURI("http://krizik.felk.cvut.cz/ontologies/jopa#entityOne"))); + statements.add(vf.createStatement(subjectIri, vf.createIRI(propertyOne), + vf.createIRI("http://krizik.felk.cvut.cz/ontologies/jopa#entityOne"))); final Assertion asOne = Assertion.createObjectPropertyAssertion(URI.create(propertyOne), false); final Set assertions = new LinkedHashSet<>(); @@ -553,9 +551,9 @@ public void findWithObjectPropertyAndPropertiesReturnsAxiomForObjectProperty() t assertions.add(asOne); setAssertions(desc, assertions); when(connectorMock - .findStatements(subjectUri, vf.createURI(propertyOne), null, false)) + .findStatements(subjectIri, vf.createIRI(propertyOne), null, false)) .thenReturn(statements); - when(connectorMock.findStatements(subjectUri, null, null, false)) + when(connectorMock.findStatements(subjectIri, null, null, false)) .thenReturn(statements); final Collection> axioms = adapter.find(desc); assertEquals(1, axioms.size()); @@ -579,10 +577,10 @@ public void testFindEntityWithBlankNodeInTypes() throws Exception { final List statements = new ArrayList<>(); final Assertion clsAssertion = Assertion.createClassAssertion(false); desc.addAssertion(clsAssertion); - statements.add(vf.createStatement(subjectUri, RDF.TYPE, vf.createBNode())); + statements.add(vf.createStatement(subjectIri, RDF.TYPE, vf.createBNode())); final String type = "http://krizik.felk.cvutcz/ontologies/jopa#entityA"; - statements.add(vf.createStatement(subjectUri, RDF.TYPE, vf.createURI(type))); - when(connectorMock.findStatements(subjectUri, RDF.TYPE, null, false)).thenReturn(statements); + statements.add(vf.createStatement(subjectIri, RDF.TYPE, vf.createIRI(type))); + when(connectorMock.findStatements(subjectIri, RDF.TYPE, null, false)).thenReturn(statements); final Collection> res = adapter.find(desc); assertEquals(1, res.size()); @@ -595,12 +593,12 @@ public void testGenerateIdentifier_ClassWithHash() throws Exception { final URI clsUri = URI.create("http://someClass.cz#class"); when( connectorMock.findStatements(any(Resource.class), eq(RDF.TYPE), - eq(vf.createURI(clsUri.toString())), eq(true))).thenReturn(Collections.emptyList()); + eq(vf.createIRI(clsUri.toString())), eq(true))).thenReturn(Collections.emptyList()); final URI res = adapter.generateIdentifier(clsUri); assertNotNull(res); assertTrue(res.toString().contains(clsUri.toString())); - verify(connectorMock).findStatements(vf.createURI(res.toString()), RDF.TYPE, - vf.createURI(clsUri.toString()), true); + verify(connectorMock).findStatements(vf.createIRI(res.toString()), RDF.TYPE, + vf.createIRI(clsUri.toString()), true); } @Test @@ -608,13 +606,13 @@ public void testGenerateIdentifier_ClassWithoutHash() throws Exception { final URI clsUri = URI.create("http://someClass.cz/class"); when( connectorMock.findStatements(any(Resource.class), eq(RDF.TYPE), - eq(vf.createURI(clsUri.toString())), eq(true))).thenReturn(Collections.emptyList()); + eq(vf.createIRI(clsUri.toString())), eq(true))).thenReturn(Collections.emptyList()); final URI res = adapter.generateIdentifier(clsUri); assertNotNull(res); assertTrue(res.toString().contains(clsUri.toString())); assertTrue(res.toString().contains("#")); - verify(connectorMock).findStatements(vf.createURI(res.toString()), RDF.TYPE, - vf.createURI(clsUri.toString()), true); + verify(connectorMock).findStatements(vf.createIRI(res.toString()), RDF.TYPE, + vf.createIRI(clsUri.toString()), true); } @Test @@ -622,12 +620,12 @@ public void testGenerateIdentifier_ClassEndsWithSlash() throws Exception { final URI clsUri = URI.create("http://someClass.cz/class/"); when( connectorMock.findStatements(any(Resource.class), eq(RDF.TYPE), - eq(vf.createURI(clsUri.toString())), eq(true))).thenReturn(Collections.emptyList()); + eq(vf.createIRI(clsUri.toString())), eq(true))).thenReturn(Collections.emptyList()); final URI res = adapter.generateIdentifier(clsUri); assertNotNull(res); assertTrue(res.toString().contains(clsUri.toString())); - verify(connectorMock).findStatements(vf.createURI(res.toString()), RDF.TYPE, - vf.createURI(clsUri.toString()), true); + verify(connectorMock).findStatements(vf.createIRI(res.toString()), RDF.TYPE, + vf.createIRI(clsUri.toString()), true); } @Test(expected = IdentifierGenerationException.class) @@ -636,7 +634,7 @@ public void testGenerateIdentifierNeverUnique() throws Exception { final Collection statements = Collections.singletonList(mock(Statement.class)); when( connectorMock.findStatements(any(Resource.class), eq(RDF.TYPE), - eq(vf.createURI(clsUri.toString())), eq(true))).thenReturn(statements); + eq(vf.createIRI(clsUri.toString())), eq(true))).thenReturn(statements); final URI res = adapter.generateIdentifier(clsUri); assert res == null; } @@ -650,13 +648,13 @@ public void testRemove() throws Exception { final Collection statements = new HashSet<>(initStatementsForDescriptor(desc) .values()); when( - connectorMock.findStatements(eq(subjectUri), any(org.openrdf.model.URI.class), - any(org.openrdf.model.Value.class), eq(false))).thenReturn(statements); + connectorMock.findStatements(eq(subjectIri), any(org.eclipse.rdf4j.model.IRI.class), + any(org.eclipse.rdf4j.model.Value.class), eq(false))).thenReturn(statements); adapter.remove(desc); for (Assertion ass : desc.getAssertions()) { - verify(connectorMock).findStatements(subjectUri, - vf.createURI(ass.getIdentifier().toString()), null, false); + verify(connectorMock).findStatements(subjectIri, + vf.createIRI(ass.getIdentifier().toString()), null, false); } verify(connectorMock).removeStatements(statements); } @@ -668,12 +666,12 @@ public void testContainsClassAssertion() throws Exception { .create("http://krizik.felk.cvut.cz/ontologies/jopa/entities#OWLClassA"))); final Set result = new HashSet<>(); result.add(mock(Statement.class)); - when(connectorMock.findStatements(eq(subjectUri), eq(RDF.TYPE), eq(vf.createURI(ax.getValue().stringValue())), + when(connectorMock.findStatements(eq(subjectIri), eq(RDF.TYPE), eq(vf.createIRI(ax.getValue().stringValue())), anyBoolean())).thenReturn(result); assertTrue(adapter.contains(ax, null)); - verify(connectorMock).findStatements(subjectUri, RDF.TYPE, - vf.createURI(ax.getValue().stringValue()), ax.getAssertion().isInferred()); + verify(connectorMock).findStatements(subjectIri, RDF.TYPE, + vf.createIRI(ax.getValue().stringValue()), ax.getAssertion().isInferred()); } @Test @@ -685,14 +683,14 @@ public void testContainsClassAssertionInContext() throws Exception { final Set result = new HashSet<>(); result.add(mock(Statement.class)); when( - connectorMock.findStatements(eq(subjectUri), eq(RDF.TYPE), - eq(vf.createURI(ax.getValue().stringValue())), anyBoolean(), - any(org.openrdf.model.URI.class))).thenReturn(result); + connectorMock.findStatements(eq(subjectIri), eq(RDF.TYPE), + eq(vf.createIRI(ax.getValue().stringValue())), anyBoolean(), + any(org.eclipse.rdf4j.model.IRI.class))).thenReturn(result); assertTrue(adapter.contains(ax, context)); - verify(connectorMock).findStatements(subjectUri, RDF.TYPE, - vf.createURI(ax.getValue().stringValue()), ax.getAssertion().isInferred(), - vf.createURI(context.toString())); + verify(connectorMock).findStatements(subjectIri, RDF.TYPE, + vf.createIRI(ax.getValue().stringValue()), ax.getAssertion().isInferred(), + vf.createIRI(context.toString())); } @Test @@ -703,21 +701,21 @@ public void testContainsDataPropertyValue() throws Exception { new Value<>(val)); final Set result = new HashSet<>(); when( - connectorMock.findStatements(eq(subjectUri), eq(RDF.TYPE), - eq(vf.createLiteral(val)), anyBoolean(), any(org.openrdf.model.URI.class))) + connectorMock.findStatements(eq(subjectIri), eq(RDF.TYPE), + eq(vf.createLiteral(val)), anyBoolean(), any(org.eclipse.rdf4j.model.IRI.class))) .thenReturn(result); assertFalse(adapter.contains(ax, context)); verify(connectorMock) - .findStatements(subjectUri, RDF.TYPE, vf.createLiteral(val), ax.getAssertion().isInferred(), - vf.createURI(context.toString())); + .findStatements(subjectIri, RDF.TYPE, vf.createLiteral(val), ax.getAssertion().isInferred(), + vf.createIRI(context.toString())); } @Test public void updatesDataPropertyToNewValue() throws Exception { final AxiomValueDescriptor desc = new AxiomValueDescriptor(SUBJECT); final URI property = URI.create("http://krizik.felk.cvut.cz/dataProperty"); - final org.openrdf.model.URI sesameProperty = vf.createURI(property.toString()); + final org.eclipse.rdf4j.model.IRI sesameProperty = vf.createIRI(property.toString()); final boolean inferred = false; final Assertion assertion = Assertion.createDataPropertyAssertion(property, inferred); final String oldValue = "oldValue"; @@ -725,16 +723,16 @@ public void updatesDataPropertyToNewValue() throws Exception { desc.addAssertion(assertion); desc.addAssertionValue(assertion, new Value<>(newValue)); final Collection statements = Collections.singleton(vf.createStatement( - subjectUri, sesameProperty, vf.createLiteral(oldValue, "en"))); + subjectIri, sesameProperty, vf.createLiteral(oldValue, "en"))); when( - connectorMock.findStatements(eq(subjectUri), eq(sesameProperty), - any(org.openrdf.model.Value.class), eq(inferred))).thenReturn(statements); + connectorMock.findStatements(eq(subjectIri), eq(sesameProperty), + any(org.eclipse.rdf4j.model.Value.class), eq(inferred))).thenReturn(statements); adapter.update(desc); - verify(connectorMock).findStatements(subjectUri, sesameProperty, null, inferred); + verify(connectorMock).findStatements(subjectIri, sesameProperty, null, inferred); verify(connectorMock).removeStatements(statements); final Collection inserted = Collections.singletonList(vf.createStatement( - subjectUri, sesameProperty, vf.createLiteral(newValue, "en"))); + subjectIri, sesameProperty, vf.createLiteral(newValue, "en"))); verify(connectorMock).addStatements(inserted); } @@ -742,24 +740,24 @@ public void updatesDataPropertyToNewValue() throws Exception { public void updatesObjectPropertyToNewValue() throws Exception { final AxiomValueDescriptor desc = new AxiomValueDescriptor(SUBJECT); final URI property = URI.create("http://krizik.felk.cvut.cz/objectProperty"); - final org.openrdf.model.URI sesameProperty = vf.createURI(property.toString()); + final org.eclipse.rdf4j.model.IRI sesameProperty = vf.createIRI(property.toString()); final boolean inferred = false; final Assertion assertion = Assertion.createObjectPropertyAssertion(property, inferred); - final org.openrdf.model.URI oldValue = vf.createURI("http://www.old-value.org"); - final org.openrdf.model.URI newValue = vf.createURI("http://www.new-value.org"); + final org.eclipse.rdf4j.model.IRI oldValue = vf.createIRI("http://www.old-value.org"); + final org.eclipse.rdf4j.model.IRI newValue = vf.createIRI("http://www.new-value.org"); desc.addAssertion(assertion); desc.addAssertionValue(assertion, new Value<>(URI.create(newValue.stringValue()))); final Collection statements = Collections.singleton(vf.createStatement( - subjectUri, sesameProperty, oldValue)); + subjectIri, sesameProperty, oldValue)); when( - connectorMock.findStatements(eq(subjectUri), eq(sesameProperty), - any(org.openrdf.model.Value.class), eq(inferred))).thenReturn(statements); + connectorMock.findStatements(eq(subjectIri), eq(sesameProperty), + any(org.eclipse.rdf4j.model.Value.class), eq(inferred))).thenReturn(statements); adapter.update(desc); - verify(connectorMock).findStatements(subjectUri, sesameProperty, null, inferred); + verify(connectorMock).findStatements(subjectIri, sesameProperty, null, inferred); verify(connectorMock).removeStatements(statements); final Collection inserted = Collections.singletonList(vf.createStatement( - subjectUri, sesameProperty, newValue)); + subjectIri, sesameProperty, newValue)); verify(connectorMock).addStatements(inserted); } @@ -767,20 +765,20 @@ public void updatesObjectPropertyToNewValue() throws Exception { public void updatesObjectPropertyToEmptyValue() throws Exception { final AxiomValueDescriptor desc = new AxiomValueDescriptor(SUBJECT); final URI property = URI.create("http://krizik.felk.cvut.cz/objectProperty"); - final org.openrdf.model.URI sesameProperty = vf.createURI(property.toString()); + final org.eclipse.rdf4j.model.IRI sesameProperty = vf.createIRI(property.toString()); final boolean inferred = false; final Assertion assertion = Assertion.createObjectPropertyAssertion(property, inferred); - final org.openrdf.model.URI oldValue = vf.createURI("http://www.old-value.org"); + final org.eclipse.rdf4j.model.IRI oldValue = vf.createIRI("http://www.old-value.org"); desc.addAssertion(assertion); desc.addAssertionValue(assertion, Value.nullValue()); final Collection statements = Collections.singleton(vf.createStatement( - subjectUri, sesameProperty, oldValue)); + subjectIri, sesameProperty, oldValue)); when( - connectorMock.findStatements(eq(subjectUri), eq(sesameProperty), - any(org.openrdf.model.Value.class), eq(inferred))).thenReturn(statements); + connectorMock.findStatements(eq(subjectIri), eq(sesameProperty), + any(org.eclipse.rdf4j.model.Value.class), eq(inferred))).thenReturn(statements); adapter.update(desc); - verify(connectorMock).findStatements(subjectUri, sesameProperty, null, inferred); + verify(connectorMock).findStatements(subjectIri, sesameProperty, null, inferred); verify(connectorMock).removeStatements(statements); verify(connectorMock, never()).addStatements(any(Collection.class)); } @@ -800,11 +798,11 @@ public void updatesTypesInContext() throws Exception { } final Collection statements = initOldTypes(); when( - connectorMock.findStatements(eq(subjectUri), eq(RDF.TYPE), - any(org.openrdf.model.Value.class), eq(inferred))).thenReturn(statements); + connectorMock.findStatements(eq(subjectIri), eq(RDF.TYPE), + any(org.eclipse.rdf4j.model.Value.class), eq(inferred))).thenReturn(statements); adapter.update(desc); - verify(connectorMock).findStatements(subjectUri, RDF.TYPE, null, inferred); + verify(connectorMock).findStatements(subjectIri, RDF.TYPE, null, inferred); verify(connectorMock).removeStatements(statements); final Collection inserted = initNewTypes(newTypes); verify(connectorMock).addStatements(inserted); @@ -812,19 +810,19 @@ public void updatesTypesInContext() throws Exception { private Collection initOldTypes() { final Collection stmts = new HashSet<>(); - stmts.add(vf.createStatement(subjectUri, RDF.TYPE, - vf.createURI("http://krizik.felk.cvut.cz/ontologies/types#tOne"))); - stmts.add(vf.createStatement(subjectUri, RDF.TYPE, - vf.createURI("http://krizik.felk.cvut.cz/ontologies/types#tTwo"))); - stmts.add(vf.createStatement(subjectUri, RDF.TYPE, - vf.createURI("http://krizik.felk.cvut.cz/ontologies/types#tThree"))); + stmts.add(vf.createStatement(subjectIri, RDF.TYPE, + vf.createIRI("http://krizik.felk.cvut.cz/ontologies/types#tOne"))); + stmts.add(vf.createStatement(subjectIri, RDF.TYPE, + vf.createIRI("http://krizik.felk.cvut.cz/ontologies/types#tTwo"))); + stmts.add(vf.createStatement(subjectIri, RDF.TYPE, + vf.createIRI("http://krizik.felk.cvut.cz/ontologies/types#tThree"))); return stmts; } private Collection initNewTypes(String[] newTypes) { final Collection stmts = new ArrayList<>(); for (String t : newTypes) { - stmts.add(vf.createStatement(subjectUri, RDF.TYPE, vf.createURI(t))); + stmts.add(vf.createStatement(subjectIri, RDF.TYPE, vf.createIRI(t))); } return stmts; } @@ -842,13 +840,13 @@ public void unwrapReturnValueFactoryWhenItMatches() throws Exception { @Test public void containsOnDefaultContextCallsConnectorWithoutContextArgument() throws Exception { when(connectorMock - .findStatements(any(Resource.class), any(org.openrdf.model.URI.class), - any(org.openrdf.model.Value.class), anyBoolean(), anyVararg())) + .findStatements(any(Resource.class), any(org.eclipse.rdf4j.model.IRI.class), + any(org.eclipse.rdf4j.model.Value.class), anyBoolean(), anyVararg())) .thenReturn(Collections.emptyList()); final String cls = "http://krizik.felk.cvut.cz/ontologies/jopa/entities#OWLClassA"; adapter.contains(new AxiomImpl<>(SUBJECT, Assertion.createClassAssertion(false), new Value<>(URI.create(cls))), null); - verify(connectorMock).findStatements(vf.createURI(SUBJECT.toString()), RDF.TYPE, vf.createURI(cls), false); + verify(connectorMock).findStatements(vf.createIRI(SUBJECT.toString()), RDF.TYPE, vf.createIRI(cls), false); } @Test diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameAdapterWithStoreTest.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameAdapterWithStoreTest.java index 4fae17fc1..d806beab4 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameAdapterWithStoreTest.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameAdapterWithStoreTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -24,18 +24,17 @@ import cz.cvut.kbss.ontodriver.sesame.config.SesameConfigParam; import cz.cvut.kbss.ontodriver.sesame.connector.Connector; import cz.cvut.kbss.ontodriver.sesame.connector.ConnectorFactory; -import info.aduna.iteration.Iterations; +import org.eclipse.rdf4j.common.iteration.Iterations; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.vocabulary.RDF; +import org.eclipse.rdf4j.repository.Repository; +import org.eclipse.rdf4j.repository.RepositoryConnection; +import org.eclipse.rdf4j.repository.RepositoryResult; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.vocabulary.RDF; -import org.openrdf.repository.Repository; -import org.openrdf.repository.RepositoryConnection; -import org.openrdf.repository.RepositoryResult; import java.net.URI; import java.util.List; @@ -97,9 +96,8 @@ public void persistIndividualInTwoClassesInIndependentTransactionsIsPossible() t adapter.persist(dTwo); adapter.commit(); - final RepositoryConnection connection = repo.getConnection(); - try { - final Resource subj = vf.createURI(SUBJECT.getIdentifier().toString()); + try (RepositoryConnection connection = repo.getConnection()) { + final Resource subj = vf.createIRI(SUBJECT.getIdentifier().toString()); final List classAssertions = Iterations.asList(connection .getStatements(subj, RDF.TYPE, null, false)); final Set types = classAssertions.stream().map(s -> URI.create(s.getObject().stringValue())).collect( @@ -107,13 +105,11 @@ public void persistIndividualInTwoClassesInIndependentTransactionsIsPossible() t assertTrue(types.contains(tOne)); assertTrue(types.contains(tTwo)); final RepositoryResult aStringProp = connection - .getStatements(subj, vf.createURI(pOne), null, false); + .getStatements(subj, vf.createIRI(pOne), null, false); assertTrue(aStringProp.hasNext()); final RepositoryResult bStringProp = connection - .getStatements(subj, vf.createURI(pTwo), null, false); + .getStatements(subj, vf.createIRI(pTwo), null, false); assertTrue(bStringProp.hasNext()); - } finally { - connection.close(); } } } diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesamePreparedStatementTest.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesamePreparedStatementTest.java index 31c491991..3cb420e53 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesamePreparedStatementTest.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesamePreparedStatementTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -14,17 +14,16 @@ */ package cz.cvut.kbss.ontodriver.sesame; +import cz.cvut.kbss.ontodriver.PreparedStatement; import cz.cvut.kbss.ontodriver.exception.OntoDriverException; import cz.cvut.kbss.ontodriver.sesame.connector.StatementExecutor; import cz.cvut.kbss.ontodriver.sesame.query.SesamePreparedStatement; -import cz.cvut.kbss.ontodriver.PreparedStatement; +import org.eclipse.rdf4j.query.TupleQueryResult; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.openrdf.query.TupleQueryResult; -import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -47,7 +46,6 @@ public void setUp() throws Exception { @Test(expected = IllegalArgumentException.class) public void testConstructorEmptyStatement() throws Exception { initStatement(""); - fail("This line should not have been reached."); } @Test diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesamePropertiesTest.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesamePropertiesTest.java index 05540f3ac..be6e8409a 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesamePropertiesTest.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesamePropertiesTest.java @@ -21,16 +21,17 @@ import cz.cvut.kbss.ontodriver.model.Value; import cz.cvut.kbss.ontodriver.sesame.connector.Connector; import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.sail.memory.MemoryStore; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; -import org.openrdf.sail.memory.MemoryStore; import java.util.*; import java.util.stream.Collectors; @@ -49,7 +50,7 @@ public class SesamePropertiesTest { @Mock private Connector connectorMock; - private URI subject; + private IRI subject; private ValueFactory vf; private MemoryStore store; @@ -59,10 +60,8 @@ public class SesamePropertiesTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - this.store = new MemoryStore(); - store.initialize(); - this.vf = store.getValueFactory(); - this.subject = vf.createURI(SUBJECT.getIdentifier().toString()); + this.vf = SimpleValueFactory.getInstance(); + this.subject = vf.createIRI(SUBJECT.getIdentifier().toString()); final SesameAdapter adapterMock = mock(SesameAdapter.class); when(adapterMock.getConnector()).thenReturn(connectorMock); when(adapterMock.getValueFactory()).thenReturn(vf); @@ -70,11 +69,6 @@ public void setUp() throws Exception { this.properties = new SesameProperties(adapterMock, () -> {}, () -> {}); } - @After - public void tearDown() throws Exception { - store.shutDown(); - } - @Test public void testGetProperties() throws Exception { final Collection statements = statementsForProperties(initProperties()); @@ -84,7 +78,7 @@ public void testGetProperties() throws Exception { assertEquals(statements.size(), result.size()); for (Axiom ax : result) { assertEquals(SUBJECT, ax.getSubject()); - final Statement stmt = vf.createStatement(subject, vf.createURI(ax.getAssertion().getIdentifier().toString()), + final Statement stmt = vf.createStatement(subject, vf.createIRI(ax.getAssertion().getIdentifier().toString()), SesameUtils.createDataPropertyLiteral(ax.getValue().getValue(), LANG, vf)); assertTrue(statements.contains(stmt)); } @@ -117,7 +111,7 @@ private Map>> initProperties() { private Collection statementsForProperties(Map>> properties) { final Collection stmts = new HashSet<>(); for (Assertion a : properties.keySet()) { - final URI property = vf.createURI(a.getIdentifier().toString()); + final IRI property = vf.createIRI(a.getIdentifier().toString()); stmts.addAll(properties.get(a).stream().map(v -> vf .createStatement(subject, property, SesameUtils.createDataPropertyLiteral(v.getValue(), LANG, vf))) .collect(Collectors.toList())); diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameStatementTest.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameStatementTest.java index 8a6b0e557..2f9cebae1 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameStatementTest.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameStatementTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -14,25 +14,21 @@ */ package cz.cvut.kbss.ontodriver.sesame; +import cz.cvut.kbss.ontodriver.ResultSet; import cz.cvut.kbss.ontodriver.sesame.connector.StatementExecutor; import cz.cvut.kbss.ontodriver.sesame.query.AskResultSet; import cz.cvut.kbss.ontodriver.sesame.query.SelectResultSet; import cz.cvut.kbss.ontodriver.sesame.query.SesameStatement; -import cz.cvut.kbss.ontodriver.ResultSet; +import org.eclipse.rdf4j.query.TupleQueryResult; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.openrdf.query.TupleQueryResult; -import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.*; -/** - * @author kidney - */ public class SesameStatementTest { private static final String SELECT_ENTITY_QUERY = "SELECT ?x WHERE { ?x a . }"; diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameUtilsTest.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameUtilsTest.java index 9d1a2cfbc..0ed75fb13 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameUtilsTest.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameUtilsTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -15,13 +15,13 @@ package cz.cvut.kbss.ontodriver.sesame; import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; +import org.eclipse.rdf4j.model.Literal; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.vocabulary.XMLSchema; +import org.eclipse.rdf4j.sail.memory.MemoryStore; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.openrdf.model.Literal; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.vocabulary.XMLSchema; -import org.openrdf.sail.memory.MemoryStore; import static org.junit.Assert.*; diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameValueConverterTest.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameValueConverterTest.java index 09704b9d0..f50be6f9a 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameValueConverterTest.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SesameValueConverterTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -17,11 +17,11 @@ import cz.cvut.kbss.ontodriver.model.Assertion; import cz.cvut.kbss.ontodriver.model.NamedResource; import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; +import org.eclipse.rdf4j.model.Literal; +import org.eclipse.rdf4j.model.Value; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.junit.Before; import org.junit.Test; -import org.openrdf.model.Literal; -import org.openrdf.model.Value; -import org.openrdf.model.impl.ValueFactoryImpl; import java.net.URI; @@ -37,14 +37,14 @@ public class SesameValueConverterTest { @Before public void setUp() { - this.converter = new SesameValueConverter(new ValueFactoryImpl(), LANG); + this.converter = new SesameValueConverter(SimpleValueFactory.getInstance(), LANG); } @Test public void convertsObjectPropertyNamedResourceToSesameUri() throws Exception { final Value res = converter.toSesameValue(assertion(Assertion.AssertionType.OBJECT_PROPERTY), value(NamedResource.create("http://krizik.felk.cvut.cz/ontologies/jopa#individual"))); - assertTrue(res instanceof org.openrdf.model.URI); + assertTrue(res instanceof org.eclipse.rdf4j.model.IRI); } private Assertion assertion(Assertion.AssertionType type) { @@ -82,7 +82,7 @@ public void convertsAnnotationPropertyLiteralValueToSesameLiteral() throws Excep final Value res = converter.toSesameValue(assertion(Assertion.AssertionType.ANNOTATION_PROPERTY), value(val)); assertTrue(res instanceof Literal); assertEquals(val, ((Literal) res).getLabel()); - assertEquals(LANG, ((Literal) res).getLanguage()); + assertEquals(LANG, ((Literal) res).getLanguage().orElse("")); } @Test @@ -90,7 +90,7 @@ public void convertsAnnotationPropertyNamedResourceToSesameUri() throws Exceptio final NamedResource val = NamedResource .create("http://krizik.felk.cvut.cz/ontologies/jopa#individualAnnotation"); final Value res = converter.toSesameValue(assertion(Assertion.AssertionType.ANNOTATION_PROPERTY), value(val)); - assertTrue(res instanceof org.openrdf.model.URI); + assertTrue(res instanceof org.eclipse.rdf4j.model.IRI); assertEquals(val.toString(), res.toString()); } diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SimpleListHandlerTest.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SimpleListHandlerTest.java index 82ff7d54b..e0b9806b2 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SimpleListHandlerTest.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/SimpleListHandlerTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -24,16 +24,15 @@ import cz.cvut.kbss.ontodriver.sesame.connector.Connector; import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils; -import org.junit.AfterClass; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.Value; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.Value; import java.util.*; @@ -45,8 +44,8 @@ @SuppressWarnings({"unchecked"}) public class SimpleListHandlerTest extends ListHandlerTestBase { - protected static URI hasSimpleListProperty; - protected static URI nextNodeProperty; + private static IRI hasSimpleListProperty; + private static IRI nextNodeProperty; @Mock private Connector connector; @@ -61,8 +60,8 @@ public class SimpleListHandlerTest extends ListHandlerTestBase { @BeforeClass public static void setUpBeforeClass() throws Exception { init(); - hasSimpleListProperty = vf.createURI(LIST_PROPERTY); - nextNodeProperty = vf.createURI(NEXT_NODE_PROPERTY); + hasSimpleListProperty = vf.createIRI(LIST_PROPERTY); + nextNodeProperty = vf.createIRI(NEXT_NODE_PROPERTY); } @Before @@ -87,11 +86,6 @@ public void setUp() throws Exception { this.handler = new SimpleListHandler(connector, vf); } - @AfterClass - public static void tearDownAfterClass() throws Exception { - close(); - } - @Test public void staticFactoryMethodForSimpleLists() throws Exception { final ListHandler h = ListHandler.createForSimpleList(connector, vf); @@ -101,13 +95,13 @@ public void staticFactoryMethodForSimpleLists() throws Exception { @Test public void loadsEmptyListAndReturnsEmptyCollection() throws Exception { - when(connector.findStatements(owner, hasSimpleListProperty, null, false, (URI[]) null)) - .thenReturn(Collections.emptyList()); + when(connector.findStatements(owner, hasSimpleListProperty, null, false, (IRI[]) null)) + .thenReturn(Collections.emptyList()); final Collection> res = handler.loadList(listDescriptor); assertNotNull(res); assertTrue(res.isEmpty()); verify(connector, never()).findStatements(any(Resource.class), eq(nextNodeProperty), - any(Value.class), any(Boolean.class), eq((URI[]) null)); + any(Value.class), any(Boolean.class), eq(null)); } @Test @@ -116,7 +110,7 @@ public void loadsSimpleList() throws Exception { initStatementsForList(simpleList); final Collection> res = handler.loadList(listDescriptor); - verify(connector).findStatements(owner, hasSimpleListProperty, null, false, (URI[]) null); + verify(connector).findStatements(owner, hasSimpleListProperty, null, false, (IRI[]) null); assertEquals(simpleList.size(), res.size()); int i = 0; for (Axiom ax : res) { @@ -131,10 +125,10 @@ private List initStatementsForList(List simpleList) final List statements = new ArrayList<>(simpleList.size()); for (NamedResource elem : simpleList) { Statement stmt; - final Resource value = vf.createURI(elem.toString()); - final URI property = subject == owner ? hasSimpleListProperty : nextNodeProperty; + final Resource value = vf.createIRI(elem.toString()); + final IRI property = subject == owner ? hasSimpleListProperty : nextNodeProperty; stmt = vf.createStatement(subject, property, value); - when(connector.findStatements(subject, property, null, false, (URI[]) null)) + when(connector.findStatements(subject, property, null, false, (IRI[]) null)) .thenReturn(Collections.singleton(stmt)); statements.add(stmt); subject = value; @@ -147,14 +141,13 @@ public void throwsICViolationExceptionWhenMultipleHasListValuesFound() throws Ex final Collection stmts = new HashSet<>(); stmts.add(mock(Statement.class)); stmts.add(mock(Statement.class)); - when(connector.findStatements(owner, hasSimpleListProperty, null, false, (URI[]) null)) - .thenReturn(stmts); + when(connector.findStatements(owner, hasSimpleListProperty, null, false, (IRI[]) null)).thenReturn(stmts); try { handler.loadList(listDescriptor); } finally { verify(connector, never()).findStatements(any(Resource.class), eq(nextNodeProperty), - any(Value.class), any(Boolean.class), any(URI[].class)); + any(Value.class), any(Boolean.class), any(IRI[].class)); } } @@ -164,41 +157,37 @@ public void throwsICViolationExceptionWhenMultipleNodeSuccessorsAreFound() throw stmts.add(mock(Statement.class)); stmts.add(mock(Statement.class)); final Resource firstElem = vf - .createURI("http://krizik.felk.cvut.cz/ontologies/jopa/firstElem"); + .createIRI("http://krizik.felk.cvut.cz/ontologies/jopa/firstElem"); final Statement firstStmt = vf.createStatement(owner, hasSimpleListProperty, firstElem); - when(connector.findStatements(owner, hasSimpleListProperty, null, false, (URI[]) null)) + when(connector.findStatements(owner, hasSimpleListProperty, null, false, (IRI[]) null)) .thenReturn(Collections.singleton(firstStmt)); - when(connector.findStatements(firstElem, nextNodeProperty, null, false, (URI[]) null)) - .thenReturn(stmts); + when(connector.findStatements(firstElem, nextNodeProperty, null, false, (IRI[]) null)).thenReturn(stmts); try { handler.loadList(listDescriptor); } finally { - verify(connector).findStatements(owner, hasSimpleListProperty, null, false, - (URI[]) null); + verify(connector).findStatements(owner, hasSimpleListProperty, null, false, (IRI[]) null); } } @Test(expected = IntegrityConstraintViolatedException.class) public void throwsICViolationExceptionWhenLiteralIsFoundInList() throws Exception { final Resource firstElem = vf - .createURI("http://krizik.felk.cvut.cz/ontologies/jopa/firstElem"); + .createIRI("http://krizik.felk.cvut.cz/ontologies/jopa/firstElem"); final Statement firstStmt = vf.createStatement(owner, hasSimpleListProperty, firstElem); - when(connector.findStatements(owner, hasSimpleListProperty, null, false, (URI[]) null)) + when(connector.findStatements(owner, hasSimpleListProperty, null, false, (IRI[]) null)) .thenReturn(Collections.singleton(firstStmt)); final Statement nextStmt = vf.createStatement(firstElem, nextNodeProperty, vf.createLiteral(System.currentTimeMillis())); - when(connector.findStatements(firstElem, nextNodeProperty, null, false, (URI[]) null)) + when(connector.findStatements(firstElem, nextNodeProperty, null, false, (IRI[]) null)) .thenReturn(Collections.singleton(nextStmt)); try { handler.loadList(listDescriptor); } finally { - verify(connector).findStatements(owner, hasSimpleListProperty, null, false, - (URI[]) null); - verify(connector) - .findStatements(firstElem, nextNodeProperty, null, false, (URI[]) null); + verify(connector).findStatements(owner, hasSimpleListProperty, null, false, (IRI[]) null); + verify(connector).findStatements(firstElem, nextNodeProperty, null, false, (IRI[]) null); } } @@ -231,8 +220,7 @@ private static SimpleListValueDescriptor initValues(int count) { Assertion.createObjectPropertyAssertion(java.net.URI.create(NEXT_NODE_PROPERTY), false)); for (int i = 0; i < count; i++) { - desc.addValue(NamedResource - .create("http://krizik.felk.cvut.cz/ontologies/jopa/entityA_" + i)); + desc.addValue(NamedResource.create("http://krizik.felk.cvut.cz/ontologies/jopa/entityA_" + i)); } return desc; } @@ -254,8 +242,7 @@ public void insertsListOnUpdateWhenThereWereNoValuesBefore() throws Exception { final SimpleListValueDescriptor descriptor = initValues(5); when( connector.findStatements(owner, hasSimpleListProperty, null, descriptor - .getListProperty().isInferred(), (URI[]) null)).thenReturn( - Collections.emptyList()); + .getListProperty().isInferred(), (IRI[]) null)).thenReturn(Collections.emptyList()); handler.updateList(descriptor); verify(connector, never()).removeStatements(any(Collection.class)); @@ -324,7 +311,7 @@ public void updateListRemovesSeveralElements() throws Exception { assertTrue(foundAsSubject); for (Statement add : added) { if (add.getObject().stringValue().equals(uri.toString())) { - fail("Found uri which shouln't have been added. " + uri); + fail("Found uri which shouldn't have been added. " + uri); } } // Make sure that all the retained nodes were added diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/TypesHandlerTest.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/TypesHandlerTest.java index 3e807d51f..582797fff 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/TypesHandlerTest.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/TypesHandlerTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -17,20 +17,17 @@ import cz.cvut.kbss.ontodriver.model.Axiom; import cz.cvut.kbss.ontodriver.model.NamedResource; import cz.cvut.kbss.ontodriver.sesame.connector.Connector; -import org.junit.AfterClass; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.model.vocabulary.RDF; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.vocabulary.RDF; -import org.openrdf.repository.Repository; -import org.openrdf.repository.sail.SailRepository; -import org.openrdf.sail.memory.MemoryStore; import java.util.Collection; import java.util.Collections; @@ -48,7 +45,6 @@ public class TypesHandlerTest { private static final String TYPE_BASE = "http://krizik.felk.cvut.cz/ontologies/jopa/type"; private static final NamedResource NAMED_PK = NamedResource.create(STR_PK); - private static Repository repo; private static ValueFactory vf; @Mock @@ -58,10 +54,7 @@ public class TypesHandlerTest { @BeforeClass public static void setUpBeforeClass() throws Exception { - final MemoryStore mStore = new MemoryStore(); - repo = new SailRepository(mStore); - repo.initialize(); - vf = repo.getValueFactory(); + vf = SimpleValueFactory.getInstance(); } @Before @@ -70,15 +63,11 @@ public void setUp() throws Exception { this.handler = new TypesHandler(connectorMock, vf); } - @AfterClass - public static void tearDownAfterClass() throws Exception { - repo.shutDown(); - } - @Test public void getsTypesWithoutContext() throws Exception { final Collection statements = initStatements(null); - when(connectorMock.findStatements(vf.createURI(STR_PK), RDF.TYPE, null, false, (URI[]) null)).thenReturn(statements); + when(connectorMock.findStatements(vf.createIRI(STR_PK), RDF.TYPE, null, false, (IRI[]) null)) + .thenReturn(statements); final Set> res = handler.getTypes(NamedResource.create(STR_PK), null, false); assertEquals(statements.size(), res.size()); final Set uris = new HashSet<>(); @@ -90,11 +79,11 @@ public void getsTypesWithoutContext() throws Exception { } } - private Collection initStatements(URI context) { + private Collection initStatements(IRI context) { final Collection statements = new HashSet<>(); - final URI subject = vf.createURI(STR_PK); + final IRI subject = vf.createIRI(STR_PK); for (int i = 0; i < 6; i++) { - final Statement stmt = vf.createStatement(subject, RDF.TYPE, vf.createURI(TYPE_BASE + i), context); + final Statement stmt = vf.createStatement(subject, RDF.TYPE, vf.createIRI(TYPE_BASE + i), context); statements.add(stmt); } return statements; @@ -102,10 +91,11 @@ private Collection initStatements(URI context) { @Test public void getsTypesIncludingInferredAndInContext() throws Exception { - final URI context = vf.createURI("http://krizik.felk.cvut.cz/ontologies/contextOne"); + final IRI context = vf.createIRI("http://krizik.felk.cvut.cz/ontologies/contextOne"); final Collection statements = initStatements(context); - when(connectorMock.findStatements(vf.createURI(STR_PK), RDF.TYPE, null, true, context)).thenReturn(statements); - final Set> res = handler.getTypes(NAMED_PK, java.net.URI.create(context.stringValue()), true); + when(connectorMock.findStatements(vf.createIRI(STR_PK), RDF.TYPE, null, true, context)).thenReturn(statements); + final Set> res = handler + .getTypes(NAMED_PK, java.net.URI.create(context.stringValue()), true); assertEquals(statements.size(), res.size()); final Set uris = new HashSet<>(); for (Axiom u : res) { @@ -114,12 +104,13 @@ public void getsTypesIncludingInferredAndInContext() throws Exception { for (Statement stmt : statements) { assertTrue(uris.contains(java.net.URI.create(stmt.getObject().stringValue()))); } - verify(connectorMock).findStatements(vf.createURI(STR_PK), RDF.TYPE, null, true, context); + verify(connectorMock).findStatements(vf.createIRI(STR_PK), RDF.TYPE, null, true, context); } @Test public void getsEmptyTypes() throws Exception { - when(connectorMock.findStatements(vf.createURI(STR_PK), RDF.TYPE, null, false, (URI[]) null)).thenReturn(Collections.emptySet()); + when(connectorMock.findStatements(vf.createIRI(STR_PK), RDF.TYPE, null, false, (IRI[]) null)) + .thenReturn(Collections.emptySet()); final Set> res = handler.getTypes(NamedResource.create(STR_PK), null, true); assertTrue(res.isEmpty()); } diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/connector/PoolingStorageConnectorTest.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/connector/PoolingStorageConnectorTest.java index 4cf526f24..3fb852ce4 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/connector/PoolingStorageConnectorTest.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/connector/PoolingStorageConnectorTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -14,24 +14,24 @@ */ package cz.cvut.kbss.ontodriver.sesame.connector; -import cz.cvut.kbss.ontodriver.sesame.environment.TestUtils; import cz.cvut.kbss.ontodriver.sesame.Transaction; import cz.cvut.kbss.ontodriver.sesame.TransactionState; +import cz.cvut.kbss.ontodriver.sesame.environment.TestUtils; import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; -import info.aduna.iteration.CloseableIteration; +import org.eclipse.rdf4j.common.iteration.CloseableIteration; +import org.eclipse.rdf4j.model.*; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.query.BooleanQuery; +import org.eclipse.rdf4j.query.QueryLanguage; +import org.eclipse.rdf4j.query.TupleQuery; +import org.eclipse.rdf4j.repository.RepositoryConnection; +import org.eclipse.rdf4j.repository.RepositoryException; +import org.eclipse.rdf4j.repository.RepositoryResult; import org.junit.Before; import org.junit.Test; import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.openrdf.model.*; -import org.openrdf.model.impl.ValueFactoryImpl; -import org.openrdf.query.BooleanQuery; -import org.openrdf.query.QueryLanguage; -import org.openrdf.query.TupleQuery; -import org.openrdf.repository.RepositoryConnection; -import org.openrdf.repository.RepositoryException; -import org.openrdf.repository.RepositoryResult; import java.lang.reflect.Field; import java.util.Collection; @@ -275,13 +275,13 @@ public void transactionRollbackReleasesRepositoryConnection() throws Exception { @Test public void findStatementsReusesRepositoryConnectionDuringTransaction() throws Exception { - final ValueFactory vf = new ValueFactoryImpl(); + final ValueFactory vf = SimpleValueFactory.getInstance(); final RepositoryConnection conn = mock(RepositoryConnection.class); - when(conn.getStatements(any(Resource.class), any(URI.class), any(Value.class), anyBoolean())) + when(conn.getStatements(any(Resource.class), any(IRI.class), any(Value.class), anyBoolean())) .thenReturn(new RepositoryResult<>(mock(CloseableIteration.class))); when(centralMock.acquireConnection()).thenReturn(conn); - final Resource res = vf.createURI(TestUtils.randomUri()); - final URI property = vf.createURI(TestUtils.randomUri()); + final Resource res = vf.createIRI(TestUtils.randomUri()); + final IRI property = vf.createIRI(TestUtils.randomUri()); connector.begin(); connector.findStatements(res, property, null, false); verify(centralMock).acquireConnection(); @@ -290,17 +290,17 @@ public void findStatementsReusesRepositoryConnectionDuringTransaction() throws E @Test(expected = SesameDriverException.class) public void exceptionInFindStatementsCausesTransactionRollback() throws Exception { - final ValueFactory vf = new ValueFactoryImpl(); + final ValueFactory vf = SimpleValueFactory.getInstance(); final RepositoryConnection conn = mock(RepositoryConnection.class); - when(conn.getStatements(any(Resource.class), any(URI.class), any(Value.class), anyBoolean())) + when(conn.getStatements(any(Resource.class), any(IRI.class), any(Value.class), anyBoolean())) .thenThrow(new RepositoryException()); when(centralMock.acquireConnection()).thenReturn(conn); - final Resource res = vf.createURI(TestUtils.randomUri()); - final URI property = vf.createURI(TestUtils.randomUri()); + final Resource res = vf.createIRI(TestUtils.randomUri()); + final IRI property = vf.createIRI(TestUtils.randomUri()); final Connector spy = spy(connector); doCallRealMethod().when(spy).begin(); spy.begin(); - when(spy.findStatements(any(Resource.class), any(URI.class), any(Value.class), anyBoolean())) + when(spy.findStatements(any(Resource.class), any(IRI.class), any(Value.class), anyBoolean())) .thenCallRealMethod(); try { spy.findStatements(res, property, null, false); diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/connector/StorageConnectorTest.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/connector/StorageConnectorTest.java index aa7b295ab..030b19d8b 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/connector/StorageConnectorTest.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/connector/StorageConnectorTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -20,15 +20,15 @@ import cz.cvut.kbss.ontodriver.sesame.config.SesameConfigParam; import cz.cvut.kbss.ontodriver.sesame.exceptions.RepositoryCreationException; import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException; +import org.eclipse.rdf4j.repository.Repository; +import org.eclipse.rdf4j.repository.config.RepositoryConfig; +import org.eclipse.rdf4j.repository.manager.RepositoryManager; +import org.eclipse.rdf4j.repository.manager.RepositoryProvider; +import org.eclipse.rdf4j.repository.sail.config.SailRepositoryConfig; +import org.eclipse.rdf4j.sail.config.SailImplConfig; +import org.eclipse.rdf4j.sail.nativerdf.config.NativeStoreConfig; import org.junit.After; import org.junit.Test; -import org.openrdf.repository.Repository; -import org.openrdf.repository.config.RepositoryConfig; -import org.openrdf.repository.manager.RepositoryManager; -import org.openrdf.repository.manager.RepositoryProvider; -import org.openrdf.repository.sail.config.SailRepositoryConfig; -import org.openrdf.sail.config.SailImplConfig; -import org.openrdf.sail.nativerdf.config.NativeStoreConfig; import java.io.File; import java.net.URI; @@ -109,8 +109,7 @@ public void connectorIsAbleToConnectToAlreadyInitializedLocalNativeStorage() thr SailImplConfig backend = new NativeStoreConfig(); final SailRepositoryConfig repoType = new SailRepositoryConfig(backend); final RepositoryConfig config = new RepositoryConfig(repoId, repoType); - final RepositoryManager repoManager = RepositoryProvider - .getRepositoryManagerOfRepository(repoUri.toASCIIString()); + final RepositoryManager repoManager = RepositoryProvider.getRepositoryManagerOfRepository(repoUri.toString()); repoManager.addRepositoryConfig(config); final Repository repo = repoManager.getRepository(repoId); repo.initialize(); diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/environment/Generator.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/environment/Generator.java index 66e0da967..6be096405 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/environment/Generator.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/environment/Generator.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -16,12 +16,12 @@ import cz.cvut.kbss.ontodriver.model.Assertion; import cz.cvut.kbss.ontodriver.model.NamedResource; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.vocabulary.RDF; -import org.openrdf.repository.Repository; -import org.openrdf.repository.RepositoryConnection; -import org.openrdf.repository.RepositoryException; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.vocabulary.RDF; +import org.eclipse.rdf4j.repository.Repository; +import org.eclipse.rdf4j.repository.RepositoryConnection; +import org.eclipse.rdf4j.repository.RepositoryException; import java.util.*; @@ -43,9 +43,9 @@ public static GeneratedData initTestData(Repository repository) throws Repositor for (int j = 0; j < individualCount; j++) { final String ind = cls + "_instance-" + RAND.nextInt(); data.individuals.add(ind); - final URI indUri = vf.createURI(ind); + final IRI indUri = vf.createIRI(ind); generatePropertiesWithValues(indUri, data, connection); - connection.add(indUri, RDF.TYPE, vf.createURI(cls)); + connection.add(indUri, RDF.TYPE, vf.createIRI(cls)); data.addValue(ind, Assertion.createClassAssertion(false), java.net.URI.create(cls)); } } @@ -55,13 +55,13 @@ public static GeneratedData initTestData(Repository repository) throws Repositor return data; } - private static void generatePropertiesWithValues(URI individual, GeneratedData data, + private static void generatePropertiesWithValues(IRI individual, GeneratedData data, RepositoryConnection connection) throws RepositoryException { final ValueFactory vf = connection.getValueFactory(); final int propCount = randomPositiveInt(20); for (int i = 0; i < propCount; i++) { final String property = "http://krizik.felk.cvut.cz/ontologies/jopa/attributes#property" + RAND.nextInt(); - final URI propertyUri = vf.createURI(property); + final IRI propertyUri = vf.createIRI(property); final int valueCount = randomPositiveInt(5); final boolean isOp = RAND.nextBoolean(); for (int j = 0; j < valueCount; j++) { @@ -69,7 +69,7 @@ private static void generatePropertiesWithValues(URI individual, GeneratedData d final Assertion a = Assertion.createObjectPropertyAssertion(java.net.URI.create(property), false); final String object = "http://krizik.felk.cvut.cz/ontologies/jopa/entities#OWLClassXY_instance" + RAND.nextInt(); - connection.add(individual, propertyUri, vf.createURI(object)); + connection.add(individual, propertyUri, vf.createIRI(object)); data.addValue(individual.toString(), a, NamedResource.create(object)); } else { final Assertion a = Assertion.createDataPropertyAssertion(java.net.URI.create(property), false); diff --git a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/query/SelectResultSetTest.java b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/query/SelectResultSetTest.java index 749b0e8f8..acdb1259f 100644 --- a/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/query/SelectResultSetTest.java +++ b/ontodriver-sesame/src/test/java/cz/cvut/kbss/ontodriver/sesame/query/SelectResultSetTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2016 Czech Technical University in Prague - * + *

* This program is free software: you can redistribute it and/or modify it under * the terms of the GNU 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 General Public License for more @@ -16,14 +16,14 @@ import cz.cvut.kbss.ontodriver.ResultSet; import cz.cvut.kbss.ontodriver.Statement; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.query.BindingSet; +import org.eclipse.rdf4j.query.TupleQueryResult; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.ValueFactoryImpl; -import org.openrdf.query.BindingSet; -import org.openrdf.query.TupleQueryResult; import java.net.URI; import java.util.Arrays; @@ -43,7 +43,7 @@ public class SelectResultSetTest { @Mock private Statement statementMock; - private ValueFactory valueFactory = new ValueFactoryImpl(); + private ValueFactory valueFactory = SimpleValueFactory.getInstance(); private ResultSet resultSet; @@ -61,21 +61,20 @@ public void setUp() throws Exception { public void getObjectOnLiteralReturnsCorrespondingJavaLiteral() throws Exception { final String x = "String"; when(bindingSetMock.getValue("x")).thenReturn(valueFactory.createLiteral(x)); - final Boolean y = false; - when(bindingSetMock.getValue("y")).thenReturn(valueFactory.createLiteral(y)); + when(bindingSetMock.getValue("y")).thenReturn(valueFactory.createLiteral(false)); final Integer z = 117; when(bindingSetMock.getValue("z")).thenReturn(valueFactory.createLiteral(z)); resultSet.next(); assertEquals(x, resultSet.getObject(0)); - assertEquals(y, resultSet.getObject("y")); + assertFalse((Boolean) resultSet.getObject("y")); assertEquals(z, resultSet.getObject(2)); } @Test public void getObjectOnSesameUriReturnsJavaUri() throws Exception { final URI x = URI.create("http://krizik.felk.cvut.cz/ontologies/jopa#John117"); - when(bindingSetMock.getValue("x")).thenReturn(valueFactory.createURI(x.toString())); + when(bindingSetMock.getValue("x")).thenReturn(valueFactory.createIRI(x.toString())); resultSet.next(); assertEquals(x, resultSet.getObject(0)); @@ -92,7 +91,7 @@ public void getObjectOnBlankNodeReturnsItAsString() throws Exception { @Test public void getObjectTypedOnUriReturnsUriWhenAskedForUri() throws Exception { final URI x = URI.create("http://krizik.felk.cvut.cz/ontologies/jopa#John117"); - when(bindingSetMock.getValue("x")).thenReturn(valueFactory.createURI(x.toString())); + when(bindingSetMock.getValue("x")).thenReturn(valueFactory.createIRI(x.toString())); resultSet.next(); assertEquals(x, resultSet.getObject(0, URI.class));