📄 rule.java
字号:
package toocom.ocgl;
import java.util.*;
import java.io.*;
/**
* This class represents the CG rules.
*
* @author Fr閐閞ic F黵st
*/
public class Rule extends ConceptualImplication{
public Rule(Terms t){
super(t);
}
/** Returns the list of projections of the hypothesis part of the rule into the graph g. If
* at least one projection exists, the rule can be applied on the graph. */
public LinkedList getHypothesisProjections(Graph g,CogitantClient client,Ontology onto,Language l) throws IOException{
return client.getGraphProjections(onto,this.getHypothesisPart(),g,l);
}
/** Returns the projections of the hypothesis part of the rule in the given graph such
* as the application of the rule produces new knowledge. */
public LinkedList getProductiveProjections(Ontology onto,Language l,CogitantClient client,Graph graph) throws IOException{
LinkedList result = new LinkedList();
LinkedList hypProj = client.getGraphProjections(onto,this.getHypothesisPart(),graph,l);
if(hypProj.size() > 0){
LinkedList concProj = client.getGraphProjections(onto,this.getConclusionPart(),graph,l);
for(Iterator i = hypProj.iterator();i.hasNext();){
Projection p = (Projection) i.next();
boolean prod = true;
for(Iterator j = concProj.iterator();j.hasNext();){
Projection pBis = (Projection) j.next();
boolean test = true;
for(Iterator k = this.getHypothesisConclusionConcepts().iterator();k.hasNext();){
Concept c = (Concept) k.next();
if(p.getCorrespondance(c.getId()) != pBis.getCorrespondance(c.getId())) test = false;
}
if(test) prod = false;
}
if(prod) result.add(p);
}
}
return result;
}
/** Apply the rule on the graph g according to the projection
* p that must exists from the hypothesis part of the rule to g. The graph g is modified
* by the application. */
public void applyRuleOnGraph(Graph g,Projection p){
// Correspondance table : axiom id / graph id
Hashtable table = new Hashtable();
for(Iterator i = this.getPureConclusionConcepts().iterator();i.hasNext();){
Concept ca = (Concept) i.next();
Concept cg = ca.cloneConcept();
g.addConcept(cg);
table.put(new Integer(ca.getId()),new Integer(cg.getId()));
}
for(Iterator i = this.getConclusionRelations().iterator();i.hasNext();){
Relation ra = (Relation) i.next();
Relation rg = ra.cloneRelation();
g.addRelation(rg);
for(int j = 1;j <= ra.getArity();j ++){
Concept c = ra.getLinkedConcept(j);
Integer cid = (Integer) table.get(new Integer(c.getId()));
if(table.get(new Integer(c.getId())) != null){
rg.setLinkedConcept(g.getConcept(cid.intValue()),j);
}
else{
rg.setLinkedConcept(g.getConcept(p.getCorrespondance(c.getId())),j);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -