Package org.languagetool.dev

Source Code of org.languagetool.dev.SentenceChecker

/* LanguageTool, a natural language style checker
* Copyright (C) 2014 Daniel Naber (http://www.danielnaber.de)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
* USA
*/
package org.languagetool.dev;

import org.languagetool.JLanguageTool;
import org.languagetool.Language;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

/**
* Run LT on a large file with one sentence per line.
* Useful to see if performance gets worse over time.
* @since 2.7
*/
class SentenceChecker {
 
  private static final int BATCH_SIZE = 1000;

  private void run(Language language, File file) throws IOException {
    JLanguageTool lt = new JLanguageTool(language);
    lt.activateDefaultPatternRules();
    Scanner scanner = new Scanner(file);
    int count = 0;
    long startTime = System.currentTimeMillis();
    while (scanner.hasNextLine()) {
      String line = scanner.nextLine();
      lt.check(line);
      if (++count % BATCH_SIZE == 0) {
        long time = (System.currentTimeMillis()-startTime);
        System.out.println(count + ". " + time + "ms per " + BATCH_SIZE + " sentences");
        startTime = System.currentTimeMillis();
      }
    }
  }

  public static void main(String[] args) throws IOException {
    if (args.length != 2) {
      System.err.println("Usage: " + SentenceChecker.class.getSimpleName() + " <langCode> <sentenceFile>");
      System.exit(1);
    }
    SentenceChecker checker = new SentenceChecker();
    checker.run(Language.getLanguageForShortName(args[0]), new File(args[1]));
  }
}
TOP

Related Classes of org.languagetool.dev.SentenceChecker

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.