org.semanticweb.HermiT.blocking.SingleDirectBlockingChecker 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!
/* Copyright 2008, 2009, 2010 by the Oxford University Computing Laboratory
This file is part of HermiT.
HermiT is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
HermiT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with HermiT. If not, see .
*/
package org.semanticweb.HermiT.blocking;
import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.Set;
import org.semanticweb.HermiT.model.AtomicConcept;
import org.semanticweb.HermiT.model.AtomicRole;
import org.semanticweb.HermiT.model.Concept;
import org.semanticweb.HermiT.model.DataRange;
import org.semanticweb.HermiT.tableau.ExtensionTable;
import org.semanticweb.HermiT.tableau.Node;
import org.semanticweb.HermiT.tableau.NodeType;
import org.semanticweb.HermiT.tableau.Tableau;
/**Single direct blocking checker.*/
public class SingleDirectBlockingChecker implements DirectBlockingChecker,Serializable {
private static final long serialVersionUID=9093753046859877016L;
protected final SetFactory m_atomicConceptsSetFactory=new SetFactory<>();
protected final Set m_atomicConceptsBuffer=new LinkedHashSet<>();
protected ExtensionTable.Retrieval m_binaryTableSearch1Bound;
@Override
public void initialize(Tableau tableau) {
m_binaryTableSearch1Bound=tableau.getExtensionManager().getBinaryExtensionTable().createRetrieval(new boolean[] { false,true },ExtensionTable.View.TOTAL);
}
@Override
public void clear() {
m_atomicConceptsSetFactory.clearNonpermanent();
m_binaryTableSearch1Bound.clear();
}
@Override
public boolean isBlockedBy(Node blocker,Node blocked) {
return
!blocker.isBlocked() &&
blocker.getNodeType()==NodeType.TREE_NODE &&
blocked.getNodeType()==NodeType.TREE_NODE &&
((SingleBlockingObject)blocker.getBlockingObject()).getAtomicConceptsLabel()==((SingleBlockingObject)blocked.getBlockingObject()).getAtomicConceptsLabel();
}
@Override
public int blockingHashCode(Node node) {
return ((SingleBlockingObject)node.getBlockingObject()).m_atomicConceptsLabelHashCode;
}
@Override
public boolean canBeBlocker(Node node) {
return node.getNodeType()==NodeType.TREE_NODE;
}
@Override
public boolean canBeBlocked(Node node) {
return node.getNodeType()==NodeType.TREE_NODE;
}
@Override
public boolean hasBlockingInfoChanged(Node node) {
return ((SingleBlockingObject)node.getBlockingObject()).m_hasChanged;
}
@Override
public void clearBlockingInfoChanged(Node node) {
((SingleBlockingObject)node.getBlockingObject()).m_hasChanged=false;
}
@Override
public void nodeInitialized(Node node) {
if (node.getBlockingObject()==null)
node.setBlockingObject(new SingleBlockingObject(node));
((SingleBlockingObject)node.getBlockingObject()).initialize();
}
@Override
public void nodeDestroyed(Node node) {
((SingleBlockingObject)node.getBlockingObject()).destroy();
}
@Override
public Node assertionAdded(Concept concept,Node node,boolean isCore) {
if (concept instanceof AtomicConcept) {
((SingleBlockingObject)node.getBlockingObject()).addAtomicConcept((AtomicConcept)concept);
return node;
}
else
return null;
}
@Override
public Node assertionRemoved(Concept concept,Node node,boolean isCore) {
if (concept instanceof AtomicConcept) {
((SingleBlockingObject)node.getBlockingObject()).removeAtomicConcept((AtomicConcept)concept);
return node;
}
else
return null;
}
@Override
public Node assertionAdded(DataRange range,Node node,boolean isCore) {
return null;
}
@Override
public Node assertionRemoved(DataRange range,Node node,boolean isCore) {
return null;
}
@Override
public Node assertionAdded(AtomicRole atomicRole,Node nodeFrom,Node nodeTo,boolean isCore) {
return null;
}
@Override
public Node assertionRemoved(AtomicRole atomicRole,Node nodeFrom,Node nodeTo,boolean isCore) {
return null;
}
@Override
public Node nodesMerged(Node mergeFrom,Node mergeInto) {
return null;
}
@Override
public Node nodesUnmerged(Node mergeFrom,Node mergeInto) {
return null;
}
@Override
public BlockingSignature getBlockingSignatureFor(Node node) {
return new SingleBlockingSignature(this,node);
}
protected Set fetchAtomicConceptsLabel(Node node) {
m_atomicConceptsBuffer.clear();
m_binaryTableSearch1Bound.getBindingsBuffer()[1]=node;
m_binaryTableSearch1Bound.open();
Object[] tupleBuffer=m_binaryTableSearch1Bound.getTupleBuffer();
while (!m_binaryTableSearch1Bound.afterLast()) {
Object concept=tupleBuffer[0];
if (concept instanceof AtomicConcept)
m_atomicConceptsBuffer.add((AtomicConcept)concept);
m_binaryTableSearch1Bound.next();
}
Set result=m_atomicConceptsSetFactory.getSet(m_atomicConceptsBuffer);
m_atomicConceptsBuffer.clear();
return result;
}
@Override
public boolean hasChangedSinceValidation(Node node) {
return false;
}
@Override
public void setHasChangedSinceValidation(Node node,boolean hasChanged) {
// do nothing
}
protected final class SingleBlockingObject implements Serializable {
private static final long serialVersionUID=-5439737072100509531L;
protected final Node m_node;
protected boolean m_hasChanged;
protected Set m_atomicConceptsLabel;
protected int m_atomicConceptsLabelHashCode;
public SingleBlockingObject(Node node) {
m_node=node;
}
public void initialize() {
m_atomicConceptsLabel=null;
m_atomicConceptsLabelHashCode=0;
m_hasChanged=true;
}
public void destroy() {
if (m_atomicConceptsLabel!=null) {
m_atomicConceptsSetFactory.removeReference(m_atomicConceptsLabel);
m_atomicConceptsLabel=null;
}
}
public Set getAtomicConceptsLabel() {
if (m_atomicConceptsLabel==null) {
m_atomicConceptsLabel=SingleDirectBlockingChecker.this.fetchAtomicConceptsLabel(m_node);
m_atomicConceptsSetFactory.addReference(m_atomicConceptsLabel);
}
return m_atomicConceptsLabel;
}
public void addAtomicConcept(AtomicConcept atomicConcept) {
if (m_atomicConceptsLabel!=null) {
// invalidate, recompute real label later if necessary
m_atomicConceptsSetFactory.removeReference(m_atomicConceptsLabel);
m_atomicConceptsLabel=null;
}
m_atomicConceptsLabelHashCode+=atomicConcept.hashCode();
m_hasChanged=true;
}
public void removeAtomicConcept(AtomicConcept atomicConcept) {
if (m_atomicConceptsLabel!=null) {
// invalidate, recompute real label later if necessary
m_atomicConceptsSetFactory.removeReference(m_atomicConceptsLabel);
m_atomicConceptsLabel=null;
}
m_atomicConceptsLabelHashCode-=atomicConcept.hashCode();
m_hasChanged=true;
}
}
protected static class SingleBlockingSignature extends BlockingSignature implements Serializable {
private static final long serialVersionUID=-7349489846772132258L;
protected final Set m_atomicConceptsLabel;
public SingleBlockingSignature(SingleDirectBlockingChecker checker,Node node) {
m_atomicConceptsLabel=((SingleBlockingObject)node.getBlockingObject()).getAtomicConceptsLabel();
checker.m_atomicConceptsSetFactory.makePermanent(m_atomicConceptsLabel);
}
@Override
public boolean blocksNode(Node node) {
return ((SingleBlockingObject)node.getBlockingObject()).getAtomicConceptsLabel()==m_atomicConceptsLabel;
}
@Override
public int hashCode() {
return m_atomicConceptsLabel.hashCode();
}
@Override
public boolean equals(Object that) {
if (this==that)
return true;
if (!(that instanceof SingleBlockingSignature))
return false;
return m_atomicConceptsLabel==((SingleBlockingSignature)that).m_atomicConceptsLabel;
}
}
}