public void TestOutcomesForSingleSentence() { const string sentence = "That_DT sounds_VBZ good_JJ ._."; var sample = POSSample.Parse(sentence); var eventStream = new POSSampleEventStream(new GenericObjectStream<POSSample>(sample)); Assert.AreEqual("DT", eventStream.Read().Outcome); Assert.AreEqual("VBZ", eventStream.Read().Outcome); Assert.AreEqual("JJ", eventStream.Read().Outcome); Assert.AreEqual(".", eventStream.Read().Outcome); Assert.Null(eventStream.Read()); }
public void TestOutcomesForSingleSentence() { const string sentence = "That_DT sounds_VBZ good_JJ ._."; var sample = POSSample.Parse(sentence); var eventStream = new POSSampleEventStream(new GenericObjectStream <POSSample>(sample)); Assert.AreEqual("DT", eventStream.Read().Outcome); Assert.AreEqual("VBZ", eventStream.Read().Outcome); Assert.AreEqual("JJ", eventStream.Read().Outcome); Assert.AreEqual(".", eventStream.Read().Outcome); Assert.Null(eventStream.Read()); }
/// <summary> /// Trains a Part of Speech model with the given parameters. /// </summary> /// <param name="languageCode">The language code.</param> /// <param name="samples">The data samples.</param> /// <param name="parameters">The machine learnable parameters.</param> /// <param name="factory">The sentence detector factory.</param> /// <param name="monitor"> /// A evaluation monitor that can be used to listen the messages during the training or it can cancel the training operation. /// This argument can be a <c>null</c> value. /// </param> /// <returns>The trained <see cref="POSModel"/> object.</returns> /// <exception cref="System.NotSupportedException">Trainer type is not supported.</exception> public static POSModel Train(string languageCode, IObjectStream<POSSample> samples, TrainingParameters parameters, POSTaggerFactory factory, Monitor monitor) { //int beamSize = trainParams.Get(Parameters.BeamSize, NameFinderME.DefaultBeamSize); var contextGenerator = factory.GetPOSContextGenerator(); var manifestInfoEntries = new Dictionary<string, string>(); var trainerType = TrainerFactory.GetTrainerType(parameters); switch (trainerType) { case TrainerType.EventModelTrainer: var es = new POSSampleEventStream(samples, contextGenerator); var trainer = TrainerFactory.GetEventTrainer(parameters, manifestInfoEntries, monitor); var eventModel = trainer.Train(es); return new POSModel(languageCode, eventModel, manifestInfoEntries, factory); case TrainerType.EventModelSequenceTrainer: var ss = new POSSampleSequenceStream(samples, contextGenerator); var trainer2 = TrainerFactory.GetEventModelSequenceTrainer(parameters, manifestInfoEntries, monitor); var seqModel = trainer2.Train(ss); return new POSModel(languageCode, seqModel, manifestInfoEntries, factory); case TrainerType.SequenceTrainer: var trainer3 = TrainerFactory.GetSequenceModelTrainer(parameters, manifestInfoEntries, monitor); // TODO: This will probably cause issue, since the feature generator uses the outcomes array var ss2 = new POSSampleSequenceStream(samples, contextGenerator); var seqPosModel = trainer3.Train(ss2); return new POSModel(languageCode, seqPosModel, manifestInfoEntries, factory); default: throw new NotSupportedException("Trainer type is not supported."); } }