if (hasOpt("--debug")) System.out.println(correctLang + "," + lang + "," + (text.length()>100?text.substring(0, 100):text));
/** * Command Line Interface * @param args command line arguments */ public static void main(String[] args) { Command command = new Command(); command.addOpt("-d", "directory", "./"); command.addOpt("-a", "alpha", "" + DEFAULT_ALPHA); command.addOpt("-s", "seed", null); command.addOpt("-l", "lang", null); command.parse(args); if (command.hasOpt("--genprofile")) { command.generateProfile(); } else if (command.hasOpt("--genprofile-text")) { command.generateProfileFromText(); } else if (command.hasOpt("--detectlang")) { command.detectLang(); } else if (command.hasOpt("--batchtest")) { command.batchTest(); } }
/** * Language detection test for each file (--detectlang option) * * <pre> * usage: --detectlang -d [profile directory] -a [alpha] -s [seed] [test file(s)] * </pre> * */ public void detectLang() { if (loadProfile()) return; for (String filename: arglist) { BufferedReader is = null; try { is = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "utf-8")); Detector detector = DetectorFactory.create(getDouble("alpha", DEFAULT_ALPHA)); if (hasOpt("--debug")) detector.setVerbose(); detector.append(is); System.out.println(filename + ":" + detector.getProbabilities()); } catch (IOException e) { e.printStackTrace(); } catch (LangDetectException e) { e.printStackTrace(); } finally { try { if (is!=null) is.close(); } catch (IOException e) {} } } }