/// <summary>
        /// Creates a new event reader based on the specified data reader using the specified context generator.
        /// </summary>
        /// <param name="dataReader">
        /// The data reader for this event reader.
        /// </param>
        /// <param name="contextGenerator">
        /// The context generator which should be used in the creation of events for this event stream.
        /// </param>
        public NameFinderEventReader(SharpEntropy.ITrainingDataReader <string> dataReader, INameContextGenerator contextGenerator)
        {
            mDataReader       = dataReader;
            mContextGenerator = contextGenerator;
            mEventIndex       = 0;
            mPreviousTags     = new Dictionary <string, string>();

            //prime events with first line of data stream.
            if (mDataReader.HasNext())
            {
                mLine = mDataReader.NextToken();
                if (mLine.Length == 0)
                {
                    mPreviousTags.Clear();
                }
                else
                {
                    AddEvents(mLine);
                }
            }
            else
            {
                mEvents = new SharpEntropy.TrainingEvent[0];
            }
        }
Пример #2
0
		/// <summary>
		/// Creates a new event reader based on the specified data reader using the specified context generator.
		/// </summary>
		/// <param name="dataReader">
		/// The data reader for this event reader.
		/// </param>
		/// <param name="contextGenerator">
		/// The context generator which should be used in the creation of events for this event stream.
		/// </param>
		public NameFinderEventReader(SharpEntropy.ITrainingDataReader<string> dataReader, INameContextGenerator contextGenerator)
		{
			mDataReader = dataReader;
			mContextGenerator = contextGenerator;
			mEventIndex = 0;
            mPreviousTags = new Dictionary<string, string>();

			//prime events with first line of data stream.
			if (mDataReader.HasNext())
			{
				mLine = mDataReader.NextToken();
				if (mLine.Length == 0)
				{
					mPreviousTags.Clear();
				}
				else
				{
					AddEvents(mLine);
				}
			}
			else
			{
				mEvents = new SharpEntropy.TrainingEvent[0];
			}
		}
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NameSampleSequenceStream"/> class.
 /// </summary>
 /// <param name="psi">The sample stream.</param>
 /// <param name="pcg">The context generator.</param>
 /// <param name="useOutcomes">if set to <c>true</c> will be used in the samples.</param>
 /// <param name="seqCodec">The sequence codec.</param>
 public NameSampleSequenceStream(IObjectStream<NameSample> psi, INameContextGenerator pcg, bool useOutcomes,
     ISequenceCodec<string> seqCodec) {
     this.psi = psi;
     this.useOutcomes = useOutcomes;
     this.pcg = pcg;
     this.seqCodec = seqCodec;
 }
