예제 #1
0
        public MDetector(MDetectorConfig config, IMModel model)
        {
            config.ThrowIfNull("config");
            config.UrlDetectorModel.ThrowIfNull("config.UrlDetectorModel");
            model.ThrowIfNull("model");

            _Model           = model;
            ThresholdPercent = config.ThresholdPercent;
            ThresholdPercentBetween3Language   = config.ThresholdPercentBetween3Language;
            ThresholdDetectingWordCount        = config.ThresholdDetectingWordCount;
            ThresholdPercentDetectingWordCount = config.ThresholdPercentDetectingWordCount;
            ThresholdAbsoluteWeightLanguage    = config.ThresholdAbsoluteWeightLanguage;
            _Tokenizer                 = new mld_tokenizer(config.UrlDetectorModel);
            _Weights                   = new float[LANGUAGES_COUNT];
            _TermCountByLanguage       = new int  [LANGUAGES_COUNT];
            _LanguageInfos             = new List <LanguageInfo>(LANGUAGES_COUNT);
            _NgramStringBuilder        = new StringBuilder(NGRAM_STRINGBUILDER_DEFAULT_LENGTH);
            _ProcessTermCallbackAction = new Action <string>(ProcessTermCallback);
        }
예제 #2
0
        //private bool                                 _Disposed;
        //private ManyLanguageDetectorModel            _ManyLanguageDetectorModel; //need to hold for suppress finalizer
        //private IMModel                              _IMModel;
        //private IRModel                              _IRModel;

        /*public ConcurrentFactory( MDetectorConfig config, ManyLanguageDetectorModel model, int instanceCount )
         *      {
         *  if ( instanceCount <= 0 ) throw (new ArgumentException("instanceCount"));
         *  if ( config == null     ) throw (new ArgumentNullException("config"));
         *  if ( model  == null     ) throw (new ArgumentNullException("model"));
         *
         *  _InstanceCount = instanceCount;
         *  _Semaphore     = new Semaphore( _InstanceCount, _InstanceCount );
         *  _Stack         = new ConcurrentStack< ILanguageDetector >();
         *              for ( int i = 0; i < _InstanceCount; i++ )
         *              {
         *      _Stack.Push( new ManyLanguageDetector( config, model ) );
         *              }
         *  //_ManyLanguageDetectorModel = model;
         *      }*/
        public ConcurrentFactory(MDetectorConfig config, IMModel model, int instanceCount)
        {
            if (instanceCount <= 0)
            {
                throw (new ArgumentException("instanceCount"));
            }
            if (config == null)
            {
                throw (new ArgumentNullException("config"));
            }
            if (model == null)
            {
                throw (new ArgumentNullException("model"));
            }

            _InstanceCount = instanceCount;
            _Semaphore     = new Semaphore(_InstanceCount, _InstanceCount);
            _Stack         = new ConcurrentStack <ILanguageDetector>();
            for (int i = 0; i < _InstanceCount; i++)
            {
                _Stack.Push(new MDetector(config, model));
            }
            //_IMModel = model;
        }
예제 #3
0
        private Txt2BinModelConverter(ref Txt2BinModelConverterConfig config)
        {
            if (config.Model == null)
            {
                throw (new ArgumentNullException("config.Model"));
            }
            if (string.IsNullOrWhiteSpace(config.OutputFileName))
            {
                throw (new ArgumentNullException("config.OutputFileName"));
            }


            _Model                 = config.Model;
            _BufferSize            = config.BufferSize.GetValueOrDefault(DEFAULT_BUFFER_SIZE);
            _OutputDirectoryName   = Path.GetDirectoryName(config.OutputFileName);
            _OutputFileNamePattern = Path.GetFileNameWithoutExtension(config.OutputFileName);
            _OutputFileExtension   = Path.GetExtension(config.OutputFileName);
            if (string.IsNullOrWhiteSpace(_OutputFileExtension))
            {
                _OutputFileExtension = DEFAULT_FILE_EXTENSION;
            }
            _OutputFileSizeInBytes = config.OutputFileSizeInBytes.GetValueOrDefault();
            _OutputFileNumber      = 0;
        }