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 aminePlatform.kernel.lexicons.*; import aminePlatform.kernel.ontology.*; import aminePlatform.util.cg.*; import aminePlatform.util.*; import javax.swing.*; import java.util.*; import java.awt.event.*; /** *
Title : LexiconTest class
*Description : Test of the Lexicon API
* @author Karim Bouzoubaa * @version 2 */ public class LexiconTest extends JDialog { public LexiconTest() { this.setTitle("LexiconTest"); StringBuffer output = new StringBuffer(""); String englishLexiconName; JScrollPane scrol; JTextArea text; Lexicon englishLexicon, frenchLexicon; Ontology ontology; Identifier mainLanguage, rootType, relationRootType; rootType = new Identifier("Univ"); relationRootType = new Identifier("Relation"); mainLanguage = new Identifier("The English language"); output.append(" ----------- RESULTS ------------\n"); try { ontology = new Ontology(rootType, relationRootType, mainLanguage); ontology.setName("myTestOntology"); englishLexicon = ontology.getLexicon(mainLanguage); englishLexiconName = englishLexicon.getLanguage().getName(); ontology.setMainLexicon(englishLexicon); output.append("\n The language of the current lexicon is: ").append(englishLexiconName); englishLexicon.replaceLanguageName("English"); englishLexiconName = englishLexicon.getLanguage().getName(); output.append("\n The new language of the current lexicon is: ").append(englishLexiconName); output.append("\n The lexicon " + englishLexiconName + " is the main lexicon: " + englishLexicon.isMainLexicon()); englishLexicon.replaceIdentifierName(rootType, "Universal"); Identifier action = new Identifier("Action"); englishLexicon.addEntry(action, null); Identifier verb = new Identifier("Verb"); englishLexicon.addConceptTypeEntry(verb); Identifier object = new Identifier("Object"); if (englishLexicon.addConceptTypeEntry(object, null)) output.append("\n Addition of type Object: Done"); else output.append("\n Addition of type Object: Already in the lexicon"); output.append("\n The identifiers currently in the lexicon are: "); for (Enumeration e = englishLexicon.getIdentifiers(); e.hasMoreElements();) { output.append(e.nextElement()).append(" "); } output.append("\n The identifier " + relationRootType.getName() + " is in the lexicon " + englishLexiconName + ": " + englishLexicon.isIdentifierKnown(relationRootType)); output.append("\n The identifier Animate is in the lexicon " + englishLexiconName + ": " + englishLexicon.isIdentifierKnown("Animate")); ArrayList listIdents = new ArrayList(); listIdents.add(relationRootType); listIdents.add(action); listIdents.add(verb); listIdents.add(object); Object[] idents = listIdents.toArray(); englishLexicon.linkSubTypesToType(idents, rootType); listIdents.clear(); Enumeration iterator; output.append("\n Direct subtypes of " + rootType.getName() + " are: "); iterator = englishLexicon.getDirectSubTypes(rootType); if (iterator != null && iterator.hasMoreElements()) { while (iterator.hasMoreElements()) { output.append(" ").append(((Identifier) iterator.nextElement()).getName()); }; } else output.append("no direct subtypes of ").append(rootType.getName()); output.append("\n Attempt to delete entry " + object.getName() + " from lexicon " + englishLexiconName); if (englishLexicon.removeEntry(object)) { output.append("\n Deletion done"); output.append("\n Direct subtypes of " + rootType.getName() + " are: "); iterator = englishLexicon.getDirectSubTypes(rootType); if (iterator != null && iterator.hasMoreElements()) { while (iterator.hasMoreElements()) { output.append(" " + ((Identifier) iterator.nextElement()).getName()); }; } else output.append("\n No direct subtypes of " + rootType.getName()); } else output.append("\n Deletion impossible"); Identifier eat = new Identifier("Eat"); Object[] arr = new Object[2]; arr[0] = verb; arr[1] = action; englishLexicon.linkTypeToSuperTypes(eat, arr) ; output.append("\n Direct supertypes of " + eat.getName() + " are: "); iterator = englishLexicon.getDirectSuperTypes(eat); if (iterator != null && iterator.hasMoreElements()) { while (iterator.hasMoreElements()) { output.append(" " + ((Identifier) iterator.nextElement()).getName()); }; } else output.append("no direct subtypes of " + rootType.getName()); output.append("\n The maximum common sub type between " + verb.getName() + " and " + action.getName() + " is: " + englishLexicon.getMaxComSubType(verb, action).getName()); output.append("\n The maximum common sub type between " + object.getName() + " and " + eat.getName() + " is: "); if (englishLexicon.getMaxComSubType(object, eat) != null) output.append(englishLexicon.getMaxComSubType(object, eat).getName()); else output.append("none"); output.append("\n The minimum common super type between " + verb.getName() + " and " + action.getName() + " is: " + englishLexicon.getMinComSuperType(verb, action).getName()); output.append("\n The minimum common super type between " + verb.getName() + " and " + eat.getName() + " is: " + englishLexicon.getMinComSuperType(verb, eat).getName()); frenchLexicon = new Lexicon(new Identifier("French"), ontology); output.append( "\n Addition of a new lexicon: " + frenchLexicon.getLanguage().getName()); output.append("\n The languages of the ontology " + ontology.getName() + " are: "); iterator = ontology.getLanguages(); while (iterator.hasMoreElements()) output.append(" " + ((Identifier) iterator.nextElement()).getName()); Identifier frenchLanguage = frenchLexicon.getLanguage(); output.append("\n Addition of a synonym for the type " + eat.getName() + " of language " + frenchLanguage.getName()); englishLexicon.addSynonym(new Identifier("Manger"), frenchLanguage, eat); output.append("\n The synonyms of " + eat.getName() + " of language " + frenchLanguage.getName() + " are: "); iterator = englishLexicon.getSynonyms(eat, frenchLanguage); if (iterator != null && iterator.hasMoreElements()) { while (iterator.hasMoreElements()) output.append(" " + ((Identifier) iterator.nextElement()).getName()); } Identifier personne = new Identifier("Personne"); frenchLexicon.addConceptTypeEntry(personne); frenchLexicon.addSynonym(new Identifier("Humain"), personne); arr[0] = new Identifier("Person"); arr[1] = new Identifier("Human"); frenchLexicon.addSynonyms(arr, englishLexicon.getLanguage(), personne); output.append("\n The synonyms of " + personne.getName() + " of language " + frenchLanguage.getName() + " are: "); iterator = englishLexicon.getSynonyms((Identifier) arr[0], frenchLanguage); output.append("\n - in " + frenchLanguage + ": "); if (iterator != null && iterator.hasMoreElements()) { while (iterator.hasMoreElements()) output.append(" " + ((Identifier) iterator.nextElement()).getName()); } iterator = englishLexicon.getSynonyms((Identifier) arr[0], englishLexicon.getLanguage()); output.append("\n - in " + englishLexicon.getLanguage() + ": "); if (iterator != null && iterator.hasMoreElements()) { while (iterator.hasMoreElements()) output.append(" " + ((Identifier) iterator.nextElement()).getName()); } } //try catch (LexiconException le) { System.out.print("\n" + le); } catch (OntologyException oe) { System.out.print("\n" + oe); } 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(); } // main public static void main(String[] args) { LexiconTest lexiconTest = new LexiconTest(); lexiconTest.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(-1); } }); } } // LexiconTest