Skip to content

Commit

Permalink
protegeproject#6 bumped owlapi to v5, got compilation errors fixed [WIP]
Browse files Browse the repository at this point in the history
Signed-off-by: Jeen Broekstra <jeen.broekstra@gmail.com>
  • Loading branch information
abrokenjester committed Nov 17, 2018
1 parent f2eece0 commit 9ed3cac
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 123 deletions.
7 changes: 3 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,16 @@
</scm>

<properties>
<logback.version>1.1.3</logback.version>
<slf4j.version>1.7.12</slf4j.version>
<owlapi.version>4.2.8</owlapi.version>
<owlapi.version>5.1.7</owlapi.version>
<rdf4j.version>2.4.1</rdf4j.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-bom</artifactId>
<version>2.4.1</version>
<version>${rdf4j.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/protege/owl/rdf/Utilities.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.protege.owl.rdf;

import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.sail.SailRepository;
import org.openrdf.sail.Sail;
import org.openrdf.sail.memory.MemoryStore;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryException;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.sail.Sail;
import org.eclipse.rdf4j.sail.memory.MemoryStore;
import org.protege.owl.rdf.api.OwlTripleStore;
import org.protege.owl.rdf.impl.OwlTripleStoreImpl;
import org.protege.owl.rdf.impl.SynchronizeTripleStoreListener;
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/protege/owl/rdf/api/OwlTripleStore.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.protege.owl.rdf.api;

import info.aduna.iteration.CloseableIteration;

import org.openrdf.model.BNode;
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryException;
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.model.BNode;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryException;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLOntologyID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObject;
import org.semanticweb.owlapi.model.OWLOntologyID;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.util.OWLObjectDuplicator;

public class AnonymousResourceHandler {
Expand Down Expand Up @@ -108,15 +109,15 @@ private Set<OWLAnnotation> duplicateAxiomAnnotations(OWLAxiom axiom, OWLObjectDu

private class SurrogateInserter extends OWLObjectDuplicator {
public SurrogateInserter(OWLDataFactory factory) {
super(factory);
super((OWLOntologyManager)factory);
}

public void visit(OWLAnonymousIndividual i) {
public OWLAnonymousIndividual visit(OWLAnonymousIndividual i) {
IRI iri = getSurrogateId(i);
setLastObject(factory.getOWLNamedIndividual(iri));
return (OWLAnonymousIndividual)t(factory.getOWLNamedIndividual(iri));
}

public void visit(OWLAnnotationAssertionAxiom axiom) {
public OWLAnnotationAssertionAxiom visit(OWLAnnotationAssertionAxiom axiom) {
OWLObject rawSubject = duplicateObject(axiom.getSubject());
OWLAnnotationSubject subject;
if (rawSubject instanceof OWLNamedIndividual) {
Expand All @@ -134,10 +135,10 @@ public void visit(OWLAnnotationAssertionAxiom axiom) {
else {
value = (OWLAnnotationValue) rawValue;
}
setLastObject(factory.getOWLAnnotationAssertionAxiom(prop, subject, value, duplicateAxiomAnnotations(axiom, this)));
return t(factory.getOWLAnnotationAssertionAxiom(prop, subject, value, duplicateAxiomAnnotations(axiom, this)));
}

public void visit(OWLAnnotation node) {
public OWLAnnotation visit(OWLAnnotation node) {
OWLAnnotationProperty prop = duplicateObject(node.getProperty());
OWLObject rawValue = duplicateObject(node.getValue());
OWLAnnotationValue val;
Expand All @@ -147,27 +148,27 @@ public void visit(OWLAnnotation node) {
else {
val = (OWLAnnotationValue) rawValue;
}
setLastObject(factory.getOWLAnnotation(prop, val));
return t(factory.getOWLAnnotation(prop, val));
}

}

private class SurrogateRemover extends OWLObjectDuplicator {

public SurrogateRemover(OWLDataFactory factory) {
super(factory);
super((OWLOntologyManager)factory);
}

public void visit(OWLNamedIndividual i) {
public OWLNamedIndividual visit(OWLNamedIndividual i) {
if (isSurrogate(i.getIRI())) {
setLastObject(getAnonymousIndividual(i.getIRI()));
return (OWLNamedIndividual)t(getAnonymousIndividual(i.getIRI()));
}
else {
setLastObject(i);
return t(i);
}
}

public void visit(OWLAnnotationAssertionAxiom axiom) {
public OWLAnnotationAssertionAxiom visit(OWLAnnotationAssertionAxiom axiom) {
OWLAnnotationSubject subject = duplicateObject(axiom.getSubject());
if (subject instanceof IRI && isSurrogate((IRI) subject)) {
subject = getAnonymousIndividual((IRI) subject);
Expand All @@ -177,17 +178,17 @@ public void visit(OWLAnnotationAssertionAxiom axiom) {
if (value instanceof IRI && isSurrogate((IRI) value)) {
value = getAnonymousIndividual((IRI) value);
}
setLastObject(factory.getOWLAnnotationAssertionAxiom(prop, subject, value, duplicateAxiomAnnotations(axiom, this)));
return t(factory.getOWLAnnotationAssertionAxiom(prop, subject, value, duplicateAxiomAnnotations(axiom, this)));
}

public void visit(OWLAnnotation node) {
public OWLAnnotation visit(OWLAnnotation node) {
node.getProperty().accept(this);
OWLAnnotationProperty prop = (OWLAnnotationProperty) duplicateObject(node.getProperty());
OWLAnnotationValue val = (OWLAnnotationValue) duplicateObject(node.getValue());
if (val instanceof IRI && isSurrogate((IRI) val)) {
val = getAnonymousIndividual((IRI) val);
}
setLastObject(factory.getOWLAnnotation(prop, val));
return t(factory.getOWLAnnotation(prop, val));
}
}
}
90 changes: 46 additions & 44 deletions src/main/java/org/protege/owl/rdf/impl/OwlTripleStoreImpl.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package org.protege.owl.rdf.impl;

import info.aduna.iteration.CloseableIteration;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.UUID;

import org.openrdf.model.BNode;
import org.openrdf.model.Statement;
import org.openrdf.model.ValueFactory;
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.RepositoryResult;
import org.openrdf.rio.RDFHandlerException;
import org.openrdf.rio.RDFWriter;
import org.openrdf.rio.rdfxml.RDFXMLWriter;
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.model.BNode;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.URI;
import org.eclipse.rdf4j.model.ValueFactory;
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.RDFHandlerException;
import org.eclipse.rdf4j.rio.RDFWriter;
import org.eclipse.rdf4j.rio.rdfxml.RDFXMLWriter;
import org.protege.owl.rdf.api.OwlTripleStore;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
Expand Down Expand Up @@ -48,10 +50,10 @@ public class OwlTripleStoreImpl implements OwlTripleStore {
public static final String BNODE_PREFIX = "_:BNode";


private org.openrdf.model.URI hashCodeProperty;
private org.openrdf.model.URI sourceOntologyProperty;
private org.openrdf.model.URI ontologyIdProperty;
private org.openrdf.model.URI ontologyVersionProperty;
private org.eclipse.rdf4j.model.URI hashCodeProperty;
private org.eclipse.rdf4j.model.URI sourceOntologyProperty;
private org.eclipse.rdf4j.model.URI ontologyIdProperty;
private org.eclipse.rdf4j.model.URI ontologyVersionProperty;

private Repository repository;
private AnonymousResourceHandler anonymousHandler;
Expand Down Expand Up @@ -92,7 +94,7 @@ public Repository getRepository() {
@Override
public void addAxiom(OWLOntologyID ontologyId, OWLAxiom axiom) throws RepositoryException {
axiom = anonymousHandler.insertSurrogates(axiom);
org.openrdf.model.URI ontologyRepresentative = getOntologyRepresentative(ontologyId);
URI ontologyRepresentative = getOntologyRepresentative(ontologyId);
if (getAxiomId(ontologyId, axiom) != null) {
return;
}
Expand All @@ -102,7 +104,7 @@ public void addAxiom(OWLOntologyID ontologyId, OWLAxiom axiom) throws Repository
@Override
public void removeAxiom(OWLOntologyID ontologyId, OWLAxiom axiom) throws RepositoryException {
axiom = anonymousHandler.insertSurrogates(axiom);
org.openrdf.model.URI axiomResource = getAxiomId(ontologyId, axiom);
URI axiomResource = getAxiomId(ontologyId, axiom);
if (axiomResource != null) {
removeAxiom(axiomResource);
}
Expand All @@ -116,7 +118,7 @@ public boolean hasAxiom(OWLOntologyID ontologyId, OWLAxiom axiom) throws Reposit

@Override
public CloseableIteration<OWLAxiom, RepositoryException> listAxioms(OWLOntologyID ontologyId) throws RepositoryException {
org.openrdf.model.URI ontologyRepresentative = getOntologyRepresentative(ontologyId);
URI ontologyRepresentative = getOntologyRepresentative(ontologyId);
final RepositoryConnection connection = repository.getConnection();
boolean success = false;
try {
Expand All @@ -131,7 +133,7 @@ public boolean hasNext() throws RepositoryException {
@Override
public OWLAxiom next() throws RepositoryException {
Statement stmt = stmts.next();
org.openrdf.model.URI axiomResource = (org.openrdf.model.URI) stmt.getSubject();
URI axiomResource = (URI) stmt.getSubject();
RepositoryConnection connection = repository.getConnection();
try {
return anonymousHandler.removeSurrogates(parseAxiom(connection, axiomResource));
Expand Down Expand Up @@ -190,18 +192,18 @@ public boolean incorporateExternalChanges() {
* @return
* @throws RepositoryException
*/
private org.openrdf.model.URI getAxiomId(OWLOntologyID ontologyId, OWLAxiom axiom) throws RepositoryException {
org.openrdf.model.URI ontologyRepresentative = getOntologyRepresentative(ontologyId);
private URI getAxiomId(OWLOntologyID ontologyId, OWLAxiom axiom) throws RepositoryException {
URI ontologyRepresentative = getOntologyRepresentative(ontologyId);
ValueFactory factory = repository.getValueFactory();
RepositoryConnection connection = repository.getConnection();
try {
org.openrdf.model.Literal hashCodeValue = factory.createLiteral(axiom.hashCode());
Literal hashCodeValue = factory.createLiteral(axiom.hashCode());
RepositoryResult<Statement> correctHashCodes = connection.getStatements(null, hashCodeProperty, hashCodeValue, false);
try {
while (correctHashCodes.hasNext()) {
Statement stmt = correctHashCodes.next();
if (stmt.getSubject() instanceof org.openrdf.model.URI) {
org.openrdf.model.URI axiomId = (org.openrdf.model.URI) stmt.getSubject();
if (stmt.getSubject() instanceof URI) {
URI axiomId = (URI) stmt.getSubject();
if (connection.hasStatement(axiomId, sourceOntologyProperty, ontologyRepresentative, false)
&& axiom.equals(parseAxiom(connection, axiomId))) {
return axiomId;
Expand Down Expand Up @@ -239,7 +241,7 @@ private org.openrdf.model.URI getAxiomId(OWLOntologyID ontologyId, OWLAxiom axio
* @throws IOException
* @throws RDFHandlerException
*/
private OWLAxiom parseAxiom(RepositoryConnection connection, org.openrdf.model.URI axiomId) throws OWLOntologyCreationException, RepositoryException, SAXException, IOException, RDFHandlerException {
private OWLAxiom parseAxiom(RepositoryConnection connection, URI axiomId) throws OWLOntologyCreationException, RepositoryException, SAXException, IOException, RDFHandlerException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Starting parse");
}
Expand Down Expand Up @@ -268,7 +270,7 @@ public OWLClassExpression parseClassExpression(BNode classExpressionNode) throws
try {
RepositoryResult<Statement> triples = connection.getStatements(classExpressionNode, null, null, false);
Statement stmt = triples.next();
org.openrdf.model.URI axiomId = (org.openrdf.model.URI) stmt.getContext();
URI axiomId = (URI) stmt.getContext();
OWLRDFConsumer consumer = consumeTriples(connection, axiomId);
String nodeName = generateName(classExpressionNode);
OWLClassExpression ce = consumer.translateClassExpression(IRI.create(nodeName));
Expand All @@ -293,7 +295,7 @@ public OWLClassExpression parseClassExpression(BNode classExpressionNode) throws
}
}

private OWLRDFConsumer consumeTriples(RepositoryConnection connection, org.openrdf.model.URI axiomId) throws OWLOntologyCreationException, RepositoryException, IOException, RDFHandlerException, SAXException {
private OWLRDFConsumer consumeTriples(RepositoryConnection connection, URI axiomId) throws OWLOntologyCreationException, RepositoryException, IOException, RDFHandlerException, SAXException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.createOntology();
OWLRDFConsumer consumer = new OWLRDFConsumer(ontology, anonymousNodeChecker, new OWLOntologyLoaderConfiguration());
Expand All @@ -315,10 +317,10 @@ private OWLRDFConsumer consumeTriples(RepositoryConnection connection, org.openr
}
String subjectName = generateName(stmt.getSubject());
String predicateName = generateName(stmt.getPredicate());
if (stmt.getObject() instanceof org.openrdf.model.Literal) {
addTriple(consumer, subjectName, predicateName, (org.openrdf.model.Literal) stmt.getObject());
if (stmt.getObject() instanceof Literal) {
addTriple(consumer, subjectName, predicateName, (Literal) stmt.getObject());
} else {
addTriple(consumer, subjectName, predicateName, (org.openrdf.model.Resource) stmt.getObject());
addTriple(consumer, subjectName, predicateName, (Resource) stmt.getObject());
}
}
if (LOGGER.isDebugEnabled()) {
Expand All @@ -333,7 +335,7 @@ private OWLRDFConsumer consumeTriples(RepositoryConnection connection, org.openr
}

private void addTriple(RDFConsumer consumer,
String subjectName, String predicateName, org.openrdf.model.Literal literal) throws SAXException {
String subjectName, String predicateName, Literal literal) throws SAXException {
String datatype;
if (literal.getDatatype() == null) {
datatype = null; // OWL2Datatype.RDF_PLAIN_LITERAL.getIRI().toString();
Expand All @@ -344,18 +346,18 @@ private void addTriple(RDFConsumer consumer,
consumer.statementWithLiteralValue(subjectName,
predicateName,
literal.stringValue(),
literal.getLanguage(),
literal.getLanguage().orElse(null),
datatype);
}

private void addTriple(RDFConsumer consumer,
String subjectName,
String predicateName,
org.openrdf.model.Resource value) throws SAXException {
Resource value) throws SAXException {
consumer.statementWithResourceValue(subjectName, predicateName, generateName(value));
}

private void removeAxiom(org.openrdf.model.URI axiomResource) throws RepositoryException {
private void removeAxiom(URI axiomResource) throws RepositoryException {
if (axiomResource == null) {
return;
}
Expand All @@ -373,7 +375,7 @@ private void removeAxiom(org.openrdf.model.URI axiomResource) throws RepositoryE
}
}

private String generateName(org.openrdf.model.Resource resource) {
private String generateName(Resource resource) {
String name;
if (resource instanceof BNode) {
name = BNODE_PREFIX + ((BNode) resource).getID();
Expand All @@ -385,7 +387,7 @@ private String generateName(org.openrdf.model.Resource resource) {
}


private org.openrdf.model.URI getOntologyRepresentative(OWLOntologyID id) throws RepositoryException {
private URI getOntologyRepresentative(OWLOntologyID id) throws RepositoryException {
if (id.isAnonymous()) {
return repository.getValueFactory().createURI(anonymousHandler.getSurrogateId(id).toString());
}
Expand All @@ -394,19 +396,19 @@ private org.openrdf.model.URI getOntologyRepresentative(OWLOntologyID id) throws
}
}

private org.openrdf.model.URI getNamedOntologyRepresentative(OWLOntologyID id) throws RepositoryException {
org.openrdf.model.URI result = null;
private URI getNamedOntologyRepresentative(OWLOntologyID id) throws RepositoryException {
URI result = null;
RepositoryConnection connection = repository.getConnection();
try {
org.openrdf.model.URI rdfId = repository.getValueFactory().createURI(id.getOntologyIRI().toString());
org.openrdf.model.URI rdfVersion = id.getVersionIRI().isPresent() ? repository
URI rdfId = repository.getValueFactory().createURI(id.getOntologyIRI().toString());
URI rdfVersion = id.getVersionIRI().isPresent() ? repository
.getValueFactory().createURI(
id.getVersionIRI().get().toString()) : null;
RepositoryResult<Statement> idStatements = connection.getStatements(null, ontologyIdProperty, rdfId, false);
try {
while (idStatements.hasNext()) {
Statement idStatement = idStatements.next();
org.openrdf.model.URI possible = (org.openrdf.model.URI) idStatement.getSubject();
URI possible = (URI) idStatement.getSubject();
RepositoryResult<Statement> versionStatements = connection.getStatements(possible, ontologyVersionProperty, null, false);
try {
if (rdfVersion == null && !versionStatements.hasNext()) {
Expand Down Expand Up @@ -444,9 +446,9 @@ private org.openrdf.model.URI getNamedOntologyRepresentative(OWLOntologyID id) t
return result;
}

private org.openrdf.model.URI createNamedOntologyRepresentative(org.openrdf.model.URI rdfId, org.openrdf.model.URI rdfVersion) throws RepositoryException {
private URI createNamedOntologyRepresentative(URI rdfId, URI rdfVersion) throws RepositoryException {
String uriString = NS + "#" + UUID.randomUUID().toString().replaceAll("-", "_");
org.openrdf.model.URI representative = repository.getValueFactory().createURI(uriString);
URI representative = repository.getValueFactory().createURI(uriString);
RepositoryConnection connection = repository.getConnection();
try {
connection.add(representative, ontologyIdProperty, rdfId);
Expand Down
Loading

0 comments on commit 9ed3cac

Please sign in to comment.