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

*

Description : Test the CG API

* @author Adil KABBAJ * @version 2 */ public class CGTest extends JDialog implements AmineConstants { public CGTest() { this.setTitle("CGTest"); 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(); output.append("\n*********** parseXXX() and toXXX() Examples ********"); CG cg1 = CG.parse("[Man:imad]<-agnt-[Drink]", mainLexicon); output.append("\nFrom LF input to LF output: \n " + cg1.toString(mainLexicon)); cg1 = CG.parse("(agnt [Drink] [Man:imad])", mainLexicon); output.append("\nFrom CGIF input to LF output: \n " + cg1.toLF(mainLexicon)); cg1 = CG.parseLF("[Man:imad]<-agnt-[Drink]", mainLexicon); output.append("\nFrom LF input to CGIF output: \n " + cg1.toCGIF(mainLexicon)); CG cg2 = CG.parse("[Drive]-\n" + "-obj->[Car],\n" + "-agnt->[Man: imad]-ageOf->[Age =25],\n" + "-manr->[Fast]", mainLexicon); output.append("\nFrom LF input to LF output (a more complex example): \n " + cg2.toLF(mainLexicon)); cg2 = CG.parseLF("[Drive]-\n" + "-obj->[Car],\n" + "-agnt->[Man: imad]-ageOf->[Age = 25],\n" + "-manr->[Fast]", mainLexicon); output.append("\nFrom LF input to CGIF output (a more complex example): \n " + cg2.toCGIF(mainLexicon)); cg2 = CG.parseCGIF("[Drive #0] [Man :imad] " + "(agnt #0 imad) (obj #0 [Car]) (manr #0 [Fast]) (ageOf imad [Intelligent])", mainLexicon); output.append("\nFrom CGIF input to LF output (a more complex example): \n " + cg2.toLF(mainLexicon)); CG.setFunctionalCG(false); cg2 = CG.parse("[Drive]-\n" + "-obj->[Car],\n" + "-agnt->[Woman],\n" + "-agnt->[Man: imad]-ageOf->[Age = 25],\n" + "-manr->[Fast]", mainLexicon); output.append("\nnon functional CG :\n " + cg2.toString(mainLexicon)); CG.setFunctionalCG(true); output.append("\nAttempt to parse non functional CG with functionalCG attribute true :"); try { cg2 = CG.parse("[Drive]-\n" + "-obj->[Car],\n" + "-agnt->[Woman],\n" + "-agnt->[Man: imad]-ageOf->[Age = 25],\n" + "-manr->[Fast]", mainLexicon); output.append("\nnon functional CG :\n " + cg2.toString(mainLexicon)); } catch (Exception ex) { output.append("\n").append(ex.getMessage()); } output.append("\nAttempt to parse the CG [Man:imad]<-agnt-[Drink]-obj->[Color]"); CG cg1B = null; try { output.append("\n******** Canonicity Error :"); cg1B = CG.parse("[Man:imad]<-agnt-[Drink]-obj->[Color]", mainLexicon); output.append("\n").append(cg1B.toString(mainLexicon)); } catch (Exception ex) { output.append("\n").append(ex.getMessage()); } CG.setCanonicity(false); cg1B = CG.parse("[Man:imad]<-agnt-[Drink]-obj->[Color]", mainLexicon); output.append("\nA non canonic cg cg1B (when canonicity is false) :\n " + cg1B.toString(mainLexicon)); Type drinkType = mainLexicon.getTypeCS(Identifier.wrap("Drink")); Concept concDrink = cg1B.findConceptWithType(drinkType); Concept concLook = Concept.parse("[Look]", mainLexicon); cg1B.replaceConcept(concDrink, concLook); output.append("\ncg1B after replacing [Drink] by [Look] :\n " + cg1B.toString(mainLexicon)); Concept concLookIn_cg1B = cg1B.findConcept(concLook); CG cgj = CG.parse("[Look]-manr->[Fast]", mainLexicon); Concept concLookIn_cgj = cgj.findConcept(concLook); CG cgRsltJoin = cg1B.join(concLookIn_cg1B, cgj, concLookIn_cgj); output.append("\nresult of join of [Look]-manr->[Fast] with cg1B around [Look]:\n " + cgRsltJoin.toString(mainLexicon)); output.append("\ncg1B has not been changed: \n " + cg1B.toString(mainLexicon)); CG copyOfCG1 = cg1.copy(); output.append("\nThe CG copyOfCG1, a copy of the simple CG cg1 : \n" + copyOfCG1.toString(mainLexicon)); Concept concWater = Concept.parse("[Water]", mainLexicon); copyOfCG1.addConcept(concWater); output.append("\nThe CG copyOfCG1 after the addition of the concept [Water]: \n " + copyOfCG1.toCGIF(mainLexicon)); // Get the Type CS of the type of name "Drink" //Type drinkType = mainLexicon.getTypeCS(Identifier.wrap("Drink")); concDrink = copyOfCG1.findConceptWithType(drinkType); RelationType relObjType = mainLexicon.getRelationTypeCS(Identifier.wrap("obj")); // Create a relation with the specified relation type, source and target concept copyOfCG1.addRelation(relObjType, concDrink, concWater); output.append("\nThe CG copyOfCG1 after the addition of the relation [Drink]-obj->[Water]: \n " + copyOfCG1.toString(mainLexicon)); output.append("\nthe simple CG cg1 has not been changed (due to the change of its copy) : \n " + cg1.toString(mainLexicon)); Lexicon frenchLexicon = ontology.getLexicon(Identifier.wrap("french")); ontology.setMixedLanguage(true); output.append("\nThe same CG cg1 with the same ontology but the language is French :\n " + cg1.toString(frenchLexicon)); output.append("\nGet all the concepts of the CG copyOfCG1 :"); Concept conc = null; for (Enumeration e = copyOfCG1.getConcepts(); e.hasMoreElements();) { conc = (Concept) e.nextElement(); output.append("\n ").append(conc.toString(mainLexicon)); } output.append("\nNumber of concepts in the CG copyOfCG1 : " + copyOfCG1.getNbrConcepts()); output.append("\nGet all the relations/branches of the CG copyOfCG1 :"); Relation relation = null; for (Enumeration e = copyOfCG1.getRelations(); e.hasMoreElements();) { relation = (Relation) e.nextElement(); output.append("\n ").append(relation.toString(mainLexicon)); } output.append("\nNumber of relations in the CG copyOfCG1 : " + copyOfCG1.getNbrRelations()); output.append("\nSelect a head (a concept) for the CG copyOfCG1 : " + copyOfCG1.selectHead().toString(mainLexicon)); output.append("\nThe CG copyOfCG1 (recall) :\n " + copyOfCG1.toString(mainLexicon)); output.append("\nRemove concept [Water] : copyOfCG1.removeConcept(concWater)"); copyOfCG1.removeConcept(concWater); output.append("\ncopyOfCG1 after the remove:\n " + copyOfCG1.toString(mainLexicon)); //Remove a relation of type obj from the CG cg1 cg1 = CG.parse("[Drive]-\n" + "-obj->[Object],\n" + "-agnt->[Person]", mainLexicon); output.append("\nThe CG cg1:\n " + cg1.toString(mainLexicon)); RelationType objType = mainLexicon.getRelationTypeCS(Identifier.wrap("obj")); Enumeration objRels = cg1.findRelations(objType); if (objRels != null) { Relation objRel = (Relation) objRels.nextElement(); cg1.removeRelation(objRel); output.append("\nThe CG cg1 after the remove of the relation obj :\n " + cg1.toString(mainLexicon)); } output.append("\nTest of equality copyOfCG1.equal(cg1) : " + copyOfCG1.equal(cg1)); output.append("\n*************************************************************\n"); output.append("\nTest : Canonical CG operations at the concept level (restrictXXX(), generalizeXXX() and analogizeType())"); output.append("\n\n********** RESTRICT EXAMPLES ***********************\n"); cg1 = CG.parse("[Drive]-\n" + "-obj->[Object],\n" + "-agnt->[Person]", mainLexicon); output.append("\nCG cg1 :\n " + cg1.toString(mainLexicon)); // Goal: restrict in cg1 the type Object of the concept [Object] to the type Car: // cg1.restrictType([Object], Car). But this call cannot be done immediately, it is // performed in several actions: // action #1: get, from the current lexicon, the Type CS of the identifier with name "Object" Type objectType = mainLexicon.getTypeCS(Identifier.wrap("Object")); // action #2: get the concept in cg1 with type Object Concept concToRestrict = cg1.getConceptWithType(objectType); // action #3: get, from the current lexicon, the Type CS of the identifier with name "Car" Type carType = mainLexicon.getTypeCS(Identifier.wrap("Car")); // action #4: do the restrictType operation cg1.restrictType(concToRestrict, carType); output.append("\nThe CG cg1 after the restriction of the type Object to Car:\n " + cg1.toString(mainLexicon)); Type busType = mainLexicon.getTypeCS(Identifier.wrap("Bus")); cg1.restrictType(concToRestrict, busType); output.append("\nThe CG cg1 after the attempt to restrict the type Car to Bus" + " \n (no restriction is done since Bus is not a subType of Car):\n " + cg1.toString(mainLexicon)); // Goal: restrict in cg1 the designator of the concept [Human] to imad: // cg1.restrictDesignator([Human], imad). // action #1: get, from the current lexicon, the Type CS of the identifier with name "Human" Type humanType = mainLexicon.getTypeCS(Identifier.wrap("Human")); // action #2: get the concept in cg1 with type Human concToRestrict = cg1.getConceptWithType(humanType); // action #3: get, from the current lexicon, the Individual CS of the identifier with name "imad" Individual imadIndividual = mainLexicon.getIndividualCS(Identifier.wrap("imad")); // action #4: do the restrictDesignator operation cg1.restrictDesignator(concToRestrict, imadIndividual); output.append("\nThe CG cg1 after the restriction of the designator of [Human] to imad:\n " + cg1.toString(mainLexicon)); output.append("\n********** GENERALIZE EXAMPLES ***********************\n"); cg1 = CG.parse("[Drive]-\n" + "-obj->[Car],\n" + "-agnt->[Man:imad]", mainLexicon); output.append("\nCG cg1 :\n " + cg1.toString(mainLexicon)); // Goal: Try to generalize in cg1 the type Car of the concept [Car] to the type Truck: // cg1.generalizeType([Car], Truck). // action #1: get, from the current lexicon, the Type CS of the identifier with name "Car" // Type carType = mainLexicon.getTypeCS(Identifier.wrap("Car")); we have already this information // action #2: get the concept in cg1 with type Car Concept concToGeneralize = cg1.getConceptWithType(carType); // action #3: get, from the current lexicon, the Type CS of the identifier with name "Truck" Type truckType = mainLexicon.getTypeCS(Identifier.wrap("Truck")); // action #4: do the restrictType operation cg1.generalizeType(concToGeneralize, truckType); output.append("\nThe CG cg1 after the attempt to generalize the type Car to Truck" + " \n (no generalization is done since Truck is not a superType of Car):\n " + cg1.toString(mainLexicon)); Type vehicleType = mainLexicon.getTypeCS(Identifier.wrap("Vehicle")); cg1.generalizeType(concToGeneralize, vehicleType); output.append("\nThe CG cg1 after the attempt to generalize the type Car to Vehicle :\n " + cg1.toString(mainLexicon)); // Goal: generalize in cg1 the designator of the concept [Man:imad] to nothing // cg1.generalizeDesignator([Man:imad]). // action #1: get, from the current lexicon, the Type CS of the identifier with name "Man" Type manType = mainLexicon.getTypeCS(Identifier.wrap("Man")); // action #2: get the concept in cg1 with type Man concToGeneralize = cg1.getConceptWithType(manType); // action #3: do the generalizeDesignator operation cg1.generalizeDesignator(concToGeneralize); output.append("\nThe CG cg1 after the generalization of the designator of [Man :imad]:\n " + cg1.toString(mainLexicon)); output.append("\n********** ANALOGIZE EXAMPLES ***********************\n"); cg1 = CG.parse("[Drive]-\n" + "-obj->[Car],\n" + "-agnt->[Man:imad]", mainLexicon); output.append("\nCG cg1 :\n " + cg1.toString(mainLexicon)); // Goal: Try to analogize in cg1 the type Car of the concept [Car] to the type Truck: // cg1.analogizeType([Car], Truck). Concept concToAnalogize = cg1.getConceptWithType(carType); cg1.analogizeType(concToAnalogize, truckType); output.append("\nThe CG cg1 after the attempt to analogize the type Car to Truck:\n " + cg1.toString(mainLexicon)); Type propositionType = mainLexicon.getTypeCS(Identifier.wrap("Proposition")); cg1.analogizeType(concToAnalogize, propositionType); output.append("\nThe CG cg1 after the attempt to analogize the type Truck to Proposition " + "\n (no analogy is done since Truck and Proposition has only the ontology root in common):\n " + cg1.toString(mainLexicon)); output.append("\n*************************************************************\n"); output.append("\nTest : Amine Object Operations (equals, maximalJoin, generalize, subsume, specialize, generalise)"); output.append("\n********** SPECIALIZE EXAMPLE ***********************\n"); CG CG1 = CG.parse("[Drive]-\n" + "-obj->[Car],\n" + "-agnt->[Person:{Bob, Andre}]", mainLexicon); output.append("\nCG1 before specialization :\n " + CG1.toString(mainLexicon)); cg2 = CG.parse("[Drive]-\n" + "-manr->[Fast],\n" + "-agnt->[Boy : {John, Bob, Sam}]", mainLexicon); output.append("\nCG cg2 :\n " + cg2.toString(mainLexicon)); CG1.specialize(cg2); output.append("\nCG1 after specialization :\n " + CG1.toString(mainLexicon)); output.append("\n\n********** MAXIMAL_JOIN EXAMPLES ***********************\n"); cg1 = CG.parse("[Drive]-\n" + "-obj->[Car],\n" + "-agnt->[Person:{Bob, Andre}]", mainLexicon); output.append("\nCG cg1 :\n " + cg1.toString(mainLexicon)); CG maximalJoinResult = (CG) cg1.maximalJoin(cg2); if (maximalJoinResult != null) output.append("\nTest cg1.maximalJoin(cg2) :\n " + maximalJoinResult.toString(mainLexicon)); output.append("\n****************************\n"); output.append("\nCG cg1 :\n " + cg1.toString(mainLexicon)); // Calling maximalJoin from CGOperations with entry concepts: // 1. Locate the entry concept [Person: {Bob, Andre}] in cg1 Type personType = mainLexicon.getTypeCS(Identifier.wrap("Person")); Concept entryConcept_cg1 = cg1.findConceptWithType(personType); // 2. Locate the entry concept [Boy : {John, Bob, Sam}] in cg2 Type boyType = mainLexicon.getTypeCS(Identifier.wrap("Boy")); Concept entryConcept_cg2 = cg2.findConceptWithType(boyType); // 3. Create an instance of CGOperations in order to call CG operations CGOperations cgOperations = new CGOperations(); // 4. Call maximalJoin operation ResMatchCG rsltMaximalJoin = cgOperations.maximalJoin(cg1, entryConcept_cg1, cg2, entryConcept_cg2); if (rsltMaximalJoin != null) output.append("\nTest cgOperations.maximalJoin(entryConcept_cg1, cg1, entryConcept_cg2, cg2) :\n" + rsltMaximalJoin.getCG().toString(mainLexicon)); output.append("\n****************************\n"); // maximalJoin with bootstrap by identical individuals cg1 = CG.parse("[Person:imad]-ageOf->[Age = 40]", mainLexicon); output.append("\nCG cg1 :\n " + cg1.toString(mainLexicon)); cg2 = CG.parse("[Person]<-agnt-[Hit]-\n" + "-obj->[Man:imad],\n" + "-instr->[Book]-poss->[Person]", mainLexicon); output.append("\nCG cg2 :\n " + cg2.toString(mainLexicon)); maximalJoinResult = (CG) cg1.maximalJoin(cg2); if (maximalJoinResult != null) output.append("\nTest cg1.maximalJoin(cg2) :\n " + maximalJoinResult.toString(mainLexicon)); else output.append("\n**** maximal join failed\n"); output.append("\n****************************\n"); // maximalJoin on nested CG with bootstrap coreferences cg1 = CG.parse("[Man *x]<-agnt-[Think]-obj->[Proposition = [Person ?x]-ageOf->[Age = 40]]", mainLexicon); output.append("\nCG cg1 :\n " + cg1.toString(mainLexicon)); cg2 = CG.parse("[Person *y]<-agnt-[Action]-obj->[Proposition = [Person]<-agnt-[Hit]-\n" + "-obj->[Man ?y],\n" + "-instr->[Book]-poss->[Person]]", mainLexicon); output.append("\nCG cg2 :\n " + cg2.toString(mainLexicon)); maximalJoinResult = (CG) cg1.maximalJoin(cg2); if (maximalJoinResult != null) output.append("\nTest cg1.maximalJoin(cg2) :\n " + maximalJoinResult.toString(mainLexicon)); else output.append("\n**** maximal join failed\n"); output.append("\n****************************\n"); // maximalJoin on nested CG with bootstrap coreferences cg1 = CG.parse("[Man *x]<-agnt-[Think]-obj->[Proposition = [Person ?x]-ageOf->[Age = 40]]", mainLexicon); output.append("\nCG cg1 :\n " + cg1.toString(mainLexicon)); cg2 = CG.parse("[Person]<-agnt-[Action]-obj->[Proposition = [Person]<-agnt-[Hit]-\n" + "-obj->[Man],\n" + "-instr->[Book]-poss->[Person]]", mainLexicon); output.append("\nCG cg2 :\n " + cg2.toString(mainLexicon)); maximalJoinResult = (CG) cg1.maximalJoin(cg2); if (maximalJoinResult != null) output.append("\nTest cg1.maximalJoin(cg2) :\n " + maximalJoinResult.toString(mainLexicon)); else output.append("\n**** maximal join failed\n"); output.append("\n****************************\n"); cg1 = CG.parse("[Drive]-\n" + "-obj->[Car],\n" + "-agnt->[Person:Andre]", mainLexicon); output.append("\nCG cg1 :\n " + cg1.toString(mainLexicon)); cg2 = CG.parse("[Drive]-\n" + "-manr->[Fast],\n" + "-agnt->[Boy : {John, Bob, Sam}]", mainLexicon); output.append("\nCG cg2 :\n " + cg2.toString(mainLexicon)); maximalJoinResult = (CG) cg1.maximalJoin(cg2); if (maximalJoinResult != null) output.append("\nTest cg1.maximalJoin(cg2) :\n " + maximalJoinResult.toString(mainLexicon)); else output.append("\n**** maximal join failed\n"); output.append("\n****************************\n"); CGOperations.setRelaxType(true); cg1 = CG.parse("[Drive]-\n" + "-obj->[Car],\n" + "-agnt->[Person : Mary]", mainLexicon); output.append("\nCG cg1 :\n" + cg1.toString(mainLexicon)); cg2 = CG.parse("[Drive]-\n" + "-manr->[Fast],\n" + "-agnt->[Boy : {John, Bob, Sam}]", mainLexicon); output.append("\nCG cg2 :\n" + cg2.toString(mainLexicon)); maximalJoinResult = (CG) cg1.maximalJoin(cg2); if (maximalJoinResult != null) output.append("\nTest cg1.maximalJoin(cg2) with parameter relaxType true:\n" + maximalJoinResult.toString(mainLexicon)); else output.append("\n**** maximal join failed\n"); output.append("\n****************************\n"); CGOperations.setRelaxType(false); maximalJoinResult = (CG) cg1.maximalJoin(cg2); if (maximalJoinResult != null) output.append("\nTest cg1.maximalJoin(cg2) :\n" + maximalJoinResult.toString(mainLexicon)); else output.append("\n**** maximal join failed\n"); output.append("\n****************************\n"); CGOperations.setCoerceDesignator(false); cg1 = CG.parse("[Drive]-\n" + "-obj->[Car],\n" + "-agnt->[Woman : Mary]", mainLexicon); output.append("\nCG cg1 :\n" + cg1.toString(mainLexicon)); cg2 = CG.parse("[Drive]-\n" + "-manr->[Fast],\n" + "-agnt->[Woman : Sue]", mainLexicon); output.append("\nCG cg2 :\n" + cg2.toString(mainLexicon)); maximalJoinResult = (CG) cg1.maximalJoin(cg2); if (maximalJoinResult != null) output.append("\nTest cg1.maximalJoin(cg2) with parameter CoerceDesignator false:\n" + maximalJoinResult.toString(mainLexicon)); else output.append("\n**** maximal join failed\n"); output.append("\n****************************\n"); CGOperations.setCoerceDesignator(true); maximalJoinResult = (CG) cg1.maximalJoin(cg2); if (maximalJoinResult != null) output.append("\nTest cg1.maximalJoin(cg2) with parameter CoerceDesignator true:\n" + maximalJoinResult.toString(mainLexicon)); else output.append("\n**** maximal join failed\n"); output.append("\n****************************\n"); cg1 = CG.parse("[Begin]-\n" + "-obj->[Session],\n" + "-srce->[Proposition = [Press]-\n" + "-obj->[Key : enter]-partOf->[Keyboard],\n" + "-agnt->[Person : John]],\n" + "-agnt->[Person : John]", mainLexicon); output.append("\nCG cg1 :\n" + cg1.toString(mainLexicon)); cg2 = CG.parse("[Begin]-\n" + "-obj->[Session],\n" + "-srce->[Proposition = [Press]-\n" + "-manr->[Fast],\n" + "-obj->[Key],\n" + "-agnt->[Man]],\n" + "-agnt->[Man]", mainLexicon); output.append("\nCG cg2 :\n" + cg2.toString(mainLexicon)); maximalJoinResult = (CG) cg1.maximalJoin(cg2); if (maximalJoinResult != null) output.append("\nTest cg1.maximalJoin(cg2) :\n" + maximalJoinResult.toString(mainLexicon)); output.append("\n****************************\n"); cg1 = CG.parse("[Begin]-\n" + "-obj->[Session],\n" + "-srce->[Proposition = [Press]-\n" + "-obj->[Key : enter]-partOf->[Keyboard],\n" + "-agnt->[Person]],\n" + "-agnt->[Person]", mainLexicon); output.append("\nCG cg1 :\n" + cg1.toString(mainLexicon)); cg2 = CG.parse("[Begin]-\n" + "-srce->[Proposition = [Look]-\n" + "-dest->[Person],\n" + "-pat->[Person]],\n" + "-agnt->[Man]", mainLexicon); output.append("\nCG cg2 :\n" + cg2.toString(mainLexicon)); maximalJoinResult = (CG) cg1.maximalJoin(cg2); if (maximalJoinResult != null) output.append("\nTest cg1.maximalJoin(cg2) :\n" + maximalJoinResult.toString(mainLexicon)); output.append("\n****************************\n"); cg1 = CG.parse("[Begin]-\n" + "-obj->[Session],\n" + "-srce->[Proposition = [Press]-\n" + "-obj->[Key : enter]-partOf->[Keyboard],\n" + "-agnt->[Person ?x]],\n" + "-agnt->[Person *x]", mainLexicon); output.append("\nCG cg1 :\n" + cg1.toString(mainLexicon)); cg2 = CG.parse("[Begin]-\n" + "-srce->[Proposition = [Look]-\n" + "-dest->[Person],\n" + "-pat->[Person]],\n" + "-agnt->[Man]", mainLexicon); output.append("\nCG cg2 :\n" + cg2.toString(mainLexicon)); maximalJoinResult = (CG) cg1.maximalJoin(cg2); if (maximalJoinResult != null) output.append("\nTest cg1.maximalJoin(cg2) :\n" + maximalJoinResult.toString(mainLexicon)); output.append("\n****************************\n"); output.append("\n\n********** GENERALISE EXAMPLE ***********************\n"); CG CGa = CG.parse("[Drive]-\n" + "-obj->[Car]-chrc->[Color : red],\n" + "-agnt->[Boy : John]", mainLexicon); output.append("\nCG CG1 before the generalisation :\n" + CGa.toString(mainLexicon)); cg2 = CG.parse("[Drive]-\n" + "-obj->[Truck],\n" + "-manr->[Fast],\n" + "-agnt->[Girl :Sue]", mainLexicon); output.append("\nCG cg2 :\n" + cg2.toString(mainLexicon)); CGa.generalise(cg2); output.append("\nCG CG1 after the generalisation :\n" + CGa.toString(mainLexicon)); output.append("\n***************************************************\n"); output.append("\n\n********** GENERALIZE EXAMPLES ***********************\n"); cg1 = CG.parse("[Drive]-\n" + "-obj->[Car]-chrc->[Color : red],\n" + "-agnt->[Boy : John]", mainLexicon); output.append("\nCG cg1 :\n" + cg1.toString(mainLexicon)); CG generalizeResult = (CG) cg1.generalize(cg2); if (generalizeResult != null) output.append("\nTest cg1.generalize(cg2) :\n" + generalizeResult.toString(mainLexicon)); output.append("\n****************************\n"); cg1 = CG.parse("[Person:{John,Sam,Sue,Mary}]<-agnt-[Drive]-obj->[Car]-chrc->[Color:red]", mainLexicon); output.append("\nCG cg1 :\n" + cg1.toString(mainLexicon)); cg2 = CG.parse("[Girl : {Sue, Mary}]<-agnt-[Drive]-" + "-obj->[Truck],\n" + "-manr->[Fast],\n", mainLexicon); output.append("\nCG cg2 :\n" + cg2.toString(mainLexicon)); generalizeResult = (CG) cg1.generalize(cg2); if (generalizeResult != null) output.append("\nTest cg1.generalize(cg2) :\n" + generalizeResult.toString(mainLexicon)); output.append("\n****************************\n"); cg1 = CG.parse("[Person:{John,Sam,Sue,Mary}]<-agnt-[Drive]-obj->[Car]-chrc->[Color:red]", mainLexicon); output.append("\nCG cg1 :\n" + cg1.toString(mainLexicon)); cg2 = CG.parse("[Girl : Sue]<-agnt-[Drive]-" + "-obj->[Truck],\n" + "-manr->[Fast],\n", mainLexicon); output.append("\nCG cg2 :\n" + cg2.toString(mainLexicon)); generalizeResult = (CG) cg1.generalize(cg2); if (generalizeResult != null) output.append("\nTest cg1.generalize(cg2) :\n" + generalizeResult.toString(mainLexicon)); output.append("\n****************************\n"); cg1 = CG.parse("[Begin]-\n" + "-obj->[Session],\n" + "-srce->[Proposition = [Press]-\n" + "-obj->[Key : enter]-partOf->[Keyboard],\n" + "-agnt->[Person ?x]],\n" + "-agnt->[Person *x]", mainLexicon); output.append("\nCG cg1 :\n" + cg1.toString(mainLexicon)); cg2 = CG.parse("[Man]<-agnt-[Begin]\n" + "-srce->[Proposition = [Boy]<-agnt-[Action]-dest->[Person] ]", mainLexicon); output.append("\nCG cg2 :\n" + cg2.toString(mainLexicon)); generalizeResult = (CG) cg1.generalize(cg2); if (generalizeResult != null) output.append("\nTest cg1.generalize(cg2) :\n" + generalizeResult.toString(mainLexicon)); output.append("\n****************************\n"); cg1 = CG.parse("[Begin]-\n" + "-obj->[Session],\n" + "-srce->[Proposition = [Press]-\n" + "-obj->[Key : enter]-partOf->[Keyboard],\n" + "-agnt->[Person ?x]],\n" + "-agnt->[Person *x]", mainLexicon); output.append("\nCG cg1 :\n" + cg1.toString(mainLexicon)); cg2 = CG.parse("[Man *y]<-agnt-[Begin]\n" + "-srce->[Proposition = [Boy ?y]<-agnt-[Action]-dest->[Person] ]", mainLexicon); output.append("\nCG cg2 :\n" + cg2.toString(mainLexicon)); generalizeResult = (CG) cg1.generalize(cg2); if (generalizeResult != null) output.append("\nTest cg1.generalize(cg2) :\n" + generalizeResult.toString(mainLexicon)); output.append("\n****************************\n"); output.append("\n\n********** SUBSUME & SUBSUME_WITH_RESULT EXAMPLES *****************\n"); cg1 = CG.parse("[Person]-childOf->[Person]", mainLexicon); output.append("\nCG cg1 :\n" + cg1.toString(mainLexicon)); CG.setCanonicity(false); cg2 = CG.parse("[Man:John]-childOf->[Boy:Bob]<-agnt-[Love]-obj->[Girl:Mary]", mainLexicon); output.append("\nCG cg2 :\n" + cg2.toString(mainLexicon)); CG subsumeResult = (CG) cg1.subsumeWithResult(cg2); output.append("\nTest cg1.subsume(cg2) : " + cg1.subsume(cg2)); if (subsumeResult != null) output.append("\nTest cg1.subsumeWithResult(cg2) :\n" + subsumeResult.toString(mainLexicon)); output.append("\n****************************\n"); cg1 = CG.parse("[Person]-childOf->[Person : {John, Sam}]", mainLexicon); output.append("\nCG cg1 :\n" + cg1.toString(mainLexicon)); cg2 = CG.parse("[Man:John]-childOf->[Boy:{Bob,John,Andre,Sam}]<-agnt-[Love]-obj->[Girl: Mary]", mainLexicon); output.append("\nCG cg2 :\n" + cg2.toString(mainLexicon)); subsumeResult = (CG) cg1.subsumeWithResult(cg2); output.append("\nTest cg1.subsume(cg2) : " + cg1.subsume(cg2)); if (subsumeResult != null) output.append("\nTest cg1.subsumeWithResult(cg2) :\n" + subsumeResult.toString(mainLexicon)); output.append("\n****************************\n"); cg1 = CG.parse("[Person]-childOf->[Person : {John, Sam}]", mainLexicon); output.append("\nCG cg1 :\n" + cg1.toString(mainLexicon)); cg2 = CG.parse("[Man:John]-childOf->[Boy:{Bob,John,Andre}]<-agnt-[Love]-obj->[Girl: Mary]", mainLexicon); output.append("\nCG cg2 :\n" + cg2.toString(mainLexicon)); subsumeResult = (CG) cg1.subsumeWithResult(cg2); output.append("\nTest cg1.subsume(cg2) : " + cg1.subsume(cg2)); if (subsumeResult != null) output.append("\nTest cg1.subsumeWithResult(cg2) :\n" + subsumeResult.toString(mainLexicon)); else output.append("\n**** subsumeWithResult failed "); output.append("\n****************************\n"); cg1 = CG.parse("[Person]<-agnt-[Begin]\n" + "-srce->[Proposition=[Person]<-agnt-[Action]-obj->[Object]]", mainLexicon); output.append("\nCG cg1 :\n" + cg1.toString(mainLexicon)); cg2 = CG.parse("[Begin]-\n" + "-obj->[Session],\n" + "-srce->[Proposition = [Press]-\n" + "-obj->[Key : enter]-partOf->[Keyboard],\n" + "-agnt->[Boy]],\n" + "-agnt->[Man]", mainLexicon); output.append("\nCG cg2 :\n" + cg2.toString(mainLexicon)); subsumeResult = (CG) cg1.subsumeWithResult(cg2); if (subsumeResult != null) output.append("\nTest cg1.subsumeWithResult(cg2) :\n" + subsumeResult.toString(mainLexicon)); else output.append("\n**** subsumeWithResult failed "); output.append("\n****************************\n"); cg1 = CG.parse("[Person *x]<-agnt-[Begin]\n" + "-srce->[Proposition=[Person *x]<-agnt-[Action]-obj->[Object]]", mainLexicon); output.append("\nCG cg1 :\n" + cg1.toString(mainLexicon)); cg2 = CG.parse("[Begin]-\n" + "-obj->[Session],\n" + "-srce->[Proposition = [Press]-\n" + "-obj->[Key : enter]-partOf->[Keyboard],\n" + "-agnt->[Boy]],\n" + "-agnt->[Man]", mainLexicon); output.append("\nCG cg2 :\n" + cg2.toString(mainLexicon)); subsumeResult = (CG) cg1.subsumeWithResult(cg2); if (subsumeResult != null) output.append("\nTest cg1.subsumeWithResult(cg2) :\n" + subsumeResult.toString(mainLexicon)); else output.append("\n**** subsumeWithResult failed "); output.append("\n"); output.append("\n****************************\n"); output.append("\n\n********** IS_CANONIC EXAMPLES *****************\n"); CG.setCanonicity(false); // we will accept to parse any CG and then we apply // the canonicity operation Type workType = mainLexicon.getTypeCS(Identifier.wrap("Work")); CG cg = (CG) workType.getCanon(); output.append("\nCanon of the concept type Work: \n" + cg.toLF(mainLexicon)); CG cg3 = CG.parse("[Man]<-agnt-[Work]-\n" + "-obj->[Finger],\n" + "-manr->[Hard],\n", mainLexicon); output.append("\nThe CG to check the canonicity :\n " + cg3.toLF(mainLexicon)); output.append("\nCheck canonicity of cg3; cg3.isCanonic() : " + cg3.isCanonic()); output.append("\n"); cg3 = CG.parse("[Man]<-agnt-[Work]-\n" + "-obj->[Job],\n" + "-manr->[Book],\n", mainLexicon); output.append("\nThe CG to check the canonicity :\n " + cg3.toLF(mainLexicon)); output.append("\nCheck canonicity of cg3; cg3.isCanonic() : " + cg3.isCanonic()); output.append("\n"); cg3 = CG.parse("[Man]<-agnt-[Work]-\n" + "-obj->[Job],\n" + "-manr->[Hard],\n", mainLexicon); output.append("\nThe CG to check the canonicity :\n " + cg3.toLF(mainLexicon)); output.append("\nCheck canonicity of cg3; cg3.isCanonic() : " + cg3.isCanonic()); output.append("\n"); output.append("\n\n********** EXPAND EXAMPLES *****************\n"); cg3 = CG.parse("[Man:imad]<-agnt-[Work]-\n" + "-obj->[Job],\n" + "-manr->[Hard],\n", mainLexicon); manType = mainLexicon.getTypeCS(Identifier.wrap("Man")); Concept concMan = cg3.findConceptWithType(manType); output.append("\nThe CG to expand :\n " + cg3.toLF(mainLexicon)); CG cgRslt = cg3.expand(concMan); if (cgRslt != null) output.append("\nExpand type Man; cg3.expand(concMan):\n" + cgRslt.toString(mainLexicon)); output.append("\n"); cg3 = CG.parse("[Man]<-agnt-[Action]-obj->[Intelligent_System]-chrc->[Hard]", mainLexicon); Type IntelligentSystem = mainLexicon.getTypeCS(Identifier.wrap("Intelligent_System")); Concept concIntelligentSystem = cg3.findConceptWithType(IntelligentSystem); output.append("\nThe CG to expand :\n " + cg3.toLF(mainLexicon)); cgRslt = cg3.expand(null, mainLexicon, concIntelligentSystem); if (cgRslt != null) output.append("\nExpand type Intelligent_System without considering canonicity; cg3.expand(concIntelligentSystem):\n" + cgRslt.toString(mainLexicon)); output.append("\n"); CG.setCanonicity(true); cgRslt = cg3.expand(null, mainLexicon, concIntelligentSystem); if (cgRslt != null) output.append("\nExpand type Intelligent_System taking into account canonicity; cg3.expand(concIntelligentSystem):\n" + cgRslt.toString(mainLexicon)); output.append("\n"); cg3 = CG.parse("[Man]-workOf->[TaxiDriver]-ageOf->[Age = 50],\n", mainLexicon); RelationType workOfType = mainLexicon.getRelationTypeCS(Identifier.wrap("workOf")); Relation relWorkOf = (Relation) cg3.findRelations(workOfType).nextElement(); output.append("\nThe CG to expand :\n " + cg3.toLF(mainLexicon)); cgRslt = cg3.expand(relWorkOf); if (cgRslt != null) output.append("\nExpand relation type workOf; cg3.expand(relWorkOf) :\n" + cgRslt.toString(mainLexicon)); output.append("\n"); 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) { CGTest cgTest = new CGTest(); cgTest.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(-1); } }); } }