/* * [Vortaroj.java] * * Summary: All dictionaries that can lookup Esperanto to English. * * Copyright: (c) 2000-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 2.2 2008-04-06 add build to title, tidy code, fix spelling errors. */ package com.mindprod.esper; /** * All dictionaries that can lookup Esperanto to English. *

* No prefix/suffix logic. We chain them together to make them * look like one. * * @author Roedy Green, Canadian Mind Products * @version 2.2 2008-04-06 add build to title, tidy code, fix spelling errors. * @since 2000 */ public final class Vortaroj implements Lookup { /** * Utwente online dictionary */ private Lookup esperantoToEnglish; /** * cache of words previously looked up */ private Lookup kasxejo; /** * words we tried looking up before and failed */ private Lookup nekonato; /** * local dictionary, from Roedy, Geneva, Ergane */ private Lookup vortaro; /** * public constructor */ public Vortaroj() { } /** * Save any changes to this dictionary, and disconnect from it. */ public void close() { esperantoToEnglish.close(); kasxejo.close(); nekonato.close(); vortaro.close(); } // end close /** * Add a definition to the dictionary. * * @param word The word to be defined in the source language. If word already exists in dictionary, new * definition replaces. * @param definition The definition of the word in the target language. If null, removes existing definition. */ public void define( String word, String definition ) { } // declare lookup objects /** * Is it possible to define new words in this dictionary? * * @return true if you can add definitions, false otherwise. */ public boolean definePossible() { return false; } /** * Looks up a word in a dictionary. It does not do prefix or suffix splitting to help find words. That is the * responsibility of other levels. * * @param word Word to translate. Lead and trailing blanks removed. accents rendered with trailing x convention, at * least for now. Eventually will switch to unicode. * * @return word or phrase for the word translated, possibly with valid HTML, but no excess garbage characters. null * if no translation found. */ public String lookup( String word ) { // convert it to lower case word = word.toLowerCase(); // look it up it various local dictionaries first // start with cache String translation = kasxejo.lookup( word ); if ( translation == null ) { // main local dict translation = vortaro.lookup( word ); } if ( translation == null ) { // if we find it in the nekonato dict, there is no point in looking // it up // on the web. Contains previous failures. translation = nekonato.lookup( word ); // If we find it, we find a dummy entry "?" } if ( translation == null ) { // look up in web dictionary translation = esperantoToEnglish.lookup( word ); if ( translation != null && translation.length() < 200 ) { // add to local cache dictionary kasxejo.define( word, translation ); } else { // add to local unknown words dictionary translation = null; nekonato.define( word, "?" ); } } // correct dummy nekonato entry if ( translation != null && translation.equals( "?" ) ) { translation = null; } return translation; } /** * Open a connection to this dictionary. */ public void open() { // get translation lookup objects esperantoToEnglish = new UtwenteEOtoEN(); esperantoToEnglish.open(); kasxejo = new LocalDict( "kasxejo.dict", false ); kasxejo.open(); nekonato = new LocalDict( "nekonato.dict", false ); nekonato.open(); vortaro = new LocalDict( "vortaro.dict", false ); vortaro.open(); } // end open } // end Vortaroj