diff --git a/webapp/config/licenser/known_exceptions.txt b/webapp/config/licenser/known_exceptions.txt index f846f0823..9ad0c3fc4 100644 --- a/webapp/config/licenser/known_exceptions.txt +++ b/webapp/config/licenser/known_exceptions.txt @@ -188,7 +188,3 @@ webapp/src/edu/ucsf/vitro/opensocial/GadgetViewRequirements.java webapp/src/edu/ucsf/vitro/opensocial/OpenSocialManager.java webapp/src/edu/ucsf/vitro/opensocial/PreparedGadget.java webapp/web/js/openSocial/shindig.js - -# This is a modified version of a Jena source file. -# It is required to make Jena 2.10.1 compatible with Pellet 2.3.1 -webapp/src/com/hp/hpl/jena/reasoner/BaseInfGraph.java \ No newline at end of file diff --git a/webapp/lib/pellet-core.jar b/webapp/lib/pellet-core.jar deleted file mode 100644 index ebaf120bb..000000000 Binary files a/webapp/lib/pellet-core.jar and /dev/null differ diff --git a/webapp/lib/pellet-datatypes.jar b/webapp/lib/pellet-datatypes.jar deleted file mode 100644 index 2e1722bb2..000000000 Binary files a/webapp/lib/pellet-datatypes.jar and /dev/null differ diff --git a/webapp/lib/pellet-el.jar b/webapp/lib/pellet-el.jar deleted file mode 100644 index 90f0d01c3..000000000 Binary files a/webapp/lib/pellet-el.jar and /dev/null differ diff --git a/webapp/lib/pellet-jena.jar b/webapp/lib/pellet-jena.jar deleted file mode 100644 index e3b7458ce..000000000 Binary files a/webapp/lib/pellet-jena.jar and /dev/null differ diff --git a/webapp/lib/pellet-rules.jar b/webapp/lib/pellet-rules.jar deleted file mode 100644 index b7aa4d850..000000000 Binary files a/webapp/lib/pellet-rules.jar and /dev/null differ diff --git a/webapp/src/com/hp/hpl/jena/reasoner/BaseInfGraph.java b/webapp/src/com/hp/hpl/jena/reasoner/BaseInfGraph.java deleted file mode 100644 index 69f40938d..000000000 --- a/webapp/src/com/hp/hpl/jena/reasoner/BaseInfGraph.java +++ /dev/null @@ -1,544 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.hp.hpl.jena.reasoner; - -import com.hp.hpl.jena.graph.*; -import com.hp.hpl.jena.graph.compose.MultiUnion; -import com.hp.hpl.jena.graph.impl.*; -import com.hp.hpl.jena.shared.*; -import com.hp.hpl.jena.util.iterator.*; -import java.util.Iterator; - -/** - * A base level implementation of the InfGraph interface. - */ -public abstract class BaseInfGraph extends GraphBase implements InfGraph { - - /** The Reasoner instance which performs all inferences and Tbox lookups */ - protected Reasoner reasoner; - - /** The graph of raw data which is being reasoned over */ - protected FGraph fdata; - - /** Flag, if set to true then derivations are recorded */ - protected boolean recordDerivations; - - /** Flag to record if the preparation call has been made and so the graph is ready for queries */ - protected volatile boolean isPrepared = false; - - /** version count */ - protected volatile int version = 0; - - /** - Inference graphs share the prefix-mapping of their underlying raw graph. - @see com.hp.hpl.jena.graph.Graph#getPrefixMapping() - */ - @Override - public PrefixMapping getPrefixMapping() - { return getRawGraph().getPrefixMapping(); } - - /** - * Constructor - * @param data the raw data file to be augmented with entailments - * @param reasoner the engine, with associated tbox data, whose find interface - * can be used to extract all entailments from the data. - */ - public BaseInfGraph(Graph data, Reasoner reasoner) { - super( ); - this.fdata = new FGraph( data ); - this.reasoner = reasoner; - } - - /** - Answer the InfCapabilities of this InfGraph. - */ - @Override - public Capabilities getCapabilities() { - if (capabilities == null) { - return getReasoner().getGraphCapabilities(); - } else { - return capabilities; - } - } - - /** - An InfCapabilities notes that size may not be accurate, and some - triples may be irremovable. - - TODO accomodate the properties of the base graph, too. - */ - public static class InfCapabilities extends AllCapabilities - { - @Override - public boolean sizeAccurate() { return false; } - @Override - public boolean deleteAllowed( boolean every ) { return !every; } - @Override - public boolean iteratorRemoveAllowed() { return false; } - @Override - public boolean findContractSafe() { return false; } - } - - /** - An InfCapabilities notes that size may not be accurate, and some - triples may be irremovable. - - TODO accomodate the properties of the base graph, too. - */ - public static class InfFindSafeCapabilities extends InfCapabilities - { - @Override - public boolean findContractSafe() { return true; } - } - - /** - @deprecated Bulk update operations are going to be removed. - @see GraphUtil for convenience helpers. - */ - - @Override - @Deprecated - public BulkUpdateHandler getBulkUpdateHandler() - { - if (bulkHandler == null) bulkHandler = new InfBulkUpdateHandler( this ); - return bulkHandler; - } - - /** - InfBulkUpdateHandler - a bulk update handler specialised for inference - graphs by code for removeAll(). - */ - static class InfBulkUpdateHandler extends SimpleBulkUpdateHandler - { - public InfBulkUpdateHandler( BaseInfGraph graph ) - { super(graph); } - - @Override - @Deprecated - public void remove( Node s, Node p, Node o ) - { - BaseInfGraph g = (BaseInfGraph) graph; - g.getRawGraph().remove( s, p, o ); - g.discardState(); - g.rebind(); - manager.notifyEvent( graph, GraphEvents.remove( s, p, o ) ); - } - - @Override - @Deprecated - public void removeAll() - { - BaseInfGraph g = (BaseInfGraph) graph; - g.getRawGraph().clear(); - g.discardState(); - g.rebind(); - g.getEventManager().notifyEvent( g, GraphEvents.removeAll ); - } - } - - @Override - public void remove( Node s, Node p, Node o ) - { - getRawGraph().remove( s, p, o ); - discardState(); - rebind(); - getEventManager().notifyEvent( this, GraphEvents.remove( s, p, o ) ); - } - - @Override - public void clear() - { - getRawGraph().clear() ; - discardState(); - rebind(); - getEventManager().notifyEvent( this, GraphEvents.removeAll ); - } - - - @Override - public TransactionHandler getTransactionHandler() - { return new InfTransactionHandler( this ); } - - public static class InfTransactionHandler - extends TransactionHandlerBase implements TransactionHandler - { - protected final BaseInfGraph base; - - public InfTransactionHandler( BaseInfGraph base ) - { this.base = base; } - - @Override - public boolean transactionsSupported() - { return getBaseHandler().transactionsSupported(); } - - protected TransactionHandler getBaseHandler() - { return base.getRawGraph().getTransactionHandler(); } - - @Override - public void begin() - { getBaseHandler().begin(); } - - @Override - public void abort() - { getBaseHandler().abort(); - base.rebind(); } - - @Override - public void commit() - { getBaseHandler().commit(); } - } - - /** - discard any state that depends on the content of fdata, because - it's just been majorly trashed, solid gone. - */ - protected void discardState() - {} - - /** - * Return the raw RDF data Graph being processed (i.e. the argument - * to the Reasonder.bind call that created this InfGraph). - */ - @Override - public Graph getRawGraph() { - return fdata.getGraph(); - } - - /** - * Return the Reasoner which is being used to answer queries to this graph. - */ - @Override - public Reasoner getReasoner() { - return reasoner; - } - - /** - * Replace the underlying data graph for this inference graph and start any - * inferences over again. This is primarily using in setting up ontology imports - * processing to allow an imports multiunion graph to be inserted between the - * inference graph and the raw data, before processing. - * @param data the new raw data graph - */ - @Override - public synchronized void rebind(Graph data) { - fdata = new FGraph(data); - isPrepared = false; - } - - /** - * Cause the inference graph to reconsult the underlying graph to take - * into account changes. Normally changes are made through the InfGraph's add and - * remove calls are will be handled appropriately. However, in some cases changes - * are made "behind the InfGraph's back" and this forces a full reconsult of - * the changed data. - */ - @Override - public synchronized void rebind() { - version++; - isPrepared = false; - } - - /** - * Reset any internal caches. Some systems, such as the tabled backchainer, - * retain information after each query. A reset will wipe this information preventing - * unbounded memory use at the expense of more expensive future queries. A reset - * does not cause the raw data to be reconsulted and so is less expensive than a rebind. - */ - @Override - public void reset() { - version++; - } - - /** - * Perform any initial processing and caching. This call is optional. Most - * engines either have negligable set up work or will perform an implicit - * "prepare" if necessary. The call is provided for those occasions where - * substantial preparation work is possible (e.g. running a forward chaining - * rule system) and where an application might wish greater control over when - * this prepration is done. - */ - @Override - public synchronized void prepare() { - // Default is to do no preparation - isPrepared = true; - } - - /** - * Returns a derivations graph. The rule reasoners typically create a - * graph containing those triples added to the base graph due to rule firings. - * In some applications it can useful to be able to access those deductions - * directly, without seeing the raw data which triggered them. In particular, - * this allows the forward rules to be used as if they were rewrite transformation - * rules. - * @return the deductions graph, if relevant for this class of inference - * engine or null if not. - */ - @Override - public Graph getDeductionsGraph() { - return null; - } - - /** - * Test a global boolean property of the graph. This might included - * properties like consistency, OWLSyntacticValidity etc. - * It remains to be seen what level of generality is needed here. We could - * replace this by a small number of specific tests for common concepts. - * @param property the URI of the property to be tested - * @return a Node giving the value of the global property, this may - * be a boolean literal, some other literal value (e.g. a size). - */ - @Override - public Node getGlobalProperty(Node property) { - throw new ReasonerException("Global property not implemented: " + property); - } - - /** - * A convenience version of getGlobalProperty which can only return - * a boolean result. - */ - @Override - public boolean testGlobalProperty(Node property) { - Node resultNode = getGlobalProperty(property); - if (resultNode.isLiteral()) { - Object result = resultNode.getLiteralValue(); - if (result instanceof Boolean) { - return ((Boolean)result).booleanValue(); - } - } - throw new ReasonerException("Global property test returned non-boolean value" + - "\nTest was: " + property + - "\nResult was: " + resultNode); - } - - /** - * Test the consistency of the bound data. This normally tests - * the validity of the bound instance data against the bound - * schema data. - * @return a ValidityReport structure - */ - @Override - public ValidityReport validate() { - checkOpen(); - return new StandardValidityReport(); - } - - /** - * An extension of the Graph.find interface which allows the caller to - * encode complex expressions in RDF and then refer to those expressions - * within the query triple. For example, one might encode a class expression - * and then ask if there are any instances of this class expression in the - * InfGraph. - * @param subject the subject Node of the query triple, may be a Node in - * the graph or a node in the parameter micro-graph or null - * @param property the property to be retrieved or null - * @param object the object Node of the query triple, may be a Node in - * the graph or a node in the parameter micro-graph. - * @param param a small graph encoding an expression which the subject and/or - * object nodes refer. - */ - @Override - public ExtendedIterator find(Node subject, Node property, Node object, Graph param) { - return cloneWithPremises(param).find(subject, property, object); - } - - /** - * Returns an iterator over Triples. - * - *

