Examples of TerminateToolException


Examples of opennlp.tools.cmdline.TerminateToolException

      try {
        featureGeneratorBytes = ModelUtil.read(bytesIn);
      } catch (IOException e) {
        CmdLineUtil.printTrainingIoError(e);
        throw new TerminateToolException(-1);
      } finally {
        try {
          bytesIn.close();
        } catch (IOException e) {
          // sorry that this can fail
View Full Code Here

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(), true);
   
    File trainingDataInFile = params.getData();
    File modelOutFile = params.getModel();
   
   
    byte featureGeneratorBytes[] = openFeatureGeneratorBytes(params.getFeaturegen());
   
   
    // TODO: Support Custom resources:
    //       Must be loaded into memory, or written to tmp file until descriptor
    //       is loaded which defines parses when model is loaded
   
    Map<String, Object> resources = loadResources(params.getResources());
       
    CmdLineUtil.checkOutputFile("name finder model", modelOutFile);
    ObjectStream<NameSample> sampleStream = openSampleData("Training", trainingDataInFile,
        params.getEncoding());

    TokenNameFinderModel model;
    try {
      if (mlParams == null) {
      model = opennlp.tools.namefind.NameFinderME.train(params.getLang(), params.getType(),
           sampleStream, featureGeneratorBytes, resources, params.getIterations(),
           params.getCutoff());
      }
      else {
        model = opennlp.tools.namefind.NameFinderME.train(
            params.getLang(), params.getType(), sampleStream,
            mlParams, featureGeneratorBytes, resources);
      }
    }
    catch (IOException e) {
      CmdLineUtil.printTrainingIoError(e);
      throw new TerminateToolException(-1);
    }
    finally {
      try {
        sampleStream.close();
      } catch (IOException e) {
View Full Code Here

Examples of opennlp.tools.cmdline.TerminateToolException

  public void run(String[] args) {
   
   
    if (args.length != 1) {
      System.out.println(getHelp());
      throw new TerminateToolException(1);
    }
   
    Detokenizer detokenizer = new DictionaryDetokenizer(
        new DetokenizationDictionaryLoader().load(new File(args[0])));
   
View Full Code Here

Examples of opennlp.tools.cmdline.TerminateToolException

  }

  public void run(String[] args) {
    if (!ArgumentParser.validateArguments(args, CVToolParams.class)) {
      System.err.println(getHelp());
      throw new TerminateToolException(1);
    }
   
    CVToolParams params = ArgumentParser.parse(args, CVToolParams.class);

    opennlp.tools.util.TrainingParameters mlParams = CmdLineUtil
        .loadTrainingParameters(params.getParams(),false);

    byte featureGeneratorBytes[] = TokenNameFinderTrainerTool
        .openFeatureGeneratorBytes(params.getFeaturegen());

    Map<String, Object> resources = TokenNameFinderTrainerTool
        .loadResources(params.getResources());

    File trainingDataInFile = params.getData();
    CmdLineUtil.checkInputFile("Training Data", trainingDataInFile);
   
    Charset encoding = params.getEncoding();

    ObjectStream<NameSample> sampleStream = TokenNameFinderTrainerTool
        .openSampleData("Training Data", trainingDataInFile, encoding);

    TokenNameFinderCrossValidator validator;
   
    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);
    }
   
    if (mlParams == null) {
      mlParams = new TrainingParameters();
      mlParams.put(TrainingParameters.ALGORITHM_PARAM, "MAXENT");
      mlParams.put(TrainingParameters.ITERATIONS_PARAM,
          Integer.toString(params.getIterations()));
      mlParams.put(TrainingParameters.CUTOFF_PARAM,
          Integer.toString(params.getCutoff()));
    }

    try {
      validator = new TokenNameFinderCrossValidator(params.getLang(),
          params.getType(), mlParams, featureGeneratorBytes, resources, listeners.toArray(new TokenNameFinderEvaluationMonitor[listeners.size()]));
      validator.evaluate(sampleStream, params.getFolds());
    } catch (IOException e) {
      CmdLineUtil.printTrainingIoError(e);
      throw new TerminateToolException(-1);
    } finally {
      try {
        sampleStream.close();
      } catch (IOException e) {
        // sorry that this can fail
View Full Code Here

Examples of opennlp.tools.cmdline.TerminateToolException

            ngramDict = POSTaggerME.buildNGramDictionary(trainingSampleStream,
                this.ngramCutoff);
            trainingSampleStream.reset();
          } catch (IOException e) {
            CmdLineUtil.printTrainingIoError(e);
            throw new TerminateToolException(-1);
          }
          System.err.println("done");
        }
      } else {
        ngramDict = this.ngramDictionary;
View Full Code Here

Examples of opennlp.tools.cmdline.TerminateToolException

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

    Charset encoding = CmdLineUtil.getEncodingParameter(args);

    if (encoding == null) {
      throw new TerminateToolException(1);
    }

    return new ADNameSampleStream(CmdLineUtil.openInFile(new File(params
        .getData())), encoding.name());
  }
View Full Code Here

Examples of opennlp.tools.cmdline.TerminateToolException

  public void run(String[] args) {
    if (!ArgumentParser
        .validateArguments(args, EvaluatorParams.class)) {
      System.err.println(getHelp());
      throw new TerminateToolException(1);
    }

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

    Charset encoding = params.getEncoding();

    TokenizerModel model = new TokenizerModelLoader().load(params.getModel());

    TokenizerEvaluationMonitor missclassifiedListener = null;
    if (params.getMisclassified()) {
      missclassifiedListener = new TokenEvaluationErrorListener();
    }

    TokenizerEvaluator evaluator = new TokenizerEvaluator(
        new opennlp.tools.tokenize.TokenizerME(model), missclassifiedListener);

    System.out.print("Evaluating ... ");
   
    File testData = params.getData();
    CmdLineUtil.checkInputFile("Test data", testData);

    ObjectStream<TokenSample> sampleStream = TokenizerTrainerTool
        .openSampleData("Test", testData, encoding);

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

Examples of opennlp.tools.cmdline.TerminateToolException

  }

  public void run(String[] args) {
    if (!ArgumentParser.validateArguments(args, Params.class)) {
      System.err.println(getHelp());
      throw new TerminateToolException(1);
    }

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

    File dictInFile = params.getInputFile();
    File dictOutFile = params.getOutputFile();
    Charset encoding = params.getEncoding();

    CmdLineUtil.checkInputFile("dictionary input file", dictInFile);
    CmdLineUtil.checkOutputFile("dictionary output file", dictOutFile);

    InputStreamReader in = null;
    OutputStream out = null;
    try {
      in = new InputStreamReader(new FileInputStream(dictInFile), encoding);
      out = new FileOutputStream(dictOutFile);

      Dictionary dict = Dictionary.parseOneEntryPerLine(in);
      dict.serialize(out);

    } catch (IOException e) {
      CmdLineUtil.printTrainingIoError(e);
      throw new TerminateToolException(-1);
    } finally {
      try {
        in.close();
        out.close();
      } catch (IOException e) {
View Full Code Here

Examples of opennlp.tools.cmdline.TerminateToolException

    try {
      return new LeipzigDoccatSampleStream(params.getLang(), 20,
          CmdLineUtil.openInFile(new File(params.getData())));
    } catch (IOException e) {
      System.err.println("Cannot open sample data: " + e.getMessage());
      throw new TerminateToolException(-1);
    }
  }
View Full Code Here

Examples of opennlp.tools.cmdline.TerminateToolException

      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 NameToSentenceSampleStream(detokenizer, nameSampleStream, 30);
  }
View Full Code Here
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.