Example #1
0
        /// <summary>
        /// Gets the sequence validator.
        /// </summary>
        public override ISequenceValidator <string> GetSequenceValidator()
        {
            var model = ArtifactProvider.GetArtifact <IMaxentModel>("chunker.model");

            if (model == null)
            {
                throw new InvalidOperationException("Unable to retrieve the chunker.model artifact.");
            }

            return(new ParserChunkerSequenceValidator(model.GetOutcomes()));
        }
Example #2
0
        /// <summary>
        /// Validates the parsed artifacts.
        /// </summary>
        /// <exception cref="InvalidFormatException">Invalid artifact map.</exception>
        public override void ValidateArtifactMap()
        {
            // Ensure that the tag dictionary is compatible with the model

            var tagDicEntry = ArtifactProvider.GetArtifact <ITagDictionary>(TagDictionaryEntryName);

            if (tagDicEntry != null && !ArtifactProvider.IsLoadedFromSerialized)
            {
                ValidatePOSDictionary((POSDictionary)tagDicEntry, Model);
            }

            dictionary = ArtifactProvider.GetArtifact <Dictionary.Dictionary>(NgramDictionaryEntryName);
        }
        /// <summary>
        /// Creates the <see cref="IAdaptiveFeatureGenerator"/>.
        /// Usually this is a set of generators contained in the <see cref="AggregatedFeatureGenerator"/>.
        /// </summary>
        /// <returns>The feature generator or null if there is no descriptor in the model.</returns>
        public virtual IAdaptiveFeatureGenerator CreateFeatureGenerators()
        {
            byte[] descriptorBytes;
            if (FeatureGenerator == null && ArtifactProvider != null)
            {
                descriptorBytes = ArtifactProvider.GetArtifact <byte[]>(TokenNameFinderModel.GeneratorDescriptorEntry);
            }
            else
            {
                descriptorBytes = FeatureGenerator;
            }

            if (descriptorBytes != null)
            {
                var descriptorIn = new MemoryStream(descriptorBytes);

                try {
                    return(GeneratorFactory.Create(descriptorIn, identifier => {
                        try {
                            if (ArtifactProvider != null)
                            {
                                return ArtifactProvider.GetArtifact <object>(identifier);
                            }
                            if (Resources.ContainsKey(identifier))
                            {
                                return Resources[identifier];
                            }

                            return null;
                        } catch (Exception ex) {
                            throw new FeatureGeneratorException("A exception with the feature generator has occured.",
                                                                ex);
                        }
                    }));
                } catch (InvalidFormatException ex) {
                    throw new FeatureGeneratorException(
                              // It is assumed that the creation of the feature generation does not
                              // fail after it succeeded once during model loading.

                              // But it might still be possible that such an exception is thrown,
                              // in this case the caller should not be forced to handle the exception
                              // and a Runtime Exception is thrown instead.

                              // If the re-creation of the feature generation fails it is assumed
                              // that this can only be caused by a programming mistake and therefore
                              // throwing a Runtime Exception is reasonable
                              "An error during the creation or re-creation of a feature generator has occurred.", ex);
                }
            }
            return(null);
        }
        /// <summary>
        /// Validates the parsed artifacts.
        /// </summary>
        /// <exception cref="InvalidFormatException">Invalid artifact map.</exception>
        public override void ValidateArtifactMap()
        {
            if (ArtifactProvider.Manifest.Contains(USE_ALPHA_NUMERIC_OPTIMIZATION))
            {
                throw new InvalidFormatException(USE_ALPHA_NUMERIC_OPTIMIZATION + " is a mandatory property!");
            }

            var abbreviationsEntry = ArtifactProvider.GetArtifact <object>(ABBREVIATIONS_ENTRY_NAME);

            if (abbreviationsEntry != null && !(abbreviationsEntry is Dictionary.Dictionary))
            {
                throw new InvalidFormatException("Abbreviations dictionary is not an valid dictionary.");
            }
        }
Example #5
0
        /// <summary>
        /// Validates the parsed artifacts.
        /// </summary>
        /// <exception cref="InvalidFormatException">Invalid artifact map.</exception>
        public override void ValidateArtifactMap()
        {
            if (ArtifactProvider.Manifest[TOKEN_END_PROPERTY] == null)
            {
                throw new InvalidFormatException(TOKEN_END_PROPERTY + " is a mandatory property!");
            }

            var abbreviationsEntry = ArtifactProvider.GetArtifact <Dic>(ABBREVIATIONS_ENTRY_NAME);

            if (abbreviationsEntry == null)
            {
                throw new InvalidFormatException(
                          "Abbreviations dictionary has wrong type, needs to be of type Dictionary!");
            }
        }