Package opennlp.tools.cmdline

Examples of opennlp.tools.cmdline.TerminateToolException


    else if ("de".equals(params.getLang())) {
      lang = LANGUAGE.DE;
      language = params.getLang();
    }
    else {
      throw new TerminateToolException(1, "Unsupported language: " + params.getLang());
    }

    int typesToGenerate = 0;

    if (params.getTypes().contains("per")) {
View Full Code Here


  static ParserType parseParserType(String typeAsString) {
    ParserType type = null;
    if(typeAsString != null && typeAsString.length() > 0) {
      type = ParserType.parse(typeAsString);
      if(type == null) {
        throw new TerminateToolException(1, "ParserType training parameter '" + typeAsString +
            "' is invalid!");
      }
    }
   
    return type;
View Full Code Here

    mlParams = CmdLineUtil.loadTrainingParameters(params.getParams(), true);
   
    if (mlParams != null) {
      if (!TrainUtil.isValid(mlParams.getSettings("build"))) {
        throw new TerminateToolException(1, "Build training parameters are invalid!");
      }
     
      if (!TrainUtil.isValid(mlParams.getSettings("check"))) {
        throw new TerminateToolException(1, "Check training parameters are invalid!");
      }
     
      if (!TrainUtil.isValid(mlParams.getSettings("attach"))) {
        throw new TerminateToolException(1, "Attach training parameters are invalid!");
      }
     
      if (!TrainUtil.isValid(mlParams.getSettings("tagger"))) {
        throw new TerminateToolException(1, "Tagger training parameters are invalid!");
      }
     
      if (!TrainUtil.isValid(mlParams.getSettings("chunker"))) {
        throw new TerminateToolException(1, "Chunker training parameters are invalid!");
      }
    }

    if(mlParams == null) {
      mlParams = ModelUtil.createTrainingParameters(params.getIterations(), params.getCutoff());
    }

    File modelOutFile = params.getModel();
    CmdLineUtil.checkOutputFile("parser model", modelOutFile);
   
    ParserModel model;
    try {

      // TODO hard-coded language reference
      HeadRules rules = new opennlp.tools.parser.lang.en.HeadRules(
          new InputStreamReader(new FileInputStream(params.getHeadRules()),
              params.getEncoding()));
     
      ParserType type = parseParserType(params.getParserType());
      if(params.getFun()){
        Parse.useFunctionTags(true);
      }
     
      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) {
      throw new TerminateToolException(-1, "IO error while reading training data or indexing data: "
          + e.getMessage(), e);
    }
    finally {
      try {
        sampleStream.close();
View Full Code Here

    ParserModel updatedParserModel;
    try {
      updatedParserModel = trainAndUpdate(originalParserModel, sampleStream, params);
    }
    catch (IOException e) {
      throw new TerminateToolException(-1, "IO error while reading training data or indexing data: "
          + e.getMessage(), e);
    }
    finally {
      try {
        sampleStream.close();
View Full Code Here

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

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

    } catch (IOException e) {
      throw new TerminateToolException(-1, "IO error while reading training data or indexing data: " + e.getMessage(), e);
    } finally {
      try {
        in.close();
        out.close();
      } catch (IOException e) {
View Full Code Here

    Dictionary mDictionary;
    try {
      System.out.println("Creating Dictionary...");
      mDictionary = createDictionary(sampleStream);
    } catch (IOException e) {
      throw new TerminateToolException(-1, "IO error while reading training data or indexing data: "
          + e.getMessage(), e);
    } finally {
      try {
        sampleStream.close();
      } catch(IOException e) {
        // sorry this can fail..
      }
    }

    System.out.println("Saving Dictionary...");
   
    OutputStream out = null;
   
    try {
      out = new FileOutputStream(dictOutFile);
      mDictionary.serialize(out);
    } catch (IOException e) {
      throw new TerminateToolException(-1, "IO error while writing dictionary file: "
          + e.getMessage(), e);
    }
    finally {
      if (out != null)
        try {
          out.close();
        } catch (IOException e) {
          // file might be damaged
          throw new TerminateToolException(-1, "Attention: Failed to correctly write dictionary:" +
              e.getMessage(), e);
        }
    }
  }
View Full Code Here

    super.run(format, args);
   
    try {
      CorefTrainer.train(params.getModel().toString(), sampleStream, true, true);
    } catch (IOException e) {
      throw new TerminateToolException(-1, "IO error while reading training data or indexing data: " +
          e.getMessage(), e);
    }
  }
View Full Code Here

      try {
        reportOutputStream = new FileOutputStream(reportFile);
        reportListener = new POSTaggerFineGrainedReportListener(
            reportOutputStream);
      } catch (FileNotFoundException e) {
        throw new TerminateToolException(-1,
            "IO error while creating POS Tagger fine-grained report file: "
                + e.getMessage());
      }
    }

    POSEvaluator evaluator = new POSEvaluator(
        new opennlp.tools.postag.POSTaggerME(model), missclassifiedListener,
        reportListener);

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

     
      TreebankLinker treebankLinker;
      try {
        treebankLinker = new TreebankLinker(args[0], LinkerMode.TEST);
      } catch (IOException e) {
        throw new TerminateToolException(-1, "Failed to load all coreferencer models!", e);
      }
     
      ObjectStream<String> lineStream =
          new PlainTextByLineStream(new InputStreamReader(System.in));
     
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.