Package opennlp.tools.cmdline

Examples of opennlp.tools.cmdline.TerminateToolException


 
  public void run(String[] args) {
   
    if (!ArgumentParser.validateArguments(args, TrainerToolParams.class)) {
      System.err.println(getHelp());
      throw new TerminateToolException(1);
    }
   
    TrainerToolParams params = ArgumentParser.parse(args,
        TrainerToolParams.class);
   
    opennlp.tools.util.TrainingParameters mlParams =
      CmdLineUtil.loadTrainingParameters(params.getParams(), false);
   
    File trainingDataInFile = params.getData();
    File modelOutFile = params.getModel();

    CmdLineUtil.checkOutputFile("sentence detector model", modelOutFile);
    ObjectStream<ChunkSample> sampleStream =
      openSampleData("Training", trainingDataInFile, params.getEncoding());
   
    ChunkerModel model;
    try {
      if (mlParams == null) {
        model = ChunkerME.train(params.getLang(), sampleStream,
            params.getCutoff(), params.getIterations());
      }
      else {
        model = ChunkerME.train(params.getLang(), sampleStream,
            new DefaultChunkerContextGenerator(), mlParams);
      }
    } catch (IOException e) {
      CmdLineUtil.printTrainingIoError(e);
      throw new TerminateToolException(-1);
    }
    finally {
      try {
        sampleStream.close();
      } catch (IOException e) {
View Full Code Here


          CmdLineUtil.openInFile(new File(params.getData())), params.getEncoding()));
     
      return new WordTagSampleStream(lineStream);
    } catch (UnsupportedEncodingException e) {
      System.err.println("Encoding not supported: " + params.getEncoding());
      throw new TerminateToolException(-1);
    }
  }