Пример #4
0
 public NameSampleSequenceStream(IObjectStream <NameSample> psi, INameContextGenerator pcg, bool useOutcomes, ISequenceCodec <string> seqCodec)
 {
     this.psi         = psi;
     this.useOutcomes = useOutcomes;
     this.pcg         = pcg;
     this.seqCodec    = seqCodec;
 }
        public NameFinderEventStream(IObjectStream <NameSample> dataStream, string type, INameContextGenerator contextGenerator, ISequenceCodec <string> codec) : base(dataStream)
        {
            this.codec = codec ?? new BioCodec();

            additionalContextFeatureGenerator = new AdditionalContextFeatureGenerator();

            this.contextGenerator = contextGenerator;
            this.contextGenerator.AddFeatureGenerator(new WindowFeatureGenerator(additionalContextFeatureGenerator, 8, 8));

            // TODO: How to make the type really do something?!
            // Type = type ?? "default";
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NameFinderME"/> using the given <see cref="TokenNameFinderModel"/>.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <exception cref="System.ArgumentNullException">model</exception>
        public NameFinderME(TokenNameFinderModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            sequenceCodec     = model.Factory.CreateSequenceCodec();
            sequenceValidator = sequenceCodec.CreateSequenceValidator();

            this.model = model.NameFinderSequenceModel;

            contextGenerator = model.Factory.CreateContextGenerator();

            // TODO: We should deprecate this. And come up with a better solution!
            additionalContextFeatureGenerator = new AdditionalContextFeatureGenerator();
            contextGenerator.AddFeatureGenerator(
                new WindowFeatureGenerator(additionalContextFeatureGenerator, 8, 8));
        }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NameSampleSequenceStream"/> class.
 /// </summary>
 /// <param name="psi">The sample stream.</param>
 /// <param name="pcg">The context generator.</param>
 public NameSampleSequenceStream(IObjectStream<NameSample> psi, INameContextGenerator pcg)
     : this(psi, pcg, true) {}
 /// <summary>
 /// Creates a new name finder with the specified model and context generator.
 /// </summary>
 /// <param name="model">
 /// The model to be used to find names.
 /// </param>
 /// <param name="contextGenerator">
 /// The context generator to be used with this name finder.
 /// </param>
 public MaximumEntropyNameFinder(SharpEntropy.IMaximumEntropyModel model, INameContextGenerator contextGenerator) :
     this(model, contextGenerator, 10)
 {
 }
 /// <summary>
 /// Creates a new name finder with the specified model and context generator.
 /// </summary>
 /// <param name="model">
 /// The model to be used to find names.
 /// </param>
 /// <param name="contextGenerator">
 /// The context generator to be used with this name finder.
 /// </param>
 /// <param name="beamSize">
 /// The size of the beam to be used in decoding this model.
 /// </param>
 public MaximumEntropyNameFinder(SharpEntropy.IMaximumEntropyModel model, INameContextGenerator contextGenerator, int beamSize)
 {
     mModel            = model;
     mContextGenerator = contextGenerator;
     mBeam             = new NameBeamSearch(this, beamSize, contextGenerator, model, beamSize);
 }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NameSampleSequenceStream"/> class using the <seealso cref="BioCodec"/> as sequence codec.
 /// </summary>
 /// <param name="psi">The sample stream.</param>
 /// <param name="pcg">The context generator.</param>
 /// <param name="useOutcomes">if set to <c>true</c> will be used in the samples.</param>
 public NameSampleSequenceStream(IObjectStream <NameSample> psi, INameContextGenerator pcg, bool useOutcomes)
     : this(psi, pcg, useOutcomes, new BioCodec())
 {
 }
Пример #11
0
 /// <summary>
 /// Creates a beam seach of the specified size using the specified model with the specified context generator.
 /// </summary>
 /// <param name="nameFinder">
 /// The associated MaximumEntropyNameFinder instance.
 /// </param>
 /// <param name="size">
 /// The size of the beam.
 /// </param>
 /// <param name="contextGenerator">
 /// The context generator used with the specified model.
 /// </param>
 /// <param name="model">
 /// The model used to determine names.
 /// </param>
 /// <param name="beamSize">
 /// The size of the beam to use in searching.
 /// </param>
 public NameBeamSearch(MaximumEntropyNameFinder nameFinder, int size, INameContextGenerator contextGenerator, SharpEntropy.IMaximumEntropyModel model, int beamSize) :
     base(size, contextGenerator, model, beamSize)
 {
     _nameFinder = nameFinder;
 }
        internal static List <Event> GenerateEvents(String[] sentence, String[] outcomes, INameContextGenerator cg)
        {
            var events = new List <Event>(outcomes.Length);

            for (int i = 0; i < outcomes.Length; i++)
            {
                events.Add(new Event(outcomes[i], cg.GetContext(i, sentence, outcomes, null)));
            }
            cg.UpdateAdaptiveData(sentence, outcomes);
            return(events);
        }
Пример #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NameSampleSequenceStream"/> class.
 /// </summary>
 /// <param name="psi">The sample stream.</param>
 /// <param name="pcg">The context generator.</param>
 public NameSampleSequenceStream(IObjectStream <NameSample> psi, INameContextGenerator pcg)
     : this(psi, pcg, true)
 {
 }
Пример #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NameSampleSequenceStream"/> class using the <seealso cref="BioCodec"/> as sequence codec.
 /// </summary>
 /// <param name="psi">The sample stream.</param>
 /// <param name="pcg">The context generator.</param>
 /// <param name="useOutcomes">if set to <c>true</c> will be used in the samples.</param>
 public NameSampleSequenceStream(IObjectStream<NameSample> psi, INameContextGenerator pcg, bool useOutcomes)
     : this(psi, pcg, useOutcomes, new BioCodec()) {}
Пример #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NameFinderME"/> using the given <see cref="TokenNameFinderModel"/>.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <exception cref="System.ArgumentNullException">model</exception>
        public NameFinderME(TokenNameFinderModel model) {
            if (model == null)
                throw new ArgumentNullException("model");

            sequenceCodec = model.Factory.CreateSequenceCodec();
            sequenceValidator = sequenceCodec.CreateSequenceValidator();

            this.model = model.NameFinderSequenceModel;

            contextGenerator = model.Factory.CreateContextGenerator();

            // TODO: We should deprecate this. And come up with a better solution!
            additionalContextFeatureGenerator = new AdditionalContextFeatureGenerator();
            contextGenerator.AddFeatureGenerator(
                new WindowFeatureGenerator(additionalContextFeatureGenerator, 8, 8));
        }
 /// <summary>
 /// Creates a new name finder with the specified model and context generator.
 /// </summary>
 /// <param name="model">
 /// The model to be used to find names.
 /// </param>
 /// <param name="contextGenerator">
 /// The context generator to be used with this name finder.
 /// </param>
 /// <param name="beamSize">
 /// The size of the beam to be used in decoding this model.
 /// </param>
 public MaximumEntropyNameFinder(SharpEntropy.IMaximumEntropyModel model, INameContextGenerator contextGenerator, int beamSize)
 {
     mModel = model;
     mContextGenerator = contextGenerator;
     mBeam = new NameBeamSearch(this, beamSize, contextGenerator, model, beamSize);
 }
 /// <summary>
 /// Creates a new name finder with the specified model and context generator.
 /// </summary>
 /// <param name="model">
 /// The model to be used to find names.
 /// </param>
 /// <param name="contextGenerator">
 /// The context generator to be used with this name finder.
 /// </param>
 public MaximumEntropyNameFinder(SharpEntropy.IMaximumEntropyModel model, INameContextGenerator contextGenerator)
     : this(model, contextGenerator, 10)
 {
 }
 /// <summary>
 /// Creates a beam seach of the specified size using the specified model with the specified context generator.
 /// </summary>
 /// <param name="nameFinder">
 /// The associated MaximumEntropyNameFinder instance.
 /// </param>
 /// <param name="size">
 /// The size of the beam.
 /// </param>
 /// <param name="contextGenerator">
 /// The context generator used with the specified model.
 /// </param>
 /// <param name="model">
 /// The model used to determine names.
 /// </param>
 /// <param name="beamSize">
 /// The size of the beam to use in searching.
 /// </param>
 public NameBeamSearch(MaximumEntropyNameFinder nameFinder, int size, INameContextGenerator contextGenerator, SharpEntropy.IMaximumEntropyModel model, int beamSize)
     : base(size, contextGenerator, model, beamSize)
 {
     mNameFinder = nameFinder;
 }