Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.semanticweb.HermiT.tableau.DLClauseEvaluator Maven / Gradle / Ivy
Go to download
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.
/* 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;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
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.DLClause;
import org.semanticweb.HermiT.model.DLPredicate;
import org.semanticweb.HermiT.model.NodeIDLessEqualThan;
import org.semanticweb.HermiT.model.NodeIDsAscendingOrEqual;
import org.semanticweb.HermiT.model.Term;
import org.semanticweb.HermiT.model.Variable;
import org.semanticweb.HermiT.monitor.TableauMonitor;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.hash.TIntObjectHashMap;
/**DLClauseEvaluator*/
public class DLClauseEvaluator implements Serializable {
private static final long serialVersionUID=4639844159658590456L;
protected static final String CRLF=System.getProperty("line.separator");
protected final InterruptFlag m_interruptFlag;
protected final ExtensionManager m_extensionManager;
protected final ExtensionTable.Retrieval[] m_retrievals;
protected final Worker[] m_workers;
protected final DLClause m_bodyDLClause;
protected final List m_headDLClauses;
/**
* @param tableau tableau
* @param bodyDLClause bodyDLClause
* @param headDLClauses headDLClauses
* @param firstAtomRetrieval firstAtomRetrieval
* @param bufferSupply bufferSupply
* @param valuesBufferManager valuesBufferManager
* @param groundDisjunctionHeaderManager groundDisjunctionHeaderManager
* @param unionDependencySetsBySize unionDependencySetsBySize
*/
public DLClauseEvaluator(Tableau tableau,DLClause bodyDLClause,List headDLClauses,ExtensionTable.Retrieval firstAtomRetrieval,BufferSupply bufferSupply,ValuesBufferManager valuesBufferManager,GroundDisjunctionHeaderManager groundDisjunctionHeaderManager,Map unionDependencySetsBySize) {
m_interruptFlag=tableau.m_interruptFlag;
m_extensionManager=tableau.m_extensionManager;
DLClauseCompiler compiler=new DLClauseCompiler(bufferSupply,valuesBufferManager,groundDisjunctionHeaderManager,unionDependencySetsBySize,this,m_extensionManager,tableau.getExistentialsExpansionStrategy(),bodyDLClause,headDLClauses,firstAtomRetrieval);
m_retrievals=new ExtensionTable.Retrieval[compiler.m_retrievals.size()];
compiler.m_retrievals.toArray(m_retrievals);
m_workers=new Worker[compiler.m_workers.size()];
compiler.m_workers.toArray(m_workers);
m_bodyDLClause=bodyDLClause;
m_headDLClauses=headDLClauses;
}
/**
* @return body length
*/
public int getBodyLength() {
return m_bodyDLClause.getBodyLength();
}
/**
* @param atomIndex atomIndex
* @return body atom
*/
public Atom getBodyAtom(int atomIndex) {
return m_bodyDLClause.getBodyAtom(atomIndex);
}
/**
* @return number of clauses
*/
public int getNumberOfDLClauses() {
return m_headDLClauses.size();
}
/**
* @param dlClauseIndex dlClauseIndex
* @return dl clause
*/
public DLClause getDLClause(int dlClauseIndex) {
return m_headDLClauses.get(dlClauseIndex);
}
/**
* @param dlClauseIndex dlClauseIndex
* @return head length
*/
public int getHeadLength(int dlClauseIndex) {
return m_headDLClauses.get(dlClauseIndex).getHeadLength();
}
/**
* @param dlClauseIndex dlClauseIndex
* @param atomIndex atomIndex
* @return head atom
*/
public Atom getHeadAtom(int dlClauseIndex,int atomIndex) {
return m_headDLClauses.get(dlClauseIndex).getHeadAtom(atomIndex);
}
/**
* @param atomIndex atomIndex
* @return tuple matched to body
*/
public Object[] getTupleMatchedToBody(int atomIndex) {
return m_retrievals[atomIndex].getTupleBuffer();
}
/**
* Evaluate.
*/
public void evaluate() {
int programCounter=0;
while (programCounter0;--count)
buffer.append(' ');
buffer.append(programCounterString);
buffer.append(": ");
buffer.append(m_workers[programCounter].toString());
buffer.append(CRLF);
}
return buffer.toString();
}
/**BufferSupply.*/
public static class BufferSupply {
protected final List m_allBuffers=new ArrayList<>();
protected final TIntObjectHashMap> m_availableBuffersByArity=new TIntObjectHashMap<>();
void reuseBuffers() {
m_availableBuffersByArity.clear();
for (Object[] buffer : m_allBuffers) {
List buffers=m_availableBuffersByArity.get(buffer.length);
if (buffers==null) {
buffers=new ArrayList<>();
m_availableBuffersByArity.put(buffer.length,buffers);
}
buffers.add(buffer);
}
}
Object[] getBuffer(int arity) {
Object[] buffer;
List buffers=m_availableBuffersByArity.get(arity);
if (buffers==null || buffers.isEmpty()) {
buffer=new Object[arity];
m_allBuffers.add(buffer);
}
else
buffer=buffers.remove(buffers.size()-1);
return buffer;
}
Object[][] getAllBuffers() {
Object[][] result=new Object[m_allBuffers.size()][];
m_allBuffers.toArray(result);
return result;
}
}
/**ValuesBufferManager.*/
public static class ValuesBufferManager {
/**Values buffer.*/
public final Object[] m_valuesBuffer;
final Map m_bodyDLPredicatesToIndexes;
/**Max number of variables*/
public final int m_maxNumberOfVariables;
final Map m_bodyNonvariableTermsToIndexes;
/**
* @param dlClauses dlClauses
* @param termsToNodes termsToNodes
*/
public ValuesBufferManager(Collection dlClauses,Map termsToNodes) {
Set bodyDLPredicates=new HashSet<>();
m_bodyNonvariableTermsToIndexes=new HashMap<>();
int maxNumberOfVariables=0;
for (DLClause dlClause : dlClauses) {
Set variables=Collections.newSetFromMap(new IdentityHashMap<>());
for (int bodyIndex=dlClause.getBodyLength()-1;bodyIndex>=0;--bodyIndex) {
Atom atom=dlClause.getBodyAtom(bodyIndex);
bodyDLPredicates.add(atom.getDLPredicate());
for (int argumentIndex=0;argumentIndexmaxNumberOfVariables)
maxNumberOfVariables=variables.size();
}
m_valuesBuffer=new Object[maxNumberOfVariables+bodyDLPredicates.size()+m_bodyNonvariableTermsToIndexes.size()];
m_bodyDLPredicatesToIndexes=new HashMap<>();
int bindingIndex=maxNumberOfVariables;
for (DLPredicate bodyDLPredicate : bodyDLPredicates) {
m_bodyDLPredicatesToIndexes.put(bodyDLPredicate,Integer.valueOf(bindingIndex));
m_valuesBuffer[bindingIndex]=bodyDLPredicate;
bindingIndex++;
}
for (Map.Entry entry : m_bodyNonvariableTermsToIndexes.entrySet()) {
Node termNode=termsToNodes.get(entry.getKey());
if (termNode==null)
throw new IllegalArgumentException("Term '"+entry.getValue()+"' is unknown to the reasoner.");
entry.setValue(Integer.valueOf(bindingIndex));
m_valuesBuffer[bindingIndex]=termNode.getCanonicalNode();
bindingIndex++;
}
m_maxNumberOfVariables=maxNumberOfVariables;
}
}
static class GroundDisjunctionHeaderManager {
protected GroundDisjunctionHeader[] m_buckets;
protected int m_numberOfElements;
protected int m_threshold;
public GroundDisjunctionHeaderManager() {
m_buckets=new GroundDisjunctionHeader[1024];
m_threshold=(int)(m_buckets.length*0.75);
m_numberOfElements=0;
}
public GroundDisjunctionHeader get(DLPredicate[] dlPredicates) {
int hashCode=0;
for (int disjunctIndex=0;disjunctIndex=m_threshold)
resize(m_buckets.length*2);
return entry;
}
protected void resize(int newCapacity) {
GroundDisjunctionHeader[] newBuckets=new GroundDisjunctionHeader[newCapacity];
for (int i=0;i>> 14);
hashCode+=(hashCode << 4);
hashCode^=(hashCode >>> 10);
return hashCode & (tableLength-1);
}
}
/**Worker.*/
public interface Worker {
/**
* @param programCounter programCounter
* @return counter
*/
int execute(int programCounter);
}
protected interface BranchingWorker extends Worker {
int getBranchingAddress();
void setBranchingAddress(int branchingAddress);
}
protected static final class CopyValues implements Worker,Serializable {
private static final long serialVersionUID=-4323769483485648756L;
protected final Object[] m_fromBuffer;
protected final int m_fromIndex;
protected final Object[] m_toBuffer;
protected final int m_toIndex;
public CopyValues(Object[] fromBuffer,int fromIndex,Object[] toBuffer,int toIndex) {
m_fromBuffer=fromBuffer;
m_fromIndex=fromIndex;
m_toBuffer=toBuffer;
m_toIndex=toIndex;
}
@Override
public int execute(int programCounter) {
m_toBuffer[m_toIndex]=m_fromBuffer[m_fromIndex];
return programCounter+1;
}
@Override
public String toString() {
return "Copy "+m_fromIndex+" --> "+m_toIndex;
}
}
protected static final class CopyDependencySet implements Worker,Serializable {
private static final long serialVersionUID=705172386083123813L;
protected final ExtensionTable.Retrieval m_retrieval;
protected final DependencySet[] m_targetDependencySets;
protected final int m_targetIndex;
public CopyDependencySet(ExtensionTable.Retrieval retrieval,DependencySet[] targetDependencySets,int targetIndex) {
m_retrieval=retrieval;
m_targetDependencySets=targetDependencySets;
m_targetIndex=targetIndex;
}
@Override
public int execute(int programCounter) {
m_targetDependencySets[m_targetIndex]=m_retrieval.getDependencySet();
return programCounter+1;
}
@Override
public String toString() {
return "Copy dependency set to "+m_targetIndex;
}
}
protected static final class BranchIfNotEqual implements BranchingWorker,Serializable {
private static final long serialVersionUID=-1880147431680856293L;
protected int m_notEqualProgramCounter;
protected final Object[] m_buffer;
protected final int m_index1;
protected final int m_index2;
public BranchIfNotEqual(int notEqualProgramCounter,Object[] buffer,int index1,int index2) {
m_notEqualProgramCounter=notEqualProgramCounter;
m_buffer=buffer;
m_index1=index1;
m_index2=index2;
}
@Override
public int execute(int programCounter) {
if (m_buffer[m_index1].equals(m_buffer[m_index2]))
return programCounter+1;
else
return m_notEqualProgramCounter;
}
@Override
public int getBranchingAddress() {
return m_notEqualProgramCounter;
}
@Override
public void setBranchingAddress(int branchingAddress) {
m_notEqualProgramCounter=branchingAddress;
}
@Override
public String toString() {
return "Branch to "+m_notEqualProgramCounter+" if "+m_index1+" != "+m_index2;
}
}
protected static final class BranchIfNotNodeIDLessEqualThan implements BranchingWorker,Serializable {
private static final long serialVersionUID=2484359261424674914L;
protected int m_notLessProgramCounter;
protected final Object[] m_buffer;
protected final int m_index1;
protected final int m_index2;
public BranchIfNotNodeIDLessEqualThan(int notLessProgramCounter,Object[] buffer,int index1,int index2) {
m_notLessProgramCounter=notLessProgramCounter;
m_buffer=buffer;
m_index1=index1;
m_index2=index2;
}
@Override
public int execute(int programCounter) {
if (((Node)m_buffer[m_index1]).getNodeID()<=((Node)m_buffer[m_index2]).getNodeID())
return programCounter+1;
else
return m_notLessProgramCounter;
}
@Override
public int getBranchingAddress() {
return m_notLessProgramCounter;
}
@Override
public void setBranchingAddress(int branchingAddress) {
m_notLessProgramCounter=branchingAddress;
}
@Override
public String toString() {
return "Branch to "+m_notLessProgramCounter+" if "+m_index1+".ID > "+m_index2+".ID";
}
}
protected static final class BranchIfNotNodeIDsAscendingOrEqual implements BranchingWorker,Serializable {
private static final long serialVersionUID=8053779312249250349L;
protected int m_branchProgramCounter;
protected final Object[] m_buffer;
protected final int[] m_nodeIndexes;
public BranchIfNotNodeIDsAscendingOrEqual(int branchProgramCounter,Object[] buffer,int[] nodeIndexes) {
m_branchProgramCounter=branchProgramCounter;
m_buffer=buffer;
m_nodeIndexes=nodeIndexes;
}
@Override
public int execute(int programCounter) {
boolean strictlyAscending=true;
boolean allEqual=true;
int lastNodeID=((Node)m_buffer[m_nodeIndexes[0]]).getNodeID();
for (int index=1;index=nodeID)
strictlyAscending=false;
if (nodeID!=lastNodeID)
allEqual=false;
lastNodeID=nodeID;
}
if ((!strictlyAscending && allEqual) || (strictlyAscending && !allEqual))
return programCounter+1;
else
return m_branchProgramCounter;
}
@Override
public int getBranchingAddress() {
return m_branchProgramCounter;
}
@Override
public void setBranchingAddress(int branchingAddress) {
m_branchProgramCounter=branchingAddress;
}
@Override
public String toString() {
return "Branch to "+m_branchProgramCounter+" if node IDs are not ascending or equal";
}
}
protected static final class OpenRetrieval implements Worker,Serializable {
private static final long serialVersionUID=8246610603084803950L;
protected final ExtensionTable.Retrieval m_retrieval;
public OpenRetrieval(ExtensionTable.Retrieval retrieval) {
m_retrieval=retrieval;
}
@Override
public int execute(int programCounter) {
m_retrieval.open();
return programCounter+1;
}
@Override
public String toString() {
return "Open "+m_retrieval.getBindingsBuffer()[m_retrieval.getBindingPositions()[0]];
}
}
protected static final class NextRetrieval implements Worker,Serializable {
private static final long serialVersionUID=-2787897558147109082L;
protected final ExtensionTable.Retrieval m_retrieval;
public NextRetrieval(ExtensionTable.Retrieval retrieval) {
m_retrieval=retrieval;
}
@Override
public int execute(int programCounter) {
m_retrieval.next();
return programCounter+1;
}
@Override
public String toString() {
return "Next "+m_retrieval.getBindingsBuffer()[m_retrieval.getBindingPositions()[0]];
}
}
protected static final class HasMoreRetrieval implements BranchingWorker,Serializable {
private static final long serialVersionUID=-2415094151423166585L;
protected int m_eofProgramCounter;
protected final ExtensionTable.Retrieval m_retrieval;
public HasMoreRetrieval(int eofProgramCounter,ExtensionTable.Retrieval retrieval) {
m_eofProgramCounter=eofProgramCounter;
m_retrieval=retrieval;
}
@Override
public int execute(int programCounter) {
if (m_retrieval.afterLast())
return m_eofProgramCounter;
else
return programCounter+1;
}
@Override
public int getBranchingAddress() {
return m_eofProgramCounter;
}
@Override
public void setBranchingAddress(int branchingAddress) {
m_eofProgramCounter=branchingAddress;
}
@Override
public String toString() {
return "Branch to "+m_eofProgramCounter+" if "+m_retrieval.getBindingsBuffer()[m_retrieval.getBindingPositions()[0]]+" is empty";
}
}
protected static final class JumpTo implements BranchingWorker,Serializable {
private static final long serialVersionUID=-6957866973028474739L;
protected int m_jumpTo;
public JumpTo(int jumpTo) {
m_jumpTo=jumpTo;
}
@Override
public int execute(int programCounter) {
return m_jumpTo;
}
@Override
public int getBranchingAddress() {
return m_jumpTo;
}
@Override
public void setBranchingAddress(int branchingAddress) {
m_jumpTo=branchingAddress;
}
@Override
public String toString() {
return "Jump to "+m_jumpTo;
}
}
protected static final class CallMatchStartedOnMonitor implements Worker,Serializable {
private static final long serialVersionUID=8736659573939242252L;
protected final TableauMonitor m_tableauMonitor;
protected final DLClauseEvaluator m_dlClauseEvaluator;
protected final int m_dlClauseIndex;
public CallMatchStartedOnMonitor(TableauMonitor tableauMonitor,DLClauseEvaluator dlClauseEvaluator,int dlClauseIndex) {
m_tableauMonitor=tableauMonitor;
m_dlClauseEvaluator=dlClauseEvaluator;
m_dlClauseIndex=dlClauseIndex;
}
@Override
public int execute(int programCounter) {
m_tableauMonitor.dlClauseMatchedStarted(m_dlClauseEvaluator,m_dlClauseIndex);
return programCounter+1;
}
@Override
public String toString() {
return "Monitor -> Match started";
}
}
protected static final class CallMatchFinishedOnMonitor implements Worker,Serializable {
private static final long serialVersionUID=1046400921858176361L;
protected final TableauMonitor m_tableauMonitor;
protected final DLClauseEvaluator m_dlClauseEvaluator;
protected final int m_dlClauseIndex;
public CallMatchFinishedOnMonitor(TableauMonitor tableauMonitor,DLClauseEvaluator dlClauseEvaluator,int dlClauseIndex) {
m_tableauMonitor=tableauMonitor;
m_dlClauseEvaluator=dlClauseEvaluator;
m_dlClauseIndex=dlClauseIndex;
}
@Override
public int execute(int programCounter) {
m_tableauMonitor.dlClauseMatchedFinished(m_dlClauseEvaluator,m_dlClauseIndex);
return programCounter+1;
}
@Override
public String toString() {
return "Monitor -> Match finished";
}
}
protected static final class SetClash implements Worker,Serializable {
private static final long serialVersionUID=-4981087765064918953L;
protected final ExtensionManager m_extensionManager;
protected final DependencySet m_dependencySet;
public SetClash(ExtensionManager extensionManager,DependencySet dependencySet) {
m_extensionManager=extensionManager;
m_dependencySet=dependencySet;
}
@Override
public int execute(int programCounter) {
m_extensionManager.setClash(m_dependencySet);
return programCounter+1;
}
@Override
public String toString() {
return "Set clash";
}
}
protected static final class DeriveUnaryFact implements Worker,Serializable {
private static final long serialVersionUID=7883620022252842010L;
protected final ExtensionManager m_extensionManager;
protected final Object[] m_valuesBuffer;
protected final boolean[] m_coreVariables;
protected final DependencySet m_dependencySet;
protected final DLPredicate m_dlPredicate;
protected final int m_argumentIndex;
public DeriveUnaryFact(ExtensionManager extensionManager,Object[] valuesBuffer,boolean[] coreVariables,DependencySet dependencySet,DLPredicate dlPredicate,int argumentIndex) {
m_extensionManager=extensionManager;
m_valuesBuffer=valuesBuffer;
m_coreVariables=coreVariables;
m_dependencySet=dependencySet;
m_argumentIndex=argumentIndex;
m_dlPredicate=dlPredicate;
}
@Override
public int execute(int programCounter) {
Node argument=(Node)m_valuesBuffer[m_argumentIndex];
boolean isCore=m_coreVariables[m_argumentIndex];
m_extensionManager.addAssertion(m_dlPredicate,argument,m_dependencySet,isCore);
return programCounter+1;
}
@Override
public String toString() {
return "Derive unary fact";
}
}
protected static final class DeriveBinaryFact implements Worker,Serializable {
private static final long serialVersionUID=1823363493615682288L;
protected final ExtensionManager m_extensionManager;
protected final Object[] m_valuesBuffer;
protected final DependencySet m_dependencySet;
protected final DLPredicate m_dlPredicate;
protected final int m_argumentIndex1;
protected final int m_argumentIndex2;
public DeriveBinaryFact(ExtensionManager extensionManager,Object[] valuesBuffer,DependencySet dependencySet,DLPredicate dlPredicate,int argumentIndex1,int argumentIndex2) {
m_extensionManager=extensionManager;
m_valuesBuffer=valuesBuffer;
m_dependencySet=dependencySet;
m_dlPredicate=dlPredicate;
m_argumentIndex1=argumentIndex1;
m_argumentIndex2=argumentIndex2;
}
@Override
public int execute(int programCounter) {
Node argument1=(Node)m_valuesBuffer[m_argumentIndex1];
Node argument2=(Node)m_valuesBuffer[m_argumentIndex2];
m_extensionManager.addAssertion(m_dlPredicate,argument1,argument2,m_dependencySet,true);
return programCounter+1;
}
@Override
public String toString() {
return "Derive binary fact";
}
}
protected static final class DeriveTernaryFact implements Worker,Serializable {
private static final long serialVersionUID=1823363493615682288L;
protected final ExtensionManager m_extensionManager;
protected final Object[] m_valuesBuffer;
protected final DependencySet m_dependencySet;
protected final DLPredicate m_dlPredicate;
protected final int m_argumentIndex1;
protected final int m_argumentIndex2;
protected final int m_argumentIndex3;
public DeriveTernaryFact(ExtensionManager extensionManager,Object[] valuesBuffer,DependencySet dependencySet,DLPredicate dlPredicate,int argumentIndex1,int argumentIndex2,int argumentIndex3) {
m_extensionManager=extensionManager;
m_valuesBuffer=valuesBuffer;
m_dependencySet=dependencySet;
m_dlPredicate=dlPredicate;
m_argumentIndex1=argumentIndex1;
m_argumentIndex2=argumentIndex2;
m_argumentIndex3=argumentIndex3;
}
@Override
public int execute(int programCounter) {
Node argument1=(Node)m_valuesBuffer[m_argumentIndex1];
Node argument2=(Node)m_valuesBuffer[m_argumentIndex2];
Node argument3=(Node)m_valuesBuffer[m_argumentIndex3];
m_extensionManager.addAssertion(m_dlPredicate,argument1,argument2,argument3,m_dependencySet,true);
return programCounter+1;
}
@Override
public String toString() {
return "Derive ternary fact";
}
}
protected static final class DeriveDisjunction implements Worker,Serializable {
private static final long serialVersionUID=-3546622575743138887L;
protected final Tableau m_tableau;
protected final Object[] m_valuesBuffer;
protected final boolean[] m_coreVariables;
protected final DependencySet m_dependencySet;
protected final GroundDisjunctionHeader m_groundDisjunctionHeader;
protected final int[] m_copyIsCore;
protected final int[] m_copyValuesToArguments;
public DeriveDisjunction(Object[] valuesBuffer,boolean[] coreVariables,DependencySet dependencySet,Tableau tableau,GroundDisjunctionHeader groundDisjunctionHeader,int[] copyIsCore,int[] copyValuesToArguments) {
m_valuesBuffer=valuesBuffer;
m_coreVariables=coreVariables;
m_dependencySet=dependencySet;
m_tableau=tableau;
m_groundDisjunctionHeader=groundDisjunctionHeader;
m_copyIsCore=copyIsCore;
m_copyValuesToArguments=copyValuesToArguments;
}
@Override
public int execute(int programCounter) {
Node[] arguments=new Node[m_copyValuesToArguments.length];
for (int argumentIndex=m_copyValuesToArguments.length-1;argumentIndex>=0;--argumentIndex)
arguments[argumentIndex]=(Node)m_valuesBuffer[m_copyValuesToArguments[argumentIndex]];
boolean[] isCore=new boolean[m_copyIsCore.length];
for (int copyIndex=m_copyIsCore.length-1;copyIndex>=0;--copyIndex) {
int copyFrom=m_copyIsCore[copyIndex];
if (copyFrom==-1)
isCore[copyIndex]=true;
else
isCore[copyIndex]=m_coreVariables[copyFrom];
}
GroundDisjunction groundDisjunction=new GroundDisjunction(m_tableau,m_groundDisjunctionHeader,arguments,isCore,m_tableau.m_dependencySetFactory.getPermanent(m_dependencySet));
if (!groundDisjunction.isSatisfied(m_tableau))
m_tableau.addGroundDisjunction(groundDisjunction);
return programCounter+1;
}
@Override
public String toString() {
return "Derive disjunction";
}
}
protected static final class DLClauseCompiler extends ConjunctionCompiler {
protected final DLClauseEvaluator m_dlClauseEvalautor;
protected final GroundDisjunctionHeaderManager m_groundDisjunctionHeaderManager;
protected final ExistentialExpansionStrategy m_existentialExpansionStrategy;
protected final DLClause m_bodyDLClause;
protected final List m_headDLClauses;
protected final boolean[] m_coreVariables;
public DLClauseCompiler(BufferSupply bufferSupply,ValuesBufferManager valuesBufferManager,GroundDisjunctionHeaderManager groundDisjunctionHeaderManager,Map unionDependencySetsBySize,DLClauseEvaluator dlClauseEvalautor,ExtensionManager extensionManager,ExistentialExpansionStrategy existentialExpansionStrategy,DLClause bodyDLClause,List headDLClauses,ExtensionTable.Retrieval firstAtomRetrieval) {
super(bufferSupply,valuesBufferManager,unionDependencySetsBySize,extensionManager,bodyDLClause.getBodyAtoms(),getHeadVariables(headDLClauses));
m_groundDisjunctionHeaderManager=groundDisjunctionHeaderManager;
m_dlClauseEvalautor=dlClauseEvalautor;
m_existentialExpansionStrategy=existentialExpansionStrategy;
m_bodyDLClause=bodyDLClause;
m_headDLClauses=headDLClauses;
m_coreVariables=new boolean[m_variables.size()];
generateCode(1,firstAtomRetrieval);
}
protected int getNumberOfHeads() {
return m_headDLClauses.size();
}
protected int getHeadLength(int dlClauseIndex) {
return m_headDLClauses.get(dlClauseIndex).getHeadLength();
}
protected Atom getHeadAtom(int dlClauseIndex,int atomIndex) {
return m_headDLClauses.get(dlClauseIndex).getHeadAtom(atomIndex);
}
@Override
protected void compileHeads() {
m_existentialExpansionStrategy.dlClauseBodyCompiled(m_workers,m_bodyDLClause,m_variables,m_valuesBufferManager.m_valuesBuffer,m_coreVariables);
for (int dlClauseIndex=0;dlClauseIndex getHeadVariables(List headDLClauses) {
List result=new ArrayList<>();
for (DLClause dlClause : headDLClauses) {
for (int headIndex=0;headIndex m_variables;
protected final Set m_boundSoFar;
protected final UnionDependencySet m_unionDependencySet;
protected final List m_retrievals;
/**Workers.*/
public final List m_workers;
protected final TIntArrayList m_labels;
/**
* @param bufferSupply bufferSupply
* @param valuesBufferManager valuesBufferManager
* @param unionDependencySetsBySize unionDependencySetsBySize
* @param extensionManager extensionManager
* @param bodyAtoms bodyAtoms
* @param headVariables headVariables
*/
public ConjunctionCompiler(BufferSupply bufferSupply,ValuesBufferManager valuesBufferManager,Map unionDependencySetsBySize,ExtensionManager extensionManager,Atom[] bodyAtoms,List headVariables) {
m_bufferSupply=bufferSupply;
m_valuesBufferManager=valuesBufferManager;
m_extensionManager=extensionManager;
m_bodyAtoms=bodyAtoms;
m_variables=new ArrayList<>();
m_boundSoFar=Collections.newSetFromMap(new IdentityHashMap<>());
int numberOfRealAtoms=0;
for (int bodyIndex=0;bodyIndex();
m_workers=new ArrayList<>();
m_labels=new TIntArrayList();
}
protected final void generateCode(int firstBodyAtomToCompile,ExtensionTable.Retrieval firstAtomRetrieval) {
m_labels.add(0);
m_retrievals.add(firstAtomRetrieval);
int afterRule=addLabel();
if (firstBodyAtomToCompile>0) {
compileCheckUnboundVariableMatches(getBodyAtom(0),firstAtomRetrieval,afterRule);
compileGenerateBindings(firstAtomRetrieval,getBodyAtom(0));
if (m_unionDependencySet!=null)
m_workers.add(new CopyDependencySet(firstAtomRetrieval,m_unionDependencySet.m_dependencySets,0));
}
compileBodyAtom(firstBodyAtomToCompile,afterRule);
setLabelProgramCounter(afterRule);
for (Worker worker : m_workers)
if (worker instanceof BranchingWorker) {
BranchingWorker branchingWorker=(BranchingWorker)worker;
int branchingAddress=branchingWorker.getBranchingAddress();
if (branchingAddress<0) {
int resolvedAddress=m_labels.get(-branchingAddress);
branchingWorker.setBranchingAddress(resolvedAddress);
}
}
}
protected final boolean occursInBodyAtomsAfter(Variable variable,int startIndex) {
for (int argumentIndex=startIndex;argumentIndex
// nextElement: retrieval.next
// goto loopStart
// afterLoop:
//
// NodeIDLessEqualThan and NodeIDsAscendingOrEqual atoms are compiled such that they
// immediately jump to the next element of the previous regular atom.
int afterLoop=addLabel();
int nextElement=addLabel();
Atom atom=getBodyAtom(bodyAtomIndex);
int[] bindingPositions=new int[atom.getArity()+1];
bindingPositions[0]=m_valuesBufferManager.m_bodyDLPredicatesToIndexes.get(atom.getDLPredicate()).intValue();
for (int argumentIndex=0;argumentIndex