Package opennlp.model

Examples of opennlp.model.EventStream


        new File(modelsDir,"en-pos-maxent.bin"));
    POSModel posModel = new POSModel(posStream);
    POSTaggerME tagger =  new POSTaggerME(posModel);
    Parser parser = new ChunkParser(chunker, tagger);
    AnswerTypeContextGenerator actg = new AnswerTypeContextGenerator(wordnetDir);
    EventStream es = new AnswerTypeEventStream(eventFile,actg,parser);
    while(es.hasNext()) {
      System.out.println(es.next().toString());
    }
  }
View Full Code Here


        "."};
   
    NameSample nameSample = new NameSample(sentence,
        new Span[]{new Span(0, 2, "person")}, false);
   
    EventStream eventStream = new NameFinderEventStream(
        ObjectStreamUtils.createObjectStream(nameSample));
   
    assertTrue(eventStream.hasNext());
    assertEquals("person-" + NameFinderME.START, eventStream.next().getOutcome());
    assertTrue(eventStream.hasNext());
    assertEquals("person-" + NameFinderME.CONTINUE, eventStream.next().getOutcome());
   
    for (int i = 0; i < 10; i++) {
      Assert.assertTrue(eventStream.hasNext());
      Assert.assertEquals(NameFinderME.OTHER, eventStream.next().getOutcome());
    }
   
    assertFalse(eventStream.hasNext());
  }
View Full Code Here

    }
    String dataFileName = new String(args[ai++]);
    String modelFileName = new String(args[ai]);
    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));
      }
View Full Code Here

        e.printStackTrace();
        System.exit(0);
      }

      try {
        EventStream es = new BasicEventStream(new PlainTextByLineDataStream(
            new FileReader(new File(dataFileName))), ",");

        while (es.hasNext())
          predictor.eval(es.next(), real);

        return;
      } catch (Exception e) {
        System.out.println("Unable to read from specified file: "
            + modelFileName);
View Full Code Here

  public void testOutcomesForSingleSentence() throws Exception {
    String sentence = "That_DT sounds_VBZ good_JJ ._.";
   
    POSSample sample = POSSample.parse(sentence);
   
    EventStream eventStream = new POSSampleEventStream(
        ObjectStreamUtils.createObjectStream(sample));
   
    Assert.assertTrue(eventStream.hasNext());
    Assert.assertEquals("DT", eventStream.next().getOutcome());
   
    Assert.assertTrue(eventStream.hasNext());
    Assert.assertEquals("VBZ", eventStream.next().getOutcome());

    Assert.assertTrue(eventStream.hasNext());
    Assert.assertEquals("JJ", eventStream.next().getOutcome());

    Assert.assertTrue(eventStream.hasNext());
    Assert.assertEquals(".", eventStream.next().getOutcome());
   
    Assert.assertFalse(eventStream.hasNext());
  }
View Full Code Here

    Map<String, String> manifestInfoEntries = new HashMap<String, String>();
   
    Factory factory = new Factory();
   
    // TODO: Fix the EventStream to throw exceptions when training goes wrong
    EventStream eventStream = new SDEventStream(samples,
        factory.createSentenceContextGenerator(languageCode, getAbbreviations(abbreviations)),
        factory.createEndOfSentenceScanner(languageCode));
   
    AbstractModel sentModel = TrainUtil.train(eventStream, mlParams.getSettings(), manifestInfoEntries);
   
View Full Code Here

    ObjectStream<SentenceSample> sampleStream =
      ObjectStreamUtils.createObjectStream(sample);
   
    Factory factory = new Factory();
   
    EventStream eventStream = new SDEventStream(sampleStream,
        factory.createSentenceContextGenerator("en"),
        factory.createEndOfSentenceScanner("en"));
   
    assertTrue(eventStream.hasNext());
    assertEquals(SentenceDetectorME.NO_SPLIT, eventStream.next().getOutcome());
   
    assertTrue(eventStream.hasNext());
    assertEquals(SentenceDetectorME.SPLIT, eventStream.next().getOutcome());

    assertTrue(eventStream.hasNext());
    assertEquals(SentenceDetectorME.NO_SPLIT, eventStream.next().getOutcome());

    assertTrue(eventStream.hasNext());
    assertEquals(SentenceDetectorME.SPLIT, eventStream.next().getOutcome());
   
    assertFalse(eventStream.hasNext());
  }
View Full Code Here

    ObjectStream<String> sentenceStream =
      ObjectStreamUtils.createObjectStream("\"<SPLIT>out<SPLIT>.<SPLIT>\"");
 
    ObjectStream<TokenSample> tokenSampleStream = new TokenSampleStream(sentenceStream);
   
    EventStream eventStream = new TokSpanEventStream(tokenSampleStream, false);
   
    assertTrue(eventStream.hasNext());
    assertEquals(TokenizerME.SPLIT, eventStream.next().getOutcome());
    assertTrue(eventStream.hasNext());
    assertTrue(eventStream.hasNext());
    assertEquals(TokenizerME.NO_SPLIT, eventStream.next().getOutcome());
    assertTrue(eventStream.hasNext());
    assertEquals(TokenizerME.NO_SPLIT, eventStream.next().getOutcome());
    assertTrue(eventStream.hasNext());
    assertEquals(TokenizerME.SPLIT, eventStream.next().getOutcome());
    assertTrue(eventStream.hasNext());
    assertEquals(TokenizerME.SPLIT, eventStream.next().getOutcome());
   
    assertFalse(eventStream.hasNext());
  }
View Full Code Here

    String largeValues = "predA=10 predB=20 A\n" + "predB=30 predA=10 B\n";

    String largeTest = "predA=20 predB=20";

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

  }
 
  public static EventStream createTrainingStream() throws IOException {
    List<Event> trainingEvents = readPpaFile("training");

    EventStream trainingStream = new ListEventStream(trainingEvents);
   
    return trainingStream;
  }
View Full Code Here

TOP

Related Classes of opennlp.model.EventStream

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.