package aminePlatform.samples.buildOntology; /******************************************************************* 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 java.util.*; import javax.swing.*; import java.awt.event.*; import java.io.File; import aminePlatform.kernel.lexicons.*; import aminePlatform.kernel.ontology.*; import aminePlatform.util.*; import aminePlatform.util.cg.*; import aminePlatform.util.parserGenerator.*; import aminePlatform.guis.util.*; /** *
Title : BuildManOntology class
*Description : BuildManOntology creates an Ontology that is used by other classes * and it illustrate the Ontology API
* @author Adil KABBAJ * @version 2 */ public class BuildManOntology { public BuildManOntology() { Identifier english = new Identifier("English"); Identifier rootIdentifier = new Identifier("Universal"); Identifier rootRelIdentifier = new Identifier("Relation"); try { Ontology ontology = new Ontology(rootIdentifier, rootRelIdentifier, english); Lexicon englishLexicon = ontology.getLexicon(english); Identifier Object = new Identifier("Object"); Identifier Animal = new Identifier("Animal"); Identifier Human = new Identifier("Human"); Identifier Action = new Identifier("Action"); Identifier Situation = new Identifier("Situation"); Identifier Attribute = new Identifier("Attribute"); Object[] objs = {Object, Animal, Human, Action, Situation, Attribute}; englishLexicon.linkSubTypesToType(objs, rootIdentifier); Identifier Proposition = new Identifier("Proposition"); englishLexicon.linkConceptTypeToSuperType(Proposition, Situation); Identifier agnt = new Identifier("agnt"); Identifier instr = new Identifier("instr"); Identifier sexOf = new Identifier("sexOf"); Identifier ageOf = new Identifier("ageOf"); Identifier intelligenceOf = new Identifier("intelligenceOf"); Identifier obj = new Identifier("obj"); Identifier pat = new Identifier("pat"); Identifier srce = new Identifier("srce"); Identifier chrc = new Identifier("chrc"); Identifier dest = new Identifier("dest"); Identifier partOf = new Identifier("partOf"); Identifier manr = new Identifier("manr"); Identifier poss = new Identifier("poss"); Identifier childOf = new Identifier("childOf"); Identifier workOf = new Identifier("workOf"); objs = new Object[] {agnt, instr, obj, pat, srce, chrc, dest, partOf, manr, childOf, workOf, poss, sexOf, intelligenceOf, ageOf}; englishLexicon.linkSubTypesToType(objs, rootRelIdentifier); Identifier Vehicle = new Identifier("Vehicle"); Identifier Machine = new Identifier("Machine"); Identifier Key = new Identifier("Key"); Identifier Keyboard = new Identifier("Keyboard"); Identifier Finger = new Identifier("Finger"); Identifier Book = new Identifier("Book"); Identifier ConsomableObject = new Identifier("ConsomableObject"); Identifier AbstractEntity = new Identifier("AbstractEntity"); objs = new Object[] {Vehicle, Machine, Key, Keyboard, Finger, Book, AbstractEntity, ConsomableObject}; englishLexicon.linkSubTypesToType(objs, Object); Identifier Fast = new Identifier("Fast"); Identifier Hard = new Identifier("Hard"); Identifier Age = new Identifier("Age"); Identifier Intelligent = new Identifier("Intelligent"); Identifier Color = new Identifier("Color"); Identifier Sex = new Identifier("Sex"); objs = new Object[] {Fast, Hard, Intelligent, Color, Sex, Age}; englishLexicon.linkSubTypesToType(objs, Attribute); Identifier Car = new Identifier("Car"); Identifier Bus = new Identifier("Bus"); Identifier Truck = new Identifier("Truck"); objs = new Object[] {Car, Bus, Truck}; englishLexicon.linkSubTypesToType(objs, Vehicle); Identifier Apple = new Identifier("Apple"); Identifier Bananas = new Identifier("Bananas"); Identifier Liquid = new Identifier("Liquid"); objs = new Object[] {Apple, Bananas, Liquid}; englishLexicon.linkSubTypesToType(objs, ConsomableObject); Identifier Water = new Identifier("Water"); Identifier Jus = new Identifier("Jus"); objs = new Object[] {Water, Jus}; englishLexicon.linkSubTypesToType(objs, Liquid); Identifier Session = new Identifier("Session"); Identifier Job = new Identifier("Job"); Identifier systemIdent = new Identifier("System"); Identifier Area = new Identifier("Area"); Identifier Urban = new Identifier("Urban"); objs = new Object[] {Job, Session, systemIdent, Area, Urban}; englishLexicon.linkSubTypesToType(objs, AbstractEntity); Identifier Intelligent_System = new Identifier("Intelligent_System"); objs = new Object[] {systemIdent, Intelligent}; englishLexicon.linkTypeToSuperTypes(Intelligent_System, objs); Identifier Man = new Identifier("Man"); Identifier Woman = new Identifier("Woman"); objs = new Object[] {Man, Woman}; englishLexicon.linkSubTypesToType(objs, Human); Identifier Boy = new Identifier("Boy"); englishLexicon.linkTypeToSuperType(Boy, Man); Identifier Girl = new Identifier("Girl"); englishLexicon.linkTypeToSuperType(Girl, Woman); Identifier TaxiDriver = new Identifier("TaxiDriver"); Identifier Scientist = new Identifier("Scientist"); objs = new Object[] {TaxiDriver, Scientist}; englishLexicon.linkSubTypesToType(objs, Job); Identifier AIScientist = new Identifier("AIScientist"); objs = new Object[] {Man, Scientist}; englishLexicon.linkTypeToSuperTypes(AIScientist, objs); Identifier Drink = new Identifier("Drink"); Identifier Drive = new Identifier("Drive"); Identifier Eat = new Identifier("Eat"); Identifier Walk = new Identifier("Walk"); Identifier Hit = new Identifier("Hit"); Identifier Go = new Identifier("Go"); Identifier Love = new Identifier("Love"); Identifier Break = new Identifier("Break"); Identifier Build = new Identifier("Build"); Identifier Rent = new Identifier("Rent"); Identifier Begin = new Identifier("Begin"); Identifier Press = new Identifier("Press"); Identifier Look = new Identifier("Look"); Identifier Work = new Identifier("Work"); Identifier Think = new Identifier("Think"); Identifier Believe = new Identifier("Believe"); Identifier Read = new Identifier("Read"); objs = new Object[] {Drink, Drive, Eat, Walk, Go, Love, Break, Build, Rent, Begin, Press, Look, Work, Think, Believe, Read, Hit}; englishLexicon.linkSubTypesToType(objs, Action); // add individuals to a Type Identifier imad = new Identifier("imad"); Identifier michael = new Identifier("michael"); Identifier karim = new Identifier("karim"); objs = new Object[] {imad, michael, karim}; englishLexicon.linkIndividualsToType(objs, Man); Identifier John = new Identifier("John"); Identifier Bob = new Identifier("Bob"); Identifier Andre = new Identifier("Andre"); Identifier Sam = new Identifier("Sam"); objs = new Object[] {John, Bob, Andre, Sam}; englishLexicon.linkIndividualsToType(objs, Boy); Identifier Mary = new Identifier("Mary"); Identifier Sue = new Identifier("Sue"); objs = new Object[] {Mary, Sue}; englishLexicon.linkIndividualsToType(objs, Girl); Identifier enter = new Identifier("enter"); englishLexicon.linkIndividualToType(enter, Key); Identifier red = new Identifier("red"); englishLexicon.linkIndividualToType(red, Color); // add Synonyms Identifier Person = new Identifier("Person"); englishLexicon.addSynonym(Person, Human); Identifier Personne = new Identifier("Personne"); Identifier Humain = new Identifier("Humain"); objs = new Object[] {Personne, Humain}; Identifier fr = new Identifier("french"); englishLexicon.addSynonyms(objs, fr, Human); Identifier Eau = new Identifier("Eau"); englishLexicon.addSynonym(Eau, fr, Water); Identifier Rapide = new Identifier("Rapide"); englishLexicon.addSynonym(Rapide, fr, Fast); englishLexicon.addSynonym(new Identifier("Homme"), fr, Man); englishLexicon.addSynonym(new Identifier("Femme"), fr, Woman); englishLexicon.addSynonym(new Identifier("Boire"), fr, Drink); englishLexicon.addSynonym(new Identifier("Conduire"), fr, Drive); englishLexicon.addSynonym(new Identifier("Sexe"), fr, Sex); englishLexicon.addSynonym(new Identifier("Voiture"), fr, Car); englishLexicon.addSynonym(new Identifier("Autobus"), fr, Bus); englishLexicon.addSynonym(new Identifier("Objet"), fr, Object); // add CS Type ManType = englishLexicon.getTypeCS(Man); // add definitions // Concept type definition ManType.setDefinition(CG.parseLF("[Human:super]-sexOf->[Sex = male]", englishLexicon)); // in CG //ManType.setDefinition("is a Person with a sexe male"); // in Text //ManType.setDefinition(Term.parse("Person(sex(male))", englishLexicon)); // in Term Type IntelligentSystemType = englishLexicon.getTypeCS(Intelligent_System); CG cgIntelligentSystemDef = CG.parseLF("[Intelligent:super]<-intelligenceOf-[System:super]<-obj-[Build]-agnt->[AIScientist]", englishLexicon); //System.out.println(cgIntelligentSystemDef.toCGIF(englishLexicon)); IntelligentSystemType.setDefinition(cgIntelligentSystemDef); // Relation type definition Type workOfType = englishLexicon.getTypeCS(workOf); CG relDef = CG.parse("[Person:x_source]<-agnt-[Work]-obj->[Job:y_target]", englishLexicon); workOfType.setDefinition(relDef); // add canons // Canon for a concept type Type WorkType = englishLexicon.getTypeCS(Work); WorkType.setCanon(CG.parseLF("[Person]<-agnt-[Work]-obj->[Job]", englishLexicon)); // Canon for a relation type Type manrType = englishLexicon.getTypeCS(manr); manrType.setCanon(CG.parseLF("[Action]-manr->[Attribute]", englishLexicon)); Type objType = englishLexicon.getTypeCS(obj); objType.setCanon(CG.parseLF("[Action]-obj->[Object]", englishLexicon)); // add situations ManType.addSituation(CG.parseLF("[Man]<-agnt-[Drink]-obj->[Water]", englishLexicon)); // in CG //ManType.addSituation("Man drinks water"); // in Text //ManType.addSituation(Term.parse("Drink(Man, Water)", englishLexicon)); // in Term ManType.addSituation(CG.parseLF("[Man]<-agnt-[Drive]-instr->[Car]", englishLexicon)); //ManType.addSituation("Man drives car"); //ManType.addSituation(Term.parse("Drive(Man, Car)", englishLexicon)); // Save the new created Lexicons/Ontology in the .ont and in .xml forms // in aminePlatform.samples.ontology. try { // Save the Lexicon/Ontology, by serialisation of Java object(s), in the specified file. ontology.store(AmineFrame.ontologyDirPath + "ManOntology.ont"); // Save the Lexicon/Ontology in the specified XML file. ontology.storeInXML(AmineFrame.ontologyDirPath + "ManOntology.xml"); } catch (Exception ex){ ex.printStackTrace(); } /***************** // Visualize the Ontology (Optional) TextualDisplayOntology txtDsplyOntFrm = new TextualDisplayOntology(ontology); txtDsplyOntFrm.displayOntology(); txtDsplyOntFrm.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(-1); } }); *******************/ } catch (Exception ex) { System.out.println(ex.getMessage()); ex.printStackTrace(); } } public static void main(String[] args) { new BuildManOntology(); } }