package aminePlatform.test.util.cg; /******************************************************************* Amine - Artificial Intelligence platform for the development of Intelligent Systems. Copyright (C) 2004 AmineGroup. GNU Lesser General Public License This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *********************************************************************/ import aminePlatform.kernel.lexicons.*; import aminePlatform.kernel.ontology.*; import aminePlatform.util.cg.*; import aminePlatform.util.*; import aminePlatform.guis.util.AmineFrame; import javax.swing.*; import java.util.*; import java.awt.event.*; /** *

Title : RelationTest class

*

Description : Test the Relation API

* @author Adil KABBAJ * @version 2 */ public class RelationTest extends JDialog implements AmineConstants { public RelationTest() { this.setTitle("RelationTest"); StringBuffer output = new StringBuffer(""); JScrollPane scrol; JTextArea text; try { // Load the Lexicons/Ontology that is stored in the specified file. Ontology ontology = Ontology.load(AmineFrame.ontologyDirPath + "ManOntology.ont"); Lexicon mainLexicon = ontology.getMainLexicon(); Relation rel1 = Relation.parse("(agnt [Man] [Drink])", mainLexicon); output.append("\nRelation rel1 : " + rel1.toString(mainLexicon)); Lexicon frenchLexicon = ontology.getLexicon(Identifier.wrap("french")); ontology.setMixedLanguage(true); output.append("\nThe same relation with the same ontology but the language is French :\n " + rel1.toString(frenchLexicon)); output.append("\n**** Error due to canonicity test: Attempt to parse (obj [Man] [Drink]) "); try { Relation rel1B = Relation.parse("(obj [Man] [Drink])", mainLexicon); output.append("\n").append(rel1B.toString(mainLexicon)); } catch (Exception pEx) { output.append("\n").append(pEx.getMessage()); } output.append("\nTest 5 : Amine Object Operations (equals, maximalJoin, generalize, subsume)"); Relation rel2 = Relation.parse("(agnt [Human :imad] [Action])", mainLexicon); output.append("\nRelation rel2 : " + rel2.toString(mainLexicon)); Relation rel3 = Relation.parse("(agnt [Human :imad] [Action :x])", mainLexicon); output.append("\nRelation rel3 : " + rel3.toString(mainLexicon)); output.append("\nTest of rel2.equal(rel3) : " + rel2.equal(rel3)); Relation maximalJoinResult = (Relation) rel1.maximalJoin(rel2); output.append("\nTest rel1.maximalJoin(rel2) :\n " + maximalJoinResult.toString(mainLexicon)); Relation generalizeResult = (Relation) rel1.generalize(rel2); output.append("\nTest rel1.generalize(rel2) :\n " + generalizeResult.toString(mainLexicon)); output.append("\nTest rel1.subsume(rel2) : " + rel1.subsume(rel2)); output.append("\nTest generalizeResult.subsume(rel2) : " + generalizeResult.subsume(rel2)); Relation subsumeWithResult = (Relation) generalizeResult.match(SUBSUME_WITH_RSLT, rel2); output.append("\nTest generalizeResult.match(SUBSUME_WITH_RSLT, rel2) :\n " + subsumeWithResult.toString(mainLexicon)); text = new JTextArea(22, 30); text.setText(output.toString()); scrol = new JScrollPane(text); this.getContentPane().add(scrol); this.setLocation(100, 100); this.setSize(400, 450); this.show(); } catch (Exception ex) { output.append(ex.getMessage()); } } public static void main(String[] args) { RelationTest relationTest = new RelationTest(); relationTest.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(-1); } }); } }