}
}
public ABox(KnowledgeBase kb, ABox abox, ATermAppl extraIndividual, boolean copyIndividuals) {
this.kb = kb;
Timer timer = kb.timers.startTimer( "cloneABox" );
this.rulesNotApplied = true;
initialized = abox.initialized;
setChanged( abox.isChanged() );
setAnonCount( abox.getAnonCount() );
cache = abox.cache;
clash = abox.clash;
dtReasoner = abox.dtReasoner;
doExplanation = abox.doExplanation;
setDisjBranchStats( abox.getDisjBranchStats() );
int extra = (extraIndividual == null)
? 0
: 1;
int nodeCount = extra + (copyIndividuals
? abox.nodes.size()
: 0);
nodes = new HashMap<ATermAppl, Node>( nodeCount );
nodeList = new ArrayList<ATermAppl>( nodeCount );
if( PelletOptions.TRACK_BRANCH_EFFECTS ) {
if( copyIndividuals ) {
branchEffects = abox.branchEffects.copy();
}
else {
branchEffects = new SimpleBranchEffectTracker();
}
}
else {
branchEffects = null;
}
// copy the queue - this must be done early so that the effects of
// adding the extra individual do not get removed
if( PelletOptions.USE_COMPLETION_QUEUE ) {
if( copyIndividuals ) {
completionQueue = abox.completionQueue.copy();
completionQueue.setABox( this );
}
else if( PelletOptions.USE_OPTIMIZED_BASIC_COMPLETION_QUEUE ) {
completionQueue = new OptimizedBasicCompletionQueue( this );
}
else {
completionQueue = new BasicCompletionQueue( this );
}
}
else {
completionQueue = null;
}
if( extraIndividual != null ) {
Individual n = new Individual( extraIndividual, this, null );
n.setNominalLevel( Node.BLOCKABLE );
n.setConceptRoot( true );
n.addType( ATermUtils.TOP, DependencySet.INDEPENDENT );
nodes.put( extraIndividual, n );
nodeList.add( extraIndividual );
if( PelletOptions.COPY_ON_WRITE ) {
sourceABox = abox;
}
}
if( copyIndividuals ) {
toBeMerged = abox.getToBeMerged();
if( sourceABox == null ) {
for( int i = 0; i < nodeCount - extra; i++ ) {
ATermAppl x = abox.nodeList.get( i );
Node node = abox.getNode( x );
Node copy = node.copyTo( this );
nodes.put( x, copy );
nodeList.add( x );
}
for( Node node : nodes.values() ) {
node.updateNodeReferences();
}
}
}
else {
toBeMerged = Collections.emptyList();
sourceABox = null;
initialized = false;
}
// Copy of the incChangeTracker looks up nodes in the new ABox, so this
// copy must follow node copying
if( PelletOptions.USE_INCREMENTAL_CONSISTENCY ) {
if( copyIndividuals ) {
incChangeTracker = abox.incChangeTracker.copy( this );
}
else {
incChangeTracker = new SimpleIncrementalChangeTracker();
}
}
else {
incChangeTracker = null;
}
assertedClashes = new HashSet<Clash>();
for( Clash clash : abox.assertedClashes ) {
assertedClashes.add( clash.copyTo( this ) );
}
if( extraIndividual == null || copyIndividuals ) {
setBranch( abox.branch );
branches = new ArrayList<Branch>( abox.branches.size() );
for( int i = 0, n = abox.branches.size(); i < n; i++ ) {
Branch branch = abox.branches.get( i );
Branch copy;
if( sourceABox == null ) {
copy = branch.copyTo( this );
copy.setNodeCount( branch.getNodeCount() + extra );
}
else {
copy = branch;
}
branches.add( copy );
}
}
else {
setBranch( DependencySet.NO_BRANCH );
branches = new ArrayList<Branch>();
}
timer.stop();
}