Komoran implements Cloneable { public List<KomoranResult> analyze(List<String> sentences, int thread) { List<KomoranResult> komoranResultList = new ArrayList<>(); try { List<Future<KomoranResult>> komoranResultFutureList = new ArrayList<>(); ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(thread); for (String line : sentences) { KomoranCallable komoranCallable = new KomoranCallable(this, line); komoranResultFutureList.add(executor.submit(komoranCallable)); } for (Future<KomoranResult> komoranResultFuture : komoranResultFutureList) { komoranResultList.add(komoranResultFuture.get()); } executor.shutdown(); } catch (Exception e) { e.printStackTrace(); } return komoranResultList; } Komoran(String modelPath);  Komoran(DEFAULT_MODEL modelType); void analyzeTextFile(String inputFilename, String outputFilename, int thread); List<KomoranResult> analyze(List<String> sentences, int thread); KomoranResult analyze(String sentence); double scoreDebug(List<String> analyzeResultList, List<String> analyzePosList); List<KomoranResult> analyze(String sentence, int nbest); void setFWDic(String filename); void setUserDic(String userDic);  }
@Test public void speedTest() throws Exception { Komoran komoran = new Komoran(DEFAULT_MODEL.STABLE); int totalTestCount = 10; int totalElapsedTime = 0; int step = 0; while (true) { InputStreamReader inputStreamReader = new InputStreamReader(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream("stress.test")), StandardCharsets.UTF_8); BufferedReader br = new BufferedReader(inputStreamReader); String line; long begin, end; long elapsedTime = 0L; while ((line = br.readLine()) != null) { begin = System.currentTimeMillis(); komoran.analyze(line); end = System.currentTimeMillis(); elapsedTime += (end - begin); } br.close(); System.out.println("Step " + step + " : " + elapsedTime); if (step == 0) { elapsedTime = 0; } totalElapsedTime += elapsedTime; step++; if (step == totalTestCount + 1) break; } System.out.println("Avg. ElapsedTime : " + totalElapsedTime / totalTestCount); }
@Test public void singleThreadSpeedTest() throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter("analyze_result.txt")); List<String> lines = FileUtil.load2List("user_data/wiki.titles"); List<KomoranResult> komoranList = new ArrayList<>(); long begin = System.currentTimeMillis(); int count = 0; for (String line : lines) { komoranList.add(this.komoran.analyze(line)); if (komoranList.size() == 1000) { for (KomoranResult komoranResult : komoranList) { bw.write(komoranResult.getPlainText()); bw.newLine(); } komoranList.clear(); } count++; if (count % 10000 == 0) { System.out.println(count); } } for (KomoranResult komoranResult : komoranList) { bw.write(komoranResult.getPlainText()); bw.newLine(); } long end = System.currentTimeMillis(); bw.close(); System.out.println("Elapsed time : " + (end - begin)); }
@Test public void bulkAnalyzeSpeedTest() { List<String> lines = FileUtil.load2List("user_data/wiki.titles"); System.out.println("Load done"); System.out.println(lines.size()); long avgElapsedTime = 0; for (int i = 0; i < 5; i++) { long begin = System.currentTimeMillis(); List<KomoranResult> komoranResultList = this.komoran.analyze(lines, 4); long end = System.currentTimeMillis(); avgElapsedTime += (end - begin); System.out.println("Elapsed time : " + (end - begin)); } System.out.println("Avg. elapsed time : " + (avgElapsedTime / 10.0)); ElapsedTimeChecker.printTimes(); }
@Test public void analyze() { KomoranResult komoranResult = this.komoran.analyze("거리에는"); List<Pair<String, String>> pairList = komoranResult.getList(); for (Pair<String, String> morphPosPair : pairList) { System.out.println(morphPosPair); } System.out.println(); List<String> nounList = komoranResult.getNouns(); for (String noun : nounList) { System.out.println(noun); } System.out.println(); List<String> verbList = komoranResult.getMorphesByTags("VV", "NNG"); for (String verb : verbList) { System.out.println(verb); } System.out.println(); List<String> eomiList = komoranResult.getMorphesByTags("EC"); for (String eomi : eomiList) { System.out.println(eomi); } System.out.println(komoranResult.getPlainText()); List<Token> tokenList = komoranResult.getTokenList(); for (Token token : tokenList) { System.out.println(token); } }
@Test public void bulkAnalyzeSpeedTest2() { List<String> lines = FileUtil.load2List("user_data/wiki.titles"); System.out.println("Load done"); System.out.println(lines.size()); long avgElapsedTime = 0; for (int i = 0; i < 12; i++) { long begin = System.currentTimeMillis(); for (String line : lines) { KomoranResult komoranResultList = this.komoran.analyze(line); } long end = System.currentTimeMillis(); if (i >= 2) { avgElapsedTime += (end - begin); } System.out.println("Elapsed time : " + (end - begin)); } System.out.println("Avg. elapsed time : " + (avgElapsedTime / 10.0)); ElapsedTimeChecker.printTimes(); }