📄 axiom.java
字号:
package toocom.ocgl;
import java.util.*;
/**
* This class represents the axioms in the ontology. An axiom contains concepts and relations
* which can be in the hypothesis part of the axiom or in the conclusion part. An axiom can be
* an hard or a soft axiom (by default an axiom is soft). An axiom also has a context of use
* which specify the way it is used in the inference engine. A finalized axiom can not be
* modified by the user, except its context of use (for instance, the axioms which express
* algebraic properties of the relation types are finalized).
*
* @author Fr閐閞ic F黵st
*/
public class Axiom extends ConceptualImplication{
private boolean hard;
private ContextOfUse cou;
private boolean finalized;
private String note;
public Axiom(Terms terms){
super(terms);
this.hard = false;
this.finalized = false;
this.cou = new ContextOfUse(true,true);
}
public Axiom(){
super(Terms.getUndefinedTerms());
this.hard = false;
this.finalized = false;
this.cou = new ContextOfUse(true,true);
}
public void setHard(boolean hard){
this.hard = hard;
}
public boolean isHard(){
return this.hard;
}
public void setFinalized(boolean b){
this.finalized = b;
}
public boolean isFinalized(){
return this.finalized;
}
public void setContextOfUse(ContextOfUse cou){
this.cou = cou;
}
public ContextOfUse getContextOfUse(){
return this.cou;
}
public void setNote(String note){
this.note = note;
}
public String getNote(){
return this.note;
}
public void destroy(Ontology onto){
onto.removeAxiom(this);
}
/** Returns the rule corresponding to the axiom. */
public Rule getCorrespondingRule(Language l){
Rule result = new Rule(this.getTerms());
result.hypothesisConcepts = (LinkedList) this.hypothesisConcepts.clone();
result.hypothesisRelations = (LinkedList) this.hypothesisRelations.clone();
result.conclusionConcepts = (LinkedList) this.conclusionConcepts.clone();
result.conclusionRelations = (LinkedList) this.conclusionRelations.clone();
return result;
}
/** Returns a clone of the Axiom as ConceptualImplication with the given relation of the
* conclusion part set by the given relation type. */
private ConceptualImplication cloneConceptualImplication(Relation rel,RelationType rt){
ConceptualImplication result = new ConceptualImplication(this.getTerms());
Hashtable conLinks = new Hashtable();
Hashtable conRel = new Hashtable();
for(Iterator i = this.getHypothesisConcepts().iterator();i.hasNext();){
Concept c = (Concept) i.next();
Concept cBis = c.cloneConcept();
result.addHypothesisConcept(cBis);
conLinks.put(c,cBis);
}
for(Iterator i = this.getPureConclusionConcepts().iterator();i.hasNext();){
Concept c = (Concept) i.next();
Concept cBis = c.cloneConcept();
result.addConclusionConcept(cBis);
conLinks.put(c,cBis);
}
for(Iterator i = this.getHypothesisRelations().iterator();i.hasNext();){
Relation r = (Relation) i.next();
Relation rBis = r.cloneRelation();
result.addHypothesisRelation(rBis);
for(int index = 1;index <= rBis.getType().getArity();index ++){
Concept cTemp = r.getLinkedConcept(index);
if(cTemp != null){
rBis.setLinkedConcept((Concept) conLinks.get(cTemp),index);
}
}
}
for(Iterator i = this.getConclusionRelations().iterator();i.hasNext();){
Relation r = (Relation) i.next();
Relation rBis = r.cloneRelation();
if(r.equals(rel)) rBis.setType(rt);
result.addConclusionRelation(rBis);
for(int index = 1;index <= rBis.getType().getArity();index ++){
Concept cTemp = r.getLinkedConcept(index);
if(cTemp != null){
rBis.setLinkedConcept((Concept) conLinks.get(cTemp),index);
}
}
}
return result;
}
/** Returns the list of constraints induced by the axiom, as graphs that can be present in
* a valid fact base. The graphs are not included in the ontology. The name of the graphs
* are (name_of_the_axiom)_CONSTRAINT_LABEL(number_of_the_constraint). */
public LinkedList getInducedConstraints(Language l){
LinkedList result = new LinkedList();
if(!this.isHard() && (this.getPureConclusionConcepts().size() == 0)){
int cpt = 1;
for(Iterator it = this.getConclusionRelations().iterator();it.hasNext();){
Relation rel = (Relation) it.next();
RelationExclusivity excluAxiom = (RelationExclusivity) rel.getType().getAxiomSchemata("toocom.ocgl.RelationExclusivity").getFirst();
if(excluAxiom != null){
RelationType exclu = (RelationType) excluAxiom.getTheOtherPrimitive(rel.getType());
if(exclu != null){
NegativeConstraint nc = new NegativeConstraint(this.cloneConceptualImplication(rel,exclu));
nc.setTerms(this.getTerms().appendAndCopy(CGConstants.getNegativeConstraintTerms()," - " + cpt + " "));
result.add(nc);
cpt ++;
}
}
for(Iterator itBis = rel.getType().getAxiomSchemata("RelationIncompatibility").iterator();itBis.hasNext();){
RelationIncompatibility incompAxiom = (RelationIncompatibility) itBis.next();
RelationType incomp = (RelationType) incompAxiom.getTheOtherPrimitive(rel.getType());
NegativeConstraint nc = new NegativeConstraint(this.cloneConceptualImplication(rel,incomp));
nc.setTerms(this.getTerms().appendAndCopy(CGConstants.getNegativeConstraintTerms()," - " + cpt + " "));
result.add(nc);
cpt ++;
}
}
}
if(this.isHard()){
PositiveConstraint pc = new PositiveConstraint(this.cloneConceptualImplication());
pc.setTerms(this.getTerms().appendAndCopy(CGConstants.getPositiveConstraintTerms()," - 1 "));
result.add(pc);
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -