Package opennlp.model

Examples of opennlp.model.MaxentModel


  public void testBestSequence() {
    String sequence[] = {"1", "2", "3", "2", "1"};
    BeamSearchContextGenerator<String> cg = new IdentityFeatureGenerator(sequence);
   
    String outcomes[] = new String[] {"1", "2", "3"};
    MaxentModel model = new IdentityModel(outcomes);
   
    BeamSearch<String> bs = new BeamSearch<String>(2, cg, model);
   
    Sequence seq = bs.bestSequence(sequence, null);
    assertNotNull(seq);
View Full Code Here


  public void testBestSequenceWithValidator() {
    String sequence[] = {"1", "2", "3", "2", "1"};
    BeamSearchContextGenerator<String> cg = new IdentityFeatureGenerator(sequence);
   
    String outcomes[] = new String[] {"1", "2", "3"};
    MaxentModel model = new IdentityModel(outcomes);
   
    BeamSearch<String> bs = new BeamSearch<String>(2, cg, model, new SequenceValidator<String>(){

      public boolean validSequence(int i, String[] inputSequence,
          String[] outcomesSequence, String outcome) {
View Full Code Here

   
    String sequence[] = new String[0];
    BeamSearchContextGenerator<String> cg = new IdentityFeatureGenerator(sequence);
   
    String outcomes[] = new String[] {"1", "2", "3"};
    MaxentModel model = new IdentityModel(outcomes);
   
    BeamSearch<String> bs = new BeamSearch<String>(3, cg, model);
   
    Sequence seq = bs.bestSequence(sequence, null);
    assertNotNull(seq);
View Full Code Here

  public void testBestSequenceOneElementInput() {
    String sequence[] = {"1"};
    BeamSearchContextGenerator<String> cg = new IdentityFeatureGenerator(sequence);
   
    String outcomes[] = new String[] {"1", "2", "3"};
    MaxentModel model = new IdentityModel(outcomes);
   
    BeamSearch<String> bs = new BeamSearch<String>(3, cg, model);
   
    Sequence seq = bs.bestSequence(sequence, null);
    assertNotNull(seq);
View Full Code Here

   
    String sequence[] = new String[0];
    BeamSearchContextGenerator<String> cg = new IdentityFeatureGenerator(sequence);
   
    String outcomes[] = new String[] {"1", "2", "3"};
    MaxentModel model = new IdentityModel(outcomes);
   
    BeamSearch<String> bs = new BeamSearch<String>(3, cg, model);
   
    Sequence seq = bs.bestSequence(sequence, null);
    assertNotNull(seq);
View Full Code Here

  public void testBestSequenceOneElementInput() {
    String sequence[] = {"1"};
    BeamSearchContextGenerator<String> cg = new IdentityFeatureGenerator(sequence);
   
    String outcomes[] = new String[] {"1", "2", "3"};
    MaxentModel model = new IdentityModel(outcomes);
   
    BeamSearch<String> bs = new BeamSearch<String>(3, cg, model);
   
    Sequence seq = bs.bestSequence(sequence, null);
    assertNotNull(seq);
View Full Code Here

  public void testBestSequence() {
    String sequence[] = {"1", "2", "3", "2", "1"};
    BeamSearchContextGenerator<String> cg = new IdentityFeatureGenerator(sequence);
   
    String outcomes[] = new String[] {"1", "2", "3"};
    MaxentModel model = new IdentityModel(outcomes);
   
    BeamSearch<String> bs = new BeamSearch<String>(2, cg, model);
   
    Sequence seq = bs.bestSequence(sequence, null);
    assertNotNull(seq);
View Full Code Here

  public void testBestSequenceWithValidator() {
    String sequence[] = {"1", "2", "3", "2", "1"};
    BeamSearchContextGenerator<String> cg = new IdentityFeatureGenerator(sequence);
   
    String outcomes[] = new String[] {"1", "2", "3"};
    MaxentModel model = new IdentityModel(outcomes);
   
    BeamSearch<String> bs = new BeamSearch<String>(2, cg, model, new SequenceValidator<String>(){

      public boolean validSequence(int i, String[] inputSequence,
          String[] outcomesSequence, String outcome) {
View Full Code Here

      modelFileName = args[ai++];
      dataFileName = args[ai++];

      ModelApplier predictor = null;
      try {
        MaxentModel m = new GenericModelReader(new File(modelFileName)).getModel();
        predictor = new ModelApplier(m);
      } catch (Exception e) {
        e.printStackTrace();
        System.exit(0);
      }
View Full Code Here

    StringReader smallReader = new StringReader(smallValues);
    EventStream smallEventStream = new RealBasicEventStream(
        new PlainTextByLineDataStream(smallReader));

    MaxentModel smallModel = GIS.trainModel(100,
        new OnePassRealValueDataIndexer(smallEventStream, 0), false);
    String[] contexts = smallTest.split(" ");
    float[] values = RealValueFileEventStream.parseContexts(contexts);
    double[] smallResults = smallModel.eval(contexts, values);

    String smallResultString = smallModel.getAllOutcomes(smallResults);
    System.out.println("smallResults: " + smallResultString);

    StringReader largeReader = new StringReader(largeValues);
    EventStream largeEventStream = new RealBasicEventStream(
        new PlainTextByLineDataStream(largeReader));

    MaxentModel largeModel = GIS.trainModel(100,
        new OnePassRealValueDataIndexer(largeEventStream, 0), false);
    contexts = largeTest.split(" ");
    values = RealValueFileEventStream.parseContexts(contexts);
    double[] largeResults = largeModel.eval(contexts, values);

    String largeResultString = smallModel.getAllOutcomes(largeResults);
    System.out.println("largeResults: " + largeResultString);

    assertEquals(smallResults.length, largeResults.length);
    for (int i = 0; i < smallResults.length; i++) {
      System.out.println(String.format(
          "classifiy with smallModel: %1$s = %2$f", smallModel.getOutcome(i),
          smallResults[i]));
      System.out.println(String.format(
          "classifiy with largeModel: %1$s = %2$f", largeModel.getOutcome(i),
          largeResults[i]));
      assertEquals(smallResults[i], largeResults[i], 0.01f);
    }
  }
View Full Code Here

TOP

Related Classes of opennlp.model.MaxentModel

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.