org.semwebcentral.sweetrules.sweetonto
Class SweetDLPCompiler

java.lang.Object
  extended byorg.semwebcentral.sweetrules.sweetonto.SweetDLPCompiler

public class SweetDLPCompiler
extends java.lang.Object


Nested Class Summary
protected  class SweetDLPCompiler.BodyExpanderVisitor
           
protected  class SweetDLPCompiler.HeadExpanderVisitor
           
protected  class SweetDLPCompiler.UnsupportedFeaturesVisitor
           
 
Field Summary
private  Logger logger
           
protected  java.util.Set m_axiomatizeEqualityForPredicates
           
protected  java.util.Set m_axiomatizeNegationForPredicates
           
protected  boolean m_basicEqualityAxiomatized
           
protected  SweetDLPCompiler.BodyExpanderVisitor m_bodyExpanderVisitor
           
protected  MemoryExtensionalDatabase m_extensionalDatabase
           
protected  java.util.Set m_extensionPredicates
           
protected  java.util.List m_finishedRules
           
protected  SweetDLPCompiler.HeadExpanderVisitor m_headExpanderVisitor
           
protected  boolean m_mergeExtensions
           
protected  java.util.List m_notFinishedRules
           
protected  int m_predicateCounter
           
protected  PredicateFactory m_predicateFactory
           
protected  int m_prefixConuter
           
protected  int m_ruleCounter
           
protected  int m_skolemFunctionCounter
           
protected  java.util.Map m_uriToExensionPredicate
           
protected  int m_variableCounter
           
private  boolean sweetDLPCompilerTreatWarningsAsErrors
           
private  boolean variableXUsed
          This flag is true if during the DLP compilation variable X is used.
private  boolean variableYUsed
          This flag is true if during the DLP compilation variable Y is used.
private  boolean variableZUsed
          This flag is true if during the DLP compilation variable Z is used.
protected static Variable X
           
protected static Variable Y
           
protected static Variable Z
           
 
Constructor Summary
SweetDLPCompiler(PredicateFactory predicateFactory, MemoryExtensionalDatabase extensionalDatabase, boolean treatWarningsAsErrors)
          Constructor for the DLP Compiler
 
Method Summary
protected  java.lang.String collapseNamespace(java.lang.String uri)
          !!!
 void compileOntology(OWLOntology ontology, boolean compileIndividuals)
           
private  void expandAllRules()
           
private  void expandOneRule()
           
protected  void generateDataTypeAssertion(java.lang.String dataTypeURI, java.lang.String value)
           
protected  Literal[] getBodyLiterals(Rule rule)
           
 java.lang.String getConceptName(java.lang.String uri)
           
 Predicate getConceptPredicate(boolean isPositive, java.lang.String uri)
           
 java.util.Set getExtensionPredicates()
           
protected  Literal[] getHeadLiterals(Rule rule)
           
protected  java.lang.Object getIndividual(OWLIndividual individual)
           
protected  Constant getIndividualConstant(OWLIndividual individual)
           
 boolean getMergeExtensions()
           
 int getPartialVariableCount()
          This returns the number of variables other than X, Y, Z To get the full count, use the methods isVariable?
protected  MemoryPredicateExtension getPredicateExtension(Predicate predicate)
           
 PredicateFactory getPredicateFactory()
           
 Program getProgram()
           
 java.lang.String getRoleName(java.lang.String uri)
           
 Predicate getRolePredicate(java.lang.String uri)
           
protected  Literal getSubstituteLiteral(OWLDescription description, Literal literal)
           
private  Variable getVariableX()
          A routine which ensures that the counter value is properly initialized whenever variable X is referenced (The assumption is that X is referenced before Y which is referenced before Z)
private  Variable getVariableY()
          A routine which ensures that the counter value is properly initialized whenever variable Y is referenced (The assumption is that X is referenced before Y which is referenced before Z)
