Examples of TerminateToolException


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);

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

    ObjectStream<POSSample> sampleStream = POSTaggerTrainerTool.openSampleData(
        "Training Data", trainingDataInFile, params.getEncoding());

    POSTaggerCrossValidator validator;
   
    POSTaggerEvaluationMonitor missclassifiedListener = null;
    if (params.getMisclassified()) {
      missclassifiedListener = new POSEvaluationErrorListener();
    }
   
    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 {
      // TODO: Move to util method ...
      POSDictionary tagdict = null;
      if (params.getDict() != null) {
        tagdict = POSDictionary.create(new FileInputStream(params.getDict()));
      }

      validator = new POSTaggerCrossValidator(params.getLang(), mlParams,
          tagdict, params.getNgram(), missclassifiedListener);
     
      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

 
  public void run(String[] args) {
   
    if (args.length < 1) {
      System.out.println(getHelp());
      throw new TerminateToolException(1);
    }
   
    ParserModel model = new ParserModelLoader().load(new File(args[args.length - 1]));
   
    Integer beamSize = CmdLineUtil.getIntParameter("-bs", args);
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);
   
    if (mlParams != null && !TrainUtil.isValid(mlParams.getSettings())) {
      System.err.println("Training parameters file is invalid!");
      throw new TerminateToolException(-1);
    }
   
    File trainingDataInFile = params.getData();
    File modelOutFile = params.getModel();
   
    CmdLineUtil.checkOutputFile("pos tagger model", modelOutFile);
    ObjectStream<POSSample> sampleStream = openSampleData("Training", trainingDataInFile,
        params.getEncoding());
   
   
    Dictionary ngramDict = null;
   
    Integer ngramCutoff = params.getNgram();
   
    if (ngramCutoff != null) {
      System.err.print("Building ngram dictionary ... ");
      try {
        ngramDict = POSTaggerME.buildNGramDictionary(sampleStream, ngramCutoff);
        sampleStream.reset();
      } catch (IOException e) {
        CmdLineUtil.printTrainingIoError(e);
        throw new TerminateToolException(-1);
      }
      System.err.println("done");
    }
   
    POSModel model;
    try {
     
      // TODO: Move to util method ...
      POSDictionary tagdict = null;
      if (params.getDict() != null) {
        tagdict = POSDictionary.create(new FileInputStream(params.getDict()));
      }
     
      if (mlParams == null) {
        // depending on model and sequence choose training method
        model = opennlp.tools.postag.POSTaggerME.train(params.getLang(),
             sampleStream, getModelType(params.getType()), tagdict, ngramDict, params.getCutoff(), params.getIterations());
      }
      else {
        model = opennlp.tools.postag.POSTaggerME.train(params.getLang(),
            sampleStream, mlParams, tagdict, ngramDict);
      }
    }
    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

    try {
      trainingDataIn = new FileInputStream(trainingDataFile);
    } catch (FileNotFoundException e) {
      System.err.println("failed");
      System.err.println("File not found: " + e.getMessage());
      throw new TerminateToolException(-1);
    }
   
    System.err.println("done");
   
    return new ParseSampleStream(
View Full Code Here

Examples of opennlp.tools.cmdline.TerminateToolException

    ParserType type = null;
    if(typeAsString != null && typeAsString.length() > 0) {
      type = ParserType.parse(typeAsString);
      if(type == null) {
        System.err.println("ParserType training parameter is invalid!");
        throw new TerminateToolException(-1);
      }
    }
   
    return type;
  }
View Full Code Here

Examples of opennlp.tools.cmdline.TerminateToolException

  // TODO: Add param to train tree insert parser
  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);
   
    if (mlParams != null) {
      if (!TrainUtil.isValid(mlParams.getSettings("build"))) {
        System.err.println("Build training parameters are invalid!");
        throw new TerminateToolException(-1);
      }
     
      if (!TrainUtil.isValid(mlParams.getSettings("check"))) {
        System.err.println("Check training parameters are invalid!");
        throw new TerminateToolException(-1);
      }
     
      if (!TrainUtil.isValid(mlParams.getSettings("attach"))) {
        System.err.println("Attach training parameters are invalid!");
        throw new TerminateToolException(-1);
      }
     
      if (!TrainUtil.isValid(mlParams.getSettings("tagger"))) {
        System.err.println("Tagger training parameters are invalid!");
        throw new TerminateToolException(-1);
      }
     
      if (!TrainUtil.isValid(mlParams.getSettings("chunker"))) {
        System.err.println("Chunker training parameters are invalid!");
        throw new TerminateToolException(-1);
      }
    }
   
    ObjectStream<Parse> sampleStream = openTrainingData(params.getData(), params.getEncoding());
   
    File modelOutFile = params.getModel();
    CmdLineUtil.checkOutputFile("parser model", modelOutFile);
   
    ParserModel model;
    try {
     
      HeadRules rules = new opennlp.tools.parser.lang.en.HeadRules(
          new InputStreamReader(new FileInputStream(params.getHeadRules()),
              params.getEncoding()));
     
      ParserType type = parseParserType(params.getParserType());
     
      if (mlParams == null) {
        if (ParserType.CHUNKING.equals(type)) {
          model = opennlp.tools.parser.chunking.Parser.train(
              params.getLang(), sampleStream, rules,
              params.getIterations(), params.getCutoff());
        }
        else if (ParserType.TREEINSERT.equals(type)) {
          model = opennlp.tools.parser.treeinsert.Parser.train(params.getLang(), sampleStream, rules, params.getIterations(),
              params.getCutoff());
        }
        else {
          throw new IllegalStateException();
        }
      }
      else {
        if (ParserType.CHUNKING.equals(type)) {
          model = opennlp.tools.parser.chunking.Parser.train(
              params.getLang(), sampleStream, rules,
              mlParams);
        }
        else if (ParserType.TREEINSERT.equals(type)) {
          model = opennlp.tools.parser.treeinsert.Parser.train(params.getLang(), sampleStream, rules,
              mlParams);
        }
        else {
          throw new IllegalStateException();
        }

      }
    }
    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);
    }
   
    TokenizerModel model = new TokenizerModelLoader().load(new File(args[0]));
   
    CommandLineTokenizer tokenizer =
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);
    }
   
    ADChunkSampleStream sampleStream = new ADChunkSampleStream(CmdLineUtil.openInFile(new File(params
        .getData())), encoding.name());
View Full Code Here

Examples of opennlp.tools.cmdline.TerminateToolException

    else if ("es".equals(params.getLang())) {
      lang = LANGUAGE.ES;
      language = params.getLang();
    }
    else {
      throw new TerminateToolException(1, "Unsupported language: " + params.getLang());
    }
   
    int typesToGenerate = 0;
   
    if (params.getTypes().contains("per")) {
View Full Code Here

Examples of opennlp.tools.cmdline.TerminateToolException

      System.setOut(new PrintStream(System.out, true, "UTF-8"));

      return new ConllXPOSSampleStream(lineStream);
    } catch (UnsupportedEncodingException e) {
      // this shouldn't happen
      throw new TerminateToolException(-1, "UTF-8 encoding is not supported: " + e.getMessage(), e);
    }
  }
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.