package aminePlatform.test.util; /******************************************************************* 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.*; import aminePlatform.guis.util.AmineFrame; import javax.swing.*; import java.util.*; import java.awt.event.*; /** *

Title : AmineSetTest class

*

Description : Test the AmineSet API

* @author Adil KABBAJ * @version 2 */ public class AmineSetTest extends JDialog implements AmineConstants { public AmineSetTest() { this.setTitle("AmineSetTest"); StringBuffer output = new StringBuffer(""); JScrollPane scrol; JTextArea text; try { // Test1 : Create, print and basic operations AmineSet Without Lexicon, Ontology ... AmineSet amineSet = AmineSet.parse("{bo, 78, true}"); output.append("\nAn amine set : " + amineSet); AmineSet emptySet = AmineSet.parse("{}"); output.append("\nThe empty set : " + emptySet); AmineSet copyOfAmineSet = amineSet.copy(); output.append("\nCopy of the amine set : " + copyOfAmineSet); output.append("\nTest copyOfAmineSet.equals(amineSet) : " + copyOfAmineSet.equals(amineSet)); output.append("\nTest copyOfAmineSet.equal(amineSet) : " + copyOfAmineSet.equal(null, null, amineSet, null)); copyOfAmineSet.add(new Integer(65)); output.append("\nCopy of the amine set after the addition of Integer 65 : \n" + copyOfAmineSet); output.append("\nTest copyOfAmineSet.equals(amineSet) : " + copyOfAmineSet.equal(null, null, amineSet, null)); output.append("\nAttempt to add the variable a23 to copyOfAmineSet : copyOfAmineSet.add(new Variable(\"a23\")) => \n" + copyOfAmineSet.add(new Variable("a23")) + " \n failed because a variable is not a simple object and so, cannot be added to an amine Set"); copyOfAmineSet.clear(); output.append("\nCopy of the amine set after copyOfAmineSet.clear() : \n" + copyOfAmineSet); output.append("\nThe original amine Set has not been changed : \n" + amineSet); copyOfAmineSet.addAll(AmineSet.parse("{jour, 67, 78, bo, ba}")); output.append("\nThe new content of copyOfAmineSet : \n" + copyOfAmineSet); output.append("\nConvert the amineSet " + copyOfAmineSet + "\n to an Amine List : " + copyOfAmineSet.toAmineList()); output.append("\nTest copyOfAmineSet.isMember(new Integer(89)) : \n" + copyOfAmineSet.isMember(new Integer(89))); output.append("\nTest copyOfAmineSet.isMember(new Integer(78)) : \n" + copyOfAmineSet.isMember(new Integer(78))); output.append("\nTest copyOfAmineSet.intersection(amineSet) : \n" + copyOfAmineSet.intersection(amineSet)); output.append("\nTest copyOfAmineSet.union(amineSet) : \n" + copyOfAmineSet.union(amineSet)); output.append("\nTest copyOfAmineSet.union(new Integer(7)) : \n" + copyOfAmineSet.union(new Integer(7))); output.append("\nTest copyOfAmineSet.isSubSet(amineSet) : \n" + copyOfAmineSet.isSubSet(amineSet)); output.append("\nTest copyOfAmineSet.isSubSet(AmineSet.parse(\"{bo, 78}\")) : \n" + copyOfAmineSet.isSubSet(AmineSet.parse("{bo, 78}"))); output.append("\n****************************************************\n"); //********* AmineSet with a specific Ontology as background *********** // Load the Lexicons/Ontology that is stored in the specified file. Ontology ontology = Ontology.load(AmineFrame.ontologyDirPath + "ManOntology.ont"); Lexicon mainLexicon = ontology.getMainLexicon(); AmineSet amineSetOnt1 = AmineSet.parse("{Drink, Man, Water, fast}", mainLexicon); output.append("\nThe AmineSet " + amineSetOnt1.toString(mainLexicon) + "\n with an ontology as background and English as Language."); Lexicon frenchLexicon = ontology.getLexicon(Identifier.wrap("french")); output.append("\nThe same amineSet with the same ontology but the language is French : \n" + amineSetOnt1.toString(frenchLexicon)); output.append("\n\n****************************************************\n"); // Test 5 : Amine Object Operations (equals, maximalJoin, generalize, subsume) output.append("\nTest 5 : Amine Object Operations (equals, maximalJoin, generalize, subsume)"); output.append("\nValue of the two sets : "); output.append("\ncopyOfAmineSet : " + copyOfAmineSet); AmineSet newSet = AmineSet.parse("{bon, 78, \"this is a sentence\", 89, jour}"); output.append("\nnewSet : " + newSet); AmineSet newSet2 = AmineSet.parse("{bon, jour, \"this is a sentence\", 78, 89}"); output.append("\nnewSet2 : " + newSet2); output.append("\nTest copyOfAmineSet.equals(newSet) : " + copyOfAmineSet.equals(newSet)); output.append("\nTest newSet.equals(newSet2) : " + newSet.equals(newSet2)); AmineSet maximalJoinResult = (AmineSet) copyOfAmineSet.maximalJoin(newSet); output.append("\nTest copyOfAmineSet.maximalJoin(newSet) : \n" + maximalJoinResult); AmineSet generalizeResult = (AmineSet) copyOfAmineSet.generalize(newSet); output.append("\nTest copyOfAmineSet.generalize(newSet) : \n" + generalizeResult); output.append("\nTest copyOfAmineSet.subsume(newSet) : \n" + copyOfAmineSet.subsume(newSet)); output.append("\nTest generalizeResult.subsume(newSet) : \n" + generalizeResult.subsume(newSet)); AmineSet subsumeWithResult = (AmineSet) generalizeResult.match(SUBSUME_WITH_RSLT, newSet); output.append("\nTest generalizeResult.match(SUBSUME_WITH_RSLT, newList) : \n" + subsumeWithResult); 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) { System.out.println(ex.getMessage()); } } public static void main(String[] args) { AmineSetTest amineSetTest = new AmineSetTest(); amineSetTest.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(-1); } }); } }