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 : AmineListTest class

*

Description : Test the AmineList API

* @author Adil KABBAJ * @version 2 */ public class AmineListTest extends JDialog implements AmineConstants { public AmineListTest() { this.setTitle("AmineListTest"); StringBuffer output = new StringBuffer(""); JScrollPane scrol; JTextArea text; try { // Create, print and perform basic operations on Amine Lists without considering Lexicons and Ontology // Test 1: Create and Print (toString) various AmineList AmineList amineSimpleList = AmineList.parse("[a, 23, 78]"); AmineList amineEmptyList = AmineList.parse("[]"); AmineList amineEmbededList = AmineList.parse("[bon, [345, \"this is a sentence\", a], www]"); AmineList amineListWithConstr = AmineList.parse("[a, 23, 78|x]"); output.append("\nA simple List : " + amineSimpleList); output.append("\nAn Empty List : " + amineEmptyList); output.append("\nAn Embeded List : " + amineEmbededList); output.append("\nAmine List With Constructor : " + amineListWithConstr); // Test 2 : Create copies of AmineList AmineList copyOfSimpleList = amineSimpleList.copy(); output.append("\nA copy of the simple List : " + copyOfSimpleList); ArrayList variables = new ArrayList(); copyOfSimpleList.getVariables(variables); output.append("\nVariables in the Simple List : " + variables.toString()); variables.clear(); AmineList copyOfListWithConstr = amineListWithConstr.copy(); output.append("\nA copy of the List With Constructor : " + copyOfListWithConstr); copyOfListWithConstr.getVariables(variables); output.append("\nVariables in the List With Constructor : " + variables.toString()); AmineList copyOfEmptyList = amineEmptyList.copy(); output.append("\nA copy of the Empty List : " + copyOfEmptyList); AmineList copyOfEmbededList = amineEmbededList.copy(); output.append("\nA copy of the Embeded List : " + copyOfEmbededList); // Test 3 : Basic operations: add(), clear(), isMember(), toAmineSet() copyOfEmbededList.add(new Double(3452)); output.append("\nAddition of double 3452 to the Embeded List : " + copyOfEmbededList); output.append("\nTest amineEmbededList.equal(copyOfEmbededList) after the addition : " + amineEmbededList.equal(copyOfEmbededList)); output.append("\nTest amineEmbededList.equal(null, null, copyOfEmbededList, null)) after the addition : " + amineEmbededList.equal(null, null, copyOfEmbededList, null)); copyOfEmbededList.clear(); output.append("\ncopyOfEmbededList.clear() : " + copyOfEmbededList); copyOfEmbededList.add(new Integer(9)); output.append("\nafter copyOfEmbededList.add(new Integer(9)) : " + copyOfEmbededList); output.append("\namineEmbededList has not been changed : " + amineEmbededList); boolean isMember = amineSimpleList.isMember(new Integer(23)); output.append("\nInteger 23 is member of [a, 23, 78] : " + isMember); AmineSet amineSet = copyOfSimpleList.toAmineSet(); if (amineSet == null) output.append("\ncannot convert the amineList " + copyOfSimpleList + " to an amineSet \n because it contains at least an element that is not a simple object (in this case the variable a)"); copyOfSimpleList.remove(0); output.append("\nConvert after the remove of the first element : " + copyOfSimpleList.toAmineSet()); output.append("\n****************************************************\n"); // Test 4 : AmineList 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(); AmineList amineListOnt1 = AmineList.parse("[Drink, Man, Water, 23, fast]", mainLexicon); output.append("\nThe List " + amineListOnt1.toString(mainLexicon) + " with an ontology as background and English as Language."); Lexicon frenchLexicon = ontology.getLexicon(Identifier.wrap("french")); output.append("\nThe same list with the same ontology but the language is French : " + amineListOnt1.toString(frenchLexicon)); output.append("\nConvert the List to an amineSet and give the result in English : " + amineListOnt1.toAmineSet().toString(mainLexicon)); Object secondElem = amineListOnt1.get(1); if (secondElem instanceof Type) { Object defDescr = ((Type) secondElem).getDefinition(); output.append("\nThe second element of the above list is not an identifier but a Type CS : " + secondElem.toString()); output.append("\nAn identifier for " + secondElem.toString() + " is : " + ((Type) secondElem).toString(mainLexicon)); if (defDescr instanceof ToString) output.append("\nDefinition of " + ((Type) secondElem).toString(mainLexicon) + " is : " + ((ToString) defDescr).toString(mainLexicon)); } // Test 5 : Amine Object Operations (equals, maximalJoin, generalize, subsume) output.append("\n\n**************************************************\n"); output.append("\nTest 5 : Amine Object Operations (equals, maximalJoin, generalize, subsume)"); output.append("\nValue of the two lists : "); output.append("\namineEmbededList : " + amineEmbededList); AmineList copyOfEmineEmbededList = amineEmbededList.copy(); output.append("\ncopyOfEmineEmbededList : " + copyOfEmineEmbededList); AmineList newList = AmineList.parse("[bon, [345, \"this is a sentence\", 89], s]"); output.append("\nnewList : " + newList.toString(mainLexicon)); output.append("\nTest amineEmbededList.equal(copyOfEmineEmbededList) : " + amineEmbededList.equal(copyOfEmineEmbededList)); output.append("\nTest amineEmbededList.equal(newList) : " + amineEmbededList.equal(newList)); AmineList maximalJoinResult = (AmineList) amineEmbededList.maximalJoin(newList); output.append("\nTest amineEmbededList.maximalJoin(newList) : " + maximalJoinResult); AmineList generalizeResult = (AmineList) amineEmbededList.generalize(newList); output.append("\nTest amineEmbededList.generalize(newList) : " + generalizeResult); output.append("\nTest amineEmbededList.subsume(newList) : " + amineEmbededList.subsume(newList)); output.append("\nTest generalizeResult.subsume(newList) : " + generalizeResult.subsume(newList)); AmineList subsumeWithResult = (AmineList) generalizeResult.match(SUBSUME_WITH_RSLT, newList); output.append("\nTest generalizeResult.match(SUBSUME_WITH_RSLT, newList) : " + 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) { output.append(ex.getMessage()); } } public static void main(String[] args) { AmineListTest amineListTest = new AmineListTest(); amineListTest.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(-1); } }); } }