/** * Add a user word to the OCR-dictionary. * * @param newword * @return */ public boolean AddUserWord(String newword) { if (!isValidWord(newword)) { BufferedWriter writer; try { writer = new BufferedWriter( new FileWriter(Mezzofanti.DATA_PATH + mConfig.GetLanguage() + ".user-words", true)); writer.write(newword + "\n"); writer.close(); closeNative(); openNative(mConfig.GetLanguage()); // change the validity in the local structure for (int i = 0; i < m_asWords.length; i++) { if (m_asWords[i].m_sBody.compareTo(newword) == 0) m_asWords[i].m_bIsValidWord = true; } return true; } catch (Exception e) { Log.v(TAG, e.toString()); return false; } } return false; }
/** constructor */ private OCR() { String text = libVer(); classInitNative(); initializeNativeDataNative(); mConfig.m_asLanguages = getLanguagesNative(); // this should be called at the beginning, // such a way nobody calls without a valid language // if not called, the recognizeNative will not work Log.v( TAG, "OCR Initialize() done - libver " + text + " no-langs-installed=" + mConfig.m_asLanguages.length); }
/** * Set the OCR-dictionary language * * @param lang the language to be set * @return true if language exists and was installed properly */ public boolean SetLanguage(String lang) { Log.v(TAG, "setLanguage to " + lang); if (mConfig.m_asLanguages == null) return false; Log.v(TAG, "noLangs=" + mConfig.m_asLanguages.length); for (int i = 0; i < mConfig.m_asLanguages.length; i++) if (mConfig.m_asLanguages[i].compareTo(lang) == 0) { mConfig.m_sLanguage = lang; openNative(lang); Log.v(TAG, "setLang succeded"); return true; } Log.v(TAG, "setLang failed"); return false; }
/** read the available OCR languages in the local vector */ public static void ReadAvailableLanguages() { mConfig.m_asLanguages = getLanguagesNative(); }