All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clarkparsia.pellet.owlapiv3.Reasoner Maven / Gradle / Ivy

There is a newer version: 2.3.6-ansell
Show newest version
// Portions Copyright (c) 2006 - 2008, Clark & Parsia, LLC.
// 
// Clark & Parsia, LLC parts of this source code are available under the terms
// of the Affero General Public License v3.
//
// Please see LICENSE.txt for full license terms, including the availability of
// proprietary exceptions.
// Questions, comments, or requests for clarification: [email protected]
//
// ---
// Portions Copyright (c) 2003 Ron Alford, Mike Grove, Bijan Parsia, Evren Sirin
// Alford, Grove, Parsia, Sirin parts of this source code are available under
// the terms of the MIT License.
//
// The MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

package com.clarkparsia.pellet.owlapiv3;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;

import org.mindswap.pellet.KnowledgeBase;
import org.mindswap.pellet.utils.ATermUtils;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDataPropertyExpression;
import org.semanticweb.owlapi.model.OWLDataRange;
import org.semanticweb.owlapi.model.OWLDatatype;
import org.semanticweb.owlapi.model.OWLException;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObject;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyChange;
import org.semanticweb.owlapi.model.OWLOntologyChangeListener;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLProperty;
import org.semanticweb.owlapi.model.OWLRuntimeException;

import aterm.ATermAppl;

