/** * Command Line Interface * @param args command line arguments */ public static void main(String[] args) throws IOException { CommandLineInterface cli = new CommandLineInterface(); cli.addOpt("-d", "directory", "./"); cli.addOpt("-a", "alpha", "" + DEFAULT_ALPHA); cli.addOpt("-s", "seed", null); cli.parse(args); if (cli.hasParam("--genprofile")) { cli.generateProfile(); } else if (cli.hasParam("--detectlang")) { cli.detectLang(); } else if (cli.hasParam("--batchtest")) { cli.batchTest(); } }
//initially set success result.setstatus("success"); for(int i = 0;i < work.length;i++){ if(!work[i].contains("#")){ CommandLineInterface CLI = new CommandLineInterface(); String IP = null; try { if(CLI.Setting(work[i],"start")) { result.setstatus("fail"); //no need to iterate further break; } } catch (JSchException | InterruptedException e) { e.printStackTrace(); } }
/** * Using all language profiles from the given directory. */ private LanguageDetector makeDetector() throws IOException { double alpha = getParamDouble("alpha", DEFAULT_ALPHA); String profileDirectory = requireParamString("directory") + "/"; Optional<Long> seed = Optional.fromNullable(getParamLongOrNull("seed")); List<LanguageProfile> languageProfiles = new LanguageProfileReader().readAll(new File(profileDirectory)); return LanguageDetectorBuilder.create(NgramExtractors.standard()) .alpha(alpha) .seed(seed) .shortTextAlgorithm(50) .withProfiles(languageProfiles) .build(); }
LanguageDetector languageDetector = makeDetector(); TextObjectFactory textObjectFactory = CommonTextObjectFactories.forDetectingOnLargeText(); result.get(correctLang).add("unknown"); if (hasParam("--debug")) System.out.println(correctLang + "," + lang + "," + (text.length() > 100 ? text.substring(0, 100) : text));
/** * 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() throws IOException { LanguageDetector languageDetector = makeDetector(); TextObjectFactory textObjectFactory = CommonTextObjectFactories.forDetectingOnLargeText(); for (String filename: arglist) { try (BufferedReader is = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "utf-8"))) { TextObject textObject = textObjectFactory.create().append(is); List<DetectedLanguage> probabilities = languageDetector.getProbabilities(textObject); System.out.println(filename + ":" + probabilities); } } }
/** * Using all language profiles from the given directory. */ private LanguageDetector makeDetector() throws IOException { double alpha = getParamDouble("alpha", DEFAULT_ALPHA); String profileDirectory = requireParamString("directory") + "/"; Optional<Long> seed = Optional.fromNullable(getParamLongOrNull("seed")); List<LanguageProfile> languageProfiles = new LanguageProfileReader().readAll(new File(profileDirectory)); return LanguageDetectorBuilder.create(NgramExtractors.standard()) .alpha(alpha) .seed(seed) .shortTextAlgorithm(50) .withProfiles(languageProfiles) .build(); }
int counter = 0; for(int i = 0;i < work.length;i++){ if(!work[i].contains("#")){ CommandLineInterface CLI = new CommandLineInterface(); String IP = null; boolean AResult; try { AResult = CLI.Setting(work[i],"start"); if (AResult) { counter++; } } catch (JSchException | InterruptedException e) { e.printStackTrace(); } } } if (work.length == 4 && counter == 4) { result.setstatus("success"); } else { result.setstatus("fail"); }
LanguageDetector languageDetector = makeDetector(); TextObjectFactory textObjectFactory = CommonTextObjectFactories.forDetectingOnLargeText(); result.get(correctLang).add("unknown"); if (hasParam("--debug")) System.out.println(correctLang + "," + lang + "," + (text.length() > 100 ? text.substring(0, 100) : text));
/** * 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() throws IOException { LanguageDetector languageDetector = makeDetector(); TextObjectFactory textObjectFactory = CommonTextObjectFactories.forDetectingOnLargeText(); for (String filename: arglist) { try (BufferedReader is = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "utf-8"))) { TextObject textObject = textObjectFactory.create().append(is); List<DetectedLanguage> probabilities = languageDetector.getProbabilities(textObject); System.out.println(filename + ":" + probabilities); } } }
/** * Command Line Interface * @param args command line arguments */ public static void main(String[] args) throws IOException { CommandLineInterface cli = new CommandLineInterface(); cli.addOpt("-d", "directory", "./"); cli.addOpt("-a", "alpha", "" + DEFAULT_ALPHA); cli.addOpt("-s", "seed", null); cli.parse(args); if (cli.hasParam("--genprofile")) { cli.generateProfile(); } else if (cli.hasParam("--detectlang")) { cli.detectLang(); } else if (cli.hasParam("--batchtest")) { cli.batchTest(); } }
boolean statusFlag = true; for(int i = 0;i < work.length;i++){ if(!work[i].contains("#")){ CommandLineInterface CLI = new CommandLineInterface(); String IP = null; boolean AResult; try { AResult = CLI.Setting(work[i],"start"); //true or false if(!AResult){ statusFlag = false; } } catch (JSchException | InterruptedException e) { e.printStackTrace(); } } } if(statusFlag){ result.setstatus("success"); }else{ result.setstatus("fail"); } }
int counter = 0; if (work.length == 4) { // <-- check the length first for (int i = 0; i < work.length; i++) { if (!work[i].contains("#")) { CommandLineInterface CLI = new CommandLineInterface(); try { if (CLI.Setting(work[i], "start")) { counter++; // <-- increment the counter. } else { break; // <-- break on any fale. } } catch (Exception e) { e.printStackTrace(); } } } } result.setstatus(counter == 4 ? "success" : "fail"); // <-- setstatus