Package opennlp.tools.postag

Examples of opennlp.tools.postag.POSTaggerCrossValidator


    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
      }
    }

    System.out.println("done");

    System.out.println();

    System.out.println("Accuracy: " + validator.getWordAccuracy());
  }
View Full Code Here


            "IO error while creating POS Tagger fine-grained report file: "
                + e.getMessage());
      }
    }

    POSTaggerCrossValidator validator;
    try {
      validator = new POSTaggerCrossValidator(params.getLang(), mlParams,
          params.getDict(), params.getNgram(), params.getTagDictCutoff(),
          params.getFactory(), missclassifiedListener, reportListener);
     
      validator.evaluate(sampleStream, params.getFolds());
    } 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 that this can fail
      }
    }

    System.out.println("done");

    if (reportListener != null) {
      System.out.println("Writing fine-grained report to "
          + params.getReportOutputFile().getAbsolutePath());
      reportListener.writeReport();

      try {
        // TODO: is it a problem to close the stream now?
        reportOutputStream.close();
      } catch (IOException e) {
        // nothing to do
      }
    }

    System.out.println();

    System.out.println("Accuracy: " + validator.getWordAccuracy());
  }
View Full Code Here

            "IO error while creating POS Tagger fine-grained report file: "
                + e.getMessage());
      }
    }

    POSTaggerCrossValidator validator;
    try {
      validator = new POSTaggerCrossValidator(params.getLang(), mlParams,
          params.getDict(), params.getNgram(), params.getTagDictCutoff(),
          params.getFactory(), missclassifiedListener, reportListener);

      validator.evaluate(sampleStream, params.getFolds());
    } 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 that this can fail
      }
    }

    System.out.println("done");

    if (reportListener != null) {
      System.out.println("Writing fine-grained report to "
          + params.getReportOutputFile().getAbsolutePath());
      reportListener.writeReport();

      try {
        // TODO: is it a problem to close the stream now?
        reportOutputStream.close();
      } catch (IOException e) {
        // nothing to do
      }
    }

    System.out.println();

    System.out.println("Accuracy: " + validator.getWordAccuracy());
  }
View Full Code Here

TOP

Related Classes of opennlp.tools.postag.POSTaggerCrossValidator

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.