예제 #1
0
        protected AbstractParserEventStream(
            IObjectStream <Parse> samples,
            IHeadRules headRules,
            ParserEventTypeEnum type,
            Dictionary.Dictionary dictionary) : base(samples)
        {
            Rules         = headRules;
            Punctuation   = headRules.PunctuationTags;
            Dictionary    = dictionary;
            FixPossesives = false;

            Type = type;

#pragma warning disable 618
            switch (type)
            {
            case ParserEventTypeEnum.Chunk:
                chunkerContextGenerator = new ChunkContextGenerator();
                break;

            case ParserEventTypeEnum.Tag:
                posContextGenerator = new DefaultPOSContextGenerator(null);
                break;
            }
#pragma warning restore 618
        }
예제 #2
0
파일: ChunkerME.cs 프로젝트: qooba/SharpNL
        /// <summary>
        /// Initializes a new instance of the <see cref="ChunkerME"/> with the specified <see cref="ChunkerModel"/>.
        /// </summary>
        /// <param name="model">The chunker model.</param>
        public ChunkerME(ChunkerModel model)
        {
            contextGenerator  = model.Factory.GetContextGenerator();
            sequenceValidator = model.Factory.GetSequenceValidator();

            this.model = model.ChunkerSequenceModel ?? new BeamSearch(model.BeamSize, model.MaxentModel);
        }
예제 #3
0
파일: ChunkerME.cs 프로젝트: knuppe/SharpNL
        /// <summary>
        /// Initializes the current instance with the specified model and the specified beam size.
        /// </summary>
        /// <param name="model">The model for this chunker</param>
        /// <param name="beamSize">The size of the beam that should be used when decoding sequences.</param>
        /// <param name="sequenceValidator">The <see cref="ISequenceValidator{String}"/> to determines whether the outcome is valid for the preceding sequence. This can be used to implement constraints on what sequences are valid..</param>
        /// <param name="contextGenerator">The context generator.</param>
        internal ChunkerME(ChunkerModel model, int beamSize, ISequenceValidator<string> sequenceValidator, IChunkerContextGenerator contextGenerator) {
            // This method is marked as deprecated in the OpenNLP, but it is required in the Parser,
            // I could change the cg in the factory, but its not ideal in this situation (i think) :P

            this.sequenceValidator = sequenceValidator;
            this.contextGenerator = contextGenerator;
            this.model = model.ChunkerSequenceModel ?? new BeamSearch(beamSize, model.MaxentModel);
        }