This code used to have the .filterKeep component uncommented. We - * think this is because of earlier history, before .matches on a literal node - * was implemented as sameValueAs rather than equals. If it turns out that - * the filter is needed, it can be commented back in, AND a corresponding - * filter added to find(Node x 3) -- and test cases, of course. - */ - @Override - public ExtendedIterator graphBaseFind(TripleMatch m) { - return graphBaseFind(m.getMatchSubject(), m.getMatchPredicate(), m.getMatchObject()) - // .filterKeep(new TripleMatchFilter(m.asTriple())) - ; - } - - /** - * Returns an iterator over Triples. - * This implementation assumes that the underlying findWithContinuation - * will have also consulted the raw data. - */ - @Override - public ExtendedIterator graphBaseFind(Node subject, Node property, Node object) { - return findWithContinuation(new TriplePattern(subject, property, object), fdata); - } - - /** - * Extended find interface used in situations where the implementator - * may or may not be able to answer the complete query. It will - * attempt to answer the pattern but if its answers are not known - * to be complete then it will also pass the request on to the nested - * Finder to append more results. - * @param pattern a TriplePattern to be matched against the data - * @param continuation either a Finder or a normal Graph which - * will be asked for additional match results if the implementor - * may not have completely satisfied the query. - */ - abstract public ExtendedIterator findWithContinuation(TriplePattern pattern, Finder continuation); - - - /** - * Basic pattern lookup interface. - * This implementation assumes that the underlying findWithContinuation - * will have also consulted the raw data. - * @param pattern a TriplePattern to be matched against the data - * @return a ExtendedIterator over all Triples in the data set - * that match the pattern - */ - public ExtendedIterator find(TriplePattern pattern) { - checkOpen(); - return findWithContinuation(pattern, fdata); - } - - /** - * Switch on/off drivation logging - */ - @Override - public void setDerivationLogging(boolean logOn) { - recordDerivations = logOn; - } - - /** - * Return the derivation of the given triple (which is the result of - * some previous find operation). - * Not all reasoneers will support derivations. - * @return an iterator over Derivation records or null if there is no derivation information - * available for this triple. - */ - @Override - public Iterator getDerivation(Triple triple) { - return null; - } - - /** - * Return the number of triples in the just the base graph - */ - @Override - public int graphBaseSize() { - checkOpen(); - return fdata.getGraph().size(); - } - - /** - Answer true iff this graph is empty. [Used to be in QueryHandler, but moved in - here because it's a more primitive operation.] - */ - @Override - public boolean isEmpty() { - return fdata.getGraph().isEmpty(); - } - - /** - * Free all resources, any further use of this Graph is an error. - */ - @Override - public void close() { - if (!closed) { - fdata.getGraph().close(); - fdata = null; - super.close(); - } - } - - /** - * Return a version stamp for this graph which can be - * used to fast-fail concurrent modification exceptions. - */ - public int getVersion() { - return version; - } - - /** - * Add one triple to the data graph, run any rules triggered by - * the new data item, recursively adding any generated triples. - */ - @Override - public synchronized void performAdd(Triple t) { - version++; - this.requirePrepared(); - fdata.getGraph().add(t); - } - - /** - * Removes the triple t (if possible) from the set belonging to this graph. - */ - @Override - public void performDelete(Triple t) { - version++; - this.requirePrepared(); - fdata.getGraph().delete(t); - } - - /** - * Return the schema graph, if any, bound into this inference graph. - */ - public abstract Graph getSchemaGraph(); - - /** - * Return a new inference graph which is a clone of the current graph - * together with an additional set of data premises. The default - * implementation loses ALL partial deductions so far. Some subclasses - * may be able to a more efficient job. - */ - public InfGraph cloneWithPremises(Graph premises) { - MultiUnion union = new MultiUnion(); - Graph raw = getRawGraph(); - union.addGraph( raw ); - union.setBaseGraph( raw ); - union.addGraph( premises ); - Graph schema = getSchemaGraph(); - if (schema != null) { - if (schema instanceof BaseInfGraph) { - BaseInfGraph ischema = (BaseInfGraph)schema; - Graph sschema = ischema.getSchemaGraph(); - if (sschema != null) union.addGraph( sschema ); - Graph rschema = ischema.getRawGraph(); - if (rschema != null) union.addGraph( rschema ); - } - - } - return getReasoner().bind(union); - } - - /** - Answer true iff this graph has been through the prepare() step. - For testing purposes. - * @return Whether the graph is prepared - */ - public synchronized boolean isPrepared() - { return isPrepared; } - - /** - * Reset prepared state to false - */ - protected synchronized void setPreparedState(boolean state) { - this.isPrepared = state; - } - - /** - * Checks whether the graph is prepared and calls {@link #prepare()} if it is not - */ - protected synchronized void requirePrepared() { - if (!this.isPrepared) this.prepare(); - } -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaAdminActions.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaAdminActions.java index 65e164714..5a9de5389 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaAdminActions.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaAdminActions.java @@ -297,9 +297,6 @@ public class JenaAdminActions extends BaseEditController { } else if (request.getParameter("inferences") != null) { memoryModel = ModelAccess.on(getServletContext()).getOntModel(FULL_INFERENCES); System.out.println("inferenceOntModel"); - } else if (request.getParameter("pellet") != null) { - memoryModel = (OntModel) getServletContext().getAttribute("pelletOntModel"); - System.out.println("pelletOntModel"); } else { memoryModel = ModelAccess.on(getServletContext()).getOntModel(); System.out.println("jenaOntModel"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java index 6a2dba03e..a843a894e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java @@ -17,10 +17,8 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URI; import java.net.URISyntaxException; -import java.text.Collator; import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; @@ -38,8 +36,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.mindswap.pellet.exceptions.InconsistentOntologyException; -import org.mindswap.pellet.jena.PelletReasonerFactory; +import org.semanticweb.owlapi.reasoner.InconsistentOntologyException; import com.hp.hpl.jena.ontology.Individual; import com.hp.hpl.jena.ontology.OntModel; @@ -837,12 +834,7 @@ public class JenaIngestController extends BaseEditController { private long doExecuteSparql(VitroRequest vreq) { OntModel jenaOntModel = ModelAccess.on(getServletContext()).getOntModel(); - OntModel source = null; - if ("pellet".equals(vreq.getParameter("reasoning"))) { - source = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - } else { - source = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM); - } + OntModel source = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM); String[] sourceModel = vreq.getParameterValues("sourceModelName"); for (int i=0; i { - - Collator collator; - - public CollationSort(VitroRequest vreq) { - this.collator = vreq.getCollator(); - } - - @Override - public int compare(String s1, String s2) { - return collator.compare(s1, s2); - } - - } - public static Model getModel(String name, HttpServletRequest request) { return getModelMaker(request).getModel(name); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/tboxreasoner/ConfiguredReasonerListener.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/tboxreasoner/ConfiguredReasonerListener.java index 8ce096af4..42ec57f1d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/tboxreasoner/ConfiguredReasonerListener.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/tboxreasoner/ConfiguredReasonerListener.java @@ -339,7 +339,7 @@ public class ConfiguredReasonerListener implements ModelChangedListener { // It originally assumed that only resources would be in object // position, but cardinality axioms will have e.g. nonNegativeIntegers. // This is a temporary workaround: all cardinality statements will - // be exposed to Pellet, regardless of configuration patterns. + // be exposed to the TBox reasoner, regardless of configuration patterns. private boolean hasCardinalityPredicate(Statement stmt) { return (stmt.getPredicate().equals(OWL.cardinality) || stmt.getPredicate().equals(OWL.minCardinality) || stmt diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/tboxreasoner/ReasonerConfiguration.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/tboxreasoner/ReasonerConfiguration.java index 8f6889ba2..ed7f33341 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/tboxreasoner/ReasonerConfiguration.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/tboxreasoner/ReasonerConfiguration.java @@ -5,9 +5,6 @@ package edu.cornell.mannlib.vitro.webapp.tboxreasoner; import java.util.HashSet; import java.util.Set; -import org.mindswap.pellet.jena.PelletReasonerFactory; - -import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDFS; @@ -25,8 +22,6 @@ public class ReasonerConfiguration { private boolean reasonOnAllDatatypePropertyStatements = false; private boolean queryForAllDatatypeProperties = false; - private OntModelSpec ontModelSpec = PelletReasonerFactory.THE_SPEC; - /** * The default reasoner configuration is designed to provide acceptable performance on larger knowledge bases. * It will classify and realize, and add inferred disjointWith statements. @@ -54,8 +49,6 @@ public class ReasonerConfiguration { public static ReasonerConfiguration PSEUDOCOMPLETE_IGNORE_DATAPROPERTIES; static { - - //ask the reasoner only to classify, realize, and infer disjointWith statements (based on a somewhat incomplete information) DEFAULT = new ReasonerConfiguration(); HashSet defaultInferenceDrivingPatternAllowSet = new HashSet<>(); @@ -164,14 +157,6 @@ public class ReasonerConfiguration { this.queryForAllDatatypeProperties = boole; } - public OntModelSpec getOntModelSpec() { - return this.ontModelSpec; - } - - public void setOntModelSpec(OntModelSpec spec) { - this.ontModelSpec = spec; - } - public boolean isIncrementalReasoningEnabled() { return this.incrementalReasoningEnabled; } diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerInversePropertyTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerInversePropertyTest.java index 12f157725..1494dc870 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerInversePropertyTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerInversePropertyTest.java @@ -6,7 +6,6 @@ import org.apache.log4j.Level; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mindswap.pellet.jena.PelletReasonerFactory; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModelSpec; @@ -16,10 +15,9 @@ import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.vocabulary.OWL; -import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; -public class SimpleReasonerInversePropertyTest extends AbstractTestClass { +public class SimpleReasonerInversePropertyTest extends SimpleReasonerTBoxHelper { long delay = 50; @@ -46,21 +44,16 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass { * basic scenarios around adding abox data * * Create a Tbox with property P inverseOf property Q. - * Pellet will compute TBox inferences. Add a statement - * a P b, and verify that b Q a is inferred. - * Add a statement c Q d and verify that d Q c - * is inferred. + * Add a statement a P b, and verify that b Q a is inferred. + * Add a statement c Q d and verify that d Q c is inferred. */ public void addABoxAssertion1(boolean sameAs ) { // set up the tbox - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - OntProperty P = tBox.createOntProperty("http://test.vivo/P"); - P.setLabel("property P", "en-US"); - OntProperty Q = tBox.createOntProperty("http://test.vivo/Q"); - Q.setLabel("property Q", "en-US"); - - P.addInverseOf(Q); + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); + setInverse(P, Q); // this is the model to receive abox inferences Model inf = ModelFactory.createDefaultModel(); @@ -109,14 +102,11 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass { public void addABoxAssertion2(boolean sameAs ) { // set up the tbox - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - - OntProperty P = tBox.createOntProperty("http://test.vivo/P"); - P.setLabel("property P", "en-US"); - OntProperty Q = tBox.createOntProperty("http://test.vivo/Q"); - Q.setLabel("property Q", "en-US"); - P.addInverseOf(Q); - + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); + setInverse(P, Q); + // this is the model to receive abox inferences Model inf = ModelFactory.createDefaultModel(); @@ -153,13 +143,11 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass { public void addABoxAssertion3(boolean sameAs) { // set up the tbox - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - OntProperty P = tBox.createOntProperty("http://test.vivo/P"); - P.setLabel("property P", "en-US"); - OntProperty Q = tBox.createOntProperty("http://test.vivo/Q"); - Q.setLabel("property Q", "en-US"); - P.addInverseOf(Q); - + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); + setInverse(P, Q); + // this is the model to receive abox inferences Model inf = ModelFactory.createDefaultModel(); @@ -197,16 +185,13 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass { public void addABoxAssertion4( boolean sameAs ) { // set up the tbox - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - OntProperty P = tBox.createOntProperty("http://test.vivo/P"); - P.setLabel("property P", "en-US"); - OntProperty R = tBox.createOntProperty("http://test.vivo/R"); - R.setLabel("property R", "en-US"); - OntProperty Q = tBox.createOntProperty("http://test.vivo/Q"); - Q.setLabel("property Q", "en-US"); - - R.addEquivalentProperty(P); - P.addInverseOf(Q); + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); + OntProperty R = createObjectProperty(tBox, "http://test.vivo/R", "property R"); + setInverse(P, Q); + setInverse(R, Q); + setEquivalent(R, P); // this is the model to receive abox inferences Model inf = ModelFactory.createDefaultModel(); @@ -250,15 +235,12 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass { public void removedABoxAssertion1(boolean sameAs) { // set up the tbox - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - OntProperty P = tBox.createOntProperty("http://test.vivo/P"); - P.setLabel("property P", "en-US"); - OntProperty Q = tBox.createOntProperty("http://test.vivo/Q"); - Q.setLabel("property Q", "en-US"); - OntProperty T = tBox.createOntProperty("http://test.vivo/T"); - Q.setLabel("property T", "en-US"); - P.addInverseOf(Q); - P.addInverseOf(T); + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); + OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T"); + setInverse(P, Q); + setInverse(P, T); // this is the model to receive abox inferences Model inf = ModelFactory.createDefaultModel(); @@ -307,20 +289,14 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass { public void removedABoxAssertion2(boolean sameAs) { // set up the tbox - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - OntProperty P = tBox.createOntProperty("http://test.vivo/P"); - P.setLabel("property P", "en-US"); - OntProperty Q = tBox.createOntProperty("http://test.vivo/Q"); - Q.setLabel("property Q", "en-US"); - OntProperty T = tBox.createOntProperty("http://test.vivo/T"); - Q.setLabel("property T", "en-US"); - P.addInverseOf(Q); - P.addEquivalentProperty(T); - - // not clear what these will do - tBox.rebind(); - tBox.prepare(); - + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); + OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T"); + setInverse(P, Q); + setInverse(T, Q); + setEquivalent(P, T); + // this is the model to receive abox inferences Model inf = ModelFactory.createDefaultModel(); @@ -360,16 +336,12 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass { */ public void removedABoxAssertion3(boolean sameAs) { - //set up the tbox - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - OntProperty P = tBox.createOntProperty("http://test.vivo/P"); - P.setLabel("property P", "en-US"); - OntProperty Q = tBox.createOntProperty("http://test.vivo/Q"); - Q.setLabel("property Q", "en-US"); - P.addInverseOf(Q); - - tBox.rebind(); // not sure what effect this has - + // set up the tbox + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); + setInverse(P, Q); + // this is the model to receive abox inferences Model inf = ModelFactory.createDefaultModel(); @@ -410,12 +382,10 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass { */ public void addTBoxInverseAssertion1(boolean sameAs) throws InterruptedException { - // Set up the TBox. - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - OntProperty P = tBox.createOntProperty("http://test.vivo/P"); - P.setLabel("property P", "en-US"); - OntProperty Q = tBox.createOntProperty("http://test.vivo/Q"); - Q.setLabel("property Q", "en-US"); + // set up the tbox + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); // this is the model to receive abox inferences Model inf = ModelFactory.createDefaultModel(); @@ -444,7 +414,7 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass { // Assert P and Q as inverses and wait for // SimpleReasonerTBoxListener thread to end - Q.addInverseOf(P); + setInverse(P, Q); while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); @@ -473,14 +443,11 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass { */ public void removeTBoxInverseAssertion1(boolean sameAs) throws InterruptedException { - // set up the tbox. - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - - OntProperty P = tBox.createOntProperty("http://test.vivo/propP"); - P.setLabel("property P", "en-US"); - OntProperty Q = tBox.createOntProperty("http://test.vivo/propQ"); - Q.setLabel("property Q", "en-US"); - Q.addInverseOf(P); + // set up the tbox + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); + setInverse(P, Q); // this is the model to receive abox inferences Model inf = ModelFactory.createDefaultModel(); @@ -505,7 +472,7 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass { // Remove P and Q inverse relationship and wait for // SimpleReasoner TBox thread to end. - Q.removeInverseProperty(P); + removeInverse(P, Q); while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); @@ -532,20 +499,14 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass { */ public void recomputeABox1(boolean sameAs) throws InterruptedException { - // set up tbox - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - - OntProperty P = tBox.createOntProperty("http://test.vivo/propP"); - P.setLabel("property P", "en-US"); - OntProperty Q = tBox.createOntProperty("http://test.vivo/propQ"); - Q.setLabel("property Q", "en-US"); - Q.addInverseOf(P); - - OntProperty X = tBox.createOntProperty("http://test.vivo/propX"); - P.setLabel("property X", "en-US"); - OntProperty Y = tBox.createOntProperty("http://test.vivo/propY"); - Q.setLabel("property Y", "en-US"); - X.addInverseOf(Y); + // set up the tbox + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); + setInverse(P, Q); + OntProperty X = createObjectProperty(tBox, "http://test.vivo/X", "property X"); + OntProperty Y = createObjectProperty(tBox, "http://test.vivo/Y", "property Y"); + setInverse(X, Y); // create abox and abox inf model and register simplereasoner // with abox. @@ -565,8 +526,8 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass { aBox.add(c,X,d); Assert.assertTrue(inf.contains(b,Q,a)); - Assert.assertTrue(inf.contains(d,Y,c)); - + Assert.assertTrue(inf.contains(d,Y,c)); + inf.remove(b,Q,a); inf.remove(d,Y,c); @@ -581,7 +542,7 @@ public class SimpleReasonerInversePropertyTest extends AbstractTestClass { Assert.assertTrue(inf.contains(b,Q,a)); Assert.assertTrue(inf.contains(d,Y,c)); } - + //==================================== Utility methods ==================== SimpleReasonerTBoxListener getTBoxListener(SimpleReasoner simpleReasoner) { return new SimpleReasonerTBoxListener(simpleReasoner, new Exception().getStackTrace()[1].getMethodName()); diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerPluginTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerPluginTest.java index 82c1fdf97..5d5509e94 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerPluginTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerPluginTest.java @@ -9,7 +9,6 @@ import org.apache.log4j.Level; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mindswap.pellet.jena.PelletReasonerFactory; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModelSpec; @@ -23,9 +22,7 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.RDFS; -import edu.cornell.mannlib.vitro.testing.AbstractTestClass; - -public class SimpleReasonerPluginTest extends AbstractTestClass { +public class SimpleReasonerPluginTest extends SimpleReasonerTBoxHelper { long delay = 50; private final static String DEFAULT_NS = "http://vivoweb.org/individual/"; @@ -53,7 +50,7 @@ public class SimpleReasonerPluginTest extends AbstractTestClass { */ @Test public void test1() { - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); + OntModel tBox = createTBoxModel(); OntProperty authorInAuthorship = tBox.createObjectProperty(authorInAuthorship_URI); OntProperty linkedAuthor = tBox.createObjectProperty(linkedAuthor_URI); diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerSameAsTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerSameAsTest.java index 81b7242f5..72089696b 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerSameAsTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerSameAsTest.java @@ -6,7 +6,6 @@ import org.apache.log4j.Level; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mindswap.pellet.jena.PelletReasonerFactory; import com.hp.hpl.jena.ontology.AnnotationProperty; import com.hp.hpl.jena.ontology.OntClass; @@ -21,10 +20,9 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.RDF; -import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; -public class SimpleReasonerSameAsTest extends AbstractTestClass { +public class SimpleReasonerSameAsTest extends SimpleReasonerTBoxHelper { long delay = 50; private static final String mostSpecificTypePropertyURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#mostSpecificType"; @@ -43,21 +41,11 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { //*/ @Test public void addSameAsABoxAssertion1() { - - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - - OntProperty P = tBox.createObjectProperty("http://test.vivo/P"); - P.setLabel("property P", "en-US"); - - OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q"); - Q.setLabel("property Q", "en-US"); - - OntProperty S = tBox.createDatatypeProperty("http://test.vivo/"); - S.setLabel("property S", "en-US"); - - OntProperty T = tBox.createDatatypeProperty("http://test.vivo/"); - T.setLabel("property T", "en-US"); - + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); + OntProperty S = createObjectProperty(tBox, "http://test.vivo/S", "property S"); + OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T"); Literal literal1 = tBox.createLiteral("Literal value 1"); Literal literal2 = tBox.createLiteral("Literal value 2"); @@ -129,21 +117,11 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { */ @Test public void removeSameAsABoxAssertion1() { - - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - - OntProperty P = tBox.createObjectProperty("http://test.vivo/P"); - P.setLabel("property P", "en-US"); - - OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q"); - Q.setLabel("property Q", "en-US"); - - OntProperty S = tBox.createDatatypeProperty("http://test.vivo/data1"); - S.setLabel("property S", "en-US"); - - OntProperty T = tBox.createDatatypeProperty("http://test.vivo/data2"); - T.setLabel("property T", "en-US"); - + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); + OntProperty S = createObjectProperty(tBox, "http://test.vivo/S", "property S"); + OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T"); Literal literal1 = tBox.createLiteral("Literal value 1"); Literal literal2 = tBox.createLiteral("Literal value 2"); @@ -186,21 +164,11 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { */ @Test public void addABoxAssertion1() { - - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - - OntProperty P = tBox.createObjectProperty("http://test.vivo/P"); - P.setLabel("property P", "en-US"); - - OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q"); - Q.setLabel("property Q", "en-US"); - - OntProperty S = tBox.createDatatypeProperty("http://test.vivo/"); - S.setLabel("property S", "en-US"); - - OntProperty T = tBox.createDatatypeProperty("http://test.vivo/"); - T.setLabel("property T", "en-US"); - + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); + OntProperty S = createObjectProperty(tBox, "http://test.vivo/S", "property S"); + OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T"); Literal literal1 = tBox.createLiteral("Literal value 1"); Literal literal2 = tBox.createLiteral("Literal value 2"); @@ -283,21 +251,11 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { */ @Test public void disabledSameAs() { - - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - - OntProperty P = tBox.createObjectProperty("http://test.vivo/P"); - P.setLabel("property P", "en-US"); - - OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q"); - Q.setLabel("property Q", "en-US"); - - OntProperty S = tBox.createDatatypeProperty("http://test.vivo/"); - S.setLabel("property S", "en-US"); - - OntProperty T = tBox.createDatatypeProperty("http://test.vivo/"); - T.setLabel("property T", "en-US"); - + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); + OntProperty S = createObjectProperty(tBox, "http://test.vivo/S", "property S"); + OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T"); Literal literal1 = tBox.createLiteral("Literal value 1"); Literal literal2 = tBox.createLiteral("Literal value 2"); @@ -369,7 +327,7 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { */ @Test public void addABoxAssertion2() { - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); + OntModel tBox = createTBoxModel(); OntProperty desc = tBox.createDatatypeProperty("http://test.vivo/desc"); desc.setLabel("property desc", "en-US"); @@ -403,21 +361,11 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { */ @Test public void removeABoxAssertion1() { - - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - - OntProperty P = tBox.createObjectProperty("http://test.vivo/P"); - P.setLabel("property P", "en-US"); - - OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q"); - Q.setLabel("property Q", "en-US"); - - OntProperty S = tBox.createDatatypeProperty("http://test.vivo/"); - S.setLabel("property S", "en-US"); - - OntProperty T = tBox.createDatatypeProperty("http://test.vivo/"); - T.setLabel("property T", "en-US"); - + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); + OntProperty S = createObjectProperty(tBox, "http://test.vivo/S", "property S"); + OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T"); Literal literal1 = tBox.createLiteral("Literal value 1"); Literal literal2 = tBox.createLiteral("Literal value 2"); @@ -453,18 +401,12 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { */ @Test public void tBoxInverseAssertion1() 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); - - OntProperty P = tBox.createOntProperty("http://test.vivo/P"); - P.setLabel("property P", "en-US"); + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); - OntProperty Q = tBox.createOntProperty("http://test.vivo/Q"); - Q.setLabel("property Q", "en-US"); + // Create ABox and Inference models and register + // the ABox reasoner listeners with the ABox and TBox OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); Model inf = ModelFactory.createDefaultModel(); @@ -482,7 +424,7 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { aBox.add(a,P,b); aBox.add(a, OWL.sameAs,b); - Q.addInverseOf(P); + setInverse(Q, P); while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); @@ -492,8 +434,8 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { Assert.assertTrue(inf.contains(b,OWL.sameAs,a)); Assert.assertTrue(inf.contains(b,P,b)); Assert.assertTrue(inf.contains(a,Q,a)); - - Q.removeInverseProperty(P); + + removeInverse(Q, P); while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); @@ -513,19 +455,12 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { * a sameAs individual. */ //@Test - public void tBoxTypeAssertion1() throws InterruptedException { - + public void tBoxTypeAssertion1() { // 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); + OntModel tBox = createTBoxModel(); + OntClass classA = createClass(tBox, "http://test.vivo/A", "class A"); + OntClass classB = createClass(tBox, "http://test.vivo/B", "class B"); + addSubclass(classA, classB); // this is the model to receive inferences Model inf = ModelFactory.createDefaultModel(); @@ -560,17 +495,13 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { */ //@Test public void tBoxSubclassAssertion1() throws InterruptedException { - - //create aBox and tBox, and SimpleReasoner to listen to them - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - // 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"); - + // Create a Tbox with a simple class hierarchy. B is a subclass of A. + OntModel tBox = createTBoxModel(); + OntClass classA = createClass(tBox, "http://test.vivo/A", "class A"); + OntClass classB = createClass(tBox, "http://test.vivo/B", "class B"); + OntClass classC = createClass(tBox, "http://test.vivo/C", "class C"); + + //create aBox and SimpleReasoner to listen to them OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); Model inf = ModelFactory.createDefaultModel(); @@ -589,17 +520,14 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { aBox.add(c, OWL.sameAs, a); // update TBox - classA.addSubClass(classB); + addSubclass(classA, 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. + addSubclass(classB, classC); // wait for SimpleReasonerTBoxListener thread to end while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { @@ -620,10 +548,7 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { 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. + removeSubclass(classA, classB); // wait for SimpleReasonerTBoxListener thread to end while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { @@ -643,8 +568,8 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { Assert.assertTrue(inf.contains(c, RDF.type, classB)); Assert.assertFalse(inf.contains(c, RDF.type, classA)); - // update TBox - classB.removeSubClass(classC); + // update TBox + removeSubclass(classB, classC); // wait for SimpleReasonerTBoxListener thread to end while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { @@ -672,24 +597,19 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { * individuals */ //@Test - public void mostSpecificTypeTest1() throws InterruptedException { + public void mostSpecificTypeTest1() { + // Create a Tbox with a simple class hierarchy. B is a subclass of A. + OntModel tBox = createTBoxModel(); + OntClass classA = createClass(tBox, "http://test.vivo/A", "class A"); + OntClass classC = createClass(tBox, "http://test.vivo/B", "class C"); + OntClass classD = createClass(tBox, "http://test.vivo/B", "class D"); + OntClass classE = createClass(tBox, "http://test.vivo/B", "class E"); + addSubclass(classA, classC); + addSubclass(classC, classD); + addSubclass(classC, classE); - // set up tbox. Pellet is reasoning; SimpleReasonerTBoxListener is not being used. - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); + // SimpleReasonerTBoxListener is not being used. 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(); @@ -755,21 +675,11 @@ public class SimpleReasonerSameAsTest extends AbstractTestClass { */ @Test public void recomputeABox1() throws InterruptedException { - - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); - - OntProperty P = tBox.createObjectProperty("http://test.vivo/P"); - P.setLabel("property P", "en-US"); - - OntProperty Q = tBox.createObjectProperty("http://test.vivo/Q"); - Q.setLabel("property Q", "en-US"); - - OntProperty S = tBox.createDatatypeProperty("http://test.vivo/"); - S.setLabel("property S", "en-US"); - - OntProperty T = tBox.createDatatypeProperty("http://test.vivo/"); - T.setLabel("property T", "en-US"); - + OntModel tBox = createTBoxModel(); + OntProperty P = createObjectProperty(tBox, "http://test.vivo/P", "property P"); + OntProperty Q = createObjectProperty(tBox, "http://test.vivo/Q", "property Q"); + OntProperty S = createObjectProperty(tBox, "http://test.vivo/S", "property S"); + OntProperty T = createObjectProperty(tBox, "http://test.vivo/T", "property T"); Literal literal1 = tBox.createLiteral("Literal value 1"); Literal literal2 = tBox.createLiteral("Literal value 2"); diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerTBoxHelper.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerTBoxHelper.java new file mode 100644 index 000000000..0c4b05cfb --- /dev/null +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerTBoxHelper.java @@ -0,0 +1,232 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.reasoner; + +import java.util.HashSet; +import java.util.Set; + +import com.hp.hpl.jena.ontology.ObjectProperty; +import com.hp.hpl.jena.ontology.OntClass; +import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.ontology.OntModelSpec; +import com.hp.hpl.jena.ontology.OntProperty; +import com.hp.hpl.jena.rdf.model.ModelFactory; + +import edu.cornell.mannlib.vitro.testing.AbstractTestClass; + +/** + * We're using a simple OntModel as the TBox in the SimpleReasoner tests, so we + * don't get tied to a particular TBox reasoner (like Pellet). + * + * But the SimpleReasoner expects certain elementary reasoning, so these methods + * impose that reasoning on the model. + * + * On the model: Thing is a class. + * + * On classes: Every class is equivalent to itself, a subclass of itself, and a + * subclass of Thing. Every class is a subclass of all its ancestors and a + * superclass of all its descendants. Every class has the same superclasses and + * subclasses as do all of its equivalent classes. + * + * On object properties: Every object property is equivalent to itself and a + * subproperty of itself. Every object property has the same inverses as do all + * of its equivalent properties. + * + * ---------------------- + * + * It's a little silly to implement this as a parent class of the unit tests. It + * would have been nicer to find a way that is more object-oriented but still + * explicit in what "reasoning" is performed. This will do for now. + */ +public class SimpleReasonerTBoxHelper extends AbstractTestClass { + private static String URI_THING = "http://www.w3.org/2002/07/owl#Thing"; + + // ---------------------------------------------------------------------- + // The model + // ---------------------------------------------------------------------- + + protected OntModel createTBoxModel() { + OntModel tBox = ModelFactory + .createOntologyModel(OntModelSpec.OWL_DL_MEM); + createClass(tBox, URI_THING, "OWL Thing"); + return tBox; + } + + // ---------------------------------------------------------------------- + // Classes + // ---------------------------------------------------------------------- + + protected OntClass createClass(OntModel tBox, String uri, String label) { + OntClass s = tBox.createClass(uri); + s.setLabel(label, "en-US"); + s.addEquivalentClass(s); + s.addSubClass(s); + thing(tBox).addSubClass(s); + return s; + } + + private OntClass thing(OntModel tBox) { + return tBox.getOntClass(URI_THING); + } + + /** + * Make sure that you establish subclass relationships before setting + * equivalent classes. + */ + protected void setEquivalent(OntClass c1, OntClass c2) { + setEquivalentClasses(equivalences(c1), equivalences(c2)); + setEquivalentClasses(equivalences(c2), equivalences(c1)); + c1.addEquivalentClass(c2); + c2.addEquivalentClass(c1); + copySubClasses(c1, c2); + copySubClasses(c2, c1); + copySuperClasses(c1, c2); + copySuperClasses(c2, c1); + } + + private void setEquivalentClasses(Set equivalences1, + Set equivalences2) { + for (OntClass c1 : equivalences1) { + for (OntClass c2 : equivalences2) { + c1.addEquivalentClass(c2); + } + } + } + + private void copySubClasses(OntClass c1, OntClass c2) { + for (OntClass sub : c1.listSubClasses().toList()) { + c2.addSubClass(sub); + } + } + + private void copySuperClasses(OntClass c1, OntClass c2) { + for (OntClass sup : c1.listSuperClasses().toList()) { + c2.addSuperClass(sup); + } + } + + private Set equivalences(OntClass c1) { + return new HashSet(c1.listEquivalentClasses().toList()); + } + + protected void addSubclass(OntClass parent, OntClass child) { + addSubclass(equivalences(parent), equivalences(child)); + } + + private void addSubclass(Set equivalentParents, + Set equivalentChildren) { + for (OntClass parent : equivalentParents) { + for (OntClass child : equivalentChildren) { + parent.addSubClass(child); + + for (OntClass ancestor : parent.listSuperClasses().toList()) { + ancestor.addSubClass(child); + } + for (OntClass descendant : child.listSubClasses().toList()) { + parent.addSubClass(descendant); + } + } + } + } + + protected void removeSubclass(OntClass parent, OntClass child) { + removeSubclass(equivalences(parent), equivalences(child)); + } + + /** + * This has the potential for problems if we set this up: + * + *

+	 * A -> B -> C
+	 * 
+	 * explicit add A -> C
+	 * 
+	 * remove A -> B
+	 * 
+ * + * But why would we do that? + */ + private void removeSubclass(Set equivalentParents, + Set equivalentChildren) { + for (OntClass parent : equivalentParents) { + for (OntClass child : equivalentChildren) { + parent.removeSubClass(child); + + for (OntClass ancestor : parent.listSuperClasses().toList()) { + ancestor.removeSubClass(child); + } + for (OntClass descendant : child.listSubClasses().toList()) { + parent.removeSubClass(descendant); + } + } + } + } + + // ---------------------------------------------------------------------- + // Object properties + // ---------------------------------------------------------------------- + + protected ObjectProperty createObjectProperty(OntModel tBox, String uri, + String label) { + ObjectProperty p = tBox.createObjectProperty(uri); + p.setLabel(label, "en-US"); + p.addEquivalentProperty(p); + p.addSubProperty(p); + return p; + } + + protected void setEquivalent(OntProperty p1, OntProperty p2) { + setEquivalentProperty(equivalences(p1), equivalences(p2)); + setEquivalentProperty(equivalences(p2), equivalences(p1)); + copyInverses(p1, p2); + copyInverses(p2, p1); + } + + private void setEquivalentProperty(Set equivalences1, + Set equivalences2) { + for (OntProperty p1 : equivalences1) { + for (OntProperty p2 : equivalences2) { + p1.addEquivalentProperty(p2); + } + } + } + + private void copyInverses(OntProperty p1, OntProperty p2) { + for (OntProperty inv : p1.listInverse().toList()) { + p2.addInverseOf(inv); + } + } + + protected void setInverse(OntProperty p1, OntProperty p2) { + setInverse(equivalences(p1), equivalences(p2)); + setInverse(equivalences(p2), equivalences(p1)); + } + + private void setInverse(Set equivalences1, + Set equivalences2) { + for (OntProperty p1 : equivalences1) { + for (OntProperty p2 : equivalences2) { + p1.addInverseOf(p2); + } + } + } + + protected void removeInverse(OntProperty p1, OntProperty p2) { + removeInverse(equivalences(p1), equivalences(p2)); + removeInverse(equivalences(p2), equivalences(p1)); + } + + private void removeInverse(Set equivalences1, + Set equivalences2) { + for (OntProperty p1 : equivalences1) { + for (OntProperty p2 : equivalences2) { + p1.removeInverseProperty(p2); + } + } + } + + private Set equivalences(OntProperty p) { + return new HashSet(p.listEquivalentProperties().toSet()); + } + +} diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerTest.java index 7b17d1303..237c18622 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/reasoner/SimpleReasonerTest.java @@ -7,7 +7,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; -import org.mindswap.pellet.jena.PelletReasonerFactory; import com.hp.hpl.jena.ontology.AnnotationProperty; import com.hp.hpl.jena.ontology.OntClass; @@ -21,11 +20,10 @@ import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.RDF; -import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; -public class SimpleReasonerTest extends AbstractTestClass { +public class SimpleReasonerTest extends SimpleReasonerTBoxHelper { private static final String mostSpecificTypePropertyURI = "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#mostSpecificType"; long delay = 50; @@ -54,15 +52,9 @@ public class SimpleReasonerTest extends AbstractTestClass { public void addABoxTypeAssertion1( boolean sameAsEnabled ){ // 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"); - + OntModel tBox = createTBoxModel(); + OntClass classA = createClass(tBox, "http://test.vivo/A", "class A"); + OntClass classB = createClass(tBox, "http://test.vivo/B", "class B"); classA.addSubClass(classB); // this is the model to receive inferences @@ -101,30 +93,18 @@ public class SimpleReasonerTest extends AbstractTestClass { public void addABoxTypeAssertion2(boolean enableSameAs){ // Create a Tbox with a simple class hierarchy. D and E are subclasses - // of C. B and C are subclasses of A. Pellet will compute TBox inferences. - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); + // of C. B and C are subclasses of A. + OntModel tBox = createTBoxModel(); + OntClass classA = createClass(tBox, "http://test.vivo/A", "class A"); + OntClass classB = createClass(tBox, "http://test.vivo/B", "class B"); + OntClass classC = createClass(tBox, "http://test.vivo/C", "class C"); + OntClass classD = createClass(tBox, "http://test.vivo/D", "class D"); + OntClass classE = createClass(tBox, "http://test.vivo/E", "class E"); + addSubclass(classA, classB); + addSubclass(classA, classC); + addSubclass(classC, classD); + addSubclass(classC, classE); - 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"); - - 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"); - - classC.addSubClass(classD); - classC.addSubClass(classE); - - classA.addSubClass(classB); - classA.addSubClass(classC); - // this is the model to receive inferences Model inf = ModelFactory.createDefaultModel(); @@ -159,12 +139,17 @@ public class SimpleReasonerTest extends AbstractTestClass { * Test inference based on class equivalence */ public void addABoxTypeAssertion3(boolean enableSameAs) 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); + + // Add classes A, B and C to the TBox + // A is equivalent to B + // C is a subclass of A + OntModel tBox = createTBoxModel(); + OntClass classA = createClass(tBox, "http://test.vivo/A", "class A"); + OntClass classB = createClass(tBox, "http://test.vivo/B", "class B"); + OntClass classC = createClass(tBox, "http://test.vivo/C", "class C"); + addSubclass(classA, classC); + setEquivalent(classA, classB); + OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); Model inf = ModelFactory.createDefaultModel(); @@ -175,22 +160,6 @@ public class SimpleReasonerTest extends AbstractTestClass { SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); tBox.register(simpleReasonerTBoxListener); - // Add classes A, B and C to the TBox - // A is equivalent to B - // C is a subclass of A - - 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"); - - classA.addEquivalentClass(classB); - classA.addSubClass(classC); - while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); } @@ -223,11 +192,13 @@ public class SimpleReasonerTest extends AbstractTestClass { */ public void addABoxTypeAssertion4(boolean enableSameAs) throws InterruptedException { - // Create TBox, ABox and Inference models and register - // the ABox reasoner listeners with the ABox and TBox - // Pellet will compute TBox inferences + // Add classes A and B to the TBox + // A is equivalent to B + OntModel tBox = createTBoxModel(); + OntClass classA = createClass(tBox, "http://test.vivo/A", "class A"); + OntClass classB = createClass(tBox, "http://test.vivo/B", "class B"); + setEquivalent(classA, classB); - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); Model inf = ModelFactory.createDefaultModel(); @@ -238,17 +209,6 @@ public class SimpleReasonerTest extends AbstractTestClass { SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); tBox.register(simpleReasonerTBoxListener); - // Add classes A and B to the TBox - // A is equivalent to B - - 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.addEquivalentClass(classB); - while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); } @@ -277,12 +237,14 @@ public class SimpleReasonerTest extends AbstractTestClass { * Test inference based on class equivalence */ public void addABoxTypeAssertion5(boolean enableSameAs) 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); + + // Add classes classes A and B to the TBox + // A is equivalent to B + OntModel tBox = createTBoxModel(); + OntClass classA = createClass(tBox, "http://test.vivo/A", "class A"); + OntClass classB = createClass(tBox, "http://test.vivo/B", "class B"); + setEquivalent(classA, classB); + OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); Model inf = ModelFactory.createDefaultModel(); @@ -293,17 +255,6 @@ public class SimpleReasonerTest extends AbstractTestClass { SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); tBox.register(simpleReasonerTBoxListener); - // Add classes classes A and B to the TBox - // A is equivalent to B - - 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.addEquivalentClass(classB); - while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); } @@ -326,11 +277,11 @@ public class SimpleReasonerTest extends AbstractTestClass { } @Test - public void removeABoxTypeAssertion1Test()throws InterruptedException{ + public void removeABoxTypeAssertion1Test() { removeABoxTypeAssertion1(true); } @Test - public void removeABoxTypeAssertion1NoSameAs()throws InterruptedException{ + public void removeABoxTypeAssertion1NoSameAs() { removeABoxTypeAssertion1(false); } /* @@ -344,22 +295,15 @@ public class SimpleReasonerTest extends AbstractTestClass { public void removeABoxTypeAssertion1(boolean enableSameAs){ // Create a Tbox with a simple class hierarchy. C is a subclass of B - // and B is a subclass of A. Pellet will compute TBox inferences. + // and B is a subclass of A. - 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"); - - OntClass classC = tBox.createClass("http://test.vivo/C"); - classC.setLabel("class C", "en-US"); + OntModel tBox = createTBoxModel(); + OntClass classA = createClass(tBox, "http://test.vivo/A", "class A"); + OntClass classB = createClass(tBox, "http://test.vivo/B", "class B"); + OntClass classC = createClass(tBox, "http://test.vivo/C", "class C"); + addSubclass(classB, classC); + addSubclass(classA, classB); - classB.addSubClass(classC); - classA.addSubClass(classB); - // this is the model to receive inferences Model inf = ModelFactory.createDefaultModel(); @@ -415,12 +359,15 @@ public class SimpleReasonerTest extends AbstractTestClass { * as a test of equivalentClass statements also. */ public void addTBoxSubClassAssertion1(boolean enableSameAs) throws InterruptedException { - - // Create TBox, ABox and Inference models and register - // the ABox reasoner listeners with the ABox and TBox - // Pellet will compute TBox inferences + // Create the TBox and add classes A, B, C and D + OntModel tBox = createTBoxModel(); + OntClass classA = createClass(tBox, "http://test.vivo/A", "class A"); + OntClass classB = createClass(tBox, "http://test.vivo/B", "class B"); + OntClass classC = createClass(tBox, "http://test.vivo/C", "class C"); + OntClass classD = createClass(tBox, "http://test.vivo/D", "class D"); - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); + // Create ABox and Inference models and register + // the ABox reasoner listeners with the ABox and TBox OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); Model inf = ModelFactory.createDefaultModel(); @@ -431,27 +378,12 @@ public class SimpleReasonerTest extends AbstractTestClass { SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); tBox.register(simpleReasonerTBoxListener); - // Add classes classes A, B, C and D to the 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"); - - OntClass classD = tBox.createClass("http://test.vivo/D"); - classD.setLabel("class D", "en-US"); - // Add a statement that individual x is of type C to the ABox Resource ind_x = aBox.createResource("http://test.vivo/x"); aBox.add(ind_x, RDF.type, classC); // Add a statement that C is a subclass of A to the TBox - - classA.addSubClass(classC); + addSubclass(classA, classC); while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); @@ -498,11 +430,17 @@ public class SimpleReasonerTest extends AbstractTestClass { */ public void addTBoxSubClassAssertion2(boolean enableSameAs) throws InterruptedException { - // Create TBox, ABox and Inference models and register - // the ABox reasoner listeners with the ABox and TBox - // Pellet will compute TBox inferences + // Create the TBox and add classes A, B, C and D. + // D is a subclass of C. + OntModel tBox = createTBoxModel(); + OntClass classA = createClass(tBox, "http://test.vivo/A", "class A"); + OntClass classB = createClass(tBox, "http://test.vivo/B", "class B"); + OntClass classC = createClass(tBox, "http://test.vivo/C", "class C"); + OntClass classD = createClass(tBox, "http://test.vivo/D", "class D"); + addSubclass(classC, classD); - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); + // Create ABox and Inference models and register + // the ABox reasoner listeners with the ABox and TBox OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); Model inf = ModelFactory.createDefaultModel(); @@ -513,23 +451,6 @@ public class SimpleReasonerTest extends AbstractTestClass { SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); tBox.register(simpleReasonerTBoxListener); - // Add classes classes A, B, C and D to the TBox - // D is a subclass of C - - 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"); - - OntClass classD = tBox.createClass("http://test.vivo/D"); - classD.setLabel("class D", "en-US"); - - classC.addSubClass(classD); - while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); } @@ -539,7 +460,7 @@ public class SimpleReasonerTest extends AbstractTestClass { aBox.add(ind_x, RDF.type, classD); // Add a statement that C is a subclass of A to the TBox - classA.addSubClass(classC); + addSubclass(classA, classC); while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); @@ -569,11 +490,30 @@ public class SimpleReasonerTest extends AbstractTestClass { * */ public void removeTBoxSubClassAssertion1(boolean enableSameAs) throws InterruptedException { - // Create TBox, ABox and Inference models and register - // the ABox reasoner listeners with the ABox and TBox - // Pellet will compute TBox inferences + // Create the TBox and add classes A, B, C, D, E, F, G and H. + // B, C and D are subclasses of A. + // E is a subclass of B. + // F and G are subclasses of C. + // H is a subclass of D. + OntModel tBox = createTBoxModel(); + OntClass classA = createClass(tBox, "http://test.vivo/A", "class A"); + OntClass classB = createClass(tBox, "http://test.vivo/B", "class B"); + OntClass classC = createClass(tBox, "http://test.vivo/C", "class C"); + OntClass classD = createClass(tBox, "http://test.vivo/D", "class D"); + OntClass classE = createClass(tBox, "http://test.vivo/E", "class E"); + OntClass classF = createClass(tBox, "http://test.vivo/F", "class F"); + OntClass classG = createClass(tBox, "http://test.vivo/G", "class G"); + OntClass classH = createClass(tBox, "http://test.vivo/H", "class H"); + addSubclass(classA, classB); + addSubclass(classA, classC); + addSubclass(classA, classD); + addSubclass(classB, classE); + addSubclass(classC, classF); + addSubclass(classC, classG); + addSubclass(classD, classH); - OntModel tBox = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC); + // Create ABox and Inference models and register + // the ABox reasoner listeners with the ABox and TBox OntModel aBox = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); Model inf = ModelFactory.createDefaultModel(); @@ -584,44 +524,6 @@ public class SimpleReasonerTest extends AbstractTestClass { SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); tBox.register(simpleReasonerTBoxListener); - // Add classes A, B, C, D, E, F, G and H to the TBox. - // B, C and D are subclasses of A. - // E is a subclass of B. - // F and G are subclasses of C. - // H is a subclass of D. - - 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"); - - 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"); - - OntClass classF = tBox.createClass("http://test.vivo/F"); - classF.setLabel("class F", "en-US"); - - OntClass classG = tBox.createClass("http://test.vivo/G"); - classG.setLabel("class G", "en-US"); - - OntClass classH = tBox.createClass("http://test.vivo/H"); - classH.setLabel("class H", "en-US"); - - classA.addSubClass(classB); - classA.addSubClass(classC); - classA.addSubClass(classD); - classB.addSubClass(classE); - classC.addSubClass(classF); - classC.addSubClass(classG); - classD.addSubClass(classH); - while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); } @@ -631,7 +533,7 @@ public class SimpleReasonerTest extends AbstractTestClass { aBox.add(ind_x, RDF.type, classE); // Remove the statement that B is a subclass of A from the TBox - classA.removeSubClass(classB); + removeSubclass(classA, classB); while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); @@ -664,13 +566,13 @@ public class SimpleReasonerTest extends AbstractTestClass { simpleReasonerTBoxListener.setStopRequested(); } - @Ignore(" needs PelletListener infrastructure which is not in this suite.") + @Ignore(" needs TBoxReasoner infrastructure which is not in this suite.") @Test public void bcdTest()throws InterruptedException{ bcd(true); } - @Ignore(" needs PelletListener infrastructure which is not in this suite.") + @Ignore(" needs TBoxReasoner infrastructure which is not in this suite.") @Test public void bcdNoSameAsTest()throws InterruptedException{ bcd(false); @@ -682,17 +584,16 @@ public class SimpleReasonerTest extends AbstractTestClass { * inference graph. * */ - // this test would need PelletListener infrastructure, which we're not + // this test would need TBoxReasoner infrastructure, which we're not // 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. + // model as the TBoxReasoner is updating it. I could simulate it by adding to the + // tBox assertions what we can count on the TBoxReasoner to infer. public void bcd(boolean enableSameAs) throws InterruptedException { - // Create TBox, ABox and Inference models and register + OntModel tBox = createTBoxModel(); + + // Create 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(); @@ -704,18 +605,11 @@ public class SimpleReasonerTest extends AbstractTestClass { // Add classes LivingThing, Flora, Brassica to the TBox // Brassica is a subClass of Flora and Flora is a subclass of Brassica - - OntClass LivingThing = tBox.createClass("http://test.vivo/LivingThing"); - LivingThing.setLabel("Living Thing", "en-US"); - - OntClass Flora = tBox.createClass("http://test.vivo/Flora"); - Flora.setLabel("Flora", "en-US"); - - OntClass Brassica = tBox.createClass("http://test.vivo/Brassica"); - Brassica.setLabel("Brassica", "en-US"); - - LivingThing.addSubClass(Flora); - Flora.addSubClass(Brassica); + OntClass LivingThing = createClass(tBox, "http://test.vivo/LivingThing", "Living Thing"); + OntClass Flora = createClass(tBox, "http://test.vivo/Flora", "Flora"); + OntClass Brassica = createClass(tBox, "http://test.vivo/Brassica", "Brassica"); + addSubclass(LivingThing, Flora); + addSubclass(Flora, Brassica); tBox.rebind(); tBox.prepare(); @@ -761,11 +655,23 @@ public class SimpleReasonerTest extends AbstractTestClass { * to an added/removed ABox type assertion. */ public void mstTest1(boolean enableSameAs) throws InterruptedException { - // Create TBox, ABox and Inference models and register + // Set up the Tbox with a class hierarchy. C is a subclass of A + // and Y. D and E are subclasses of C. B is a subclass of D. + OntModel tBox = createTBoxModel(); + OntClass classA = createClass(tBox, "http://test.vivo/A", "class A"); + OntClass classB = createClass(tBox, "http://test.vivo/B", "class B"); + OntClass classC = createClass(tBox, "http://test.vivo/C", "class C"); + OntClass classD = createClass(tBox, "http://test.vivo/D", "class D"); + OntClass classE = createClass(tBox, "http://test.vivo/E", "class E"); + OntClass classY = createClass(tBox, "http://test.vivo/Y", "class Y"); + addSubclass(classA, classC); + addSubclass(classY, classC); + addSubclass(classC, classD); + addSubclass(classC, classE); + addSubclass(classD, classB); + + // Create 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(); @@ -776,38 +682,8 @@ public class SimpleReasonerTest extends AbstractTestClass { SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); tBox.register(simpleReasonerTBoxListener); - // Set up the Tbox with a class hierarchy. C is a subclass of A - // and Y. D and E are subclasses C. B is a subclass of D. - // Pellet will compute TBox inferences. - AnnotationProperty mostSpecificType = tBox.createAnnotationProperty(mostSpecificTypePropertyURI); - 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"); - - 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"); - - OntClass classY = tBox.createClass("http://test.vivo/Y"); - classE.setLabel("class Y", "en-US"); - - classY.addSubClass(classC); - classA.addSubClass(classC); - - classC.addSubClass(classD); - classC.addSubClass(classE); - - classD.addSubClass(classB); - while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); } @@ -848,11 +724,17 @@ public class SimpleReasonerTest extends AbstractTestClass { * to an added ABox type assertion. */ public void mstTest2(boolean enableSameAs) throws InterruptedException { - // Create TBox, ABox and Inference models and register + // Set up the Tbox with a class hierarchy. A, B, and C are all equivalent. + // This implies that they are all subclasses of each other. + OntModel tBox = createTBoxModel(); + OntClass classA = createClass(tBox, "http://test.vivo/A", "class A"); + OntClass classB = createClass(tBox, "http://test.vivo/B", "class B"); + OntClass classC = createClass(tBox, "http://test.vivo/C", "class C"); + setEquivalent(classA, classB); + setEquivalent(classB, classC); + + // Create 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(); @@ -863,25 +745,8 @@ public class SimpleReasonerTest extends AbstractTestClass { SimpleReasonerTBoxListener simpleReasonerTBoxListener = getTBoxListener(simpleReasoner); tBox.register(simpleReasonerTBoxListener); - // Set up the Tbox with a class hierarchy. B is a subclass of A, - // C is a subclass of B, and A is a subclass of C. - // Pellet should infer these three classes to be equivalent. - AnnotationProperty mostSpecificType = tBox.createAnnotationProperty(mostSpecificTypePropertyURI); - 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"); - - classA.addSubClass(classB); - classB.addSubClass(classC); - classC.addSubClass(classA); - while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); } @@ -911,11 +776,18 @@ public class SimpleReasonerTest extends AbstractTestClass { * to an added/removed TBox assertions. */ public void mstTest3(boolean enableSameAs) throws InterruptedException { - // Create TBox, ABox and Inference models and register + // Set up the Tbox with classes A, B, C, D, E, F and G + OntModel tBox = createTBoxModel(); + OntClass classA = createClass(tBox, "http://test.vivo/A", "class A"); + OntClass classB = createClass(tBox, "http://test.vivo/B", "class B"); + OntClass classC = createClass(tBox, "http://test.vivo/C", "class C"); + OntClass classD = createClass(tBox, "http://test.vivo/D", "class D"); + OntClass classE = createClass(tBox, "http://test.vivo/E", "class E"); + OntClass classF = createClass(tBox, "http://test.vivo/F", "class F"); + OntClass classG = createClass(tBox, "http://test.vivo/G", "class G"); + + // Create 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(); @@ -928,30 +800,6 @@ public class SimpleReasonerTest extends AbstractTestClass { OntClass OWL_THING = tBox.createClass(OWL.Thing.getURI()); AnnotationProperty mostSpecificType = tBox.createAnnotationProperty(mostSpecificTypePropertyURI); - - // Set up the Tbox with classes A, B, C, D, - // E, F and G - - 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"); - - 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"); - - OntClass classF = tBox.createClass("http://test.vivo/F"); - classF.setLabel("class F", "en-US"); - - OntClass classG = tBox.createClass("http://test.vivo/G"); - classE.setLabel("class G", "en-US"); while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); @@ -975,17 +823,13 @@ public class SimpleReasonerTest extends AbstractTestClass { Assert.assertTrue(inf.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classD.getURI()))); Assert.assertTrue(inf.contains(ind_y, mostSpecificType, ResourceFactory.createResource(classF.getURI()))); - // Set up a class hierarchy. - // Pellet will compute TBox inferences. - - classA.addSubClass(classB); - classA.addSubClass(classC); - classA.addSubClass(classD); - - classC.addSubClass(classE); - - classD.addSubClass(classF); - classD.addSubClass(classG); + // Set up a class hierarchy. + addSubclass(classA, classB); + addSubclass(classA, classC); + addSubclass(classA, classD); + addSubclass(classC, classE); + addSubclass(classD, classF); + addSubclass(classD, classG); while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); @@ -996,7 +840,7 @@ public class SimpleReasonerTest extends AbstractTestClass { // If F is removed as a subclass of D, then D should once again be a most specific type // for y. - classD.removeSubClass(classF); + removeSubclass(classD, classF); while (!VitroBackgroundThread.getLivingThreads().isEmpty()) { Thread.sleep(delay); diff --git a/webapp/web/jenaIngest/sparqlConstruct.jsp b/webapp/web/jenaIngest/sparqlConstruct.jsp index d02f8ea2f..06aba09c6 100644 --- a/webapp/web/jenaIngest/sparqlConstruct.jsp +++ b/webapp/web/jenaIngest/sparqlConstruct.jsp @@ -174,17 +174,5 @@ PREFIX <%=prefixText%>: <<%=urlText%>><%}}%> <% } %> - - - - -

include pellet reasoning

-
-
-
- -

- include Pellet OWL-DL reasoning

-
-
+ +