예제 #1
0
        /// <summary>
        /// Updates the feature generator with the given descriptor.
        /// </summary>
        /// <param name="descriptor">The descriptor.</param>
        /// <returns>A updated <see cref="ITokenNameFinder"/> model.</returns>
        public TokenNameFinderModel UpdateFeatureGenerator(byte[] descriptor)
        {
            if (artifactMap == null || !artifactMap.ContainsKey(MaxentModelEntry))
            {
                return(null);
            }

            TokenNameFinderModel model;
            var meModel = artifactMap[MaxentModelEntry] as IMaxentModel;

            if (meModel != null)
            {
                model = new TokenNameFinderModel(
                    Language,
                    meModel,
                    1,
                    descriptor,
                    new Dictionary <string, object>(),
                    new Dictionary <string, string>(),
                    Factory.CreateSequenceCodec(),
                    Factory);

                goto found;
            }

            var scModel = artifactMap[MaxentModelEntry] as ISequenceClassificationModel <string>;

            if (scModel != null)
            {
                model = new TokenNameFinderModel(
                    Language,
                    NameFinderSequenceModel,
                    descriptor,
                    new Dictionary <string, object>(),
                    new Dictionary <string, string>(),
                    Factory.CreateSequenceCodec(),
                    Factory);
                goto found;
            }

            throw new NotSupportedException("Unexpected model type in the artifact map.");

found:

            model.artifactMap.Clear();
            model.artifactMap.AddRange(artifactMap);
            model.artifactMap[GeneratorDescriptorEntry] = descriptor;

            return(model);
        }
예제 #2
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));
        }
예제 #3
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));
        }
예제 #4
0
 private static bool HasOtherAsOutcome(TokenNameFinderModel nameFinderModel) {
     var outcomes = nameFinderModel.NameFinderSequenceModel.GetOutcomes();
     return outcomes.Any(s => s.Equals(NameFinderME.Other));
 }
예제 #5
0
        /// <summary>
        /// Updates the feature generator with the given descriptor.
        /// </summary>
        /// <param name="descriptor">The descriptor.</param>
        /// <returns>A updated <see cref="ITokenNameFinder"/> model.</returns>
        public TokenNameFinderModel UpdateFeatureGenerator(byte[] descriptor) {
            if (artifactMap == null || !artifactMap.ContainsKey(MaxentModelEntry))
                return null;

            TokenNameFinderModel model;
            var meModel = artifactMap[MaxentModelEntry] as IMaxentModel;
            if (meModel != null) {
                model = new TokenNameFinderModel(
                    Language, 
                    meModel, 
                    1, 
                    descriptor, 
                    new Dictionary<string, object>(), 
                    new Dictionary<string, string>(), 
                    Factory.CreateSequenceCodec(),
                    Factory);

                goto found;
            } 

            var scModel = artifactMap[MaxentModelEntry] as ISequenceClassificationModel<string>;
            if (scModel != null) {
                model = new TokenNameFinderModel(
                    Language, 
                    NameFinderSequenceModel, 
                    descriptor, 
                    new Dictionary<string, object>(), 
                    new Dictionary<string, string>(), 
                    Factory.CreateSequenceCodec(),
                    Factory);
                goto found;
            }

            throw new NotSupportedException("Unexpected model type in the artifact map.");

            found:

            model.artifactMap.Clear();
            model.artifactMap.AddRange(artifactMap);
            model.artifactMap[GeneratorDescriptorEntry] = descriptor;

            return model;
        }