/**
 * 

* Title: *

*

* Description: *

*

* Copyright: Copyright (c) 2007 *

*

* Company: Clark & Parsia, LLC. *

* * @author Evren Sirin */ @Deprecated public class Reasoner implements OWLOntologyChangeListener { public static Logger log = Logger.getLogger( Reasoner.class.getName() ); private static final long serialVersionUID = 8438190652175258123L; private AxiomConverter converter; protected KnowledgeBase kb; private PelletLoader loader; private OWLOntologyManager manager; private OWLDataFactory factory; private interface EntityMapper { public T map(ATermAppl term); } private class IndividualMapper implements EntityMapper { public OWLIndividual map(ATermAppl term) { if( ATermUtils.isBnode( term ) ) { return factory.getOWLAnonymousIndividual( ( (ATermAppl) term.getArgument( 0 ) ).getName() ); } else { return factory.getOWLNamedIndividual( iri( term ) ); } } } private class LiteralMapper implements EntityMapper { public OWLLiteral map(ATermAppl term) { String lexValue = ((ATermAppl) term.getArgument( 0 )).toString(); ATermAppl lang = (ATermAppl) term.getArgument( 1 ); ATermAppl dtype = (ATermAppl) term.getArgument( 2 ); if( dtype.equals( ATermUtils.PLAIN_LITERAL_DATATYPE ) ) { if( lang.equals( ATermUtils.EMPTY ) ) return factory.getOWLStringLiteral( lexValue ); else return factory.getOWLStringLiteral( lexValue, lang.toString() ); } else { OWLDatatype datatype = DT_MAPPER.map( dtype ); return factory.getOWLTypedLiteral( lexValue, datatype ); } } } private class ObjectPropertyMapper implements EntityMapper { public OWLObjectProperty map(ATermAppl term) { if( ATermUtils.TOP_OBJECT_PROPERTY.equals( term ) ) return factory.getOWLTopObjectProperty(); if( ATermUtils.BOTTOM_OBJECT_PROPERTY.equals( term ) ) return factory.getOWLBottomObjectProperty(); return factory.getOWLObjectProperty( iri( term ) ); } } private class DataPropertyMapper implements EntityMapper { public OWLDataProperty map(ATermAppl term) { if( ATermUtils.TOP_DATA_PROPERTY.equals( term ) ) return factory.getOWLTopDataProperty(); if( ATermUtils.BOTTOM_DATA_PROPERTY.equals( term ) ) return factory.getOWLBottomDataProperty(); return factory.getOWLDataProperty( iri( term ) ); } } private class DatatypeMapper implements EntityMapper { public OWLDatatype map(ATermAppl term) { return factory.getOWLDatatype( iri( term ) ); } } private class ClassMapper implements EntityMapper { public OWLClass map(ATermAppl term) { if( term.equals( ATermUtils.TOP ) ) return factory.getOWLThing(); else if( term.equals( ATermUtils.BOTTOM ) ) return factory.getOWLNothing(); else return factory.getOWLClass( iri( term ) ); } } private EntityMapper IND_MAPPER = new IndividualMapper(); private EntityMapper LIT_MAPPER = new LiteralMapper(); private EntityMapper OP_MAPPER = new ObjectPropertyMapper(); private EntityMapper DP_MAPPER = new DataPropertyMapper(); private EntityMapper DT_MAPPER = new DatatypeMapper(); private EntityMapper CLASS_MAPPER = new ClassMapper(); @SuppressWarnings("unchecked") private EntityMapper DESC_MAPPER = (EntityMapper) (EntityMapper) CLASS_MAPPER; @SuppressWarnings("unchecked") private EntityMapper DR_MAPPER = (EntityMapper) (EntityMapper) DT_MAPPER; private static IRI iri(ATermAppl term) { if( term.getArity() != 0 ) throw new OWLRuntimeException( "Trying to convert an anonymous term " + term ); return IRI.create( term.getName() ); } /** * Create an empty reasoner. * * @param manager * ontology manager for this reasoner */ public Reasoner(OWLOntologyManager manager) { this( manager, new KnowledgeBase() ); } /** * Create a reasoner instance with the given KB. Any changes to the KB will * effect this reasoner. * * @param manager * ontology manager for this reasoner * @param kb * underlying KB instance */ public Reasoner(OWLOntologyManager manager, KnowledgeBase kb) { this.kb = kb; this.loader = new PelletLoader( kb ); this.manager = manager; this.factory = manager.getOWLDataFactory(); this.converter = new AxiomConverter( kb, factory ); loader.setManager( manager ); } public void classify() { kb.classify(); } public void clearOntologies() { loader.clear(); } /** * Convert an axiom represented in ATermAppl format to OWLAxiom * * @param term - * axiom represented as an ATermAppl * @return axiom as an OWLAxiom or null if conversion fails */ public OWLAxiom convertAxiom(ATermAppl term) { return converter.convert( term ); } /** * Convert a set of axioms represented in ATermAppl format to * a set of OWLAxioms * * @param terms - * axioms represented as an ATermAppl * @return axioms as OWLAxiom objects * @throws OWLRuntimeException - * if conversion fails for one of the axioms */ public Set convertAxioms(Set terms) throws OWLRuntimeException { Set result = new HashSet(); for( ATermAppl term : terms ) { OWLAxiom axiom = converter.convert( term ); if( axiom == null ) throw new OWLRuntimeException( "Cannot convert: " + term ); result.add( axiom ); } return result; } public void dispose() { kb = null; } public Set> getAncestorClasses(OWLClassExpression c) { return toOWLEntitySetOfSet( kb.getSuperClasses( loader.term( c ) ), CLASS_MAPPER ); } public Set> getAncestorProperties(OWLDataProperty p) { return toOWLEntitySetOfSet( kb.getSuperProperties( loader.term( p ) ), DP_MAPPER ); } public Set> getAncestorProperties(OWLObjectProperty p) { return toOWLEntitySetOfSet( kb.getSuperProperties( loader.term( p ) ), OP_MAPPER ); } /** * Return the set of all named classes defined in any of the ontologies * loaded in the reasoner. * * @return set of OWLClass objects */ public Set getClasses() { return toOWLEntitySet( kb.getClasses(), CLASS_MAPPER ); } public Set getComplementClasses(OWLClassExpression c) { return toOWLEntitySet( kb.getComplements( loader.term( c ) ), CLASS_MAPPER ); } public Set getDataProperties() { return toOWLEntitySet( kb.getDataProperties(), DP_MAPPER ); } public Map> getDataPropertyRelationships( OWLNamedIndividual individual) { Map> values = new HashMap>(); Set dataProps = getDataProperties(); for( OWLDataProperty prop : dataProps ) { Set set = getRelatedValues( individual, prop ); if( !set.isEmpty() ) values.put( prop, set ); } return values; } public Set> getDescendantClasses(OWLClassExpression c) { return toOWLEntitySetOfSet( kb.getSubClasses( loader.term( c ) ), CLASS_MAPPER ); } public Set> getDescendantProperties(OWLDataProperty p) { return toOWLEntitySetOfSet( kb.getSubProperties( loader.term( p ), false ), DP_MAPPER ); } public Set> getDescendantProperties(OWLObjectProperty p) { return toOWLEntitySetOfSet( kb.getSubProperties( loader.term( p ), false ), OP_MAPPER ); } public Set getDifferentFromIndividuals(OWLIndividual ind) { return toOWLEntitySet( kb.getDifferents( loader.term( ind ) ), IND_MAPPER ); } public Set> getDisjointClasses(OWLClassExpression c) { return toOWLEntitySetOfSet( kb.getDisjoints( loader.term( c ) ), CLASS_MAPPER ); } public Set> getDomains(OWLDataProperty p) { ATermAppl some = ATermUtils.makeSomeValues( loader.term( p ), ATermUtils.TOP_LIT ); return toOWLEntitySetOfSet( kb.getSuperClasses( some ), DESC_MAPPER ); } public Set> getDomains(OWLObjectProperty p) { ATermAppl some = ATermUtils.makeSomeValues( loader.term( p ), ATermUtils.TOP ); return toOWLEntitySetOfSet( kb.getSuperClasses( some ), DESC_MAPPER ); } public Set getEquivalentClasses(OWLClassExpression c) { return toOWLEntitySet( kb.getEquivalentClasses( loader.term( c ) ), CLASS_MAPPER ); } public Set getAllEquivalentClasses(OWLClassExpression c) { return toOWLEntitySet( kb.getAllEquivalentClasses( loader.term( c ) ), CLASS_MAPPER ); } public Set getEquivalentProperties(OWLDataProperty p) { return toOWLEntitySet( kb.getEquivalentProperties( loader.term( p ) ), DP_MAPPER ); } public Set getEquivalentProperties(OWLObjectProperty p) { return toOWLEntitySet( kb.getEquivalentProperties( loader.term( p ) ), OP_MAPPER ); } /** * Returns the explanation for the last performed reasoning operation. The * last reasoning operation must be a boolean query that checks for a * specific entailment, e.g. concept satisfiability, subclass entailment, * etc. Note that, the options for turning on the explanation feature should * be enabled to retrieve any explanation. * * @return the explanation as a set of axioms that cause the entailment * @throws OWLRuntimeException - * if no explanation was generated or axioms in the explanation * cannot be converted to OWLAxioms */ public Set getExplanation() throws OWLRuntimeException { Set explanation = kb.getExplanationSet(); if( explanation == null || explanation.isEmpty() ) throw new OWLRuntimeException( "No explanation computed" ); return convertAxioms( explanation ); } public Set getInconsistentClasses() { return toOWLEntitySet( kb.getUnsatisfiableClasses(), CLASS_MAPPER ); } /** * Return the set of all individuals defined in any of the ontologies loaded * in the reasoner. * * @return set of OWLIndividual objects */ public Set getIndividuals() { return toOWLEntitySet( kb.getIndividuals(), IND_MAPPER ); } /** * Returns all or only direct instances of a concept expression */ public Set getIndividuals(OWLClassExpression clsC, boolean direct) { Set all = toOWLEntitySet( kb.getInstances( loader.term( clsC ), direct ), IND_MAPPER ); Set ret = new HashSet( all.size() ); for( OWLIndividual i : all ) { if( !i.isAnonymous() ) ret.add( i.asOWLNamedIndividual() ); } return ret; } public Set> getInverseProperties(OWLObjectProperty prop) { return Collections.singleton( toOWLEntitySet( kb.getInverses( loader.term( prop ) ), OP_MAPPER ) ); } /** * @return Returns the kb. */ public KnowledgeBase getKB() { return kb; } public Set getLoadedOntologies() { return loader.getOntologies(); } public PelletLoader getLoader() { return loader; } public OWLOntologyManager getManager() { return manager; } public Set getObjectProperties() { return toOWLEntitySet( kb.getObjectProperties(), OP_MAPPER ); } public Map> getObjectPropertyRelationships( OWLNamedIndividual individual) { Map> values = new HashMap>(); Set objProps = getObjectProperties(); for( OWLObjectProperty prop : objProps ) { Set set = getRelatedIndividuals( individual, prop ); if( !set.isEmpty() ) values.put( prop, set ); } return values; } /** * Return all the object and data properties defined in the loaded * ontologies */ public Set> getProperties() { Set> properties = new HashSet>(); properties.addAll( getObjectProperties() ); properties.addAll( getDataProperties() ); return properties; } public Map> getDataPropertyAssertions(OWLDataProperty prop) { Map> map = new HashMap>(); ATermAppl p = loader.term( prop ); for( ATermAppl candidate : kb.getIndividuals() ) { List list = kb.getDataPropertyValues( p, candidate ); if( list.isEmpty() ) continue; OWLIndividual subj = IND_MAPPER.map( candidate ); Set objects = toOWLEntitySet( list, LIT_MAPPER ); map.put( subj, objects ); } return map; } public Map> getObjectPropertyAssertions(OWLObjectProperty prop) { Map> result = new HashMap>(); ATermAppl p = loader.term( prop ); Map> values = kb.getPropertyValues( p ); for( Map.Entry> entry : values.entrySet() ) { ATermAppl subjTerm = entry.getKey(); List objTerms = entry.getValue(); OWLIndividual subj = IND_MAPPER.map( subjTerm ); Set objects = toOWLEntitySet( objTerms, IND_MAPPER ); result.put( subj, objects ); } return result; } public Set getRanges(OWLDataProperty p) { return toOWLEntitySet( kb.getRanges( loader.term( p ) ), DR_MAPPER ); } public Set getRanges(OWLObjectProperty p) { return toOWLEntitySet( kb.getRanges( loader.term( p ) ), DESC_MAPPER ); } public Set getRelatedIndividuals(OWLNamedIndividual subject, OWLObjectPropertyExpression property) { final Set all = toOWLEntitySet( kb.getObjectPropertyValues( loader .term( property ), loader.term( subject ) ), IND_MAPPER ); if( all.isEmpty() ) return Collections.emptySet(); Set ret = new HashSet( all.size() ); for( OWLIndividual ind : all ) { if( !ind.isAnonymous() ) ret.add( ind.asOWLNamedIndividual() ); } return ret; } public Set getRelatedValues(OWLNamedIndividual subject, OWLDataPropertyExpression property) { return toOWLEntitySet( kb.getDataPropertyValues( loader.term( property ), loader .term( subject ) ), LIT_MAPPER ); } /** * Return a set of sameAs individuals given a specific individual based on * axioms in the ontology * * @param ind - * specific individual to test * @return * @throws OWLException */ public Set getSameAsIndividuals(OWLIndividual ind) { return toOWLEntitySet( kb.getSames( loader.term( ind ) ), IND_MAPPER ); } public Set> getSubClasses(OWLClassExpression c) { return toOWLEntitySetOfSet( kb.getSubClasses( loader.term( c ), true ), CLASS_MAPPER ); } public Set> getSubProperties(OWLDataProperty p) { return toOWLEntitySetOfSet( kb.getSubProperties( loader.term( p ), true ), DP_MAPPER ); } public Set> getSubProperties(OWLObjectProperty p) { return toOWLEntitySetOfSet( kb.getSubProperties( loader.term( p ), true ), OP_MAPPER ); } public Set> getSuperClasses(OWLClassExpression c) { return toOWLEntitySetOfSet( kb.getSuperClasses( loader.term( c ), true ), CLASS_MAPPER ); } public Set> getSuperProperties(OWLDataProperty p) { return toOWLEntitySetOfSet( kb.getSuperProperties( loader.term( p ), true ), DP_MAPPER ); } public Set> getSuperProperties(OWLObjectProperty p) { return toOWLEntitySetOfSet( kb.getSuperProperties( loader.term( p ), true ), OP_MAPPER ); } // public Set> getTypes(OWLNamedIndividual individual) { // return toOWLEntitySetOfSet( kb.getTypes( loader.term( individual ), true ), CLASS_MAPPER ); // } /** * Returns all the named classes that this individual belongs. This returns * a set of sets where each set is an equivalent class * * @param ind * @return Set of OWLClassExpression objects * @throws OWLException */ public Set> getTypes(OWLNamedIndividual ind, boolean direct) { return toOWLEntitySetOfSet( kb.getTypes( loader.term( ind ), direct ), CLASS_MAPPER ); } public Set getUnsatisfiableClasses() { return toOWLEntitySet( kb.getUnsatisfiableClasses(), CLASS_MAPPER ); } public boolean hasDataPropertyRelationship(OWLNamedIndividual subject, OWLDataPropertyExpression property, OWLLiteral object) { return kb.hasPropertyValue( loader.term( subject ), loader.term( property ), loader .term( object ) ); } public boolean hasDomain(OWLDataProperty p, OWLClassExpression c) { return kb.hasDomain( loader.term( p ), loader.term( c ) ); } public boolean hasDomain(OWLObjectProperty p, OWLClassExpression c) { return kb.hasDomain( loader.term( p ), loader.term( c ) ); } public boolean hasObjectPropertyRelationship(OWLNamedIndividual subject, OWLObjectPropertyExpression property, OWLNamedIndividual object) { return kb.hasPropertyValue( loader.term( subject ), loader.term( property ), loader .term( object ) ); } public boolean hasRange(OWLDataProperty p, OWLDataRange d) { return kb.hasRange( loader.term( p ), loader.term( d ) ); } public boolean hasRange(OWLObjectProperty p, OWLClassExpression c) { return kb.hasRange( loader.term( p ), loader.term( c ) ); } /** * Checks if the given individual is a direct or indirect instance of the * given type */ public boolean hasType(OWLNamedIndividual individual, OWLClassExpression type, boolean direct) { if( direct ) return getTypes( individual, direct ).contains( type ); else return kb.isType( loader.term( individual ), loader.term( type ) ); } public boolean isAntiSymmetric(OWLObjectProperty p) { return kb.isAsymmetricProperty( loader.term( p ) ); } //@Override public boolean isAsymmetric(OWLObjectProperty p) { return kb.isAsymmetricProperty( loader.term( p ) ); } public boolean isClassified() { return kb.isClassified(); } public boolean isComplementOf(OWLClassExpression c1, OWLClassExpression c2) { return kb.isComplement( loader.term( c1 ), loader.term( c2 ) ); } /** * Returns true if the loaded ontology is consistent. * * @param c * @return * @throws OWLException */ public boolean isConsistent() { return kb.isConsistent(); } /** * @deprecated Use {@link #isSatisfiable(OWLClassExpression)} instead */ public boolean isConsistent(OWLClassExpression d) { return isSatisfiable( d ); } public boolean isConsistent(OWLOntology ontology) { setOntology( ontology ); return isConsistent(); } public boolean isDefined(OWLClass cls) { ATermAppl term = loader.term( cls ); return kb.isClass( term ); } public boolean isDefined(OWLDataProperty prop) { ATermAppl term = loader.term( prop ); return kb.isDatatypeProperty( term ); } public boolean isDefined(OWLIndividual ind) { ATermAppl term = loader.term( ind ); return kb.isIndividual( term ); } public boolean isDefined(OWLObjectProperty prop) { ATermAppl term = loader.term( prop ); return kb.isObjectProperty( term ); } /** * Test if two individuals are owl:DifferentFrom each other. * * @return * @throws OWLException */ public boolean isDifferentFrom(OWLIndividual ind1, OWLIndividual ind2) { return kb.isDifferentFrom( loader.term( ind1 ), loader.term( ind2 ) ); } public boolean isDisjointWith(OWLDataProperty p1, OWLDataProperty p2) { return kb.isDisjointProperty( loader.term( p1 ), loader.term( p2 ) ); } public boolean isDisjointWith(OWLClassExpression c1, OWLClassExpression c2) { return kb.isDisjointClass( loader.term( c1 ), loader.term( c2 ) ); } public boolean isDisjointWith(OWLObjectProperty p1, OWLObjectProperty p2) { return kb.isDisjointProperty( loader.term( p1 ), loader.term( p2 ) ); } // public boolean isEntailed(OWLOntology ont) { // return isEntailed( ont.getAxioms() ); // } // // public boolean isEntailed(Set axioms) { // EntailmentChecker entailmentChecker = new EntailmentChecker( this ); // return entailmentChecker.isEntailed(axioms); // } // // public boolean isEntailed(OWLAxiom axiom) { // return isEntailed(Collections.singleton(axiom)); // } public boolean isEquivalentClass(OWLClassExpression c1, OWLClassExpression c2) { return kb.isEquivalentClass( loader.term( c1 ), loader.term( c2 ) ); } public boolean isEquivalentProperty(OWLDataProperty p1, OWLDataProperty p2) { return kb.isEquivalentProperty( loader.term( p1 ), loader.term( p2 ) ); } public boolean isEquivalentProperty(OWLObjectProperty p1, OWLObjectProperty p2) { return kb.isEquivalentProperty( loader.term( p1 ), loader.term( p2 ) ); } public boolean isFunctional(OWLDataProperty p) { return kb.isFunctionalProperty( loader.term( p ) ); } public boolean isFunctional(OWLObjectProperty p) { return kb.isFunctionalProperty( loader.term( p ) ); } public boolean isInverseFunctional(OWLObjectProperty p) { return kb.isInverseFunctionalProperty( loader.term( p ) ); } public boolean isInverseOf(OWLObjectProperty p1, OWLObjectProperty p2) { return kb.isInverse( loader.term( p1 ), loader.term( p2 ) ); } public boolean isIrreflexive(OWLObjectProperty p) { return kb.isIrreflexiveProperty( loader.term( p ) ); } public boolean isRealised() { return kb.isRealized(); } public boolean isReflexive(OWLObjectProperty p) { return kb.isReflexiveProperty( loader.term( p ) ); } /** * Test if two individuals are owl:DifferentFrom each other. * * @return * @throws OWLException */ public boolean isSameAs(OWLIndividual ind1, OWLIndividual ind2) { return kb.isSameAs( loader.term( ind1 ), loader.term( ind2 ) ); } /** * Returns true if the given class is satisfiable. * * @param c * @return * @throws OWLException */ public boolean isSatisfiable(OWLClassExpression d) { if( !kb.isConsistent() ) return false; return kb.isSatisfiable( loader.term( d ) ); } public boolean isSubClassOf(OWLClassExpression c1, OWLClassExpression c2) { return kb.isSubClassOf( loader.term( c1 ), loader.term( c2 ) ); } public boolean isSubPropertyOf(OWLDataProperty c1, OWLDataProperty c2) { return kb.isSubPropertyOf( loader.term( c1 ), loader.term( c2 ) ); } public boolean isSubPropertyOf(OWLObjectProperty c1, OWLObjectProperty c2) { return kb.isSubPropertyOf( loader.term( c1 ), loader.term( c2 ) ); } public boolean isSubTypeOf(OWLDatatype d1, OWLDatatype d2) { return kb.isSubClassOf( loader.term( d1 ), loader.term( d2 ) ); } public boolean isSymmetric(OWLObjectProperty p) { return kb.isSymmetricProperty( loader.term( p ) ); } public boolean isTransitive(OWLObjectProperty p) { return kb.isTransitiveProperty( loader.term( p ) ); } public void loadOntologies(Set ontologies) { if( manager == null ) { log .warning( "Cannot load an ontology without an ontology manager. Use setManager(OWLOntologyManager) first." ); return; } loader.load( ontologies ); } public void loadOntology(OWLOntology ontology) { loadOntologies( Collections.singleton( ontology ) ); } /** * Listens to ontology changes and refreshes the underlying KB. Applies some * of the ontology changes incrementally but applies full reload if * incremental update cannot be handled for one of the changes. All * additions can be handled incrementally but removal of some axioms cannot * be handled. Note that, the incremental processing here is meant to refer * only loading and not reasoning, i.e. it is different from the incremental * reasoning support provided by Pellet. */ public void ontologiesChanged(List changes) { boolean changesApplied = loader.applyChanges( changes ); if( !changesApplied ) { refresh(); } } public void realise() { kb.realize(); } public void refresh() { loader.reload(); } /** * This will first clear the ontologies and then load the give ontology with * is imports */ public void setOntology(OWLOntology ontology) { clearOntologies(); loadOntologies( Collections.singleton( ontology ) ); } private Set> toOWLEntitySetOfSet(Set> setOfTerms, EntityMapper mapper) { Set> results = new HashSet>(); for( Set terms : setOfTerms ) { Set entitySet = toOWLEntitySet( terms, mapper ); if( !entitySet.isEmpty() ) results.add( entitySet ); } return results; } private Set toOWLEntitySet(Collection terms, EntityMapper mapper) { Set results = new HashSet(); for( ATermAppl term : terms ) results.add( mapper.map( term ) ); return results; } public void unloadOntologies(Set ontologies) { loader.unload( ontologies ); refresh(); } public void unloadOntology(OWLOntology ontology) { unloadOntologies( Collections.singleton( ontology ) ); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy