Package opennlp.tools.util

Examples of opennlp.tools.util.TrainingParameters


  }

  public static final TrainingParameters loadTrainingParams(String inFileValue,
      boolean isSequenceTrainingAllowed) throws ResourceInitializationException {

    TrainingParameters params;
    if (inFileValue != null) {
      InputStream paramsIn = null;
      try {
        paramsIn = new FileInputStream(new File(inFileValue));

        params = new opennlp.tools.util.TrainingParameters(paramsIn);
      } catch (IOException e) {
        throw new ResourceInitializationException(e);
      }
      finally {
        try {
          if (paramsIn != null)
            paramsIn.close();
        } catch (IOException e) {
        }
      }

      if (!TrainUtil.isValid(params.getSettings())) {
        throw new ResourceInitializationException(new Exception("Training parameters file is invalid!"));
      }

      if (!isSequenceTrainingAllowed && TrainUtil.isSequenceTraining(params.getSettings())) {
        throw new ResourceInitializationException(new Exception("Sequence training is not supported!"));
      }
    }
    else {
      params = TrainingParameters.defaultParams();
View Full Code Here


    }
   
    SentenceDetectorFactory sdFactory = SentenceDetectorFactory.create(
            null, language, true, null, eos);
   
    TrainingParameters mlParams = ModelUtil.createTrainingParameters(100, 5);
   
    ObjectStream<SentenceSample> samples = ObjectStreamUtils.createObjectStream(sentenceSamples);
   
    Writer samplesOut = null;
   
View Full Code Here

 
  // its optional, passing null is allowed
  public static TrainingParameters loadTrainingParameters(String paramFile,
      boolean supportSequenceTraining) {
   
    TrainingParameters params = null;
   
    if (paramFile != null) {
     
      checkInputFile("Training Parameter", new File(paramFile));
     
      InputStream paramsIn = null;
      try {
        paramsIn = new FileInputStream(new File(paramFile));
       
        params = new opennlp.tools.util.TrainingParameters(paramsIn);
      } catch (IOException e) {
        // TODO: print error and exit
        e.printStackTrace();
      }
      finally {
        try {
          if (paramsIn != null)
            paramsIn.close();
        } catch (IOException e) {
        }
      }
     
      if (!TrainUtil.isValid(params.getSettings())) {
        System.err.println("Training parameters file is invalid!");
        throw new TerminateToolException(-1);
      }
     
      if (!supportSequenceTraining && TrainUtil.isSequenceTraining(params.getSettings())) {
        System.err.println("Sequence training is not supported!");
        throw new TerminateToolException(-1);
      }
    }
   
View Full Code Here

   * @return A dictionary object.
   */
  public static Dictionary buildDictionary(ObjectStream<Parse> data, HeadRules rules, int cutoff)
      throws IOException {
   
    TrainingParameters params = new TrainingParameters();
    params.put("dict", TrainingParameters.CUTOFF_PARAM, Integer.toString(cutoff));
   
    return buildDictionary(data, rules, params);
  }
View Full Code Here

    CmdLineUtil.writeModel("tokenizer", modelOutFile, model);
  }

  public static TrainingParameters createTrainingParameters(Integer iterations, Integer cutoff) {
    TrainingParameters mlParams = new TrainingParameters();
    mlParams.put(TrainingParameters.ALGORITHM_PARAM, "MAXENT");
    mlParams.put(TrainingParameters.ITERATIONS_PARAM,
        iterations.toString());
    mlParams.put(TrainingParameters.CUTOFF_PARAM, cutoff.toString());
    return mlParams;
  }
View Full Code Here

 
  public static ParserModel train(String languageCode,
      ObjectStream<Parse> parseSamples, HeadRules rules, int iterations, int cut)
      throws IOException {
   
    TrainingParameters params = new TrainingParameters();
    params.put("dict", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));

    params.put("tagger", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("tagger", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));
    params.put("chunker", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("chunker", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));
    params.put("check", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("check", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));
    params.put("build", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("build", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));
   
    return train(languageCode, parseSamples, rules, params);
  }
View Full Code Here

      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()));
View Full Code Here

  */
  @Deprecated
  public static ParserModel train(String languageCode, ObjectStream<Parse> parseSamples, HeadRules rules, int iterations, int cut)
      throws IOException {
   
    TrainingParameters params = new TrainingParameters();
    params.put("dict", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));

    params.put("tagger", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("tagger", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));
    params.put("chunker", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("chunker", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));
    params.put("check", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("check", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));
    params.put("build", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("build", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));

    return train(languageCode, parseSamples, rules, params);
  }
View Full Code Here

      detailedFMeasureListener = new ChunkerDetailedFMeasureListener();
      listeners.add(detailedFMeasureListener);
    }
   
    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()));
View Full Code Here

    if (params.getMisclassified()) {
      errorListener = new SentenceEvaluationErrorListener();
    }
   
    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()));
View Full Code Here

TOP

Related Classes of opennlp.tools.util.TrainingParameters

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.