org.semanticweb.HermiT.datalog.DatalogEngine Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.semanticweb.hermit Show documentation
Show all versions of org.semanticweb.hermit Show documentation
HermiT is reasoner for ontologies written using the Web Ontology Language (OWL). Given an OWL file, HermiT can determine whether or not the ontology is consistent, identify subsumption relationships between classes, and much more.
This is the maven build of HermiT and is designed for people who wish to use HermiT from within the OWL API. It is now versioned in the main HermiT version repository, although not officially supported by the HermiT developers.
The version number of this package is a composite of the HermiT version and a value representing the OWLAPI release it is compatible with. Note that the group id for the upstream HermiT is com.hermit-reasoner, while this fork is released under net.sourceforge.owlapi.
This fork exists to allow HermiT users to use newer OWLAPI versions than the ones supported by the original HermiT codebase.
This package includes the Jautomata library (http://jautomata.sourceforge.net/), and builds with it directly. This library appears to be no longer under active development, and so a "fork" seems appropriate. No development is intended or anticipated on this code base.
The newest version!
package org.semanticweb.HermiT.datalog;
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 org.semanticweb.HermiT.existentials.ExistentialExpansionStrategy;
import org.semanticweb.HermiT.model.Atom;
import org.semanticweb.HermiT.model.AtomicRole;
import org.semanticweb.HermiT.model.Concept;
import org.semanticweb.HermiT.model.DLClause;
import org.semanticweb.HermiT.model.DLOntology;
import org.semanticweb.HermiT.model.DataRange;
import org.semanticweb.HermiT.model.Term;
import org.semanticweb.HermiT.model.Variable;
import org.semanticweb.HermiT.tableau.DLClauseEvaluator;
import org.semanticweb.HermiT.tableau.ExtensionManager;
import org.semanticweb.HermiT.tableau.InterruptFlag;
import org.semanticweb.HermiT.tableau.Node;
import org.semanticweb.HermiT.tableau.Tableau;
/**
* Datalog engine.
*/
public final class DatalogEngine {
protected final InterruptFlag m_interruptFlag;
protected final DLOntology m_dlOntology;
protected final Map m_termsToNodes;
protected final Map m_nodesToTerms;
protected final Map> m_termsToEquivalenceClasses;
protected final Map m_termsToRepresentatives;
protected ExtensionManager m_extensionManager;
/**
* @param dlOntology dlOntology
*/
public DatalogEngine(DLOntology dlOntology) {
for (DLClause dlClause : dlOntology.getDLClauses())
if (dlClause.getHeadLength()>1)
throw new IllegalArgumentException("The supplied DL ontology contains rules with disjunctive heads.");
m_interruptFlag=new InterruptFlag(0);
m_dlOntology=dlOntology;
m_termsToNodes=new HashMap<>();
m_nodesToTerms=new HashMap<>();
m_termsToEquivalenceClasses=new HashMap<>();
m_termsToRepresentatives=new HashMap<>();
}
/**
* Interrupt.
*/
public void interrupt() {
m_interruptFlag.interrupt();
}
/**
* @return true if no clashes
*/
public boolean materialize() {
if (m_extensionManager==null) {
m_termsToNodes.clear();
m_nodesToTerms.clear();
m_termsToEquivalenceClasses.clear();
m_termsToRepresentatives.clear();
Tableau tableau=new Tableau(m_interruptFlag,null,NullExistentialExpansionStrategy.INSTANCE,false,m_dlOntology,null,new HashMap());
Set noAtoms=Collections.emptySet();
tableau.isSatisfiable(true,false,noAtoms,noAtoms,noAtoms,noAtoms,m_termsToNodes,null,null);
for (Map.Entry entry : m_termsToNodes.entrySet())
m_nodesToTerms.put(entry.getValue(),entry.getKey());
m_extensionManager=tableau.getExtensionManager();
Node node=tableau.getFirstTableauNode();
while (node!=null) {
Term term=m_nodesToTerms.get(node);
Term canonicalTerm=m_nodesToTerms.get(node.getCanonicalNode());
Set equivalenceClass=m_termsToEquivalenceClasses.get(canonicalTerm);
if (equivalenceClass==null) {
equivalenceClass=new HashSet<>();
m_termsToEquivalenceClasses.put(canonicalTerm,equivalenceClass);
}
if (!term.equals(canonicalTerm))
m_termsToEquivalenceClasses.put(term,equivalenceClass);
equivalenceClass.add(term);
m_termsToRepresentatives.put(term,canonicalTerm);
node=node.getNextTableauNode();
}
}
return !m_extensionManager.containsClash();
}
/**
* @return ontology
*/
public DLOntology getDLOntology() {
return m_dlOntology;
}
/**
* @param term term
* @return equivalence classes
*/
public Set getEquivalenceClass(Term term) {
return m_termsToEquivalenceClasses.get(term);
}
/**
* @param term term
* @return representative
*/
public Term getRepresentative(Term term) {
return m_termsToRepresentatives.get(term);
}
protected static class NullExistentialExpansionStrategy implements ExistentialExpansionStrategy {
public static final ExistentialExpansionStrategy INSTANCE=new NullExistentialExpansionStrategy();
@Override
public void initialize(Tableau tableau) {
}
@Override
public void additionalDLOntologySet(DLOntology additionalDLOntology) {
}
@Override
public void additionalDLOntologyCleared() {
}
@Override
public void clear() {
}
@Override
public boolean expandExistentials(boolean finalChance) {
return false;
}
@Override
public void assertionAdded(Concept concept,Node node,boolean isCore) {
}
@Override
public void assertionAdded(DataRange dataRange,Node node,boolean isCore) {
}
@Override
public void assertionCoreSet(Concept concept,Node node) {
}
@Override
public void assertionCoreSet(DataRange dataRange,Node node) {
}
@Override
public void assertionRemoved(Concept concept,Node node,boolean isCore) {
}
@Override
public void assertionRemoved(DataRange dataRange,Node node,boolean isCore) {
}
@Override
public void assertionAdded(AtomicRole atomicRole,Node nodeFrom,Node nodeTo,boolean isCore) {
}
@Override
public void assertionCoreSet(AtomicRole atomicRole,Node nodeFrom,Node nodeTo) {
}
@Override
public void assertionRemoved(AtomicRole atomicRole,Node nodeFrom,Node nodeTo,boolean isCore) {
}
@Override
public void nodesMerged(Node mergeFrom,Node mergeInto) {
}
@Override
public void nodesUnmerged(Node mergeFrom,Node mergeInto) {
}
@Override
public void nodeStatusChanged(Node node) {
}
@Override
public void nodeInitialized(Node node) {
}
@Override
public void nodeDestroyed(Node node) {
}
@Override
public void branchingPointPushed() {
}
@Override
public void backtrack() {
}
@Override
public void modelFound() {
}
@Override
public boolean isDeterministic() {
return true;
}
@Override
public boolean isExact() {
return true;
}
@Override
public void dlClauseBodyCompiled(List workers,DLClause dlClause,List variables,Object[] valuesBuffer,boolean[] coreVariables) {
}
}
}