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 : TermTest class
*Description : Test the Term API
* @author Adil KABBAJ * @version 2 */ public class TermTest extends JDialog implements AmineConstants { public TermTest() { this.setTitle("TermTest"); StringBuffer output = new StringBuffer(""); JScrollPane scrol; JTextArea text; try { // Test1 : Create, print and basic operations on Term Without Lexicon, Ontology ... Term simpleTerm = (Term) Term.parse("pere(Ahmad, Karim)"); output.append("\nA simple term : " + simpleTerm); Term embededTerm = (Term) Term.parse( "person(Ahmed, 34, address(453, \"Ishbilya road\", Rabat), TaxiDriver)"); output.append("\nAn embeded term : \n " + embededTerm); Term copyOfEmbededTerm = (Term) embededTerm.copy(); output.append("\nCopy of the embeded term : \n " + copyOfEmbededTerm); output.append("\nTest embededTerm.equal(copyOfEmbededTerm) : \n " + embededTerm.equal(copyOfEmbededTerm)); output.append("\nTest embededTerm.equal(null, null, copyOfEmbededTerm, null) : \n " + embededTerm.equal(null, null, copyOfEmbededTerm, null)); copyOfEmbededTerm.set(2, new Integer(69)); output.append("\nThe new value of copyOfEmbededTerm after the change of 34 by 69 : \n " + copyOfEmbededTerm); output.append("\nTest embededTerm.equal(copyOfEmbededTerm) after the change :\n " + embededTerm.equal(copyOfEmbededTerm)); output.append("\nTest embededTerm.equal(null, null, copyOfEmbededTerm, null) after the change :\n " + embededTerm.equal(null, null, copyOfEmbededTerm, null)); output.append("\nThe original embeded term has not been changed :\n " + embededTerm); output.append("\n****************************************************\n"); //********* Term 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(); Term termOnt1 = (Term) Term.parse("Drink(Man, Water, fast, [Car, Bus, Pxv])", mainLexicon); output.append("\nThe Term " + termOnt1.toString(mainLexicon) + " with an ontology as background and English as Language."); Lexicon frenchLexicon = ontology.getLexicon(Identifier.wrap("french")); output.append("\nThe same term with the same ontology but the language is French :\n " + termOnt1.toString(frenchLexicon)); Term termOnt2 = (Term) AmineList.parse( "Drink(Man, Water, qsV23, {Car, Vxv, Bus})", mainLexicon); Term termOnt3 = (Term) AmineList.parse( "Boire(Homme, Eau, qsV23, {Vxv, Voiture, Autobus})", frenchLexicon); output.append("\nis the term " + termOnt2.toString(mainLexicon) + "\n " + " equal to " + termOnt3.toString(frenchLexicon) + " : " + termOnt2.equal(termOnt3)); // Test 5 : Amine Object Operations (equals, maximalJoin, generalize, subsume) output.append("\n****************************************************\n"); output.append("\nTest 5 : Amine Object Operations (equals, maximalJoin, generalize, subsume)"); output.append("\nValue of the two Terms :\n "); Term term1 = (Term) Term.parse( "person(Ahmed, x, address(453, \"Casablanca Road\", v), TaxiDriver)"); output.append("\nTerm1 :" + term1); Term term2 = (Term) Term.parse("person(Ahmed, 34, address(453, R, Rabat), P)"); output.append("\nTerm2 : " + term2); Term term3 = (Term) Term.parse("person(Ahmed, 34, address(453, x, Rabat), y)"); output.append("\nTerm3 : " + term3); output.append("\nTest term2.equal(term3) : " + term2.equal(term3)); output.append("\nTest term1.equal(term2) : " + term1.equal(term2)); Term maximalJoinResult = (Term) term1.maximalJoin(term2); output.append("\nTest term1.maximalJoin(term2) :\n " + maximalJoinResult); Term generalizeResult = (Term) term1.generalize(term2); output.append("\nTest term1.generalize(term2) :\n " + generalizeResult); output.append("\nTest term1.subsume(term2) : " + term1.subsume(term2)); output.append("\nTest generalizeResult.subsume(term2) : " + generalizeResult.subsume(term2)); Term subsumeWithResult = (Term) generalizeResult.match(SUBSUME_WITH_RSLT, term2); output.append("\nTest generalizeResult.match(SUBSUME_WITH_RSLT, term2) :\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) { TermTest termTest = new TermTest(); termTest.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(-1); } }); } }