View Full Code Here

  public void run(String[] args) {

    if (!ArgumentParser.validateArguments(args, EvaluatorParams.class)) {
      System.err.println(getHelp());
      throw new TerminateToolException(1);
    }
   
    EvalToolParams params = ArgumentParser.parse(args, EvalToolParams.class);
   
    File testData =params.getData();

    CmdLineUtil.checkInputFile("Test data", testData);

    Charset encoding = params.getEncoding();

    ChunkerModel model = new ChunkerModelLoader().load(params.getModel());
   
    List<EvaluationMonitor<ChunkSample>> listeners = new LinkedList<EvaluationMonitor<ChunkSample>>();
    ChunkerDetailedFMeasureListener detailedFMeasureListener = null;
    if(params.getMisclassified()) {
      listeners.add(new ChunkEvaluationErrorListener());
    }
    if(params.getDetailedF()) {
      detailedFMeasureListener = new ChunkerDetailedFMeasureListener();
      listeners.add(detailedFMeasureListener);
    }

    ChunkerEvaluator evaluator = new ChunkerEvaluator(new ChunkerME(model,
        ChunkerME.DEFAULT_BEAM_SIZE, new DefaultChunkerSequenceValidator()),
        listeners.toArray(new ChunkerEvaluationMonitor[listeners.size()]));
   
    final ObjectStream<ChunkSample> sampleStream = ChunkerTrainerTool.openSampleData("Test",
        testData, encoding);

    final PerformanceMonitor monitor = new PerformanceMonitor("sent");

    ObjectStream<ChunkSample> measuredSampleStream = new ObjectStream<ChunkSample>() {

      public ChunkSample read() throws IOException {
        monitor.incrementCounter();
        return sampleStream.read();
      }

      public void reset() throws IOException {
        sampleStream.reset();
      }

      public void close() throws IOException {
        sampleStream.close();
      }
    };

    monitor.startAndPrintThroughput();

    try {
      evaluator.evaluate(measuredSampleStream);
    } catch (IOException e) {
      System.err.println("failed");
      System.err.println("Reading test data error " + e.getMessage());
      throw new TerminateToolException(-1);
    } finally {
      try {
        measuredSampleStream.close();
      } catch (IOException e) {
        // sorry that this can fail
View Full Code Here

      detokenizer = new DictionaryDetokenizer(new DetokenizationDictionary(
          new FileInputStream(new File(params.getDetokenizer()))));
    } catch (IOException e) {
      System.err.println("Error while loading detokenizer dict: "
          + e.getMessage());
      throw new TerminateToolException(-1);
    }

    return new NameToTokenSampleStream(detokenizer, nameSampleStream);
  }
View Full Code Here

  public void run(String[] args) {

    if (!ArgumentParser
        .validateArguments(args, EvalToolParams.class)) {
      System.err.println(getHelp());
      throw new TerminateToolException(1);
    }

    EvalToolParams params = ArgumentParser.parse(args,
        EvalToolParams.class);

    File testData = params.getData();
    CmdLineUtil.checkInputFile("Test data", testData);

    Charset encoding = params.getEncoding();

    TokenNameFinderModel model = new TokenNameFinderModelLoader().load(params
        .getModel());
   
    List<EvaluationMonitor<NameSample>> listeners = new LinkedList<EvaluationMonitor<NameSample>>();
    if (params.getMisclassified()) {
      listeners.add(new NameEvaluationErrorListener());
    }
    TokenNameFinderDetailedFMeasureListener detailedFListener = null;
    if (params.getDetailedF()) {
      detailedFListener = new TokenNameFinderDetailedFMeasureListener();
      listeners.add(detailedFListener);
    }

    TokenNameFinderEvaluator evaluator = new TokenNameFinderEvaluator(
        new NameFinderME(model),
        listeners.toArray(new TokenNameFinderEvaluationMonitor[listeners.size()]));

    final ObjectStream<NameSample> sampleStream = TokenNameFinderTrainerTool.openSampleData("Test",
        testData, encoding);

    final PerformanceMonitor monitor = new PerformanceMonitor("sent");

    ObjectStream<NameSample> measuredSampleStream = new ObjectStream<NameSample>() {

      public NameSample read() throws IOException {
        monitor.incrementCounter();
        return sampleStream.read();
      }

      public void reset() throws IOException {
        sampleStream.reset();
      }

      public void close() throws IOException {
        sampleStream.close();
      }
    };

    monitor.startAndPrintThroughput();

    try {
      evaluator.evaluate(measuredSampleStream);
    } catch (IOException e) {
      System.err.println("failed");
      System.err.println("Reading test data error " + e.getMessage());
      throw new TerminateToolException(-1);
    } finally {
      try {
        measuredSampleStream.close();
      } catch (IOException e) {
        // sorry that this can fail
View Full Code Here

  }
 
  public void run(String[] args) {
    if (!ArgumentParser.validateArguments(args, TrainerToolParams.class)) {
      System.err.println(getHelp());
      throw new TerminateToolException(1);
    }
   
    TrainerToolParams params = ArgumentParser.parse(args,
        TrainerToolParams.class);
   
    opennlp.tools.util.TrainingParameters mlParams =
      CmdLineUtil.loadTrainingParameters(params.getParams(), false);
   
    File trainingDataInFile = params.getData();
    File modelOutFile = params.getModel();

    CmdLineUtil.checkOutputFile("document categorizer model", modelOutFile);
    ObjectStream<DocumentSample> sampleStream =
        openSampleData("Training", trainingDataInFile, params.getEncoding());
   
    DoccatModel model;
    try {
      if (mlParams == null) {
       model = DocumentCategorizerME.train(params.getLang(), sampleStream,
           params.getCutoff(), params.getIterations());
      }
      else {
        model = DocumentCategorizerME.train(params.getLang(), sampleStream,
            mlParams);
      }
    } catch (IOException e) {
      CmdLineUtil.printTrainingIoError(e);
      throw new TerminateToolException(-1);
    }
    finally {
      try {
        sampleStream.close();
      } catch (IOException e) {
View Full Code Here

      detokenizer = new DictionaryDetokenizer(new DetokenizationDictionary(
          new FileInputStream(new File(params.getDetokenizer()))));
    } catch (IOException e) {
      System.err.println("Error while loading detokenizer dict: "
          + e.getMessage());
      throw new TerminateToolException(-1);
    }

    return new POSToTokenSampleStream(detokenizer, posSampleStream);
  }
View Full Code Here

  }

  public void run(String[] args) {
    if (args.length != 1) {
      System.out.println(getHelp());
      throw new TerminateToolException(1);
    }
   
    ChunkerModel model = new ChunkerModelLoader().load(new File(args[0]));
   
    ChunkerME chunker = new ChunkerME(model, ChunkerME.DEFAULT_BEAM_SIZE,
View Full Code Here

    Detokenizer detokenizer;
    try {
      detokenizer = new DictionaryDetokenizer(new DetokenizationDictionary(new FileInputStream(new File(params.getDetokenizer()))));
    } catch (IOException e) {
      System.err.println("Error while loading detokenizer dict: " + e.getMessage());
      throw new TerminateToolException(-1);
    }
   
    return new POSToSentenceSampleStream(detokenizer, posSampleStream, 30);
  }
View Full Code Here

  public void run(String[] args) {
   
    if (args.length != 1) {
      System.out.println(getHelp());
      throw new TerminateToolException(1);
    }
   
    DoccatModel model = new DoccatModelLoader().load(new File(args[0]));
   
    DocumentCategorizerME doccat = new DocumentCategorizerME(model);
View Full Code Here

TOP

Related Classes of opennlp.tools.cmdline.TerminateToolException

Copyright © 2018 www.massapicom. 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.