protected DLClause clausifyKey(OWLHasKeyAxiom object) {
List<Atom> headAtoms=new ArrayList<Atom>();
List<Atom> bodyAtoms=new ArrayList<Atom>();
// we have two named individuals (corresponding to X1 and X2) that
// might have to be equated
Variable X2=Variable.create("X2");
Variable X1=Variable.create("X1");
headAtoms.add(Atom.create(Equality.INSTANCE,X1,X2));
// keys only work on datatypes and named individuals
bodyAtoms.add(Atom.create(AtomicConcept.INTERNAL_NAMED,X1));
bodyAtoms.add(Atom.create(AtomicConcept.INTERNAL_NAMED,X2));
// the concept expression of a hasKey statement is either a concept
// name or a negated concept name after normalization
OWLClassExpression description=object.getClassExpression();
if (description instanceof OWLClass) {
OWLClass owlClass=(OWLClass)description;
if (!owlClass.isOWLThing()) {
bodyAtoms.add(Atom.create(AtomicConcept.create(owlClass.getIRI().toString()),X1));
bodyAtoms.add(Atom.create(AtomicConcept.create(owlClass.getIRI().toString()),X2));
}
}
else if (description instanceof OWLObjectComplementOf) {
OWLClassExpression internal=((OWLObjectComplementOf)description).getOperand();
if (internal instanceof OWLClass) {
OWLClass owlClass=(OWLClass)internal;
bodyAtoms.add(Atom.create(AtomicConcept.create(owlClass.getIRI().toString()),X1));
bodyAtoms.add(Atom.create(AtomicConcept.create(owlClass.getIRI().toString()),X2));
}
else {
throw new IllegalStateException("Internal error: invalid normal form.");
}
}
else {
throw new IllegalStateException("Internal error: invalid normal form.");
}
int y_ind=1;
// object properties always go to the body
for (OWLObjectPropertyExpression p : object.getObjectPropertyExpressions()) {
Variable y;
y=Variable.create("Y"+y_ind);
y_ind++;
bodyAtoms.add(getRoleAtom(p,X1,y));
bodyAtoms.add(getRoleAtom(p,X2,y));
// also the key criteria are named in case of object properties
bodyAtoms.add(Atom.create(AtomicConcept.INTERNAL_NAMED,y));
}
// data properties go to the body, but with different variables
// the head gets an atom asserting inequality between that data values
for (OWLDataPropertyExpression d : object.getDataPropertyExpressions()) {
Variable y;
y=Variable.create("Y"+y_ind);
y_ind++;
bodyAtoms.add(getRoleAtom(d,X1,y));
Variable y2;
y2=Variable.create("Y"+y_ind);
y_ind++;
bodyAtoms.add(getRoleAtom(d,X2,y2));
headAtoms.add(Atom.create(Inequality.INSTANCE,y,y2));
}