private  Variable getVariableZ()
          A routine which ensures that the counter value is properly initialized whenever variable Z is referenced (The assumption is that X is referenced before Y which is referenced before Z)
private  void handleDLPWarning(SweetWarning warning)
          Handles the DLP warning, i.e. logs a message and based on the treat as error flag conditionally throws an exception
private  void initialize(PredicateFactory predicateFactory, MemoryExtensionalDatabase extensionalDatabase, boolean treatWarningsAsErrors)
          Routine to initialize the member variables
 boolean isFinished()
           
 boolean isHorn()
           
 boolean isVariableXused()
          Retreives a flag which indicates whether or not the variable X is used
 boolean isVariableYused()
          Retreives a flag which indicates whether or not the variable X is used
 boolean isVariableZused()
          Retreives a flag which indicates whether or not the variable X is used
protected  java.lang.String newSkolemFunction()
           
protected  Variable newVariable()
           
protected  java.lang.String nextRuleLabel()
           
private  void processClassAxiom(OWLClassAxiom classAxiom)
           
protected  Predicate processEnumeration(OWLEnumeration enumeration)
           
private  void processIndividual(OWLIndividual individual)
          Process an OWL individual
private  void processIndividualMembership(java.lang.String individualURI, OWLDescription memberOfDescription)
           
protected  void processIndividualMembershipMerged(java.lang.String individualURI, OWLDescription memberOfDescription)
           
protected  void processIndividualMembershipNonMerged(java.lang.String individualURI, OWLDescription memberOfDescription)
           
private  void processProperty(OWLProperty owlProperty)
          Process an OWL property
private  void processPropertyAxiom(OWLPropertyAxiom propertyAxiom)
           
 void processPropertyInstance(java.lang.String propertyURI, java.lang.String subjectURI, java.lang.String objectURI, java.lang.String swrlAtomType, java.lang.String objectDataType)
           
protected  void processPropertyInstanceMerged(java.lang.String propertyURI, java.lang.String subjectURI, java.lang.String objectURI, java.lang.String swrlAtomType, java.lang.String objectDataType)
           
protected  void processPropertyInstanceNotMerged(java.lang.String propertyURI, java.lang.String subjectURI, java.lang.String objectURI, java.lang.String swrlAtomType, java.lang.String objectDataType)
           
private  void processSubClass(OWLDescription superClass, OWLDescription subClass)
           
private  void processSubProperty(OWLProperty superProperty, OWLProperty subProperty)
           
 void setMergeExtensions(boolean mergeExtensions)
           
private  void warnBodyUniversalInsource()
          The error for a body universal
private  void warnCardinalityRestrictionInSource()
           
private  void warnDisjointClassAxiom()
          Flags a warning if the unsupported class axiom disjointwith/disjointclass is encountered
private  void warnFunctionalPropertyInSource()
          Flags a warning on encountering functional property in the source
private  void warnHeadExistentialInsource()
          The error for a head existential
private  void warnInvalidEnumerationInSource()
          Flags a warning if an enumeration of cardinality not equal to 1 is encountered
private  void warnInverseFunctionalPropertyInSource()
          Flags a warning on encountering inverse functional property in the source
private  void warnOWLDifferentIndividualsAxiomInSource()
          Flags a warning if a different individual axiom is in the source OWL
private  void warnOWLNotInSource()
          Flags a warning if it encounters negation in the source
private  void warnOWLSameIndividualsAxiomInSource()
          Flags a warning if a same individual axiom is in the source OWL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

X

protected static final Variable X

Y

protected static final Variable Y

Z

protected static final Variable Z

variableXUsed

private boolean variableXUsed
This flag is true if during the DLP compilation variable X is used. This helps in finding the total number of variables used at the end


variableYUsed

private boolean variableYUsed
This flag is true if during the DLP compilation variable Y is used. This helps in finding the total number of variables used at the end


variableZUsed

private boolean variableZUsed
This flag is true if during the DLP compilation variable Z is used. This helps in finding the total number of variables used at the end


