package aminePlatform.test.kernel; /******************************************************************* 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 javax.swing.*; import java.util.*; import java.awt.event.*; import aminePlatform.kernel.lexicons.*; import aminePlatform.kernel.ontology.*; import aminePlatform.util.cg.*; import aminePlatform.util.*; import aminePlatform.guis.util.AmineFrame; /** *

Title : OntologyTest class

*

Description : Test the Lexicon API using the ontology ManOntology already * defined and stored in directory : aminePlatform.samples.ontology

* @author Adil KABBAJ * @version 2 */ public class OntologyTest extends JDialog { public OntologyTest() { this.setTitle("OntologyTest"); StringBuffer output = new StringBuffer(""); JScrollPane scrol; JTextArea text; Ontology ontology = null; Lexicon englishLexicon = null; // Load the Lexicons/Ontology that is stored in the specified file. try { ontology = Ontology.load(AmineFrame.ontologyDirPath + "ManOntology.ont"); englishLexicon = ontology.getMainLexicon(); Identifier Action = englishLexicon.getIdentifier("Action"); Identifier Drive = englishLexicon.getIdentifier("Drive"); Identifier Man = englishLexicon.getIdentifier("Man"); Identifier Person = englishLexicon.getIdentifier("Person"); Identifier typeIdent; output.append("Subtypes of ").append(Action).append(" : "); Enumeration e = englishLexicon.getSubTypes(Action); if (e != null) while (e.hasMoreElements()) { typeIdent = (Identifier) e.nextElement(); output.append(typeIdent).append(" "); } else output.append("none \n"); output.append("\n************************************"); output.append("\nMinimal common superType of ").append(Drive).append(" and "); output.append(Man).append(" is : "); Identifier minComSuperType = englishLexicon.getMinComSuperType(Drive, Man); output.append(minComSuperType).append("\n************************************"); Identifier fr = new Identifier("french"); output.append("\nSynonyms of ").append(Person).append(" in ").append(fr).append(": "); e = englishLexicon.getSynonyms(Person, fr); // returns an Enumeration if (e != null) while (e.hasMoreElements()) { typeIdent = (Identifier) e.nextElement(); output.append(typeIdent).append(" "); } else output.append("none \n"); Type ManType = englishLexicon.getTypeCS(Man); // The definition of Man in CG CG cg = (CG) ManType.getDefinition(); // Note the casting to CG if (cg != null) { String cgTxt = cg.toCGIF(englishLexicon); output.append("\nDefinition of ").append(Man).append(" is :").append(cgTxt); } /*** The definition of Man in Text String text = (String) ManType.getDefinition(); // Note the casting to String if (text != null) { System.out.println("Definition of " + Man + " is :\n" + text); } ***/ // The definition of Man in Term //Term term = (Term) ManType.getDefinition(); // Note the casting to Term Object descrMan = ManType.getDefinition(); if (descrMan instanceof ToString) { //System.out.println("Definition of Man in English is : " + ((ToString) descrMan).toString(englishLexicon)); output.append("\nDefinition of Man in English is : \n"); output.append(((ToString) descrMan).toString(englishLexicon)); } output.append("\n************************************"); Lexicon frenchLexicon = ontology.getLexicon(fr); output.append("\nDefinition of Man in French is : \n"); output.append(((ToString) ManType.getDefinition()).toString(frenchLexicon)); output.append("\n************************************"); output.append("\nA situation for Man in English : \n"); output.append(((ToString) ManType.getSituationAt(1).getDescription()).toString(englishLexicon)); output.append("\n************************************"); output.append("\nThe situation in French : \n"); output.append(((ToString) ManType.getSituationAt(1).getDescription()).toString(frenchLexicon)); 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){ ex.printStackTrace(); } } public static void main(String[] args) { OntologyTest ontologyTest = new OntologyTest(); ontologyTest.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(-1); } }); } }