org.semanticweb.HermiT.tableau.TupleIndex 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
an value representing releases of this packaged version. So, 1.3.7.1 is the
first release of the mavenized version of HermiT based on the 1.3.7 release
of HermiT.
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.
/* 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.tableau;
import java.io.Serializable;
public final class TupleIndex implements Serializable {
private static final long serialVersionUID=-4284072092430590904L;
protected static final float LOAD_FACTOR=0.7f;
protected static final int BUCKET_OFFSET=1;
protected final int[] m_indexingSequence;
protected final TrieNodeManager m_trieNodeManager;
protected int m_root;
protected int[] m_buckets;
protected int m_bucketsLengthMinusOne; // must be all ones in binary!
protected int m_resizeThreshold;
protected int m_numberOfNodes;
public TupleIndex(int[] indexingSequence) {
m_indexingSequence=indexingSequence;
m_trieNodeManager=new TrieNodeManager();
clear();
}
public int sizeInMemoy() {
return m_buckets.length*4+m_trieNodeManager.size();
}
public int[] getIndexingSequence() {
return m_indexingSequence;
}
public void clear() {
m_trieNodeManager.clear();
m_root=m_trieNodeManager.newTrieNode();
m_trieNodeManager.initializeTrieNode(m_root,-1,-1,-1,-1,-1,null);
m_buckets=new int[16];
m_bucketsLengthMinusOne=m_buckets.length-1;
m_resizeThreshold=(int)(m_buckets.length*LOAD_FACTOR);
m_numberOfNodes=0;
}
public int addTuple(Object[] tuple,int potentialTupleIndex) {
int trieNode=m_root;
for (int position=0;position=m_resizeThreshold) {
resizeBuckets();
bucketIndex=getIndexFor(hashCode,m_bucketsLengthMinusOne);
}
child=m_trieNodeManager.newTrieNode();
int nextSibling=m_trieNodeManager.getTrieNodeComponent(parent,TRIE_NODE_FIRST_CHILD);
if (nextSibling!=-1)
m_trieNodeManager.setTrieNodeComponent(nextSibling,TRIE_NODE_PREVIOUS_SIBLING,child);
m_trieNodeManager.setTrieNodeComponent(parent,TRIE_NODE_FIRST_CHILD,child);
m_trieNodeManager.initializeTrieNode(child,parent,-1,-1,nextSibling,m_buckets[bucketIndex]-BUCKET_OFFSET,object);
m_buckets[bucketIndex]=child+BUCKET_OFFSET;
m_numberOfNodes++;
return child;
}
protected void resizeBuckets() {
if (m_buckets.length==0x40000000)
m_resizeThreshold=Integer.MAX_VALUE;
else {
int[] newBuckets=new int[m_buckets.length*2];
int newBucketsLengthMinusOne=newBuckets.length-1;
for (int bucketIndex=m_bucketsLengthMinusOne;bucketIndex>=0;--bucketIndex) {
int trieNode=m_buckets[bucketIndex]-BUCKET_OFFSET;
while (trieNode!=-1) {
int nextTrieNode=m_trieNodeManager.getTrieNodeComponent(trieNode,TRIE_NODE_NEXT_ENTRY);
int hashCode=m_trieNodeManager.getTrieNodeObject(trieNode).hashCode()+m_trieNodeManager.getTrieNodeComponent(trieNode,TRIE_NODE_PARENT);
int newBucketIndex=getIndexFor(hashCode,newBucketsLengthMinusOne);
m_trieNodeManager.setTrieNodeComponent(trieNode,TRIE_NODE_NEXT_ENTRY,newBuckets[newBucketIndex]-BUCKET_OFFSET);
newBuckets[newBucketIndex]=trieNode+BUCKET_OFFSET;
trieNode=nextTrieNode;
}
}
m_buckets=newBuckets;
m_bucketsLengthMinusOne=newBucketsLengthMinusOne;
m_resizeThreshold=(int)(m_buckets.length*LOAD_FACTOR);
}
}
protected static int getIndexFor(int hashCode,int tableLengthMinusOne) {
hashCode+=~(hashCode << 9);
hashCode^=(hashCode >>> 14);
hashCode+=(hashCode << 4);
hashCode^=(hashCode >>> 10);
return hashCode & tableLengthMinusOne;
}
protected static final int TRIE_NODE_PARENT=0;
protected static final int TRIE_NODE_FIRST_CHILD=1;
protected static final int TRIE_NODE_TUPLE_INDEX=1;
protected static final int TRIE_NODE_PREVIOUS_SIBLING=2;
protected static final int TRIE_NODE_NEXT_SIBLING=3;
protected static final int TRIE_NODE_NEXT_ENTRY=4;
protected static final int TRIE_NODE_SIZE=5;
protected static final int TRIE_NODE_PAGE_SIZE=1024;
protected static final class TrieNodeManager implements Serializable {
private static final long serialVersionUID=-1978070096232682717L;
protected int[][] m_indexPages;
protected Object[][] m_objectPages;
protected int m_firstFreeTrieNode;
protected int m_numberOfPages;
public TrieNodeManager() {
clear();
}
public int size() {
int size=m_indexPages.length*4+m_objectPages.length*4;
for (int i=m_indexPages.length-1;i>=0;--i)
if (m_indexPages[i]!=null)
size+=m_indexPages[i].length*4;
for (int i=m_objectPages.length-1;i>=0;--i)
if (m_objectPages[i]!=null)
size+=m_objectPages[i].length*4;
return size;
}
public void clear() {
m_indexPages=new int[10][];
m_indexPages[0]=new int[TRIE_NODE_SIZE*TRIE_NODE_PAGE_SIZE];
m_objectPages=new Object[10][];
m_objectPages[0]=new Object[TRIE_NODE_PAGE_SIZE];
m_numberOfPages=1;
m_firstFreeTrieNode=0;
setTrieNodeComponent(m_firstFreeTrieNode,TRIE_NODE_NEXT_SIBLING,-1);
}
public int getTrieNodeComponent(int trieNode,int component) {
return m_indexPages[trieNode / TRIE_NODE_PAGE_SIZE][(trieNode % TRIE_NODE_PAGE_SIZE)*TRIE_NODE_SIZE+component];
}
public void setTrieNodeComponent(int trieNode,int component,int value) {
m_indexPages[trieNode / TRIE_NODE_PAGE_SIZE][(trieNode % TRIE_NODE_PAGE_SIZE)*TRIE_NODE_SIZE+component]=value;
}
public Object getTrieNodeObject(int trieNode) {
return m_objectPages[trieNode / TRIE_NODE_PAGE_SIZE][trieNode % TRIE_NODE_PAGE_SIZE];
}
public void setTrieNodeObject(int trieNode,Object object) {
m_objectPages[trieNode / TRIE_NODE_PAGE_SIZE][trieNode % TRIE_NODE_PAGE_SIZE]=object;
}
public void initializeTrieNode(int trieNode,int parent,int firstChild,int previousSibling,int nextSibling,int nextEntry,Object object) {
int pageIndex=trieNode / TRIE_NODE_PAGE_SIZE;
int indexInPage=trieNode % TRIE_NODE_PAGE_SIZE;
int[] indexPage=m_indexPages[pageIndex];
int start=indexInPage*TRIE_NODE_SIZE;
indexPage[start+TRIE_NODE_PARENT]=parent;
indexPage[start+TRIE_NODE_FIRST_CHILD]=firstChild;
indexPage[start+TRIE_NODE_PREVIOUS_SIBLING]=previousSibling;
indexPage[start+TRIE_NODE_NEXT_SIBLING]=nextSibling;
indexPage[start+TRIE_NODE_NEXT_ENTRY]=nextEntry;
m_objectPages[pageIndex][indexInPage]=object;
}
public int newTrieNode() {
int newTrieNode=m_firstFreeTrieNode;
int nextFreeTrieNode=getTrieNodeComponent(m_firstFreeTrieNode,TRIE_NODE_NEXT_SIBLING);
if (nextFreeTrieNode!=-1)
m_firstFreeTrieNode=nextFreeTrieNode;
else {
m_firstFreeTrieNode++;
if (m_firstFreeTrieNode<0)
throw new OutOfMemoryError("The space of nodes in TupleIndex was exhausted: the ontology is just too large.");
int pageIndex=m_firstFreeTrieNode / TRIE_NODE_PAGE_SIZE;
if (pageIndex>=m_numberOfPages) {
if (pageIndex>=m_indexPages.length) {
int[][] newIndexPages=new int[m_indexPages.length*3/2][];
System.arraycopy(m_indexPages,0,newIndexPages,0,m_indexPages.length);
m_indexPages=newIndexPages;
Object[][] newObjectPages=new Object[m_objectPages.length*3/2][];
System.arraycopy(m_objectPages,0,newObjectPages,0,m_objectPages.length);
m_objectPages=newObjectPages;
}
m_indexPages[pageIndex]=new int[TRIE_NODE_SIZE*TRIE_NODE_PAGE_SIZE];
m_objectPages[pageIndex]=new Object[TRIE_NODE_PAGE_SIZE];
m_numberOfPages++;
}
setTrieNodeComponent(m_firstFreeTrieNode,TRIE_NODE_NEXT_SIBLING,-1);
}
return newTrieNode;
}
public void deleteTrieNode(int trieNode) {
setTrieNodeComponent(trieNode,TRIE_NODE_NEXT_SIBLING,m_firstFreeTrieNode);
setTrieNodeObject(trieNode,null);
m_firstFreeTrieNode=trieNode;
}
}
public static class TupleIndexRetrieval implements Serializable {
private static final long serialVersionUID=3052986474027614595L;
protected final TupleIndex m_tupleIndex;
protected final Object[] m_bindingsBuffer;
protected final int[] m_selectionIndices;
protected final int m_selectionIndicesLength;
protected final int m_indexingSequenceLength;
protected int m_currentTrieNode;
public TupleIndexRetrieval(TupleIndex tupleIndex,Object[] bindingsBuffer,int[] selectionIndices) {
m_tupleIndex=tupleIndex;
m_bindingsBuffer=bindingsBuffer;
m_selectionIndices=selectionIndices;
m_selectionIndicesLength=m_selectionIndices.length;
m_indexingSequenceLength=tupleIndex.m_indexingSequence.length;
}
public void open() {
m_currentTrieNode=m_tupleIndex.m_root;
for (int position=0;position
© 2015 - 2025 Weber Informatics LLC | Privacy Policy