m_ruleCounter

protected int m_ruleCounter

m_notFinishedRules

protected java.util.List m_notFinishedRules

m_finishedRules

protected java.util.List m_finishedRules

m_headExpanderVisitor

protected SweetDLPCompiler.HeadExpanderVisitor m_headExpanderVisitor

m_bodyExpanderVisitor

protected SweetDLPCompiler.BodyExpanderVisitor m_bodyExpanderVisitor

m_predicateFactory

protected PredicateFactory m_predicateFactory

m_extensionalDatabase

protected MemoryExtensionalDatabase m_extensionalDatabase

m_uriToExensionPredicate

protected java.util.Map m_uriToExensionPredicate

m_extensionPredicates

protected java.util.Set m_extensionPredicates

m_prefixConuter

protected int m_prefixConuter

m_variableCounter

protected int m_variableCounter

m_skolemFunctionCounter

protected int m_skolemFunctionCounter

m_predicateCounter

protected int m_predicateCounter

m_mergeExtensions

protected boolean m_mergeExtensions

m_axiomatizeEqualityForPredicates

protected java.util.Set m_axiomatizeEqualityForPredicates

m_axiomatizeNegationForPredicates

protected java.util.Set m_axiomatizeNegationForPredicates

m_basicEqualityAxiomatized

protected boolean m_basicEqualityAxiomatized

sweetDLPCompilerTreatWarningsAsErrors

private boolean sweetDLPCompilerTreatWarningsAsErrors

logger

private Logger logger
Constructor Detail

SweetDLPCompiler

public SweetDLPCompiler(PredicateFactory predicateFactory,
                        MemoryExtensionalDatabase extensionalDatabase,
                        boolean treatWarningsAsErrors)
Constructor for the DLP Compiler

Parameters:
predicateFactory - The predicate factory to hold the predicates
extensionalDatabase - The extensional database to hold instance data
treatWarningsAsErrors - This flag indicates that warnings should be treated as errors
Method Detail

initialize

private void initialize(PredicateFactory predicateFactory,
                        MemoryExtensionalDatabase extensionalDatabase,
                        boolean treatWarningsAsErrors)
Routine to initialize the member variables

Parameters:
predicateFactory - The predicate factory to hold the predicates
extensionalDatabase - The extensional database to hold instance data
treatWarningsAsErrors - This flag indicates that warnings should be treated as errors

setMergeExtensions

public void setMergeExtensions(boolean mergeExtensions)

getMergeExtensions

public boolean getMergeExtensions()

getPredicateFactory

public PredicateFactory getPredicateFactory()

getProgram

public Program getProgram()

isHorn

public boolean isHorn()

getExtensionPredicates

public java.util.Set getExtensionPredicates()

isFinished

public boolean isFinished()

expandOneRule

private void expandOneRule()
                    throws OWLException
Throws:
OWLException

expandAllRules

private void expandAllRules()
                     throws OWLException
Throws:
OWLException

compileOntology

public void compileOntology(OWLOntology ontology,
                            boolean compileIndividuals)
                     throws OWLException,
                            SweetDLPCompilerException
Throws:
OWLException
SweetDLPCompilerException

processProperty

private void processProperty(OWLProperty owlProperty)
                      throws OWLException,
                             SweetDLPCompilerException
Process an OWL property

Parameters:
owlProperty - The property to process
Throws:
OWLException - if an error occurs
SweetDLPCompilerException

processClassAxiom

private void processClassAxiom(OWLClassAxiom classAxiom)
                        throws OWLException,
                               SweetDLPCompilerException
Throws:
OWLException
SweetDLPCompilerException

processSubClass

private void processSubClass(OWLDescription superClass,
                             OWLDescription subClass)
                      throws OWLException
Throws:
OWLException

processPropertyAxiom

private void processPropertyAxiom(OWLPropertyAxiom propertyAxiom)
                           throws OWLException,
                                  SweetDLPCompilerException
Throws:
OWLException
SweetDLPCompilerException

processSubProperty

private void processSubProperty(OWLProperty superProperty,
                                OWLProperty subProperty)
                         throws OWLException
Throws:
OWLException

processIndividual

private void processIndividual(OWLIndividual individual)
                        throws OWLException
Process an OWL individual

Parameters:
individual - The individual to process
Throws:
OWLException - if an error occurs

processIndividualMembership

private void processIndividualMembership(java.lang.String individualURI,
                                         OWLDescription memberOfDescription)
                                  throws OWLException
Throws:
OWLException

generateDataTypeAssertion

protected void generateDataTypeAssertion(java.lang.String dataTypeURI,
                                         java.lang.String value)
                                  throws OWLException
Throws:
OWLException

processIndividualMembershipMerged

protected void processIndividualMembershipMerged(java.lang.String individualURI,
                                                 OWLDescription memberOfDescription)
                                          throws OWLException
Throws:
OWLException

processIndividualMembershipNonMerged

protected void processIndividualMembershipNonMerged(java.lang.String individualURI,
                                                    OWLDescription memberOfDescription)
                                             throws OWLException
Throws:
OWLException

processPropertyInstance

public void processPropertyInstance(java.lang.String propertyURI,
                                    java.lang.String subjectURI,
                                    java.lang.String objectURI,
                                    java.lang.String swrlAtomType,
                                    java.lang.String objectDataType)
                             throws OWLException
Throws:
OWLException

processPropertyInstanceMerged

protected void processPropertyInstanceMerged(java.lang.String propertyURI,
                                             java.lang.String subjectURI,
                                             java.lang.String objectURI,
                                             java.lang.String swrlAtomType,
                                             java.lang.String objectDataType)

processPropertyInstanceNotMerged

protected void processPropertyInstanceNotMerged(java.lang.String propertyURI,
                                                java.lang.String subjectURI,
                                                java.lang.String objectURI,
                                                java.lang.String swrlAtomType,
                                                java.lang.String objectDataType)

nextRuleLabel

protected java.lang.String nextRuleLabel()

getHeadLiterals

protected Literal[] getHeadLiterals(Rule rule)

getBodyLiterals

protected Literal[] getBodyLiterals(Rule rule)

getSubstituteLiteral

protected Literal getSubstituteLiteral(OWLDescription description,
                                       Literal literal)
                                throws SweetDLPCompilerException
Throws:
SweetDLPCompilerException

collapseNamespace

protected java.lang.String collapseNamespace(java.lang.String uri)
!!!HACK!!!, collapse namespace does not actually collapse because the code to collapse has been commented out. We don't want the namespace to be collapsed.

