📄 inferenceengineframe.java
字号:
RelationType rt = (RelationType) i.next();
for(Iterator j = rt.getAxiomSchemata("toocom.ocgl.RelationExclusivity").iterator();j.hasNext();){
RelationExclusivity exclu = (RelationExclusivity) j.next();
RelationType rtBis = (RelationType) exclu.getTheOtherPrimitive(rt);
if((rtBis != null) && (!temp.contains(rtBis))){
LinkedList excluList = exclu.getOperationalForm(onto,mf.getOntologyLanguage());
Graph gTemp = (Graph) excluList.get(0);
implicitConstraints.add(gTemp);
if(message) System.out.println("implicit constraint " + gTemp.getTerm(mf.getOntologyLanguage()));
for(int index = 1;index < excluList.size();index ++){
Axiom a = (Axiom) excluList.get(index);
implicitRules.add(a);
if(message) System.out.println("implicit rule " + a.getTerm(mf.getOntologyLanguage()));
}
}
}
for(Iterator j = rt.getAxiomSchemata("toocom.ocgl.RelationIncompatibility").iterator();j.hasNext();){
RelationIncompatibility incomp = (RelationIncompatibility) j.next();
RelationType rtBis = (RelationType) incomp.getTheOtherPrimitive(rt);
if((rtBis != null) && (!temp.contains(rtBis))){
LinkedList excluList = incomp.getOperationalForm(onto,mf.getOntologyLanguage());
Graph gTemp = (Graph) excluList.get(0);
implicitConstraints.add(gTemp);
if(message) System.out.println("implicit constraint " + gTemp.getTerm(mf.getOntologyLanguage()));
for(int index = 1;index < excluList.size();index ++){
Axiom a = (Axiom) excluList.get(index);
implicitRules.add(a);
if(message) System.out.println("implicit rule " + a.getTerm(mf.getOntologyLanguage()));
}
}
}
temp.add(rt);
}
}
public Rule getSelectedRule(){
return this.selectedRule;
}
public Constraint getSelectedConstraint(){
return this.selectedConstraint;
}
public Graph getSelectedQuestion(){
return this.selectedQuestion;
}
public Projection getProjection(){
if(((this.selectedRule != null) || (this.selectedConstraint != null) || (this.selectedQuestion != null)) && (currentProj >= 0) && (currentProj < projections.size()))
return (Projection) projections.get(currentProj);
else return null;
}
public void saveKB(){
if((kb.getGraph() != null) && !kb.getGraph().isEmpty()){
IOInterface.saveGraph(this,Constants.APPLICATION_DIRECTORY,mf.getOntology(),mf.getOntologyLanguage(),kb.getGraph());
}
}
public boolean loadKB(){
kb.clearGraph();
this.removeAllSelections();
Graph g = IOInterface.loadGraph(this,Constants.APPLICATION_DIRECTORY,mf.getOntology(),mf.getOntologyLanguage());
if(g != null){
kb.setGraph(g);
kb.repaint();
//this.repaint();
return true;
}
else return false;
}
public void checkKB(){
if(kb.getGraph() != null) OntoEval.graphVerification(kb.getGraph(),mf.getOntology(),mf.getOntologyLanguage()).displayResults(mf,CGConstants.GRAPH + CGConstants.TESTS_RESULTS);
}
public void setPrimitiveMode(int mode){
kb.setPrimitiveMode(mode);
this.createConcept.setBackground(null);
this.createRelation.setBackground(null);
this.destroyPrimitive.setBackground(null);
this.linkPrimitives.setBackground(null);
if(mode == 0){
this.createConcept.setBackground(Constants.SELECTED_BUTTON_COLOR);
}
if(mode == 1){
this.createRelation.setBackground(Constants.SELECTED_BUTTON_COLOR);
}
if(mode == 2){
this.destroyPrimitive.setBackground(Constants.SELECTED_BUTTON_COLOR);
}
if(mode == 3){
this.linkPrimitives.setBackground(Constants.SELECTED_BUTTON_COLOR);
}
this.repaint();
}
public void removeAllSelections(){
this.selectedQuestion = null;
this.selectedRule = null;
this.selectedConstraint = null;
this.ruleList.clearSelection();
this.constraintList.clearSelection();
this.questionList.clearSelection();
}
public void init(){
this.setPrimitiveMode(0);
kb.getGraph().destroy(mf.getOntology());
kb.clearGraph();
try{
mf.getCogitantClient().closeServerOntology();
mf.getCogitantClient().createServerSupport(mf.getOntology(),mf.getOntologyLanguage());
}
catch(Exception e){
System.out.println(e.getMessage());
}
this.removeAllSelections();
kb.repaint();
this.repaint();
}
public void selectRule(){
int index = this.ruleList.getSelectedIndex();
this.removeAllSelections();
this.ruleList.setSelectedIndex(index);
try{
if(index != -1){
this.setPrimitiveMode(-1);
int cpt = 0;
for(Iterator i = this.explicitRules.iterator();i.hasNext() && (cpt <= index);){
Object temp = i.next();
if(cpt == index){
if((selectedRule == null) || ((selectedRule != null) && (!selectedRule.equals((Rule) temp)))){
selectedRule = (Rule) temp;
this.projections = mf.getCogitantClient().getGraphProjections(mf.getOntology(),selectedRule.getHypothesisPart(),kb.getGraph(),mf.getOntologyLanguage());
currentProj = 0;
this.kb.changeProjection();
this.kb.repaint();
this.graph.setGraphicalObject(selectedRule);
this.graph.repaint();
}
}
cpt ++;
}
}
}
catch(IOException e){
projections.clear();
System.out.println(e.getMessage());
}
}
public void selectConstraint(){
int index = this.constraintList.getSelectedIndex();
this.removeAllSelections();
this.constraintList.setSelectedIndex(index);
try{
if(index != -1){
this.setPrimitiveMode(-1);
int cpt = 0;
for(Iterator i = this.explicitConstraints.iterator();i.hasNext() && (cpt <= index);){
Object temp = i.next();
if(cpt == index){
if((selectedConstraint == null) || ((selectedConstraint != null) && (!selectedConstraint.equals((Constraint) temp)))){
selectedConstraint = (Constraint) temp;
this.projections = selectedConstraint.getConstraintProjections(kb.getGraph(),mf.getCogitantClient(),mf.getOntology(),mf.getOntologyLanguage());
currentProj = 0;
this.kb.changeProjection();
this.kb.repaint();
this.graph.setGraphicalObject(selectedConstraint);
this.graph.repaint();
}
}
cpt ++;
}
}
}
catch(IOException e){
projections.clear();
System.out.println(e.getMessage());
}
}
public void selectQuestion(){
int index = this.questionList.getSelectedIndex();
this.removeAllSelections();
this.questionList.setSelectedIndex(index);
try{
if(index != -1){
this.setPrimitiveMode(-1);
int cpt = 0;
for(Iterator i = this.questions.iterator();i.hasNext() && (cpt <= index);){
Object temp = i.next();
if(cpt == index){
if((selectedQuestion == null) || ((selectedQuestion != null) && (!selectedQuestion.equals((Graph) temp)))){
selectedQuestion = (Graph) temp;
this.projections = mf.getCogitantClient().getGraphProjections(mf.getOntology(),selectedQuestion,kb.getGraph(),mf.getOntologyLanguage());
currentProj = 0;
this.kb.changeProjection();
this.kb.repaint();
this.graph.setGraphicalObject(selectedQuestion);
this.graph.repaint();
}
}
cpt ++;
}
}
}
catch(IOException e){
projections.clear();
System.out.println(e.getMessage());
}
}
public void applyRule(){
try{
TooCoMProgressBar pb = new TooCoMProgressBar(mf,Constants.APPLYING_AXIOM_MESSAGE);
Graph safeGraph = kb.getGraph().cloneGraph();
kb.setGraph(kb.getGraph());
if((selectedRule != null) && (currentProj >= 0) && (currentProj < projections.size())){
selectedRule.applyRuleOnGraph(kb.getGraph(),(Projection) projections.get(currentProj));
kb.repaint();
}
this.saturation(mf.getOntology(),this.implicitRules,kb.getGraph());
kb.repaint();
Constraint cons = this.checkConstraints();
kb.repaint();
if(cons != null){
Object[] tab = new Object[2];
tab[0] = new String(Constants.CANCEL_RULE_APPLICATION_OPTION);
tab[1] = new String(Constants.INITIALIZATION_OF_ENGINE_OPTION);
int choice = JOptionPane.showOptionDialog(this,Constants.IMPLICIT_CONSTRAINT_BROKEN_MESSAGE + " : " + cons.getTerm(mf.getOntologyLanguage()),Constants.CONSTRAINT_BROKEN_MESSAGE,0,JOptionPane.INFORMATION_MESSAGE,null,tab,null);
if((choice == 0) || (choice == JOptionPane.CLOSED_OPTION)){
kb.setGraph(safeGraph);
this.removeAllSelections();
this.projections.clear();
this.currentProj = -1;
}
if(choice == 1) this.init();
kb.repaint();
this.repaint();
}
pb.setValue(100);
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
public void addQuestion(){
Object[] tab = {"Create Question","Load Question"};
int option = JOptionPane.showOptionDialog(this,Constants.ADD_QUESTION_MESSAGE,Constants.ADD_QUESTION_TITLE,JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,null,tab,null);
if(option == 0){
GraphEditionFrame gef = new GraphEditionFrame(this.mf,this);
}
if(option == 1){
JFileChooser fileChooser = new JFileChooser(Constants.APPLICATION_DIRECTORY);
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fileChooser.setAcceptAllFileFilterUsed(false);
fileChooser.setFileFilter(new CGXMLFileFilter());
if(fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){
try{
this.setPrimitiveMode(-1);
Graph question = CGXMLParser.loadGraph(mf.getOntology(),mf.getOntologyLanguage(),fileChooser.getSelectedFile().getPath(),true);
if(question == null) JOptionPane.showMessageDialog(this,Constants.NOT_VALID_GRAPH_FILE);
else{
this.questions.add(question);
((DefaultListModel) questionList.getModel()).addElement(question.getTerm(mf.getOntologyLanguage()));
questionList.setSelectedIndex(questionList.getModel().getSize() - 1);
questionList.ensureIndexIsVisible(questionList.getModel().getSize() - 1);
this.selectQuestion();
this.toFront();
}
}
catch(IOException e){
JOptionPane.showMessageDialog(this,Constants.NOT_VALID_GRAPH_FILE);
}
}
}
}
public void updateQuestions(Graph question){
this.questions.add(question);
((DefaultListModel) questionList.getModel()).addElement(question.getTerm(mf.getOntologyLanguage()));
questionList.setSelectedIndex(questionList.getModel().getSize() - 1);
questionList.ensureIndexIsVisible(questionList.getModel().getSize() - 1);
this.selectQuestion();
this.toFront();
}
public void nextProjection(){
if(projections.size() > 0){
if(currentProj < (projections.size() -1)) currentProj ++;
else currentProj = 0;
}
kb.changeProjection();
kb.repaint();
}
public void previousProjection(){
if(projections.size() > 0){
if(currentProj > 0) currentProj--;
else currentProj = projections.size() - 1;
}
kb.changeProjection();
kb.repaint();
}
/** Saturates the graph with the given rules. */
public void saturation(Ontology onto,LinkedList rules,Graph g){
try{
if(g != null){
for(Iterator i = rules.iterator();i.hasNext();){
Rule implicitRule = (Rule) i.next();
LinkedList projList = implicitRule.getProductiveProjections(mf.getOntology(),mf.getOntologyLanguage(),mf.getCogitantClient(),g);
while(projList.size() > 0){
implicitRule.applyRuleOnGraph(g,(Projection) projList.getFirst());
projList = implicitRule.getProductiveProjections(mf.getOntology(),mf.getOntologyLanguage(),mf.getCogitantClient(),g);
}
}
}
}
catch(IOException e){
System.out.println(e.getMessage());
}
}
/** Checks the implicite constraints on the current graph, returns the first broken constraint
* or null if any constraint is broken. */
public Constraint checkConstraints(){
try{
for(Iterator i = this.implicitConstraints.iterator();i.hasNext();){
Constraint constraint = (Constraint) i.next();
this.projections = constraint.getConstraintProjections(kb.getGraph(),mf.getCogitantClient(),mf.getOntology(),mf.getOntologyLanguage());
if(this.projections.size() > 0){
this.removeAllSelections();
this.selectedConstraint = constraint;
System.out.println();
System.out.println("IMPLICIT CONSTRAINT BROKEN " + constraint.getTerm(mf.getOntologyLanguage()) + " : " + constraint.toString(mf.getOntologyLanguage()));
this.currentProj = 0;
this.kb.changeProjection();
this.kb.repaint();
return constraint;
}
}
kb.repaint();
return null;
}
catch(Exception e){
System.out.println(e.getMessage());
return null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -