merge changes from trunk to rdf api branch and fix issue with listeners notifying before triples are actually added/removed
This commit is contained in:
parent
94a34e274b
commit
6e8a4dfff1
27 changed files with 1429 additions and 1316 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
@ -30,7 +32,7 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
|
||||||
|
|
||||||
public class RDFServiceGraphBulkUpdater extends SimpleBulkUpdateHandler {
|
public class RDFServiceGraphBulkUpdater extends SimpleBulkUpdateHandler {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(SparqlGraphBulkUpdater.class);
|
private static final Log log = LogFactory.getLog(RDFServiceGraphBulkUpdater.class);
|
||||||
private RDFServiceGraph graph;
|
private RDFServiceGraph graph;
|
||||||
|
|
||||||
public RDFServiceGraphBulkUpdater(RDFServiceGraph graph) {
|
public RDFServiceGraphBulkUpdater(RDFServiceGraph graph) {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -35,6 +35,7 @@ import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.SparqlDataset;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.SparqlDataset;
|
||||||
|
@ -90,7 +91,8 @@ public class WebappDaoFactorySDBPrep implements Filter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OntModelSelector oms = (OntModelSelector) _ctx.getAttribute("unionOntModelSelector");
|
OntModelSelector oms = ModelContext.getUnionOntModelSelector(_ctx);
|
||||||
|
OntModelSelector baseOms = ModelContext.getBaseOntModelSelector(_ctx);
|
||||||
String defaultNamespace = (String) _ctx.getAttribute("defaultNamespace");
|
String defaultNamespace = (String) _ctx.getAttribute("defaultNamespace");
|
||||||
WebappDaoFactory wadf = null;
|
WebappDaoFactory wadf = null;
|
||||||
VitroRequest vreq = new VitroRequest((HttpServletRequest) request);
|
VitroRequest vreq = new VitroRequest((HttpServletRequest) request);
|
||||||
|
@ -112,7 +114,7 @@ public class WebappDaoFactorySDBPrep implements Filter {
|
||||||
Dataset dataset = new RDFServiceDataset(rdfService);
|
Dataset dataset = new RDFServiceDataset(rdfService);
|
||||||
wadf = new WebappDaoFactorySDB(rdfService, oms, config);
|
wadf = new WebappDaoFactorySDB(rdfService, oms, config);
|
||||||
WebappDaoFactory assertions = new WebappDaoFactorySDB(
|
WebappDaoFactory assertions = new WebappDaoFactorySDB(
|
||||||
rdfService, oms, config, SDBDatasetMode.ASSERTIONS_ONLY);
|
rdfService, baseOms, config, SDBDatasetMode.ASSERTIONS_ONLY);
|
||||||
vreq.setWebappDaoFactory(wadf);
|
vreq.setWebappDaoFactory(wadf);
|
||||||
vreq.setAssertionsWebappDaoFactory(assertions);
|
vreq.setAssertionsWebappDaoFactory(assertions);
|
||||||
vreq.setFullWebappDaoFactory(wadf);
|
vreq.setFullWebappDaoFactory(wadf);
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.rdfservice;
|
package edu.cornell.mannlib.vitro.webapp.rdfservice;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl;
|
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeListener;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeListener;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl;
|
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
|
|
@ -0,0 +1,217 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.sdb;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.graph.BulkUpdateHandler;
|
||||||
|
import com.hp.hpl.jena.graph.Capabilities;
|
||||||
|
import com.hp.hpl.jena.graph.Graph;
|
||||||
|
import com.hp.hpl.jena.graph.GraphEventManager;
|
||||||
|
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
|
||||||
|
import com.hp.hpl.jena.graph.Node;
|
||||||
|
import com.hp.hpl.jena.graph.Reifier;
|
||||||
|
import com.hp.hpl.jena.graph.TransactionHandler;
|
||||||
|
import com.hp.hpl.jena.graph.Triple;
|
||||||
|
import com.hp.hpl.jena.graph.TripleMatch;
|
||||||
|
import com.hp.hpl.jena.graph.impl.GraphWithPerform;
|
||||||
|
import com.hp.hpl.jena.graph.impl.SimpleBulkUpdateHandler;
|
||||||
|
import com.hp.hpl.jena.graph.impl.SimpleEventManager;
|
||||||
|
import com.hp.hpl.jena.graph.query.QueryHandler;
|
||||||
|
import com.hp.hpl.jena.graph.query.SimpleQueryHandler;
|
||||||
|
import com.hp.hpl.jena.shared.AddDeniedException;
|
||||||
|
import com.hp.hpl.jena.shared.DeleteDeniedException;
|
||||||
|
import com.hp.hpl.jena.shared.PrefixMapping;
|
||||||
|
import com.hp.hpl.jena.shared.impl.PrefixMappingImpl;
|
||||||
|
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
||||||
|
import com.hp.hpl.jena.util.iterator.WrappedIterator;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.EmptyReifier;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.ModelChange;
|
||||||
|
|
||||||
|
public class ListeningGraph implements GraphWithPerform {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(ListeningGraph.class);
|
||||||
|
|
||||||
|
private RDFServiceSDB rdfServiceSDB;
|
||||||
|
private String graphURI;
|
||||||
|
|
||||||
|
private BulkUpdateHandler bulkUpdateHandler;
|
||||||
|
private GraphEventManager eventManager;
|
||||||
|
private PrefixMapping prefixMapping = new PrefixMappingImpl();
|
||||||
|
private Reifier reifier = new EmptyReifier(this);
|
||||||
|
private QueryHandler queryHandler;
|
||||||
|
|
||||||
|
public ListeningGraph(String graphURI, RDFServiceSDB rdfServiceSDB) {
|
||||||
|
this.graphURI = graphURI;
|
||||||
|
this.rdfServiceSDB = rdfServiceSDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(Triple triple) throws AddDeniedException {
|
||||||
|
performAdd(triple);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void performAdd(Triple triple) throws AddDeniedException {
|
||||||
|
this.rdfServiceSDB.notifyListeners(triple, ModelChange.Operation.ADD, graphURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Triple triple) throws DeleteDeniedException {
|
||||||
|
performDelete(triple);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void performDelete(Triple triple) throws DeleteDeniedException {
|
||||||
|
this.rdfServiceSDB.notifyListeners(triple, ModelChange.Operation.REMOVE, graphURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Triple arg0) {
|
||||||
|
return contains(arg0.getSubject(), arg0.getPredicate(), arg0.getObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Node subject, Node predicate, Node object) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean dependsOn(Graph arg0) {
|
||||||
|
return false; // who knows?
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExtendedIterator<Triple> find(TripleMatch arg0) {
|
||||||
|
Triple t = arg0.asTriple();
|
||||||
|
return find(t.getSubject(), t.getPredicate(), t.getObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExtendedIterator<Triple> find(Node subject, Node predicate, Node object) {
|
||||||
|
List<Triple> triplist = new ArrayList<Triple>();
|
||||||
|
return WrappedIterator.create(triplist.iterator());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BulkUpdateHandler getBulkUpdateHandler() {
|
||||||
|
if (this.bulkUpdateHandler == null) {
|
||||||
|
this.bulkUpdateHandler = new SimpleBulkUpdateHandler(this);
|
||||||
|
}
|
||||||
|
return this.bulkUpdateHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Capabilities getCapabilities() {
|
||||||
|
return capabilities;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GraphEventManager getEventManager() {
|
||||||
|
if (eventManager == null) {
|
||||||
|
eventManager = new SimpleEventManager(this);
|
||||||
|
}
|
||||||
|
return eventManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PrefixMapping getPrefixMapping() {
|
||||||
|
return prefixMapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Reifier getReifier() {
|
||||||
|
return reifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GraphStatisticsHandler getStatisticsHandler() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransactionHandler getTransactionHandler() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClosed() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return (size() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIsomorphicWith(Graph arg0) {
|
||||||
|
throw new UnsupportedOperationException("isIsomorphicWith() not supported " +
|
||||||
|
"by SPARQL graphs");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueryHandler queryHandler() {
|
||||||
|
if (queryHandler == null) {
|
||||||
|
queryHandler = new SimpleQueryHandler(this);
|
||||||
|
}
|
||||||
|
return queryHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
int size = find(null, null, null).toList().size();
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static Capabilities capabilities = new Capabilities() {
|
||||||
|
|
||||||
|
public boolean addAllowed() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addAllowed(boolean everyTriple) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canBeEmpty() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteAllowed() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteAllowed(boolean everyTriple) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean findContractSafe() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean handlesLiteralTyping() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean iteratorRemoveAllowed() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean sizeAccurate() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.sdb;
|
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.sdb;
|
||||||
|
|
||||||
import org.apache.commons.dbcp.BasicDataSource;
|
import org.apache.commons.dbcp.BasicDataSource;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.sdb;
|
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.sdb;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
@ -35,6 +37,7 @@ import com.hp.hpl.jena.sdb.Store;
|
||||||
import com.hp.hpl.jena.sdb.StoreDesc;
|
import com.hp.hpl.jena.sdb.StoreDesc;
|
||||||
import com.hp.hpl.jena.sdb.sql.SDBConnection;
|
import com.hp.hpl.jena.sdb.sql.SDBConnection;
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
|
import com.hp.hpl.jena.vocabulary.OWL;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapper;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapper;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.SparqlGraph;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.SparqlGraph;
|
||||||
|
@ -83,8 +86,6 @@ public class RDFServiceSDB extends RDFServiceImpl implements RDFService {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<ModelChange> csIt = changeSet.getModelChanges().iterator();
|
|
||||||
|
|
||||||
SDBConnection conn = null;
|
SDBConnection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = new SDBConnection(bds.getConnection());
|
conn = new SDBConnection(bds.getConnection());
|
||||||
|
@ -97,46 +98,46 @@ public class RDFServiceSDB extends RDFServiceImpl implements RDFService {
|
||||||
boolean transaction = conn.getTransactionHandler().transactionsSupported();
|
boolean transaction = conn.getTransactionHandler().transactionsSupported();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (transaction) {
|
if (transaction) {
|
||||||
conn.getTransactionHandler().begin();
|
conn.getTransactionHandler().begin();
|
||||||
} else {
|
|
||||||
for (Object o : changeSet.getPreChangeEvents()) {
|
|
||||||
this.notifyListenersOfEvent(o);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Object o : changeSet.getPreChangeEvents()) {
|
||||||
|
this.notifyListenersOfEvent(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<ModelChange> csIt = changeSet.getModelChanges().iterator();
|
||||||
while (csIt.hasNext()) {
|
while (csIt.hasNext()) {
|
||||||
ModelChange modelChange = csIt.next();
|
ModelChange modelChange = csIt.next();
|
||||||
|
modelChange.getSerializedModel().mark(Integer.MAX_VALUE);
|
||||||
dataset.getLock().enterCriticalSection(Lock.WRITE);
|
dataset.getLock().enterCriticalSection(Lock.WRITE);
|
||||||
try {
|
try {
|
||||||
Model model = dataset.getNamedModel(modelChange.getGraphURI());
|
Model model = dataset.getNamedModel(modelChange.getGraphURI());
|
||||||
model.enterCriticalSection(Lock.WRITE);
|
operateOnModel(model, modelChange, dataset);
|
||||||
try {
|
|
||||||
model.register(new ModelListener(modelChange.getGraphURI(), this));
|
|
||||||
if (modelChange.getOperation() == ModelChange.Operation.ADD) {
|
|
||||||
model.read(modelChange.getSerializedModel(), null,
|
|
||||||
getSerializationFormatString(modelChange.getSerializationFormat()));
|
|
||||||
} else if (modelChange.getOperation() == ModelChange.Operation.REMOVE) {
|
|
||||||
model.remove(parseModel(modelChange));
|
|
||||||
removeBlankNodesWithSparqlUpdate(dataset, model, modelChange.getGraphURI());
|
|
||||||
} else {
|
|
||||||
log.error("unrecognized operation type");
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
model.leaveCriticalSection();
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
dataset.getLock().leaveCriticalSection();
|
dataset.getLock().leaveCriticalSection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transaction) {
|
if (transaction) {
|
||||||
for (Object o : changeSet.getPreChangeEvents()) {
|
|
||||||
this.notifyListenersOfEvent(o);
|
|
||||||
}
|
|
||||||
conn.getTransactionHandler().commit();
|
conn.getTransactionHandler().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// notify listeners of triple changes
|
||||||
|
csIt = changeSet.getModelChanges().iterator();
|
||||||
|
while (csIt.hasNext()) {
|
||||||
|
ModelChange modelChange = csIt.next();
|
||||||
|
modelChange.getSerializedModel().reset();
|
||||||
|
Model model = ModelFactory.createModelForGraph(
|
||||||
|
new ListeningGraph(modelChange.getGraphURI(), this));
|
||||||
|
operateOnModel(model, modelChange, null);
|
||||||
|
}
|
||||||
|
|
||||||
for (Object o : changeSet.getPostChangeEvents()) {
|
for (Object o : changeSet.getPostChangeEvents()) {
|
||||||
this.notifyListenersOfEvent(o);
|
this.notifyListenersOfEvent(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
if (transaction) {
|
if (transaction) {
|
||||||
|
@ -150,6 +151,25 @@ public class RDFServiceSDB extends RDFServiceImpl implements RDFService {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void operateOnModel(Model model, ModelChange modelChange, Dataset dataset) {
|
||||||
|
model.enterCriticalSection(Lock.WRITE);
|
||||||
|
try {
|
||||||
|
if (modelChange.getOperation() == ModelChange.Operation.ADD) {
|
||||||
|
model.read(modelChange.getSerializedModel(), null,
|
||||||
|
getSerializationFormatString(modelChange.getSerializationFormat()));
|
||||||
|
} else if (modelChange.getOperation() == ModelChange.Operation.REMOVE) {
|
||||||
|
model.remove(parseModel(modelChange));
|
||||||
|
if (dataset != null) {
|
||||||
|
removeBlankNodesWithSparqlUpdate(dataset, model, modelChange.getGraphURI());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.error("unrecognized operation type");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
model.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void removeBlankNodesWithSparqlUpdate(Dataset dataset, Model model, String graphURI) {
|
private void removeBlankNodesWithSparqlUpdate(Dataset dataset, Model model, String graphURI) {
|
||||||
|
|
||||||
Model blankNodeModel = ModelFactory.createDefaultModel();
|
Model blankNodeModel = ModelFactory.createDefaultModel();
|
||||||
|
@ -414,12 +434,10 @@ public class RDFServiceSDB extends RDFServiceImpl implements RDFService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addedStatement(Statement stmt) {
|
public void addedStatement(Statement stmt) {
|
||||||
log.debug("adding " + stmt + " to " + graphURI);
|
|
||||||
s.notifyListeners(stmt.asTriple(), ModelChange.Operation.ADD, graphURI);
|
s.notifyListeners(stmt.asTriple(), ModelChange.Operation.ADD, graphURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removedStatement(Statement stmt) {
|
public void removedStatement(Statement stmt) {
|
||||||
log.debug("removing " + stmt + " from " + graphURI);
|
|
||||||
s.notifyListeners(stmt.asTriple(), ModelChange.Operation.REMOVE, graphURI);
|
s.notifyListeners(stmt.asTriple(), ModelChange.Operation.REMOVE, graphURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,4 +22,7 @@ public interface ReasonerPlugin {
|
||||||
Model aboxInferencesModel,
|
Model aboxInferencesModel,
|
||||||
OntModel TBoxInferencesModel);
|
OntModel TBoxInferencesModel);
|
||||||
|
|
||||||
|
public void setSimpleReasoner(SimpleReasoner simpleReasoner);
|
||||||
|
|
||||||
|
public SimpleReasoner getSimpleReasoner();
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -49,12 +49,14 @@ public class SimpleReasonerTBoxListener extends StatementListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addedStatement(Statement statement) {
|
public void addedStatement(Statement statement) {
|
||||||
|
|
||||||
ModelUpdate mu = new ModelUpdate(statement, ModelUpdate.Operation.ADD, JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL);
|
ModelUpdate mu = new ModelUpdate(statement, ModelUpdate.Operation.ADD, JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL);
|
||||||
processUpdate(mu);
|
processUpdate(mu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removedStatement(Statement statement) {
|
public void removedStatement(Statement statement) {
|
||||||
|
|
||||||
ModelUpdate mu = new ModelUpdate(statement, ModelUpdate.Operation.RETRACT, JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL);
|
ModelUpdate mu = new ModelUpdate(statement, ModelUpdate.Operation.RETRACT, JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL);
|
||||||
processUpdate(mu);
|
processUpdate(mu);
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,7 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
try {
|
try {
|
||||||
ReasonerPlugin plugin = (ReasonerPlugin) Class.forName(
|
ReasonerPlugin plugin = (ReasonerPlugin) Class.forName(
|
||||||
classname).getConstructors()[0].newInstance();
|
classname).getConstructors()[0].newInstance();
|
||||||
|
plugin.setSimpleReasoner(simpleReasoner);
|
||||||
pluginList.add(plugin);
|
pluginList.add(plugin);
|
||||||
} catch(Throwable t) {
|
} catch(Throwable t) {
|
||||||
ss.info(this, "Could not instantiate reasoner plugin " + classname);
|
ss.info(this, "Could not instantiate reasoner plugin " + classname);
|
||||||
|
|
|
@ -42,44 +42,42 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
||||||
@Test
|
@Test
|
||||||
public void addABoxAssertion1() {
|
public void addABoxAssertion1() {
|
||||||
|
|
||||||
|
// set up the tbox
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
|
|
||||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||||
P.setLabel("property P", "en-US");
|
P.setLabel("property P", "en-US");
|
||||||
|
|
||||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
||||||
Q.setLabel("property Q", "en-US");
|
Q.setLabel("property Q", "en-US");
|
||||||
|
|
||||||
P.addInverseOf(Q);
|
P.addInverseOf(Q);
|
||||||
|
|
||||||
// this is the model to receive inferences
|
// this is the model to receive abox inferences
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
Model inf = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
// create an ABox and register the SimpleReasoner listener with it
|
// create an abox and register the SimpleReasoner listener with it
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||||
|
|
||||||
// Individuals a, b, c and d
|
// add assertions to the abox and verify inferences
|
||||||
Resource a = aBox.createResource("http://test.vivo/a");
|
Resource a = aBox.createResource("http://test.vivo/a");
|
||||||
Resource b = aBox.createResource("http://test.vivo/b");
|
Resource b = aBox.createResource("http://test.vivo/b");
|
||||||
Resource c = aBox.createResource("http://test.vivo/c");
|
Resource c = aBox.createResource("http://test.vivo/c");
|
||||||
Resource d = aBox.createResource("http://test.vivo/d");
|
Resource d = aBox.createResource("http://test.vivo/d");
|
||||||
|
|
||||||
// b Q a is inferred from a P b
|
|
||||||
aBox.add(a,P,b);
|
aBox.add(a,P,b);
|
||||||
Assert.assertTrue(inf.contains(b,Q,a));
|
Assert.assertTrue(inf.contains(b,Q,a));
|
||||||
|
|
||||||
// d P c is inferred from c Q d.
|
|
||||||
aBox.add(c,Q,d);
|
aBox.add(c,Q,d);
|
||||||
Assert.assertTrue(inf.contains(d,P,c));
|
Assert.assertTrue(inf.contains(d,P,c));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* don't infer if it's already in the abox
|
* don't infer statements already in the abox
|
||||||
|
* (never infer because it's in the abox already)
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void addABoxAssertion2() {
|
public void addABoxAssertion2() {
|
||||||
|
|
||||||
|
// set up the tbox
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
|
|
||||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||||
|
@ -88,10 +86,10 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
||||||
Q.setLabel("property Q", "en-US");
|
Q.setLabel("property Q", "en-US");
|
||||||
P.addInverseOf(Q);
|
P.addInverseOf(Q);
|
||||||
|
|
||||||
// this is the model to receive inferences
|
// this is the model to receive abox inferences
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
Model inf = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
// create an ABox and add statement b Q a
|
// create an ABox and add data (no inferencing happening yet)
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
// Individuals a, b, c and d
|
// Individuals a, b, c and d
|
||||||
Resource a = aBox.createResource("http://test.vivo/a");
|
Resource a = aBox.createResource("http://test.vivo/a");
|
||||||
|
@ -101,38 +99,42 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
||||||
// register SimpleReasoner
|
// register SimpleReasoner
|
||||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||||
|
|
||||||
// b Q a is inferred from a P b, but it is already in the abox
|
Assert.assertFalse(inf.contains(b,Q,a));
|
||||||
|
|
||||||
|
// add data and verify inferences
|
||||||
aBox.add(a,P,b);
|
aBox.add(a,P,b);
|
||||||
Assert.assertFalse(inf.contains(b,Q,a));
|
Assert.assertFalse(inf.contains(b,Q,a));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* don't infer if it's already in the abox
|
* don't infer statements already in the abox
|
||||||
|
* (remove the inference when it is asserted)
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void addABoxAssertion3() {
|
public void addABoxAssertion3() {
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
|
||||||
|
|
||||||
|
// set up the tbox
|
||||||
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||||
P.setLabel("property P", "en-US");
|
P.setLabel("property P", "en-US");
|
||||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
||||||
Q.setLabel("property Q", "en-US");
|
Q.setLabel("property Q", "en-US");
|
||||||
P.addInverseOf(Q);
|
P.addInverseOf(Q);
|
||||||
|
|
||||||
// this is the model to receive inferences
|
// this is the model to receive abox inferences
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
Model inf = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
// create an ABox and register SimpleReasoner
|
// create abox and register SimpleReasoner
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||||
|
|
||||||
// Individuals a, b, c and d
|
// add statements to the abox and verify inferences
|
||||||
Resource a = aBox.createResource("http://test.vivo/a");
|
Resource a = aBox.createResource("http://test.vivo/a");
|
||||||
Resource b = aBox.createResource("http://test.vivo/b");
|
Resource b = aBox.createResource("http://test.vivo/b");
|
||||||
|
|
||||||
// b Q a is inferred from a P b, but it is already in the abox
|
|
||||||
aBox.add(a,P,b);
|
aBox.add(a,P,b);
|
||||||
aBox.add(b,Q,a);
|
Assert.assertTrue(inf.contains(b,Q,a));
|
||||||
|
aBox.add(b,Q,a); // this should cause the inference to be removed
|
||||||
Assert.assertFalse(inf.contains(b,Q,a));
|
Assert.assertFalse(inf.contains(b,Q,a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,8 +145,8 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
||||||
@Test
|
@Test
|
||||||
public void addABoxAssertion4() {
|
public void addABoxAssertion4() {
|
||||||
|
|
||||||
|
// set up the tbox
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
|
|
||||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||||
P.setLabel("property P", "en-US");
|
P.setLabel("property P", "en-US");
|
||||||
OntProperty R = tBox.createOntProperty("http://test.vivo/R");
|
OntProperty R = tBox.createOntProperty("http://test.vivo/R");
|
||||||
|
@ -153,27 +155,24 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
||||||
Q.setLabel("property Q", "en-US");
|
Q.setLabel("property Q", "en-US");
|
||||||
|
|
||||||
R.addEquivalentProperty(P);
|
R.addEquivalentProperty(P);
|
||||||
P.addEquivalentProperty(R);
|
|
||||||
P.addInverseOf(Q);
|
P.addInverseOf(Q);
|
||||||
|
|
||||||
// this is the model to receive inferences
|
// this is the model to receive abox inferences
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
Model inf = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
// create an ABox and register the SimpleReasoner listener with it
|
// create an ABox and register the SimpleReasoner with it
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||||
|
|
||||||
// a, b, c and d
|
// add abox statements and verify inferences
|
||||||
Resource a = aBox.createResource("http://test.vivo/a");
|
Resource a = aBox.createResource("http://test.vivo/a");
|
||||||
Resource b = aBox.createResource("http://test.vivo/b");
|
Resource b = aBox.createResource("http://test.vivo/b");
|
||||||
Resource c = aBox.createResource("http://test.vivo/c");
|
Resource c = aBox.createResource("http://test.vivo/c");
|
||||||
Resource d = aBox.createResource("http://test.vivo/d");
|
Resource d = aBox.createResource("http://test.vivo/d");
|
||||||
|
|
||||||
// b Q a is inferred from a R b.
|
|
||||||
aBox.add(a,R,b);
|
aBox.add(a,R,b);
|
||||||
Assert.assertTrue(inf.contains(b,Q,a));
|
Assert.assertTrue(inf.contains(b,Q,a));
|
||||||
|
|
||||||
// d P c is inferred from c Q d.
|
|
||||||
aBox.add(c,Q,d);
|
aBox.add(c,Q,d);
|
||||||
Assert.assertTrue(inf.contains(d,P,c));
|
Assert.assertTrue(inf.contains(d,P,c));
|
||||||
Assert.assertTrue(inf.contains(d,R,c));
|
Assert.assertTrue(inf.contains(d,R,c));
|
||||||
|
@ -181,11 +180,14 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* basic scenarios around removing abox data
|
* basic scenarios around removing abox data
|
||||||
|
* don't remove an inference if it's still
|
||||||
|
* entailed by something else in the abox.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void removedABoxAssertion1() {
|
public void removedABoxAssertion1() {
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
|
||||||
|
|
||||||
|
// set up the tbox
|
||||||
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||||
P.setLabel("property P", "en-US");
|
P.setLabel("property P", "en-US");
|
||||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
||||||
|
@ -195,24 +197,23 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
||||||
P.addInverseOf(Q);
|
P.addInverseOf(Q);
|
||||||
P.addInverseOf(T);
|
P.addInverseOf(T);
|
||||||
|
|
||||||
// this is the model to receive inferences
|
// this is the model to receive abox inferences
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
Model inf = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
// create an ABox and register the SimpleReasoner listener with it
|
// create an ABox and register the SimpleReasoner with it
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||||
|
|
||||||
// Individuals a, b, c and d
|
// add statements to the abox and verify inferences
|
||||||
Resource a = aBox.createResource("http://test.vivo/a");
|
Resource a = aBox.createResource("http://test.vivo/a");
|
||||||
Resource b = aBox.createResource("http://test.vivo/b");
|
Resource b = aBox.createResource("http://test.vivo/b");
|
||||||
Resource c = aBox.createResource("http://test.vivo/c");
|
Resource c = aBox.createResource("http://test.vivo/c");
|
||||||
Resource d = aBox.createResource("http://test.vivo/d");
|
Resource d = aBox.createResource("http://test.vivo/d");
|
||||||
|
|
||||||
// b Q a is inferred from a P b.
|
|
||||||
aBox.add(a,P,b);
|
aBox.add(a,P,b);
|
||||||
Assert.assertTrue(inf.contains(b,Q,a));
|
Assert.assertTrue(inf.contains(b,Q,a));
|
||||||
|
|
||||||
// d P c is inferred from c Q d and from c T d
|
// d P c is inferred from c Q d and also from c T d
|
||||||
aBox.add(c,Q,d);
|
aBox.add(c,Q,d);
|
||||||
aBox.add(c,T,d);
|
aBox.add(c,T,d);
|
||||||
Assert.assertTrue(inf.contains(d,P,c));
|
Assert.assertTrue(inf.contains(d,P,c));
|
||||||
|
@ -221,16 +222,18 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
||||||
Assert.assertFalse(inf.contains(b,Q,a));
|
Assert.assertFalse(inf.contains(b,Q,a));
|
||||||
|
|
||||||
aBox.remove(c,Q,d);
|
aBox.remove(c,Q,d);
|
||||||
Assert.assertTrue(inf.contains(d,P,c));
|
Assert.assertTrue(inf.contains(d,P,c)); // still inferred from c T d
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* removing abox data with equivalent and inverse properties
|
* removing abox data with equivalent and inverse properties
|
||||||
|
* don't remove inference if it's still inferred.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void removedABoxAssertion2() {
|
public void removedABoxAssertion2() {
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
|
||||||
|
|
||||||
|
// set up the tbox
|
||||||
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||||
P.setLabel("property P", "en-US");
|
P.setLabel("property P", "en-US");
|
||||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
||||||
|
@ -238,26 +241,29 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
||||||
OntProperty T = tBox.createOntProperty("http://test.vivo/T");
|
OntProperty T = tBox.createOntProperty("http://test.vivo/T");
|
||||||
Q.setLabel("property T", "en-US");
|
Q.setLabel("property T", "en-US");
|
||||||
P.addInverseOf(Q);
|
P.addInverseOf(Q);
|
||||||
Q.addInverseOf(P);
|
|
||||||
P.addEquivalentProperty(T);
|
P.addEquivalentProperty(T);
|
||||||
T.addEquivalentProperty(P);
|
|
||||||
|
|
||||||
// this is the model to receive inferences
|
// not clear what these will do
|
||||||
|
tBox.rebind();
|
||||||
|
tBox.prepare();
|
||||||
|
|
||||||
|
// this is the model to receive abox inferences
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
Model inf = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
// create an ABox and register the SimpleReasoner listener with it
|
// create an abox and register the SimpleReasoner listener with it
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||||
|
|
||||||
// Individuals a, b, c and d
|
// add abox data and verify inferences
|
||||||
Resource a = aBox.createResource("http://test.vivo/a");
|
Resource a = aBox.createResource("http://test.vivo/a");
|
||||||
Resource b = aBox.createResource("http://test.vivo/b");
|
Resource b = aBox.createResource("http://test.vivo/b");
|
||||||
|
|
||||||
// b Q a is inferred from a P b and a T b.
|
// b Q a is inferred from a P b and also from a T b.
|
||||||
aBox.add(a,P,b);
|
aBox.add(a,P,b);
|
||||||
aBox.add(a,T,b);
|
aBox.add(a,T,b);
|
||||||
Assert.assertTrue(inf.contains(b,Q,a));
|
Assert.assertTrue(inf.contains(b,Q,a));
|
||||||
Assert.assertFalse(inf.contains(a,P,b));
|
Assert.assertFalse(inf.contains(a,P,b));
|
||||||
|
Assert.assertFalse(inf.contains(a,T,b));
|
||||||
|
|
||||||
aBox.remove(a,P,b);
|
aBox.remove(a,P,b);
|
||||||
Assert.assertTrue(inf.contains(b,Q,a));
|
Assert.assertTrue(inf.contains(b,Q,a));
|
||||||
|
@ -268,80 +274,81 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void removedABoxAssertion3() {
|
public void removedABoxAssertion3() {
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
|
||||||
|
|
||||||
|
//set up the tbox
|
||||||
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||||
P.setLabel("property P", "en-US");
|
P.setLabel("property P", "en-US");
|
||||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
||||||
Q.setLabel("property Q", "en-US");
|
Q.setLabel("property Q", "en-US");
|
||||||
P.addInverseOf(Q);
|
P.addInverseOf(Q);
|
||||||
|
|
||||||
// this is the model to receive inferences
|
tBox.rebind(); // not sure what effect this has
|
||||||
|
|
||||||
|
// this is the model to receive abox inferences
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
Model inf = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
// create an ABox and register the SimpleReasoner listener with it
|
// create the abox and add some data - no reasoning is happening yet
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
|
|
||||||
Resource a = aBox.createResource("http://test.vivo/a");
|
Resource a = aBox.createResource("http://test.vivo/a");
|
||||||
Resource b = aBox.createResource("http://test.vivo/b");
|
Resource b = aBox.createResource("http://test.vivo/b");
|
||||||
aBox.add(a,P,b);
|
aBox.add(a,P,b);
|
||||||
|
|
||||||
|
// register the SimpleReasoner
|
||||||
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||||
|
|
||||||
|
// add abox statements and verify inferences
|
||||||
aBox.add(b,Q,a);
|
aBox.add(b,Q,a);
|
||||||
|
|
||||||
Assert.assertFalse(inf.contains(b,Q,a));
|
Assert.assertFalse(inf.contains(b,Q,a));
|
||||||
Assert.assertFalse(inf.contains(a,P,b));
|
Assert.assertFalse(inf.contains(a,P,b)); // this could be inferred from b Q a, but
|
||||||
|
// it's already in the abox
|
||||||
aBox.remove(a,P,b);
|
aBox.remove(a,P,b);
|
||||||
Assert.assertTrue(inf.contains(a,P,b));
|
Assert.assertTrue(inf.contains(a,P,b)); // now it gets added to inference model
|
||||||
|
// when it's removed from the abox
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Basic scenario around adding an inverseOf assertion to the
|
* adding an inverseOf assertion to the tbox
|
||||||
* TBox
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void addTBoxInverseAssertion1() throws InterruptedException {
|
public void addTBoxInverseAssertion1() throws InterruptedException {
|
||||||
|
|
||||||
// Create TBox, ABox and Inference models and register
|
// Set up the TBox.
|
||||||
// the ABox reasoner listeners with the ABox and TBox
|
|
||||||
// Pellet will compute TBox inferences
|
|
||||||
|
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
|
|
||||||
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
OntProperty P = tBox.createOntProperty("http://test.vivo/P");
|
||||||
P.setLabel("property P", "en-US");
|
P.setLabel("property P", "en-US");
|
||||||
|
|
||||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
OntProperty Q = tBox.createOntProperty("http://test.vivo/Q");
|
||||||
Q.setLabel("property Q", "en-US");
|
Q.setLabel("property Q", "en-US");
|
||||||
|
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
// this is the model to receive abox inferences
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
Model inf = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
// abox
|
||||||
|
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
|
|
||||||
|
// set up SimpleReasoner and register it with abox. register
|
||||||
|
// SimpleReasonerTBoxListener with the tbox.
|
||||||
|
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||||
aBox.register(simpleReasoner);
|
aBox.register(simpleReasoner);
|
||||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||||
tBox.register(simpleReasonerTBoxListener);
|
tBox.register(simpleReasonerTBoxListener);
|
||||||
|
|
||||||
// Individuals a, b, c and d
|
// add abox data
|
||||||
Resource a = aBox.createResource("http://test.vivo/a");
|
Resource a = aBox.createResource("http://test.vivo/a");
|
||||||
Resource b = aBox.createResource("http://test.vivo/b");
|
Resource b = aBox.createResource("http://test.vivo/b");
|
||||||
Resource c = aBox.createResource("http://test.vivo/c");
|
Resource c = aBox.createResource("http://test.vivo/c");
|
||||||
Resource d = aBox.createResource("http://test.vivo/d");
|
Resource d = aBox.createResource("http://test.vivo/d");
|
||||||
|
|
||||||
// abox statements
|
|
||||||
aBox.add(a,P,b);
|
aBox.add(a,P,b);
|
||||||
aBox.add(c,P,d);
|
aBox.add(c,P,d);
|
||||||
aBox.add(b,Q,a);
|
aBox.add(b,Q,a);
|
||||||
|
|
||||||
// Assert P and Q as inverses and wait for SimpleReasoner TBox
|
// Assert P and Q as inverses and wait for
|
||||||
// thread to end
|
// SimpleReasonerTBoxListener thread to end
|
||||||
|
|
||||||
Q.addInverseOf(P);
|
Q.addInverseOf(P);
|
||||||
|
|
||||||
tBox.rebind();
|
|
||||||
tBox.prepare();
|
|
||||||
|
|
||||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||||
Thread.sleep(delay);
|
Thread.sleep(delay);
|
||||||
}
|
}
|
||||||
|
@ -349,47 +356,43 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
||||||
// Verify inferences
|
// Verify inferences
|
||||||
Assert.assertTrue(inf.contains(d,Q,c));
|
Assert.assertTrue(inf.contains(d,Q,c));
|
||||||
Assert.assertFalse(inf.contains(b,Q,a));
|
Assert.assertFalse(inf.contains(b,Q,a));
|
||||||
|
Assert.assertFalse(inf.contains(a,P,b));
|
||||||
|
|
||||||
simpleReasonerTBoxListener.setStopRequested();
|
simpleReasonerTBoxListener.setStopRequested();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Basic scenario around removing an inverseOf assertion to the
|
* removing an inverseOf assertion from the tbox
|
||||||
* TBox
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void removeTBoxInverseAssertion1() throws InterruptedException {
|
public void removeTBoxInverseAssertion1() throws InterruptedException {
|
||||||
|
|
||||||
// Create TBox, ABox and Inference models and register
|
// set up the tbox.
|
||||||
// the ABox reasoner listeners with the ABox and TBox
|
|
||||||
// Pellet will compute TBox inferences
|
|
||||||
|
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
|
|
||||||
// set up TBox and Abox
|
|
||||||
|
|
||||||
OntProperty P = tBox.createOntProperty("http://test.vivo/propP");
|
OntProperty P = tBox.createOntProperty("http://test.vivo/propP");
|
||||||
P.setLabel("property P", "en-US");
|
P.setLabel("property P", "en-US");
|
||||||
|
|
||||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/propQ");
|
OntProperty Q = tBox.createOntProperty("http://test.vivo/propQ");
|
||||||
Q.setLabel("property Q", "en-US");
|
Q.setLabel("property Q", "en-US");
|
||||||
|
|
||||||
Q.addInverseOf(P);
|
Q.addInverseOf(P);
|
||||||
|
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
// this is the model to receive abox inferences
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
Model inf = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
// abox
|
||||||
|
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
|
|
||||||
|
// set up SimpleReasoner and SimpleReasonerTBox listener,
|
||||||
|
// register them with abox and tbox
|
||||||
|
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||||
aBox.register(simpleReasoner);
|
aBox.register(simpleReasoner);
|
||||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||||
tBox.register(simpleReasonerTBoxListener);
|
tBox.register(simpleReasonerTBoxListener);
|
||||||
// Individuals a, b, c and d
|
|
||||||
|
// add statements to the abox and verify inference
|
||||||
Resource c = aBox.createResource("http://test.vivo/c");
|
Resource c = aBox.createResource("http://test.vivo/c");
|
||||||
Resource d = aBox.createResource("http://test.vivo/d");
|
Resource d = aBox.createResource("http://test.vivo/d");
|
||||||
|
|
||||||
// abox statements
|
|
||||||
aBox.add(c,P,d);
|
aBox.add(c,P,d);
|
||||||
|
|
||||||
Assert.assertTrue(inf.contains(d,Q,c));
|
Assert.assertTrue(inf.contains(d,Q,c));
|
||||||
|
|
||||||
// Remove P and Q inverse relationship and wait for
|
// Remove P and Q inverse relationship and wait for
|
||||||
|
@ -397,14 +400,11 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
||||||
|
|
||||||
Q.removeInverseProperty(P);
|
Q.removeInverseProperty(P);
|
||||||
|
|
||||||
tBox.rebind();
|
|
||||||
tBox.prepare();
|
|
||||||
|
|
||||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||||
Thread.sleep(delay);
|
Thread.sleep(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify inferences
|
// Verify inference has been removed
|
||||||
Assert.assertFalse(inf.contains(d,Q,c));
|
Assert.assertFalse(inf.contains(d,Q,c));
|
||||||
|
|
||||||
simpleReasonerTBoxListener.setStopRequested();
|
simpleReasonerTBoxListener.setStopRequested();
|
||||||
|
@ -416,12 +416,9 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
||||||
@Test
|
@Test
|
||||||
public void recomputeABox1() throws InterruptedException {
|
public void recomputeABox1() throws InterruptedException {
|
||||||
|
|
||||||
// Create TBox, ABox and Inference models and register
|
// set up tbox
|
||||||
// the ABox reasoner listeners with the ABox and TBox
|
|
||||||
// Pellet will compute TBox inferences
|
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
|
|
||||||
// set up TBox and Abox
|
|
||||||
OntProperty P = tBox.createOntProperty("http://test.vivo/propP");
|
OntProperty P = tBox.createOntProperty("http://test.vivo/propP");
|
||||||
P.setLabel("property P", "en-US");
|
P.setLabel("property P", "en-US");
|
||||||
OntProperty Q = tBox.createOntProperty("http://test.vivo/propQ");
|
OntProperty Q = tBox.createOntProperty("http://test.vivo/propQ");
|
||||||
|
@ -434,21 +431,23 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass {
|
||||||
Q.setLabel("property Y", "en-US");
|
Q.setLabel("property Y", "en-US");
|
||||||
X.addInverseOf(Y);
|
X.addInverseOf(Y);
|
||||||
|
|
||||||
|
// create abox and abox inf model and register simplereasoner
|
||||||
|
// with abox.
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
Model inf = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||||
aBox.register(simpleReasoner);
|
aBox.register(simpleReasoner);
|
||||||
// Individuals a, b, c and d
|
|
||||||
|
// abox statements
|
||||||
Resource a = aBox.createResource("http://test.vivo/a");
|
Resource a = aBox.createResource("http://test.vivo/a");
|
||||||
Resource b = aBox.createResource("http://test.vivo/b");
|
Resource b = aBox.createResource("http://test.vivo/b");
|
||||||
Resource c = aBox.createResource("http://test.vivo/c");
|
Resource c = aBox.createResource("http://test.vivo/c");
|
||||||
Resource d = aBox.createResource("http://test.vivo/d");
|
Resource d = aBox.createResource("http://test.vivo/d");
|
||||||
|
|
||||||
// abox statements
|
|
||||||
aBox.add(a,P,b);
|
aBox.add(a,P,b);
|
||||||
aBox.add(c,X,d);
|
aBox.add(c,X,d);
|
||||||
|
|
||||||
|
//recompute whole abox
|
||||||
simpleReasoner.recompute();
|
simpleReasoner.recompute();
|
||||||
|
|
||||||
while (simpleReasoner.isRecomputing()) {
|
while (simpleReasoner.isRecomputing()) {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mindswap.pellet.jena.PelletReasonerFactory;
|
import org.mindswap.pellet.jena.PelletReasonerFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.ontology.AnnotationProperty;
|
||||||
import com.hp.hpl.jena.ontology.OntClass;
|
import com.hp.hpl.jena.ontology.OntClass;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
|
@ -16,6 +17,7 @@ import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||||
import com.hp.hpl.jena.vocabulary.OWL;
|
import com.hp.hpl.jena.vocabulary.OWL;
|
||||||
import com.hp.hpl.jena.vocabulary.RDF;
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
|
|
||||||
|
@ -25,6 +27,7 @@ import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
|
||||||
public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||||
|
|
||||||
long delay = 50;
|
long delay = 50;
|
||||||
|
private static final String mostSpecificTypePropertyURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#mostSpecificType";
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void suppressErrorOutput() {
|
public void suppressErrorOutput() {
|
||||||
|
@ -103,10 +106,10 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||||
OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q");
|
OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q");
|
||||||
Q.setLabel("property Q", "en-US");
|
Q.setLabel("property Q", "en-US");
|
||||||
|
|
||||||
OntProperty S = tBox.createDatatypeProperty("http://test.vivo/");
|
OntProperty S = tBox.createDatatypeProperty("http://test.vivo/data1");
|
||||||
S.setLabel("property S", "en-US");
|
S.setLabel("property S", "en-US");
|
||||||
|
|
||||||
OntProperty T = tBox.createDatatypeProperty("http://test.vivo/");
|
OntProperty T = tBox.createDatatypeProperty("http://test.vivo/data2");
|
||||||
T.setLabel("property T", "en-US");
|
T.setLabel("property T", "en-US");
|
||||||
|
|
||||||
Literal literal1 = tBox.createLiteral("Literal value 1");
|
Literal literal1 = tBox.createLiteral("Literal value 1");
|
||||||
|
@ -147,8 +150,7 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* basic scenario of adding an abox assertion for
|
* adding abox assertion for individual in sameAs chain.
|
||||||
* an individual is sameAs another.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void addABoxAssertion1() {
|
public void addABoxAssertion1() {
|
||||||
|
@ -182,10 +184,23 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||||
Resource b = aBox.createResource("http://test.vivo/b");
|
Resource b = aBox.createResource("http://test.vivo/b");
|
||||||
Resource c = aBox.createResource("http://test.vivo/c");
|
Resource c = aBox.createResource("http://test.vivo/c");
|
||||||
Resource d = aBox.createResource("http://test.vivo/d");
|
Resource d = aBox.createResource("http://test.vivo/d");
|
||||||
|
Resource e = aBox.createResource("http://test.vivo/e");
|
||||||
|
Resource f = aBox.createResource("http://test.vivo/f");
|
||||||
|
|
||||||
aBox.add(a,OWL.sameAs,b);
|
aBox.add(a,OWL.sameAs,b);
|
||||||
|
aBox.add(b,OWL.sameAs,e);
|
||||||
|
aBox.add(e,OWL.sameAs,f);
|
||||||
|
|
||||||
Assert.assertTrue(inf.contains(b,OWL.sameAs,a));
|
Assert.assertTrue(inf.contains(b,OWL.sameAs,a));
|
||||||
|
Assert.assertTrue(inf.contains(e,OWL.sameAs,a));
|
||||||
|
Assert.assertTrue(inf.contains(e,OWL.sameAs,b));
|
||||||
|
Assert.assertTrue(inf.contains(a,OWL.sameAs,e));
|
||||||
|
Assert.assertTrue(inf.contains(f,OWL.sameAs,e));
|
||||||
|
Assert.assertTrue(inf.contains(f,OWL.sameAs,b));
|
||||||
|
Assert.assertTrue(inf.contains(f,OWL.sameAs,a));
|
||||||
|
Assert.assertTrue(inf.contains(b,OWL.sameAs,f));
|
||||||
|
Assert.assertTrue(inf.contains(a,OWL.sameAs,f));
|
||||||
|
|
||||||
|
|
||||||
aBox.add(a,P,c);
|
aBox.add(a,P,c);
|
||||||
aBox.add(a,S,literal1);
|
aBox.add(a,S,literal1);
|
||||||
|
@ -196,24 +211,48 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||||
Assert.assertTrue(inf.contains(b,S,literal1));
|
Assert.assertTrue(inf.contains(b,S,literal1));
|
||||||
Assert.assertTrue(inf.contains(a,Q,d));
|
Assert.assertTrue(inf.contains(a,Q,d));
|
||||||
Assert.assertTrue(inf.contains(a,T,literal2));
|
Assert.assertTrue(inf.contains(a,T,literal2));
|
||||||
|
Assert.assertTrue(inf.contains(e,P,c));
|
||||||
|
Assert.assertTrue(inf.contains(e,S,literal1));
|
||||||
|
Assert.assertTrue(inf.contains(e,Q,d));
|
||||||
|
Assert.assertTrue(inf.contains(e,T,literal2));
|
||||||
|
Assert.assertTrue(inf.contains(f,P,c));
|
||||||
|
Assert.assertTrue(inf.contains(f,S,literal1));
|
||||||
|
Assert.assertTrue(inf.contains(f,Q,d));
|
||||||
|
Assert.assertTrue(inf.contains(f,T,literal2));
|
||||||
|
|
||||||
|
aBox.remove(b,OWL.sameAs,e);
|
||||||
|
|
||||||
|
Assert.assertTrue(inf.contains(b,OWL.sameAs,a));
|
||||||
|
Assert.assertFalse(inf.contains(e,OWL.sameAs,a));
|
||||||
|
Assert.assertFalse(inf.contains(e,OWL.sameAs,b));
|
||||||
|
Assert.assertFalse(inf.contains(a,OWL.sameAs,e));
|
||||||
|
Assert.assertTrue(inf.contains(f,OWL.sameAs,e));
|
||||||
|
Assert.assertFalse(inf.contains(f,OWL.sameAs,b));
|
||||||
|
Assert.assertFalse(inf.contains(f,OWL.sameAs,a));
|
||||||
|
Assert.assertFalse(inf.contains(b,OWL.sameAs,f));
|
||||||
|
Assert.assertFalse(inf.contains(a,OWL.sameAs,f));
|
||||||
|
|
||||||
|
Assert.assertTrue(inf.contains(b,P,c));
|
||||||
|
Assert.assertTrue(inf.contains(b,S,literal1));
|
||||||
|
Assert.assertTrue(inf.contains(a,Q,d));
|
||||||
|
Assert.assertTrue(inf.contains(a,T,literal2));
|
||||||
|
Assert.assertFalse(inf.contains(e,P,c));
|
||||||
|
Assert.assertFalse(inf.contains(e,S,literal1));
|
||||||
|
Assert.assertFalse(inf.contains(e,Q,d));
|
||||||
|
Assert.assertFalse(inf.contains(e,T,literal2));
|
||||||
|
Assert.assertFalse(inf.contains(f,P,c));
|
||||||
|
Assert.assertFalse(inf.contains(f,S,literal1));
|
||||||
|
Assert.assertFalse(inf.contains(f,Q,d));
|
||||||
|
Assert.assertFalse(inf.contains(f,T,literal2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* adding abox assertion for individuals that are sameAs
|
* sameAs with datatype properties
|
||||||
* each other.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void addABoxAssertion2() {
|
public void addABoxAssertion2() {
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
|
|
||||||
OntClass classA = tBox.createClass("http://test.vivo/A");
|
|
||||||
classA.setLabel("class A", "en-US");
|
|
||||||
|
|
||||||
OntClass classB = tBox.createClass("http://test.vivo/B");
|
|
||||||
classB.setLabel("class B", "en-US");
|
|
||||||
|
|
||||||
classA.addSubClass(classB);
|
|
||||||
|
|
||||||
OntProperty desc = tBox.createDatatypeProperty("http://test.vivo/desc");
|
OntProperty desc = tBox.createDatatypeProperty("http://test.vivo/desc");
|
||||||
desc.setLabel("property desc", "en-US");
|
desc.setLabel("property desc", "en-US");
|
||||||
|
|
||||||
|
@ -234,14 +273,10 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||||
aBox.add(a,desc,desc1);
|
aBox.add(a,desc,desc1);
|
||||||
aBox.add(b,desc,desc2);
|
aBox.add(b,desc,desc2);
|
||||||
aBox.add(a,OWL.sameAs,b);
|
aBox.add(a,OWL.sameAs,b);
|
||||||
aBox.add(a, RDF.type, classB);
|
|
||||||
|
|
||||||
Assert.assertTrue(inf.contains(a,desc,desc2));
|
Assert.assertTrue(inf.contains(a,desc,desc2));
|
||||||
Assert.assertTrue(inf.contains(a,RDF.type,classA));
|
|
||||||
Assert.assertTrue(inf.contains(b,desc,desc1));
|
Assert.assertTrue(inf.contains(b,desc,desc1));
|
||||||
Assert.assertTrue(inf.contains(b,OWL.sameAs,a));
|
Assert.assertTrue(inf.contains(b,OWL.sameAs,a));
|
||||||
Assert.assertTrue(inf.contains(b,RDF.type,classB));
|
|
||||||
Assert.assertTrue(inf.contains(b,RDF.type,classA));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -295,11 +330,11 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* adding an inverseOf assertion for individuals who are sameAs
|
* adding and removing an inverseOf assertion for individuals who
|
||||||
* each other.
|
* are sameAs each other.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void addTBoxInverseAssertion1() throws InterruptedException {
|
public void tBoxInverseAssertion1() throws InterruptedException {
|
||||||
|
|
||||||
// Create TBox, ABox and Inference models and register
|
// Create TBox, ABox and Inference models and register
|
||||||
// the ABox reasoner listeners with the ABox and TBox
|
// the ABox reasoner listeners with the ABox and TBox
|
||||||
|
@ -329,26 +364,274 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass {
|
||||||
aBox.add(a,P,b);
|
aBox.add(a,P,b);
|
||||||
aBox.add(a, OWL.sameAs,b);
|
aBox.add(a, OWL.sameAs,b);
|
||||||
|
|
||||||
// Assert P and Q as inverses and wait for SimpleReasoner TBox
|
|
||||||
// thread to end
|
|
||||||
|
|
||||||
Q.addInverseOf(P);
|
Q.addInverseOf(P);
|
||||||
|
|
||||||
tBox.rebind();
|
|
||||||
tBox.prepare();
|
|
||||||
|
|
||||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||||
Thread.sleep(delay);
|
Thread.sleep(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify inferences
|
|
||||||
Assert.assertTrue(inf.contains(b,Q,a));
|
Assert.assertTrue(inf.contains(b,Q,a));
|
||||||
Assert.assertTrue(inf.contains(b,OWL.sameAs,a));
|
Assert.assertTrue(inf.contains(b,OWL.sameAs,a));
|
||||||
Assert.assertTrue(inf.contains(b,P,b));
|
Assert.assertTrue(inf.contains(b,P,b));
|
||||||
Assert.assertTrue(inf.contains(a,Q,a));
|
Assert.assertTrue(inf.contains(a,Q,a));
|
||||||
|
|
||||||
|
Q.removeInverseProperty(P);
|
||||||
|
|
||||||
|
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||||
|
Thread.sleep(delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertFalse(inf.contains(b,Q,a));
|
||||||
|
Assert.assertTrue(inf.contains(b,OWL.sameAs,a));
|
||||||
|
Assert.assertTrue(inf.contains(b,P,b));
|
||||||
|
Assert.assertFalse(inf.contains(a,Q,a));
|
||||||
|
|
||||||
simpleReasonerTBoxListener.setStopRequested();
|
simpleReasonerTBoxListener.setStopRequested();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* adding and removing a type assertion for an individual who has
|
||||||
|
* a sameAs individual.
|
||||||
|
*/
|
||||||
|
//@Test
|
||||||
|
public void tBoxTypeAssertion1() throws InterruptedException {
|
||||||
|
|
||||||
|
// Create a Tbox with a simple class hierarchy. B is a subclass of A.
|
||||||
|
// Pellet will compute TBox inferences
|
||||||
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
|
|
||||||
|
OntClass classA = tBox.createClass("http://test.vivo/A");
|
||||||
|
classA.setLabel("class A", "en-US");
|
||||||
|
|
||||||
|
OntClass classB = tBox.createClass("http://test.vivo/B");
|
||||||
|
classB.setLabel("class B", "en-US");
|
||||||
|
|
||||||
|
classA.addSubClass(classB);
|
||||||
|
|
||||||
|
// this is the model to receive inferences
|
||||||
|
Model inf = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
|
// create an ABox and register the SimpleReasoner listener with it
|
||||||
|
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
|
aBox.register(new SimpleReasoner(tBox, aBox, inf));
|
||||||
|
|
||||||
|
Resource x = aBox.createResource("http://test.vivo/x");
|
||||||
|
Resource y = aBox.createResource("http://test.vivo/y");
|
||||||
|
Resource z = aBox.createResource("http://test.vivo/z");
|
||||||
|
|
||||||
|
aBox.add(x,OWL.sameAs,y);
|
||||||
|
aBox.add(y,OWL.sameAs,z);
|
||||||
|
aBox.add(x,RDF.type,classB);
|
||||||
|
|
||||||
|
Assert.assertTrue(inf.contains(y,RDF.type,classB));
|
||||||
|
Assert.assertTrue(inf.contains(y,RDF.type,classA));
|
||||||
|
Assert.assertTrue(inf.contains(z,RDF.type,classB));
|
||||||
|
Assert.assertTrue(inf.contains(z,RDF.type,classA));
|
||||||
|
|
||||||
|
aBox.remove(x,RDF.type,classB);
|
||||||
|
Assert.assertFalse(inf.contains(y,RDF.type,classB));
|
||||||
|
Assert.assertFalse(inf.contains(y,RDF.type,classA));
|
||||||
|
Assert.assertFalse(inf.contains(z,RDF.type,classB));
|
||||||
|
Assert.assertFalse(inf.contains(z,RDF.type,classA));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* adding and removing subclass assertion when there is an
|
||||||
|
* individual member who has a sameAs individual.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void tBoxSubclassAssertion1() throws InterruptedException {
|
||||||
|
|
||||||
|
//create aBox and tBox, and SimpleReasoner to listen to them
|
||||||
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
|
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
|
Model inf = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
|
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||||
|
aBox.register(simpleReasoner);
|
||||||
|
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
||||||
|
tBox.register(simpleReasonerTBoxListener);
|
||||||
|
|
||||||
|
// set up TBox
|
||||||
|
OntClass classA = tBox.createClass("http://test.vivo/A");
|
||||||
|
classA.setLabel("class A", "en-US");
|
||||||
|
OntClass classB = tBox.createClass("http://test.vivo/B");
|
||||||
|
classB.setLabel("class B", "en-US");
|
||||||
|
OntClass classC = tBox.createClass("http://test.vivo/C");
|
||||||
|
classC.setLabel("class C", "en-US");
|
||||||
|
|
||||||
|
// set up ABox
|
||||||
|
Resource a = aBox.createResource("http://test.vivo/a");
|
||||||
|
Resource b = aBox.createResource("http://test.vivo/b");
|
||||||
|
Resource c = aBox.createResource("http://test.vivo/c");
|
||||||
|
|
||||||
|
aBox.add(a, RDF.type, classC);
|
||||||
|
aBox.add(a, OWL.sameAs, b);
|
||||||
|
aBox.add(c, OWL.sameAs, a);
|
||||||
|
|
||||||
|
// update TBox
|
||||||
|
classA.addSubClass(classB);
|
||||||
|
|
||||||
|
// wait for SimpleReasonerTBoxListener thread to end
|
||||||
|
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||||
|
Thread.sleep(delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
classB.addSubClass(classC);
|
||||||
|
classA.addSubClass(classC); // simulate what Pellet would infer, and
|
||||||
|
// thus what the SimpleReasonerTBoxListener
|
||||||
|
// would be notified of.
|
||||||
|
|
||||||
|
// wait for SimpleReasonerTBoxListener thread to end
|
||||||
|
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||||
|
Thread.sleep(delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify inferences
|
||||||
|
Assert.assertFalse(inf.contains(a, RDF.type, classC));
|
||||||
|
Assert.assertTrue(inf.contains(a, RDF.type, classB));
|
||||||
|
Assert.assertTrue(inf.contains(a, RDF.type, classA));
|
||||||
|
|
||||||
|
Assert.assertTrue(inf.contains(b, RDF.type, classC));
|
||||||
|
Assert.assertTrue(inf.contains(b, RDF.type, classB));
|
||||||
|
Assert.assertTrue(inf.contains(b, RDF.type, classA));
|
||||||
|
|
||||||
|
Assert.assertTrue(inf.contains(c, RDF.type, classC));
|
||||||
|
Assert.assertTrue(inf.contains(c, RDF.type, classB));
|
||||||
|
Assert.assertTrue(inf.contains(c, RDF.type, classA));
|
||||||
|
|
||||||
|
// update TBox
|
||||||
|
classA.removeSubClass(classB);
|
||||||
|
classA.removeSubClass(classC); // simulate what Pellet would infer, and
|
||||||
|
// thus what the SimpleReasonerTBoxListener
|
||||||
|
// would be notified of.
|
||||||
|
|
||||||
|
// wait for SimpleReasonerTBoxListener thread to end
|
||||||
|
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||||
|
Thread.sleep(delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify inferences
|
||||||
|
Assert.assertFalse(inf.contains(a, RDF.type, classC));
|
||||||
|
Assert.assertTrue(inf.contains(a, RDF.type, classB));
|
||||||
|
Assert.assertFalse(inf.contains(a, RDF.type, classA));
|
||||||
|
|
||||||
|
Assert.assertTrue(inf.contains(b, RDF.type, classC));
|
||||||
|
Assert.assertTrue(inf.contains(b, RDF.type, classB));
|
||||||
|
Assert.assertFalse(inf.contains(b, RDF.type, classA));
|
||||||
|
|
||||||
|
Assert.assertTrue(inf.contains(c, RDF.type, classC));
|
||||||
|
Assert.assertTrue(inf.contains(c, RDF.type, classB));
|
||||||
|
Assert.assertFalse(inf.contains(c, RDF.type, classA));
|
||||||
|
|
||||||
|
// update TBox
|
||||||
|
classB.removeSubClass(classC);
|
||||||
|
|
||||||
|
// wait for SimpleReasonerTBoxListener thread to end
|
||||||
|
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||||
|
Thread.sleep(delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify inferences
|
||||||
|
Assert.assertFalse(inf.contains(a, RDF.type, classC));
|
||||||
|
Assert.assertFalse(inf.contains(a, RDF.type, classB));
|
||||||
|
Assert.assertFalse(inf.contains(a, RDF.type, classA));
|
||||||
|
|
||||||
|
Assert.assertTrue(inf.contains(b, RDF.type, classC));
|
||||||
|
Assert.assertFalse(inf.contains(b, RDF.type, classB));
|
||||||
|
Assert.assertFalse(inf.contains(b, RDF.type, classA));
|
||||||
|
|
||||||
|
Assert.assertTrue(inf.contains(c, RDF.type, classC));
|
||||||
|
Assert.assertFalse(inf.contains(c, RDF.type, classB));
|
||||||
|
Assert.assertFalse(inf.contains(c, RDF.type, classA));
|
||||||
|
|
||||||
|
simpleReasonerTBoxListener.setStopRequested();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* test that mostSpecificType inferences propagate to sameAs
|
||||||
|
* individuals
|
||||||
|
*/
|
||||||
|
//@Test
|
||||||
|
public void mostSpecificTypeTest1() throws InterruptedException {
|
||||||
|
|
||||||
|
// set up tbox. Pellet is reasoning; SimpleReasonerTBoxListener is not being used.
|
||||||
|
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
||||||
|
AnnotationProperty mostSpecificType = tBox.createAnnotationProperty(mostSpecificTypePropertyURI);
|
||||||
|
|
||||||
|
OntClass classA = tBox.createClass("http://test.vivo/A");
|
||||||
|
classA.setLabel("class A", "en-US");
|
||||||
|
OntClass classC = tBox.createClass("http://test.vivo/C");
|
||||||
|
classC.setLabel("class C", "en-US");
|
||||||
|
OntClass classD = tBox.createClass("http://test.vivo/D");
|
||||||
|
classD.setLabel("class D", "en-US");
|
||||||
|
OntClass classE = tBox.createClass("http://test.vivo/E");
|
||||||
|
classE.setLabel("class E", "en-US");
|
||||||
|
|
||||||
|
classA.addSubClass(classC);
|
||||||
|
classC.addSubClass(classD);
|
||||||
|
classC.addSubClass(classE);
|
||||||
|
|
||||||
|
// this will receive the abox inferences
|
||||||
|
Model inf = ModelFactory.createDefaultModel();
|
||||||
|
|
||||||
|
// abox
|
||||||
|
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||||
|
|
||||||
|
// set up SimpleReasoner and register it with abox
|
||||||
|
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
||||||
|
aBox.register(simpleReasoner);
|
||||||
|
|
||||||
|
// add & remove ABox type statements and verify inferences
|
||||||
|
Resource a = aBox.createResource("http://test.vivo/a");
|
||||||
|
Resource b = aBox.createResource("http://test.vivo/b");
|
||||||
|
Resource c = aBox.createResource("http://test.vivo/c");
|
||||||
|
Resource d = aBox.createResource("http://test.vivo/d");
|
||||||
|
|
||||||
|
aBox.add(a, OWL.sameAs, b);
|
||||||
|
aBox.add(c, OWL.sameAs, b);
|
||||||
|
aBox.add(d, OWL.sameAs, a);
|
||||||
|
|
||||||
|
aBox.add(a, RDF.type, classD);
|
||||||
|
aBox.add(d, RDF.type, classC);
|
||||||
|
Assert.assertFalse(inf.contains(a,RDF.type,classD));
|
||||||
|
Assert.assertTrue(inf.contains(a,RDF.type,classC));
|
||||||
|
Assert.assertTrue(inf.contains(b,RDF.type, classD));
|
||||||
|
Assert.assertTrue(inf.contains(b,RDF.type, classC));
|
||||||
|
Assert.assertTrue(inf.contains(c,RDF.type, classD));
|
||||||
|
Assert.assertTrue(inf.contains(c,RDF.type, classC));
|
||||||
|
Assert.assertTrue(inf.contains(d,RDF.type, classD));
|
||||||
|
Assert.assertFalse(inf.contains(d,RDF.type, classC));
|
||||||
|
|
||||||
|
Assert.assertTrue(inf.contains(a, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||||
|
Assert.assertTrue(inf.contains(b, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||||
|
Assert.assertTrue(inf.contains(c, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||||
|
Assert.assertTrue(inf.contains(d, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||||
|
Assert.assertFalse(inf.contains(a, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||||
|
Assert.assertFalse(inf.contains(b, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||||
|
Assert.assertFalse(inf.contains(c, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||||
|
Assert.assertFalse(inf.contains(d, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||||
|
|
||||||
|
aBox.remove(a, RDF.type, classD);
|
||||||
|
Assert.assertFalse(inf.contains(a,RDF.type,classD));
|
||||||
|
Assert.assertTrue(inf.contains(a,RDF.type,classC));
|
||||||
|
Assert.assertFalse(inf.contains(b,RDF.type, classD));
|
||||||
|
Assert.assertTrue(inf.contains(b,RDF.type, classC));
|
||||||
|
Assert.assertFalse(inf.contains(c,RDF.type, classD));
|
||||||
|
Assert.assertTrue(inf.contains(c,RDF.type, classC));
|
||||||
|
Assert.assertFalse(inf.contains(d,RDF.type, classD));
|
||||||
|
Assert.assertFalse(inf.contains(d,RDF.type, classC));
|
||||||
|
Assert.assertTrue(inf.contains(a, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||||
|
Assert.assertTrue(inf.contains(b, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||||
|
Assert.assertTrue(inf.contains(c, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||||
|
Assert.assertTrue(inf.contains(d, mostSpecificType, ResourceFactory.createResource(classC.getURI())));
|
||||||
|
Assert.assertFalse(inf.contains(a, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||||
|
Assert.assertFalse(inf.contains(b, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||||
|
Assert.assertFalse(inf.contains(c, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||||
|
Assert.assertFalse(inf.contains(d, mostSpecificType, ResourceFactory.createResource(classD.getURI())));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Basic scenario around recomputing the ABox inferences
|
* Basic scenario around recomputing the ABox inferences
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -13,7 +13,6 @@ import com.hp.hpl.jena.ontology.AnnotationProperty;
|
||||||
import com.hp.hpl.jena.ontology.OntClass;
|
import com.hp.hpl.jena.ontology.OntClass;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
import com.hp.hpl.jena.ontology.OntProperty;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
@ -28,7 +27,6 @@ import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
|
||||||
|
|
||||||
public class SimpleReasonerTest extends AbstractTestClass {
|
public class SimpleReasonerTest extends AbstractTestClass {
|
||||||
|
|
||||||
private Resource objectProperty = ResourceFactory.createResource("http://www.w3.org/2002/07/owl#ObjectProperty");
|
|
||||||
private static final String mostSpecificTypePropertyURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#mostSpecificType";
|
private static final String mostSpecificTypePropertyURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#mostSpecificType";
|
||||||
long delay = 50;
|
long delay = 50;
|
||||||
|
|
||||||
|
@ -591,8 +589,12 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
||||||
* inference graph.
|
* inference graph.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
//@Test - enable this in 1.5 - will need to add in PelletListener infrastructure
|
//@Test - this test would need PelletListener infrastructure, which we're not
|
||||||
public void removeTBoxSubClassAssertion2() throws InterruptedException {
|
// testing in this suite. The reason it doesn't work as it is because
|
||||||
|
// the SimpleReasonerTBoxListener is not listening to the tBox inference
|
||||||
|
// model as Pellet is updating it. I could simulate it by adding to the
|
||||||
|
// tBox assertions what we can count on Pellet to infer.
|
||||||
|
public void bcdTest() throws InterruptedException {
|
||||||
// Create TBox, ABox and Inference models and register
|
// Create TBox, ABox and Inference models and register
|
||||||
// the ABox reasoner listeners with the ABox and TBox
|
// the ABox reasoner listeners with the ABox and TBox
|
||||||
// Pellet will compute TBox inferences
|
// Pellet will compute TBox inferences
|
||||||
|
@ -621,6 +623,9 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
||||||
LivingThing.addSubClass(Flora);
|
LivingThing.addSubClass(Flora);
|
||||||
Flora.addSubClass(Brassica);
|
Flora.addSubClass(Brassica);
|
||||||
|
|
||||||
|
tBox.rebind();
|
||||||
|
tBox.prepare();
|
||||||
|
|
||||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||||
Thread.sleep(delay);
|
Thread.sleep(delay);
|
||||||
}
|
}
|
||||||
|
@ -632,6 +637,8 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
||||||
// Remove the statement that Brassica is a subclass of Flora from the TBox
|
// Remove the statement that Brassica is a subclass of Flora from the TBox
|
||||||
Flora.removeSubClass(Brassica);
|
Flora.removeSubClass(Brassica);
|
||||||
|
|
||||||
|
tBox.rebind();
|
||||||
|
tBox.prepare();
|
||||||
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
while (!VitroBackgroundThread.getLivingThreads().isEmpty()) {
|
||||||
Thread.sleep(delay);
|
Thread.sleep(delay);
|
||||||
}
|
}
|
||||||
|
@ -647,411 +654,6 @@ public class SimpleReasonerTest extends AbstractTestClass {
|
||||||
simpleReasonerTBoxListener.setStopRequested();
|
simpleReasonerTBoxListener.setStopRequested();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* tests rdfs:subPropertyOf materialization for object properties.
|
|
||||||
*/
|
|
||||||
// @Test uncomment when sub/equiv property inferencing is enabled. sjm222 5/13/2011
|
|
||||||
public void addABoxAssertion1() throws InterruptedException {
|
|
||||||
|
|
||||||
// Create TBox, ABox and Inference models and register
|
|
||||||
// the ABox reasoner listeners with the ABox and TBox
|
|
||||||
// Pellet will compute TBox inferences
|
|
||||||
|
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
|
||||||
|
|
||||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
|
||||||
aBox.register(simpleReasoner);
|
|
||||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
|
||||||
tBox.register(simpleReasonerTBoxListener);
|
|
||||||
|
|
||||||
// Add object properties propA and propB to the TBox.
|
|
||||||
// propB is a sub-property of propA.
|
|
||||||
|
|
||||||
OntProperty propA = tBox.createOntProperty("http://test.vivo/propA");
|
|
||||||
tBox.add(propA, RDF.type, objectProperty);
|
|
||||||
propA.setLabel("propA", "en-US");
|
|
||||||
|
|
||||||
OntProperty propB = tBox.createOntProperty("http://test.vivo/propB");
|
|
||||||
tBox.add(propB, RDF.type, objectProperty);
|
|
||||||
propB.setLabel("propB", "en-US");
|
|
||||||
|
|
||||||
propA.addSubProperty(propB);
|
|
||||||
|
|
||||||
// Add the assertion that x propB y to the ABox
|
|
||||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
|
||||||
Resource ind_y = aBox.createResource("http://test.vivo/y");
|
|
||||||
aBox.add(ind_x, propB, ind_y);
|
|
||||||
|
|
||||||
// Verify that x propA y was inferred
|
|
||||||
Statement xay = ResourceFactory.createStatement(ind_x, propA, ind_y);
|
|
||||||
Assert.assertTrue(inf.contains(xay));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test that when a statement is asserted, that it not
|
|
||||||
* added to the inference graph.
|
|
||||||
*/
|
|
||||||
// @Test uncomment when sub/equiv property inferencing is enabled. sjm222 5/13/2011
|
|
||||||
public void addABoxAssertion2(){
|
|
||||||
|
|
||||||
// Create TBox, ABox and Inference models and register
|
|
||||||
// the ABox reasoner listeners with the ABox and TBox
|
|
||||||
// Pellet will compute TBox inferences
|
|
||||||
|
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
|
||||||
|
|
||||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
|
||||||
aBox.register(simpleReasoner);
|
|
||||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
|
||||||
tBox.register(simpleReasonerTBoxListener);
|
|
||||||
|
|
||||||
// Add object properties propA and propB to the TBox.
|
|
||||||
// propB is a sub-property of propA.
|
|
||||||
|
|
||||||
OntProperty propA = tBox.createOntProperty("http://test.vivo/propA");
|
|
||||||
tBox.add(propA, RDF.type, objectProperty);
|
|
||||||
propA.setLabel("propA", "en-US");
|
|
||||||
|
|
||||||
OntProperty propB = tBox.createOntProperty("http://test.vivo/propB");
|
|
||||||
tBox.add(propB, RDF.type, objectProperty);
|
|
||||||
propB.setLabel("propB", "en-US");
|
|
||||||
|
|
||||||
propA.addSubProperty(propB);
|
|
||||||
|
|
||||||
// Add the assertion that x propB y to the ABox
|
|
||||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
|
||||||
Resource ind_y = aBox.createResource("http://test.vivo/y");
|
|
||||||
aBox.add(ind_x, propB, ind_y);
|
|
||||||
|
|
||||||
// Verify that x propA y was inferred
|
|
||||||
Statement xby = ResourceFactory.createStatement(ind_x, propB, ind_y);
|
|
||||||
Assert.assertFalse(inf.contains(xby));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test inference based on property equivalence
|
|
||||||
*/
|
|
||||||
// @Test uncomment when sub/equiv property inferencing is enabled. sjm222 5/13/2011
|
|
||||||
public void addABoxAssertion4(){
|
|
||||||
|
|
||||||
// Create TBox, ABox and Inference models and register
|
|
||||||
// the ABox reasoner listeners with the ABox and TBox
|
|
||||||
// Pellet will compute TBox inferences
|
|
||||||
|
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
|
||||||
|
|
||||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
|
||||||
aBox.register(simpleReasoner);
|
|
||||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
|
||||||
tBox.register(simpleReasonerTBoxListener);
|
|
||||||
|
|
||||||
// Add properties A, B and C to the TBox
|
|
||||||
// A is equivalent to B
|
|
||||||
// C is a subclass of A
|
|
||||||
|
|
||||||
OntProperty propA = tBox.createOntProperty("http://test.vivo/A");
|
|
||||||
tBox.add(propA, RDF.type, objectProperty);
|
|
||||||
propA.setLabel("property A", "en-US");
|
|
||||||
|
|
||||||
OntProperty propB = tBox.createOntProperty("http://test.vivo/B");
|
|
||||||
tBox.add(propB, RDF.type, objectProperty);
|
|
||||||
propB.setLabel("property B", "en-US");
|
|
||||||
|
|
||||||
OntProperty propC = tBox.createOntProperty("http://test.vivo/C");
|
|
||||||
tBox.add(propC, RDF.type, objectProperty);
|
|
||||||
propC.setLabel("property C", "en-US");
|
|
||||||
|
|
||||||
propA.addEquivalentProperty(propB);
|
|
||||||
propA.addSubProperty(propC);
|
|
||||||
|
|
||||||
// Add a statement that individual x is of type C to the ABox
|
|
||||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
|
||||||
Resource ind_y = aBox.createResource("http://test.vivo/y");
|
|
||||||
|
|
||||||
aBox.add(ind_x, propC, ind_y);
|
|
||||||
|
|
||||||
// Verify that "x A y" was inferred
|
|
||||||
Statement xAy = ResourceFactory.createStatement(ind_x, propA, ind_y);
|
|
||||||
Assert.assertTrue(inf.contains(xAy));
|
|
||||||
|
|
||||||
// Verify that "x B y" was inferred
|
|
||||||
Statement xBy = ResourceFactory.createStatement(ind_x, propB, ind_y);
|
|
||||||
Assert.assertTrue(inf.contains(xBy));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The sub-property is not of the same type as the super
|
|
||||||
* property so no inference should be materialized.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// @Test uncomment when sub/equiv property inferencing is enabled. sjm222 5/13/2011
|
|
||||||
public void addABoxAssertion5(){
|
|
||||||
|
|
||||||
// Create TBox, ABox and Inference models and register
|
|
||||||
// the ABox reasoner listeners with the ABox and TBox
|
|
||||||
// Pellet will compute TBox inferences
|
|
||||||
|
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
|
||||||
|
|
||||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
|
||||||
aBox.register(simpleReasoner);
|
|
||||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
|
||||||
tBox.register(simpleReasonerTBoxListener);
|
|
||||||
|
|
||||||
// Add object properties propA and propB to the TBox.
|
|
||||||
// propB is a sub-property of propA.
|
|
||||||
|
|
||||||
OntProperty propA = tBox.createOntProperty("http://test.vivo/propA");
|
|
||||||
tBox.add(propA, RDF.type, objectProperty);
|
|
||||||
propA.setLabel("propA", "en-US");
|
|
||||||
|
|
||||||
OntProperty propB = tBox.createOntProperty("http://test.vivo/propB");
|
|
||||||
Resource datatypeProperty = ResourceFactory.createResource("http://www.w3.org/2002/07/owl#DatatypeProperty");
|
|
||||||
tBox.add(propB, RDF.type, datatypeProperty);
|
|
||||||
propB.setLabel("propB", "en-US");
|
|
||||||
|
|
||||||
propA.addSubProperty(propB);
|
|
||||||
|
|
||||||
// Add the assertion that x propB y to the ABox
|
|
||||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
|
||||||
Resource ind_y = aBox.createResource("http://test.vivo/y");
|
|
||||||
aBox.add(ind_x, propB, ind_y);
|
|
||||||
|
|
||||||
// Verify that x propA y was not inferred
|
|
||||||
Statement xay = ResourceFactory.createStatement(ind_x, propA, ind_y);
|
|
||||||
Assert.assertFalse(inf.contains(xay));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test inference based on property equivalence
|
|
||||||
*/
|
|
||||||
// @Test uncomment when sub/equiv property inferencing is enabled. sjm222 5/13/2011
|
|
||||||
public void addABoxAssertion6() {
|
|
||||||
|
|
||||||
// Create TBox, ABox and Inference models and register
|
|
||||||
// the ABox reasoner listeners with the ABox and TBox
|
|
||||||
// Pellet will compute TBox inferences
|
|
||||||
|
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
|
||||||
|
|
||||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
|
||||||
aBox.register(simpleReasoner);
|
|
||||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
|
||||||
tBox.register(simpleReasonerTBoxListener);
|
|
||||||
|
|
||||||
// Add properties A and B to the TBox
|
|
||||||
// A is equivalent to B
|
|
||||||
|
|
||||||
OntProperty propA = tBox.createOntProperty("http://test.vivo/A");
|
|
||||||
tBox.add(propA, RDF.type, objectProperty);
|
|
||||||
propA.setLabel("property A", "en-US");
|
|
||||||
|
|
||||||
OntProperty propB = tBox.createOntProperty("http://test.vivo/B");
|
|
||||||
tBox.add(propB, RDF.type, objectProperty);
|
|
||||||
propB.setLabel("property B", "en-US");
|
|
||||||
|
|
||||||
propA.addEquivalentProperty(propB);
|
|
||||||
|
|
||||||
// Add the statement x B y to the ABox
|
|
||||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
|
||||||
Resource ind_y = aBox.createResource("http://test.vivo/y");
|
|
||||||
aBox.add(ind_x, propB, ind_y);
|
|
||||||
|
|
||||||
// Verify that "x A y" was inferred
|
|
||||||
Statement xAy = ResourceFactory.createStatement(ind_x, propA, ind_y);
|
|
||||||
Assert.assertTrue(inf.contains(xAy));
|
|
||||||
|
|
||||||
// Remove the statement that x B y from the ABox
|
|
||||||
aBox.remove(ind_x, propB, ind_y);
|
|
||||||
|
|
||||||
// Verify that "x is of type A" was removed from the inference graph
|
|
||||||
Assert.assertFalse(inf.contains(xAy));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test the addition of a subPropertyOf statement to
|
|
||||||
* the TBox. The instance data that is the basis
|
|
||||||
* for the inference is in the ABox.
|
|
||||||
*
|
|
||||||
* Since the addition of an owl:equivalentProperty
|
|
||||||
* statement is implemented as two calls to the
|
|
||||||
* method that handles the addition of an
|
|
||||||
* rdfs:subPropetyOf statement, this test serves
|
|
||||||
* as a test of equivalentProperty assertions also.
|
|
||||||
*/
|
|
||||||
// @Test uncomment when sub/equiv property inferencing is enabled. sjm222 5/13/2011
|
|
||||||
public void addTBoxSubPropertyAssertion1(){
|
|
||||||
|
|
||||||
// Create TBox, ABox and Inference models and register
|
|
||||||
// the ABox reasoner listeners with the ABox and TBox
|
|
||||||
// Pellet will compute TBox inferences
|
|
||||||
|
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
|
||||||
|
|
||||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
|
||||||
aBox.register(simpleReasoner);
|
|
||||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
|
||||||
tBox.register(simpleReasonerTBoxListener);
|
|
||||||
|
|
||||||
// Add properties A, B, C and D to the TBox
|
|
||||||
OntProperty propA = tBox.createOntProperty("http://test.vivo/A");
|
|
||||||
tBox.add(propA, RDF.type, objectProperty);
|
|
||||||
propA.setLabel("property A", "en-US");
|
|
||||||
|
|
||||||
OntProperty propB = tBox.createOntProperty("http://test.vivo/B");
|
|
||||||
tBox.add(propB, RDF.type, objectProperty);
|
|
||||||
propB.setLabel("property B", "en-US");
|
|
||||||
|
|
||||||
OntProperty propC = tBox.createOntProperty("http://test.vivo/C");
|
|
||||||
tBox.add(propC, RDF.type, objectProperty);
|
|
||||||
propB.setLabel("property C", "en-US");
|
|
||||||
|
|
||||||
OntProperty propD = tBox.createOntProperty("http://test.vivo/D");
|
|
||||||
tBox.add(propD, RDF.type, objectProperty);
|
|
||||||
propB.setLabel("property D", "en-US");
|
|
||||||
|
|
||||||
// Add the statement "x C y" to the ABox
|
|
||||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
|
||||||
Resource ind_y = aBox.createResource("http://test.vivo/y");
|
|
||||||
aBox.add(ind_x, propC, ind_y);
|
|
||||||
|
|
||||||
// Add a statement that C is a sub-property of A to the TBox
|
|
||||||
|
|
||||||
propA.addSubProperty(propC);
|
|
||||||
|
|
||||||
// Verify that "x A y" was inferred
|
|
||||||
Statement xAy = ResourceFactory.createStatement(ind_x, propA, ind_y);
|
|
||||||
Assert.assertTrue(inf.contains(xAy));
|
|
||||||
|
|
||||||
// Verify that "x B y" was not inferred
|
|
||||||
Statement xBy = ResourceFactory.createStatement(ind_x, propB, ind_y);
|
|
||||||
Assert.assertFalse(inf.contains(xBy));
|
|
||||||
|
|
||||||
// Verify that "x D y" was not inferred
|
|
||||||
Statement xDy = ResourceFactory.createStatement(ind_x, propD, ind_y);
|
|
||||||
Assert.assertFalse(inf.contains(xDy));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test the removal of a subPropertyOf statement from
|
|
||||||
* the TBox. The instance data that is the basis
|
|
||||||
* for the inference is in the ABox graph and the
|
|
||||||
* inference graph.
|
|
||||||
*
|
|
||||||
* Since the addition of an owl:equivalentProperty
|
|
||||||
* statement is implemented as two calls to the
|
|
||||||
* method that handles the addition of an
|
|
||||||
* rdfs:subPropertyOf statement, this test serves
|
|
||||||
* as a test of equivalentProperty assertions also.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// @Test uncomment when sub/equiv property inferencing is enabled. sjm222 5/13/2011
|
|
||||||
public void removeTBoxSubPropertyAssertion1(){
|
|
||||||
// Create TBox, ABox and Inference models and register
|
|
||||||
// the ABox reasoner listeners with the ABox and TBox
|
|
||||||
// Pellet will compute TBox inferences
|
|
||||||
|
|
||||||
OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
|
|
||||||
OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
|
||||||
Model inf = ModelFactory.createDefaultModel();
|
|
||||||
|
|
||||||
SimpleReasoner simpleReasoner = new SimpleReasoner(tBox, aBox, inf);
|
|
||||||
aBox.register(simpleReasoner);
|
|
||||||
SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner);
|
|
||||||
tBox.register(simpleReasonerTBoxListener);
|
|
||||||
|
|
||||||
// Add properties A, B, C, D, E, F, G and H to the TBox.
|
|
||||||
// B, C and D are subproperties of A.
|
|
||||||
// E is a subproperty of B.
|
|
||||||
// F and G are subproperties of C.
|
|
||||||
// H is a subproperty of D.
|
|
||||||
|
|
||||||
OntProperty propA = tBox.createOntProperty("http://test.vivo/A");
|
|
||||||
tBox.add(propA, RDF.type, objectProperty);
|
|
||||||
propA.setLabel("property A", "en-US");
|
|
||||||
|
|
||||||
OntProperty propB = tBox.createOntProperty("http://test.vivo/B");
|
|
||||||
tBox.add(propB, RDF.type, objectProperty);
|
|
||||||
propB.setLabel("property B", "en-US");
|
|
||||||
|
|
||||||
OntProperty propC = tBox.createOntProperty("http://test.vivo/C");
|
|
||||||
tBox.add(propC, RDF.type, objectProperty);
|
|
||||||
propB.setLabel("property C", "en-US");
|
|
||||||
|
|
||||||
OntProperty propD = tBox.createOntProperty("http://test.vivo/D");
|
|
||||||
tBox.add(propD, RDF.type, objectProperty);
|
|
||||||
propB.setLabel("property D", "en-US");
|
|
||||||
|
|
||||||
OntProperty propE = tBox.createOntProperty("http://test.vivo/E");
|
|
||||||
tBox.add(propE, RDF.type, objectProperty);
|
|
||||||
propB.setLabel("property E", "en-US");
|
|
||||||
|
|
||||||
OntProperty propF = tBox.createOntProperty("http://test.vivo/F");
|
|
||||||
tBox.add(propF, RDF.type, objectProperty);
|
|
||||||
propB.setLabel("property F", "en-US");
|
|
||||||
|
|
||||||
OntProperty propG = tBox.createOntProperty("http://test.vivo/G");
|
|
||||||
tBox.add(propG, RDF.type, objectProperty);
|
|
||||||
propB.setLabel("property G", "en-US");
|
|
||||||
|
|
||||||
OntProperty propH = tBox.createOntProperty("http://test.vivo/H");
|
|
||||||
tBox.add(propH, RDF.type, objectProperty);
|
|
||||||
propB.setLabel("property H", "en-US");
|
|
||||||
|
|
||||||
propA.addSubProperty(propB);
|
|
||||||
propA.addSubProperty(propC);
|
|
||||||
propA.addSubProperty(propD);
|
|
||||||
propB.addSubProperty(propE);
|
|
||||||
propC.addSubProperty(propF);
|
|
||||||
propC.addSubProperty(propG);
|
|
||||||
propD.addSubProperty(propH);
|
|
||||||
|
|
||||||
// Add the statement "x E y" to the ABox
|
|
||||||
Resource ind_x = aBox.createResource("http://test.vivo/x");
|
|
||||||
Resource ind_y = aBox.createResource("http://test.vivo/y");
|
|
||||||
aBox.add(ind_x, propE, ind_y);
|
|
||||||
|
|
||||||
// Remove the statement that B is a subproperty of A from the TBox
|
|
||||||
propA.removeSubProperty(propB);
|
|
||||||
|
|
||||||
// Verify that "x A y" is not in the inference graph
|
|
||||||
Statement xAy = ResourceFactory.createStatement(ind_x, propA, ind_y);
|
|
||||||
Assert.assertFalse(inf.contains(xAy));
|
|
||||||
|
|
||||||
// Verify that "x B y" is in the inference graph
|
|
||||||
Statement xBy = ResourceFactory.createStatement(ind_x, propB, ind_y);
|
|
||||||
Assert.assertTrue(inf.contains(xBy));
|
|
||||||
|
|
||||||
// Add statements "w F z" and "w H z" to the ABox
|
|
||||||
Resource ind_z = aBox.createResource("http://test.vivo/z");
|
|
||||||
Resource ind_w = aBox.createResource("http://test.vivo/w");
|
|
||||||
aBox.add(ind_w, propF, ind_z);
|
|
||||||
aBox.add(ind_w, propH, ind_z);
|
|
||||||
|
|
||||||
// Remove the statement that C is a subproperty of A from the TBox
|
|
||||||
propA.removeSubProperty(propC);
|
|
||||||
|
|
||||||
// Verify that "w A z" is in the inference graph
|
|
||||||
Statement wAz = ResourceFactory.createStatement(ind_w, propA, ind_z);
|
|
||||||
Assert.assertTrue(inf.contains(wAz));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test computation of mostSpecificType annotations in response
|
* Test computation of mostSpecificType annotations in response
|
||||||
* to an added/removed ABox type assertion.
|
* to an added/removed ABox type assertion.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue