⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inferenceengineframe.java

📁 toocom源代码,主要应用在本体匹配方面!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package toocom.ui;

import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.awt.*;
import java.lang.*; 
import toocom.ocgl.*;
import toocom.iotools.*;
import java.io.*;
import javax.swing.filechooser.*;

/** 
 * This class represents the graphical window into which the inference engine is running.
 *
 * @author Fr閐閞ic F黵st
 */
public class InferenceEngineFrame extends JDialog implements ActionListener{
	
	private MainFrame mf;
	// Tool bar
	private JToolBar tb;
	private JButton loadKB;
	private JButton saveKB;
	private JButton checkKB;
	private JButton init;
	private JButton createConcept;
	private JButton createRelation;
	private JButton destroyPrimitive;
	private JButton linkPrimitives;
	public JList ruleList;
	private JButton applyRule;
	public JList constraintList;
	public JList questionList;
	private JButton addQuestion;
	// KB display panel
	private KBDisplayArea kb; 
	// Axioms and questions display panel
	private GraphDisplayArea graph;
	// Rules and constraints
	private LinkedList implicitRules;
	public LinkedList explicitRules;
	private LinkedList implicitConstraints;
	public LinkedList explicitConstraints;
	public LinkedList questions;
	private int graphServerID;
	// Projections
	private Rule selectedRule;
	private Constraint selectedConstraint;
	private Graph selectedQuestion;
	private LinkedList projections;
	private int currentProj;

	
	public InferenceEngineFrame(MainFrame mf){
		super(mf,Constants.INFERENCE_ENGINE_FRAME_TITLE + " - " + mf.getOntology().getTerm(mf.getOntologyLanguage()));
		this.mf = mf;
		this.implicitRules = new LinkedList();
		this.explicitRules = new LinkedList();
		this.implicitConstraints = new LinkedList();
		this.explicitConstraints = new LinkedList();
		this.questions = new LinkedList();
		this.operationalization(true);
		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		this.setLocation(1,1);
		this.setSize(mf.getSize().width - 10,mf.getSize().height -10);
		// Creating tool bar
		this.tb = new JToolBar();
		this.tb.setBackground(Constants.KB_TOOLBAR_COLOR);
		this.tb.setLayout(new FlowLayout(FlowLayout.CENTER));
		this.tb.setFloatable(false);
		// Load KB Button
    	this.loadKB = new JButton(new InterfaceIcon(Constants.LOAD_KB_ICON));
		this.loadKB.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.loadKB.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));

		this.loadKB.setPreferredSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));

		this.loadKB.setBorder(BorderFactory.createRaisedBevelBorder());
		this.loadKB.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			loadKB();
    		}
    	});
    	this.loadKB.setToolTipText(Constants.LOAD_KB_TIPTEXT);
    	this.loadKB.setVisible(true);
    	// Create Concept Button
		this.createConcept = new JButton(new InterfaceIcon(Constants.CREATE_CONCEPT_ICON));
		this.createConcept.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.createConcept.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.createConcept.setBorder(BorderFactory.createRaisedBevelBorder());
		this.createConcept.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			setPrimitiveMode(0);
    		}
    	});
    	this.createConcept.setToolTipText(Constants.CREATE_CONCEPT_TIPTEXT);
    	this.createConcept.setVisible(true);
    	// Save knowledge base Button
    	this.saveKB = new JButton(new InterfaceIcon(Constants.SAVE_KB_ICON));
		this.saveKB.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.saveKB.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.saveKB.setBorder(BorderFactory.createRaisedBevelBorder());
		this.saveKB.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			saveKB();
    		}
    	});
    	this.saveKB.setToolTipText(Constants.SAVE_KB_TIPTEXT);
    	this.saveKB.setVisible(true);
    	// Check knowledge base Button
    	this.checkKB = new JButton(new InterfaceIcon(Constants.CHECK_KB_ICON));
		this.checkKB.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.checkKB.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.checkKB.setBorder(BorderFactory.createRaisedBevelBorder());
		this.checkKB.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			checkKB();
    		}
    	});
    	this.checkKB.setToolTipText(Constants.CHECK_KB_TIPTEXT);
    	this.checkKB.setVisible(true);
    	// Exit running mode button
		this.init = new JButton(new InterfaceIcon(Constants.INIT_ICON));
		this.init.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.init.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.init.setBorder(BorderFactory.createRaisedBevelBorder());
		this.init.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			init();
    		}
    	});
    	this.init.setToolTipText(Constants.INIT_TIPTEXT);
    	this.init.setVisible(true);
    	// Create Relation Button
		this.createRelation = new JButton(new InterfaceIcon(Constants.CREATE_RELATION_ICON));
		this.createRelation.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.createRelation.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.createRelation.setBorder(BorderFactory.createRaisedBevelBorder());
		this.createRelation.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			setPrimitiveMode(1);
    		}
    	});
    	this.createRelation.setToolTipText(Constants.CREATE_RELATION_TIPTEXT);
    	this.createRelation.setVisible(true);
		// Destroy Button
		this.destroyPrimitive = new JButton(new InterfaceIcon(Constants.DESTROY_PRIMITIVE_ICON));
		this.destroyPrimitive.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.destroyPrimitive.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.destroyPrimitive.setBorder(BorderFactory.createRaisedBevelBorder());
		this.destroyPrimitive.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			setPrimitiveMode(2);
    		}
    	});
    	this.destroyPrimitive.setToolTipText(Constants.DESTROY_PRIMITIVE_TIPTEXT);
		// Link Button
		this.linkPrimitives = new JButton(new InterfaceIcon(Constants.LINK_PRIMITIVES_ICON));
		this.linkPrimitives.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.linkPrimitives.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.linkPrimitives.setBorder(BorderFactory.createRaisedBevelBorder());
		this.linkPrimitives.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			setPrimitiveMode(3);
    		}
    	});
    	this.linkPrimitives.setToolTipText(Constants.LINK_PRIMITIVES_TIPTEXT);
    	// Add Buttons
		Box b1 = new Box(BoxLayout.Y_AXIS);
		b1.add(loadKB);
		b1.add(createConcept);
		this.tb.add(b1);
		Box b2 = new Box(BoxLayout.Y_AXIS);
		b2.add(saveKB);
		b2.add(createRelation);
		this.tb.add(b2);
		Box b3 = new Box(BoxLayout.Y_AXIS);
		b3.add(checkKB);
		b3.add(linkPrimitives);
		this.tb.add(b3);
		Box b4 = new Box(BoxLayout.Y_AXIS);
		b4.add(init);
		b4.add(destroyPrimitive);
		this.tb.add(b4);
    	this.tb.addSeparator();
		// Rule list
		Label ruleLabel = new Label(Constants.RULES_TEXT);
		Box ruleBox = new Box(BoxLayout.Y_AXIS);
		this.ruleList = new JList(new DefaultListModel());
		this.ruleList.setCellRenderer(new TooCoMAxiomListCellRenderer());
		this.ruleList.setFixedCellWidth(Constants.RULE_LIST_CELL_WIDTH);
		this.ruleList.setVisibleRowCount(Constants.RULE_LIST_VISIBLE_ROW_COUNT);
		this.ruleList.addMouseListener(new MouseAdapter(){
    		public void mouseClicked(MouseEvent e){
    			selectRule();
    		}
    	});
    	JScrollPane jsp1 = new JScrollPane(ruleList);
	   	for(Iterator i = explicitRules.iterator();i.hasNext();){
    		Rule r = (Rule) i.next();
    		((DefaultListModel) ruleList.getModel()).addElement(r.getTerm(mf.getOntologyLanguage()));
    	}
    	ruleBox.add(ruleLabel);
    	ruleBox.add(jsp1);
		this.tb.add(ruleBox);
		this.applyRule = new JButton(new InterfaceIcon(Constants.APPLY_RULE_ICON));
		this.applyRule.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.applyRule.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.applyRule.setBorder(BorderFactory.createRaisedBevelBorder());
		this.applyRule.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			applyRule();
    		}
    	});
    	this.applyRule.setToolTipText(Constants.APPLY_RULE_TIPTEXT);
    	this.applyRule.setVisible(true);
    	this.tb.add(this.applyRule);
    	this.tb.addSeparator();
    	// Constraint list
    	Label constraintLabel = new Label(Constants.CONSTRAINTS_TEXT);
		Box constraintBox = new Box(BoxLayout.Y_AXIS);
    	this.constraintList = new JList(new DefaultListModel());
		this.constraintList.setCellRenderer(new TooCoMAxiomListCellRenderer());
		this.constraintList.setFixedCellWidth(Constants.CONSTRAINT_LIST_CELL_WIDTH);
		this.constraintList.setVisibleRowCount(Constants.CONSTRAINT_LIST_VISIBLE_ROW_COUNT);
		this.constraintList.addMouseListener(new MouseAdapter(){
    		public void mouseClicked(MouseEvent e){
    			selectConstraint();
    		}
    	});
    	JScrollPane jsp2 = new JScrollPane(constraintList);
	   		for(Iterator i = explicitConstraints.iterator();i.hasNext();){
    		Constraint c = (Constraint) i.next();
    		((DefaultListModel) constraintList.getModel()).addElement(c.getTerm(mf.getOntologyLanguage()));
    	}
	   	constraintBox.add(constraintLabel);
    	constraintBox.add(jsp2);
		this.tb.add(constraintBox);
		this.tb.addSeparator();
       	// Question list
    	Label questionLabel = new Label(Constants.QUESTIONS_TEXT);
		Box questionBox = new Box(BoxLayout.Y_AXIS);
       	this.questionList = new JList(new DefaultListModel());
		this.questionList.setCellRenderer(new TooCoMAxiomListCellRenderer());
		this.questionList.setFixedCellWidth(Constants.QUESTION_LIST_CELL_WIDTH);
		this.questionList.setVisibleRowCount(Constants.QUESTION_LIST_VISIBLE_ROW_COUNT);
		this.questionList.addMouseListener(new MouseAdapter(){
    		public void mouseClicked(MouseEvent e){
    			selectQuestion();
    		}
    	});
    	JScrollPane jsp3 = new JScrollPane(questionList);
    	questionBox.add(questionLabel);
    	questionBox.add(jsp3);
		this.tb.add(questionBox);
		this.addQuestion = new JButton(new InterfaceIcon(Constants.ADD_QUESTION_ICON));
		this.addQuestion.setMaximumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));
		this.addQuestion.setMinimumSize(new Dimension(Constants.INTERNAL_FRAME_BUTTON_DIM,Constants.INTERNAL_FRAME_BUTTON_DIM));		
		this.addQuestion.setBorder(BorderFactory.createRaisedBevelBorder());
		this.addQuestion.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			addQuestion();
    		}
    	});
    	this.addQuestion.setToolTipText(Constants.ADD_QUESTION_TIPTEXT);
    	this.addQuestion.setVisible(true);
    	this.tb.add(addQuestion);
    	// Creating kb display panel
		this.kb = new KBDisplayArea(mf,this);
    	// Creating axioms display panel
    	this.graph = new GraphDisplayArea(mf,this);
    	// Add tool bar and panels to the frame
    	this.getContentPane().setLayout(new BorderLayout());
		this.getContentPane().add(tb,BorderLayout.NORTH);
    	JScrollPane left = new JScrollPane(kb);
    	JScrollPane right = new JScrollPane(graph);
    	JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,left,right);
	    splitPane.setDividerSize(Constants.SPLIT_DIVIDER_SIZE);
	    splitPane.setOneTouchExpandable(true);
    	this.getContentPane().add(splitPane,BorderLayout.CENTER);
		this.getRootPane().registerKeyboardAction(this,"Next Projection",KeyStroke.getKeyStroke(Constants.NEXT_PROJECTION_KEY),JComponent.WHEN_IN_FOCUSED_WINDOW);
		this.getRootPane().registerKeyboardAction(this,"Previous Projection",KeyStroke.getKeyStroke(Constants.PREVIOUS_PROJECTION_KEY),JComponent.WHEN_IN_FOCUSED_WINDOW);
		this.setVisible(true);
		this.toFront();

	}
	
	public void dispose(){
		try{
			if(mf.getCogitantClient() != null) mf.getCogitantClient().closeServerOntology();
			// DESTRUCTION DES GRAPHES ET REGLES OPERATIONELLES?
		}
		catch(IOException e){
		}
	}
	
	public void actionPerformed(ActionEvent event){
		if(event.getActionCommand().equals("Next Projection")) this.nextProjection();
		if(event.getActionCommand().equals("Previous Projection")) this.previousProjection();
	}
	
	public void operationalization(boolean message){
		Ontology onto = mf.getOntology();
		// Axiom Schemas
		for(Iterator i = onto.getAxiomSchemata().iterator();i.hasNext();){
			AxiomSchema as = (AxiomSchema) i.next();
			LinkedList opForm = as.getOperationalForm(onto,mf.getOntologyLanguage());
			for(Iterator j = opForm.iterator();j.hasNext();){
				ConceptualImplication impl = (ConceptualImplication) j.next();
				//if(impl.getClass().getName().equals("toocom.ocgl.NegativeConstraint"))
				
				//A FINIR
			}
			
		}
		// Axioms
		for(Iterator i = NamedObject.sortListByName(onto.getAxioms(),mf.getOntologyLanguage()).iterator();i.hasNext();){
			Axiom a = (Axiom) i.next();
			if(message) System.out.print("axiom " + a.getTerm(mf.getOntologyLanguage()));
			if(a.getContextOfUse().isInferential()){
				if(a.getContextOfUse().isExplicit()){
					explicitRules.add(a);
					LinkedList constraintList = a.getInducedConstraints(mf.getOntologyLanguage());
					for(Iterator j = constraintList.iterator();j.hasNext();){
						Graph gTemp = (Graph) j.next();
						if(message) System.out.print("implicit constraint " + gTemp.getTerm(mf.getOntologyLanguage()));
						implicitConstraints.add(gTemp);
					}
				}
				else{
					implicitRules.add(a);
					if(message) System.out.print("implicit rule " + a.getTerm(mf.getOntologyLanguage()));
				}
			}
			else{
				LinkedList constraintList = a.getInducedConstraints(mf.getOntologyLanguage());
				if(a.getContextOfUse().isExplicit()){
					for(Iterator j = constraintList.iterator();j.hasNext();){
						Graph gTemp = (Graph) j.next();
						explicitConstraints.add(gTemp);
						if(message) System.out.print("explicit constraint " + gTemp.getTerm(mf.getOntologyLanguage()));
					}
				}
				else{
					for(Iterator j = constraintList.iterator();j.hasNext();){
						Graph gTemp = (Graph) j.next();
						implicitConstraints.add(gTemp);
						if(message) System.out.print("implicit constraint " + gTemp.getTerm(mf.getOntologyLanguage()));
					}
				}
			}
			if(message) System.out.println();
		}
		// Exclusions and incompatibilities
		LinkedList temp = new LinkedList();
		for(Iterator i = onto.getRelationTypes().iterator();i.hasNext();){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -