📄 relationexclusivity.java
字号:
package toocom.ocgl;
import java.util.*;
import java.awt.Graphics;
/**
* This class represents the exclusivity between two relations, that concepts can not
* be linked by the two relations and that one the relation can always link the concepts.
*
* @author Fr閐閞ic F黵st
*/
public class RelationExclusivity extends AxiomSchemaTwo{
public RelationExclusivity(RelationType r1,RelationType r2){
super(CGConstants.getRelationExclusivityTerms(),r1,r2);
}
public void paint(Graphics g,Language l){
GraphicsToolkit.drawLinkedCrossCircle(g,super.cp1.x,super.cp1.y,super.cp2.x,super.cp2.y,CGConstants.EXCLUSIVITY_COLOR,super.cp1.getBounds(g,l),super.cp2.getBounds(g,l));
}
/** Two primitives can be exclusive if they are relations, if they are not in
* isA relation, and if they are not exclusive with a third primitive. */
public boolean isValid(){
return (super.cp1 instanceof RelationType) &&
(super.cp2 instanceof RelationType) &&
!super.cp1.isA(super.cp2) && !super.cp2.isA(super.cp1) &&
!super.cp1.hasAxiomSchema("toocom.ocgl.RelationExclusivity") &&
!super.cp2.hasAxiomSchema("toocom.ocgl.RelationExclusivity");
}
/** Returns from the given list of relation types the list of those that can
* be linked to the given relation type by an exclusivity. */
public static LinkedList getLinkablePrimitives(Collection relationTypes, RelationType rt){
LinkedList result = new LinkedList();
for(Iterator i = relationTypes.iterator();i.hasNext();){
RelationType rtTemp = (RelationType) i.next();
RelationExclusivity re = new RelationExclusivity(rt,rtTemp);
if(re.isValid()) result.add(rtTemp);
re.destroy();
}
return result;
}
public Axiom getAxiomForm(){
/*Axiom axiom1 = new Axiom(CGConstants.getRelationExclusivityTerms().append(" 1").appendWithSeparator(((RelationType) super.cp1).getTerm(l)," - ").appendWithSeparator(((RelationType) super.cp2).getTerm(l)," - "),l);
Relation r1 = new Relation((RelationType) super.cp1);
Relation r2 = new Relation((RelationType) super.cp2);
r2.getTerms().denyTerms();
axiom1.addHypothesisRelation(r1);
axiom1.addConclusionRelation(r2);
for(int j = 1;j <= ((RelationType) super.cp1).getSignature().getArity();j ++){
ConceptType ct = ((RelationType) super.cp1).getSignature().getConceptType(j);
Concept c = new Concept(ct);
r1.setLinkedConcept(c,j);
r2.setLinkedConcept(c,j);
axiom1.addHypothesisConcept(c);
}
Axiom axiom2 = new Axiom(CGConstants.getRelationExclusivityTerms().append(" 2").appendWithSeparator(((RelationType) super.cp1).getTerm(l)," - ").appendWithSeparator(((RelationType) super.cp2).getTerm(l)," - "),l); Relation r1 = new Relation((RelationType) super.cp2);
Relation r2 = new Relation((RelationType) super.cp1);
r2.getTerms().denyTerms();
axiom2.addHypothesisRelation(r1);
axiom2.addConclusionRelation(r2);
for(int j = 1;j <= ((RelationType) super.cp1).getSignature().getArity();j ++){
ConceptType ct = ((RelationType) super.cp1).getSignature().getConceptType(j);
Concept c = new Concept(ct);
r1.setLinkedConcept(c,j);
r2.setLinkedConcept(c,j);
axiom2.addHypothesisConcept(c);
}*/
return null;
}
/** Returns the list of Rules and Constraints that represent the
* exclusivity between the two relation types. The first object of the list is the
* constraint and the others objects are rules. The operational form of the
* exclusivity does not depend on the context of use. */
public LinkedList getOperationalForm(Ontology onto, Language l){
LinkedList result = new LinkedList();
NegativeConstraint nc = new NegativeConstraint(CGConstants.getNegativeConstraintTerms().appendAndCopy(CGConstants.getRelationExclusivityTerms()," : ").appendAndCopy(super.cp1.getTerms()," - ").appendAndCopy(super.cp2.getTerms()," - "));
Relation r1 = new Relation((RelationType) super.cp1);
Relation r2 = new Relation((RelationType) super.cp2);
nc.addHypothesisRelation(r1);
nc.addConclusionRelation(r2);
for(int i = 1;i <= ((RelationType) super.cp1).getSignature().getArity();i ++){
ConceptType ct = ((RelationType) super.cp1).getSignature().getConceptType(i);
Concept c = new Concept(ct);
r1.setLinkedConcept(c,i);
r2.setLinkedConcept(c,i);
nc.addHypothesisConcept(c);
}
result.add(nc);
for(int i = 1;i <= ((RelationType) super.cp1).getSignature().getArity();i ++){
Rule rule = new Rule(CGConstants.getRuleTerms().appendAndCopy(CGConstants.getRelationExclusivityTerms()," : ").appendAndCopy(super.cp1.getTerms(),i + " - ").appendAndCopy(super.cp2.getTerms()," - "));
Relation r3 = new Relation((RelationType) super.cp1);
Relation r4 = new Relation((RelationType) super.cp2);
rule.addHypothesisRelation(r3);
rule.addHypothesisRelation(r4);
for(int j = 1;j <= ((RelationType) super.cp1).getSignature().getArity();j ++){
ConceptType ct = ((RelationType) super.cp1).getSignature().getConceptType(j);
Concept c = new Concept(ct);
r3.setLinkedConcept(c,j);
if(i != j){
r4.setLinkedConcept(c,j);
rule.addHypothesisConcept(c);
}
else{
Concept cbis = new Concept(ct);
r4.setLinkedConcept(cbis,j);
rule.addHypothesisConcept(c);
rule.addHypothesisConcept(cbis);
Relation r = new Relation(onto.getDifferenceRelationType());
r.setLinkedConcept(c,1);
r.setLinkedConcept(cbis,2);
rule.addConclusionRelation(r);
}
}
result.add(rule);
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -