Package opennlp.model

Examples of opennlp.model.AbstractModelWriter


        es = new RealBasicEventStream(new PlainTextByLineDataStream(datafr));
      }

      File outputFile = new File(modelFileName);

      AbstractModelWriter writer;

      AbstractModel model;
      if (type.equals("maxent")) {
  GIS.SMOOTHING_OBSERVATION = SMOOTHING_OBSERVATION;

        if (!real) {
          model = GIS.trainModel(es, maxit, cutoff, sigma);
        } else {
          model = GIS.trainModel(maxit,
         new OnePassRealValueDataIndexer(es, cutoff),             
         USE_SMOOTHING);
        }

  writer = new SuffixSensitiveGISModelWriter(model, outputFile);

      } else if (type.equals("perceptron")) {
        //System.err.println("Perceptron training");
        model = new PerceptronTrainer().trainModel(maxit, new OnePassDataIndexer(es, cutoff), cutoff);

  writer = new SuffixSensitivePerceptronModelWriter(model, outputFile);

      } else {
        throw new RuntimeException("Unknown model type: " + type);
      }

      writer.persist();


    } catch (Exception e) {
      System.out.print("Unable to create model due to exception: ");
      System.out.println(e);
View Full Code Here


      String dataFileName = args[ai];
      String modelFileName =
        dataFileName.substring(0,dataFileName.lastIndexOf('.'))
        + "Model.txt";
      File outputFile = new File(modelFileName);
      AbstractModelWriter writer = null;
      try {
        FileReader datafr = new FileReader(new File(dataFileName));
        EventStream es;
        if (!real) {
          es = new BasicEventStream(new PlainTextByLineDataStream(datafr));
        }
        else {
          es = new RealBasicEventStream(new PlainTextByLineDataStream(datafr));
        }
        GIS.SMOOTHING_OBSERVATION = SMOOTHING_OBSERVATION;
        AbstractModel model;
        if (type.equals("maxent")) {
       
          if (!real) {
            model = GIS.trainModel(es,USE_SMOOTHING);
          }
          else {
            model = GIS.trainModel(100, new OnePassRealValueDataIndexer(es,0), USE_SMOOTHING);
          }
          writer =  new SuffixSensitiveGISModelWriter(model, outputFile);
        }
        else if (type.equals("perceptron")){
          System.err.println("Perceptron training");
          model = new PerceptronTrainer().trainModel(10, new OnePassDataIndexer(es,0),0);
          writer = new SuffixSensitivePerceptronModelWriter(model, outputFile);
        }
        else {
          System.err.println("Unknown model type: "+type);
          model = null;
        }
       
        writer.persist();
      } catch (Exception e) {
        System.out.print("Unable to create model due to exception: ");
        System.out.println(e);
        e.printStackTrace();
      }
View Full Code Here

        es = new RealBasicEventStream(new PlainTextByLineDataStream(datafr));
      }

      File outputFile = new File(modelFileName);

      AbstractModelWriter writer;

      AbstractModel model;
      if (type.equals("maxent")) {
  GIS.SMOOTHING_OBSERVATION = SMOOTHING_OBSERVATION;

        if (!real) {
          model = GIS.trainModel(es, maxit, cutoff, sigma);
        } else {
          model = GIS.trainModel(maxit,
         new OnePassRealValueDataIndexer(es, cutoff),             
         USE_SMOOTHING);
        }

  writer = new SuffixSensitiveGISModelWriter(model, outputFile);

      } else if (type.equals("perceptron")) {
        //System.err.println("Perceptron training");
        model = new PerceptronTrainer().trainModel(maxit, new OnePassDataIndexer(es, cutoff), cutoff);

  writer = new SuffixSensitivePerceptronModelWriter(model, outputFile);

      } else {
        throw new RuntimeException("Unknown model type: " + type);
      }

      writer.persist();


    } catch (Exception e) {
      System.out.print("Unable to create model due to exception: ");
      System.out.println(e);
View Full Code Here

TOP

Related Classes of opennlp.model.AbstractModelWriter

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.