예제 #4
0
파일: ChunkerME.cs 프로젝트: qooba/SharpNL
        /// <summary>
        /// Initializes the current instance with the specified model and the specified beam size.
        /// </summary>
        /// <param name="model">The model for this chunker</param>
        /// <param name="beamSize">The size of the beam that should be used when decoding sequences.</param>
        /// <param name="sequenceValidator">The <see cref="ISequenceValidator{String}"/> to determines whether the outcome is valid for the preceding sequence. This can be used to implement constraints on what sequences are valid..</param>
        /// <param name="contextGenerator">The context generator.</param>
        internal ChunkerME(ChunkerModel model, int beamSize, ISequenceValidator <string> sequenceValidator, IChunkerContextGenerator contextGenerator)
        {
            // This method is marked as deprecated in the OpenNLP, but it is required in the Parser,
            // I could change the cg in the factory, but its not ideal in this situation (i think) :P

            this.sequenceValidator = sequenceValidator;
            this.contextGenerator  = contextGenerator;
            this.model             = model.ChunkerSequenceModel ?? new BeamSearch(beamSize, model.MaxentModel);
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChunkSampleSequenceStream" /> class using the given parameters.
        /// </summary>
        /// <param name="samples">The chunk samples.</param>
        /// <param name="contextGenerator">The chunker context generator.</param>
        /// <exception cref="System.ArgumentNullException">
        /// The <paramref name="samples"/> is null.
        /// or
        /// The <paramref name="contextGenerator"/> is null.
        /// </exception>
        public ChunkSampleSequenceStream(IObjectStream<ChunkSample> samples, IChunkerContextGenerator contextGenerator) {
            if (samples == null)
                throw new ArgumentNullException("samples");

            if (contextGenerator == null)
                throw new ArgumentNullException("contextGenerator");

            this.samples = samples;
            this.contextGenerator = contextGenerator;
        }
예제 #6
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 reader.
 /// </param>
 public ChunkerEventReader(SharpEntropy.ITrainingDataReader <string> dataReader, IChunkerContextGenerator contextGenerator)
 {
     mContextGenerator = contextGenerator;
     mDataReader       = dataReader;
     mEventIndex       = 0;
     if (dataReader.HasNext())
     {
         AddNewEvents();
     }
     else
     {
         mEvents = new SharpEntropy.TrainingEvent[0];
     }
 }
예제 #7
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 reader.
		/// </param>
        public ChunkerEventReader(SharpEntropy.ITrainingDataReader<string> dataReader, IChunkerContextGenerator contextGenerator)
		{
			mContextGenerator = contextGenerator;
			mDataReader = dataReader;
			mEventIndex = 0;
			if (dataReader.HasNext())
			{
				AddNewEvents();
			}
			else
			{
				mEvents = new SharpEntropy.TrainingEvent[0];
			}
		}
예제 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChunkSampleSequenceStream" /> class using the given parameters.
        /// </summary>
        /// <param name="samples">The chunk samples.</param>
        /// <param name="contextGenerator">The chunker context generator.</param>
        /// <exception cref="System.ArgumentNullException">
        /// The <paramref name="samples"/> is null.
        /// or
        /// The <paramref name="contextGenerator"/> is null.
        /// </exception>
        public ChunkSampleSequenceStream(IObjectStream <ChunkSample> samples, IChunkerContextGenerator contextGenerator)
        {
            if (samples == null)
            {
                throw new ArgumentNullException(nameof(samples));
            }

            if (contextGenerator == null)
            {
                throw new ArgumentNullException(nameof(contextGenerator));
            }

            this.samples          = samples;
            this.contextGenerator = contextGenerator;
        }
예제 #9
0
 public ChunkBeamSearch(MaximumEntropyChunker maxentChunker, int size, IChunkerContextGenerator contextGenerator, SharpEntropy.IMaximumEntropyModel model) : base(size, contextGenerator, model)
 {
     mMaxentChunker = maxentChunker;
 }
예제 #10
0
		/// <summary>
		/// Creates a chunker using the specified model and context generator and decodes the
		/// model using a beam search of the specified size.
		/// </summary>
		/// <param name="model">The maximum entropy model for this chunker</param>
		/// <param name="contextGenerator">The context generator to be used by the specified model</param>
		/// <param name="beamSize">The size of the beam that should be used when decoding sequences</param>
		public MaximumEntropyChunker(SharpEntropy.IMaximumEntropyModel model, IChunkerContextGenerator contextGenerator, int beamSize)
		{
			Beam = new ChunkBeamSearch(this, beamSize, contextGenerator, model);
			Model = model;
		}
예제 #11
0
 /// <summary>
 /// Creates a chunker using the specified model and context generator and decodes the
 /// model using a beam search of the specified size.
 /// </summary>
 /// <param name="model">
 /// The maximum entropy model for this chunker.
 /// </param>
 /// <param name="contextGenerator">
 /// The context generator to be used by the specified model.
 /// </param>
 /// <param name="beamSize">
 /// The size of the beam that should be used when decoding sequences.
 /// </param>
 public MaximumEntropyChunker(SharpEntropy.IMaximumEntropyModel model, IChunkerContextGenerator contextGenerator, int beamSize)
 {
     mBeam  = new ChunkBeamSearch(this, beamSize, contextGenerator, model);
     mModel = model;
 }
예제 #12
0
 public ChunkBeamSearch(MaximumEntropyChunker maxentChunker, int size, IChunkerContextGenerator contextGenerator, SharpEntropy.IMaximumEntropyModel model)
     : base(size, contextGenerator, model)
 {
     _maxentChunker = maxentChunker;
 }
예제 #13
0
		/// <summary>
		/// Creates a chunker using the specified model and context generator.
		/// </summary>
		/// <param name="model">The maximum entropy model for this chunker</param>
		/// <param name="contextGenerator">The context generator to be used by the specified model</param>
		public MaximumEntropyChunker(SharpEntropy.IMaximumEntropyModel model, IChunkerContextGenerator contextGenerator):
            this(model, contextGenerator, 10){}
예제 #14
0
		/// <summary>
		/// Creates a chunker using the specified model and context generator.
		/// </summary>
		/// <param name="model">
		/// The maximum entropy model for this chunker.
		/// </param>
		/// <param name="contextGenerator">
		/// The context generator to be used by the specified model.
		/// </param>
		public MaximumEntropyChunker(MaxEntropyModel_Interface model, IChunkerContextGenerator contextGenerator):this(model, contextGenerator, 10)
		{
		}
예제 #15
0
파일: ChunkerME.cs 프로젝트: knuppe/SharpNL
        /// <summary>
        /// Initializes a new instance of the <see cref="ChunkerME"/> with the specified <see cref="ChunkerModel"/>.
        /// </summary>
        /// <param name="model">The chunker model.</param>
        public ChunkerME(ChunkerModel model) {
            contextGenerator = model.Factory.GetContextGenerator();
            sequenceValidator = model.Factory.GetSequenceValidator();

            this.model = model.ChunkerSequenceModel ?? new BeamSearch(model.BeamSize, model.MaxentModel);
        }
예제 #16
0
			public ChunkBeamSearch(MaximumEntropyChunker maxentChunker, int size, IChunkerContextGenerator contextGenerator, MaxEntropyModel_Interface model):base(size, contextGenerator, model)
			{
				mMaxentChunker = maxentChunker;
			}
예제 #17
0
 /// <summary>
 /// Creates a chunker using the specified model and context generator.
 /// </summary>
 /// <param name="model">
 /// The maximum entropy model for this chunker.
 /// </param>
 /// <param name="contextGenerator">
 /// The context generator to be used by the specified model.
 /// </param>
 public MaximumEntropyChunker(SharpEntropy.IMaximumEntropyModel model, IChunkerContextGenerator contextGenerator) : this(model, contextGenerator, 10)
 {
 }
예제 #18
0
 /// <summary>
 /// Creates a new event stream based on the specified data stream using the specified context generator.
 /// </summary>
 /// <param name="samples">The samples for this event stream.</param>
 /// <param name="cg">The context generator which should be used in the creation of events for this event stream.</param>
 public ChunkerEventStream(IObjectStream <ChunkSample> samples, IChunkerContextGenerator cg) : base(samples)
 {
     this.cg = cg;
 }
예제 #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChunkSampleSequenceStream"/> class using the given parameters.
 /// </summary>
 /// <param name="samples">The chunk samples.</param>
 /// <param name="contextGenerator">The chunker context generator.</param>
 public ChunkSampleSequenceStream(IObjectStream <ChunkSample> samples, IChunkerContextGenerator contextGenerator)
 {
     this.samples          = samples;
     this.contextGenerator = contextGenerator;
 }
예제 #20
0
		/// <summary>
		/// Creates a chunker using the specified model and context generator and decodes the
		/// model using a beam search of the specified size.
		/// </summary>
		/// <param name="model">
		/// The maximum entropy model for this chunker.
		/// </param>
		/// <param name="contextGenerator">
		/// The context generator to be used by the specified model.
		/// </param>
		/// <param name="beamSize">
		/// The size of the beam that should be used when decoding sequences.
		/// </param>
		public MaximumEntropyChunker(MaxEntropyModel_Interface model, IChunkerContextGenerator contextGenerator, int beamSize)
		{
			mBeam = new ChunkBeamSearch(this, beamSize, contextGenerator, model);
			mModel = model;
		}