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

*

Description : Test the Concept API

* @author Adil KABBAJ * @version 2 */ public class ConceptTest extends JDialog implements AmineConstants { public ConceptTest() { this.setTitle("ConceptTest"); 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(); Concept conc1 = Concept.parse("[Man]", mainLexicon); output.append("\nA simple concept with type only : " + conc1.toString(mainLexicon)); Concept conc1a = Concept.parse("[Man : karim]", mainLexicon); output.append("\nA simple concept with type and specific individual :" + conc1a.toString(mainLexicon)); Concept conc1b = Concept.parse("[Man : {karim, michael, imad}]", mainLexicon); output.append("\nA simple concept with type and a set of designators :\n " + conc1b.toString(mainLexicon)); Concept conc1c = Concept.parse("[Man #23]", mainLexicon); output.append("\nA simple concept with type and a pseudo-designator : " + conc1c.toString(mainLexicon)); conc1 = Concept.parse("[Man : x]", mainLexicon); output.append("\nA simple concept with type and a variable designator : " + conc1.toString(mainLexicon)); Individual indImad = mainLexicon.getIndividualCS(Identifier.wrap("imad")); conc1.setDesignator(indImad); output.append("\nChange of the simple concept designator : " + conc1.toString(mainLexicon)); conc1.setCoreferent(new Variable("c")); output.append("\nAdding a coreferent to the simple concept : " + conc1.toString(mainLexicon)); Term term = (Term) Term.parse("agnt(Drink, Man(imad))", mainLexicon); conc1.setDescriptor(term); output.append("\nAdding a descriptor to the simple concept : \n " + conc1.toString(mainLexicon)); Concept copyOfConc1 = conc1.copy(); output.append("\nA copy of the simple concept : \n " + copyOfConc1.toString(mainLexicon)); copyOfConc1.setCoreferent(null); Term term2 = (Term) copyOfConc1.getDescriptor(); term2.set(1, "Walk"); output.append("\nThe copy of the simple concept after change; " + "\n coreference null and Drink is replaced by the string Walk : \n " + copyOfConc1.toString(mainLexicon)); CG cgDescr = CG.parse("[Man:imad]<-agnt-[Drink]", mainLexicon); copyOfConc1.setDescriptor(cgDescr); output.append("\nChange of the descriptor of the copy of the simple concept : \n " + copyOfConc1.toString(mainLexicon)); output.append("\nthe simple concept has not been changed (due to the change of its copy) : \n " + conc1.toString(mainLexicon)); Lexicon frenchLexicon = ontology.getLexicon(Identifier.wrap("french")); ontology.setMixedLanguage(true); output.append("\nThe same concept with the same ontology but the language is French :\n " + conc1.toString(frenchLexicon)); Concept concContext = Concept.parse("[Proposition = [Man]<-agnt-[Drink]-obj->[Water]]", mainLexicon); output.append("\nA concept that is a context : \n " + concContext.toString(mainLexicon)); output.append("\nAttempt to parse [Proposition = [Man]<-agnt-[Drink]-obj->[Fast]] "); try { concContext = Concept.parse("[Proposition = [Man]<-agnt-[Drink]-obj->[Fast]]", mainLexicon); output.append("\n").append(concContext.toString(mainLexicon)); } catch (Exception pEx) { output.append("\n").append(pEx.getMessage()); } output.append("\n\n**************************************************\n"); output.append("\nTest 5 : Amine Object Operations (equals, maximalJoin, generalize, subsume)"); output.append("\nConcept conc1 : " + conc1.toString(mainLexicon)); output.append("\nModified copy of conc1; copyOfConc1 :\n " + copyOfConc1.toString(mainLexicon)); output.append("\nTest of copyOfConc1.equal(conc1) : \n " + copyOfConc1.equal(conc1)); Concept conc2 = Concept.parse("[Man : x ?d = agnt(y, man(imad))]", mainLexicon); output.append("\nConcept conc2 : " + conc2.toString(mainLexicon)); output.append("\nTest of conc2.equal(conc1) : " + conc2.equal(conc1)); Concept maximalJoinResult = (Concept) conc1.maximalJoin(conc2); output.append("\nTest conc1.maximalJoin(conc2) : " + maximalJoinResult.toString(mainLexicon)); Concept generalizeResult = (Concept) conc1.generalize(conc2); output.append("\nTest conc1.generalize(conc2) : " + generalizeResult.toString(mainLexicon)); output.append("\nTest conc1.subsume(conc2) : " + conc1.subsume(conc2)); output.append("\nTest generalizeResult.subsume(conc2) : " + generalizeResult.subsume(conc2)); Concept subsumeWithResult = (Concept) generalizeResult.match(SUBSUME_WITH_RSLT, conc2); output.append("\nTest generalizeResult.match(SUBSUME_WITH_RSLT, conc2) :\n " + subsumeWithResult.toString(mainLexicon)); output.append("\n\n**************************************************\n"); output.append("\nAnother Test 5 : Amine Object Operations (equals, maximalJoin, generalize, subsume)"); conc1b = Concept.parse("[Man = [Person:imad]<-agnt-[Drink]]", mainLexicon); output.append("\nConcept conc1b : " + conc1b.toString(mainLexicon)); Concept conc2b = Concept.parse("[Man = [Man]<-agnt-[Action]]", mainLexicon); output.append("\nConcept conc2b : " + conc2b.toString(mainLexicon)); maximalJoinResult = (Concept) conc1b.maximalJoin(conc2b); output.append("\nTest conc1b.maximalJoin(conc2b) : " + maximalJoinResult.toString(mainLexicon)); generalizeResult = (Concept) conc1b.generalize(conc2b); output.append("\nTest conc1b.generalize(conc2b) : " + generalizeResult.toString(mainLexicon)); output.append("\nTest conc1b.subsume(conc2b) : " + conc1b.subsume(conc2b)); output.append("\nTest generalizeResult.subsume(conc2b) : " + generalizeResult.subsume(conc2b)); subsumeWithResult = (Concept) generalizeResult.match(SUBSUME_WITH_RSLT, conc2b); output.append("\nTest generalizeResult.match(SUBSUME_WITH_RSLT, conc2b) :\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) { ConceptTest conceptTest = new ConceptTest(); conceptTest.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(-1); } }); } }