Parameters:
uri - URI to be collapsed (BUT IT WON'T BE COLLAPSED)
Returns:
URI **NOT THE COLLAPSED**

getConceptName

public java.lang.String getConceptName(java.lang.String uri)

getRoleName

public java.lang.String getRoleName(java.lang.String uri)

getConceptPredicate

public Predicate getConceptPredicate(boolean isPositive,
                                     java.lang.String uri)

getRolePredicate

public Predicate getRolePredicate(java.lang.String uri)

newVariable

protected Variable newVariable()

newSkolemFunction

protected java.lang.String newSkolemFunction()

getIndividual

protected java.lang.Object getIndividual(OWLIndividual individual)
                                  throws OWLException
Throws:
OWLException

getIndividualConstant

protected Constant getIndividualConstant(OWLIndividual individual)
                                  throws OWLException
Throws:
OWLException

processEnumeration

protected Predicate processEnumeration(OWLEnumeration enumeration)
                                throws OWLException,
                                       SweetDLPCompilerException
Throws:
OWLException
SweetDLPCompilerException

getPredicateExtension

protected MemoryPredicateExtension getPredicateExtension(Predicate predicate)

warnFunctionalPropertyInSource

private void warnFunctionalPropertyInSource()
                                     throws SweetDLPCompilerException
Flags a warning on encountering functional property in the source

Throws:
SweetDLPCompilerException - if warnings should be treated as errors

warnInvalidEnumerationInSource

private void warnInvalidEnumerationInSource()
                                     throws SweetDLPCompilerException
Flags a warning if an enumeration of cardinality not equal to 1 is encountered

Throws:
SweetDLPCompilerException - if warnings should be treated as errors

warnInverseFunctionalPropertyInSource

private void warnInverseFunctionalPropertyInSource()
                                            throws SweetDLPCompilerException
Flags a warning on encountering inverse functional property in the source

Throws:
SweetDLPCompilerException - if warnings should be treated as errors

warnDisjointClassAxiom

private void warnDisjointClassAxiom()
                             throws SweetDLPCompilerException
Flags a warning if the unsupported class axiom disjointwith/disjointclass is encountered

Throws:
SweetDLPCompilerException - if warnings should be treated as errors

warnOWLSameIndividualsAxiomInSource

private void warnOWLSameIndividualsAxiomInSource()
                                          throws SweetDLPCompilerException
Flags a warning if a same individual axiom is in the source OWL

Throws:
SweetDLPCompilerException - if warnings should be treated as errors

warnCardinalityRestrictionInSource

private void warnCardinalityRestrictionInSource()
                                         throws SweetDLPCompilerException
Throws:
SweetDLPCompilerException

warnOWLDifferentIndividualsAxiomInSource

private void warnOWLDifferentIndividualsAxiomInSource()
                                               throws SweetDLPCompilerException
Flags a warning if a different individual axiom is in the source OWL

Throws:
SweetDLPCompilerException - if warnings should be treated as errors

warnOWLNotInSource

private void warnOWLNotInSource()
                         throws SweetDLPCompilerException
Flags a warning if it encounters negation in the source

Throws:
SweetDLPCompilerException - if warnings are to be treated as errors

warnHeadExistentialInsource

private void warnHeadExistentialInsource()
                                  throws SweetDLPCompilerException
The error for a head existential

Throws:
SweetDLPCompilerException - if warnings are to be treated as errors

warnBodyUniversalInsource

private void warnBodyUniversalInsource()
                                throws SweetDLPCompilerException
The error for a body universal

Throws:
SweetDLPCompilerException - if warnings are to be treated as errors

handleDLPWarning

private void handleDLPWarning(SweetWarning warning)
                       throws SweetDLPCompilerException
Handles the DLP warning, i.e. logs a message and based on the treat as error flag conditionally throws an exception

Parameters:
warning - The warning to be handled
Throws:
SweetDLPCompilerException - if warnings are to be treated as errors

getVariableX

private Variable getVariableX()
A routine which ensures that the counter value is properly initialized whenever variable X is referenced (The assumption is that X is referenced before Y which is referenced before Z)

Returns:
The variable X

getVariableY

private Variable getVariableY()
A routine which ensures that the counter value is properly initialized whenever variable Y is referenced (The assumption is that X is referenced before Y which is referenced before Z)

Returns:
The variable Y

getVariableZ

private Variable getVariableZ()
A routine which ensures that the counter value is properly initialized whenever variable Z is referenced (The assumption is that X is referenced before Y which is referenced before Z)

Returns:
The variable Z

isVariableXused

public boolean isVariableXused()
Retreives a flag which indicates whether or not the variable X is used

Returns:
true if variable X is used

isVariableYused

public boolean isVariableYused()
Retreives a flag which indicates whether or not the variable X is used

Returns:
true if variable Y is used

isVariableZused

public boolean isVariableZused()
Retreives a flag which indicates whether or not the variable X is used

Returns:
true if variable Z is used

getPartialVariableCount

public int getPartialVariableCount()
This returns the number of variables other than X, Y, Z To get the full count, use the methods isVariable?used () to check the status of X, Y, Z

Returns:
The partial count (not including X, Y, Z) of variables