コード例 #1
0
        /// <summary>
        /// Attempts to get the compiled FST from the resources, and if that fails, will create it from scratch
        /// </summary>
        public MeasureFSTRecognizer(System.Globalization.CultureInfo culture, int priority,
                                    Core.Resources.IResourceDataAccessor accessor)
            : base(TokenType.Measurement, priority, "Measurement", "MeasureFSTRecognizer")
        {
            if (culture == null)
            {
                throw new ArgumentNullException();
            }
            if (culture.IsNeutralCulture)
            {
                throw new ArgumentException("Cannot compute measurement patterns for neutral cultures");
            }
            if (culture.NumberFormat == null)
            {
                throw new ArgumentException("No number format info available for the specified culture");
            }
            if (accessor == null)
            {
                accessor = new ResourceFileResourceAccessor();
            }

            LanguagePlatform.Lingua.FST.FST fst = null;

            bool attemptLoad = true;

            if (attemptLoad &&
                accessor.GetResourceStatus(culture, Core.Resources.LanguageResourceType.MeasurementFST, true) !=
                Core.Resources.ResourceStatus.NotAvailable)
            {
                // TODO should _Culture be set to the _actual_ culture of the loaded FST, i.e.
                //  the invariant culture for the generic/canonical one?

                byte[] data = accessor.GetResourceData(culture, Core.Resources.LanguageResourceType.MeasurementFST, true);
                if (data == null)
                {
                    throw new Core.LanguagePlatformException(Core.ErrorCode.ResourceNotAvailable);
                }

                fst = LanguagePlatform.Lingua.FST.FST.Create(data);
            }
            else
            {
                fst = CreateFST(culture, Core.CultureInfoExtensions.UseBlankAsWordSeparator(culture));
            }

            _FSTRecognizer = new FSTRecognizer(fst, culture);
        }
コード例 #2
0
        public NumberFSTRecognizer(System.Globalization.CultureInfo culture, int priority)
            : base(TokenType.Number, priority, "Number", "NumberFSTRecognizer")
        {
            if (culture == null)
            {
                throw new ArgumentNullException();
            }
            if (culture.IsNeutralCulture)
            {
                throw new ArgumentException("Cannot compute number patterns for neutral cultures");
            }
            if (culture.NumberFormat == null)
            {
                throw new ArgumentException("No number format info available for the specified culture");
            }

            LanguagePlatform.Lingua.FST.FST fst = CreateFST(culture, Core.CultureInfoExtensions.UseBlankAsWordSeparator(culture));
            _FSTRecognizer = new FSTRecognizer(fst, culture);
        }