Exemplo n.º 1
0
            public static ConcurrentFactory GetConcurrentFactory()
            {
                var f = _ConcurrentFactory;

                if (f == null)
                {
                    lock ( _SyncLock )
                    {
                        f = _ConcurrentFactory;
                        if (f == null)
                        {
                            {
                                var modelConfig = new ModelConfig()
                                {
                                    Filenames   = Config.MODEL_FILENAMES,
                                    RowCapacity = Config.MODEL_ROW_CAPACITY,
                                    NGramsType  = Config.MODEL_NGRAMS_TYPE
                                };
                                var model  = new ModelNative(modelConfig);   //new ModelHalfNative( modelConfig ); //new ModelClassic( modelConfig );
                                var config = new ClassifierConfig(Config.URL_DETECTOR_RESOURCES_XML_FILENAME);

                                f = new ConcurrentFactory(config, model, Config.CONCURRENT_FACTORY_INSTANCE_COUNT);
                                _ConcurrentFactory = f;
                            }
                            {
                                GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                                GC.WaitForPendingFinalizers();
                                GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                            }
                        }
                    }
                }
                return(f);
            }
Exemplo n.º 2
0
        public Classifier(ClassifierConfig config, IModel model)
        {
            #region [.check config.]
            config.ThrowIfNull("config");
            config.UrlDetectorModel.ThrowIfNull("config.UrlDetectorConfig");
            model.ThrowIfNull("model");
            #endregion

            _Model            = model;
            _Tokenizer        = new ClassifyTokenizer(config.UrlDetectorModel);
            _ScalarProducts   = new double[_Model.TotalClassCount];
            _TextTFDictionary = new Dictionary <string, int>(TEXT_TF_DICTIONARY_CAPACITY);
            _ClassInfo        = new ClassifyInfo[_Model.TotalClassCount];
            for (int i = 0, len = _Model.TotalClassCount; i < len; i++)
            {
                _ClassInfo[i].ClassIndex = i;
            }
        }
Exemplo n.º 3
0
        public ConcurrentFactory(ClassifierConfig config, IModel model, int instanceCount)
        {
            if (instanceCount <= 0)
            {
                throw (new ArgumentException("instanceCount"));
            }
            if (config == null)
            {
                throw (new ArgumentNullException("config"));
            }
            if (model == null)
            {
                throw (new ArgumentNullException("model"));
            }

            _Semaphore = new Semaphore(instanceCount, instanceCount);
            _Stack     = new ConcurrentStack <Classifier>();
            for (int i = 0; i < instanceCount; i++)
            {
                _Stack.Push(new Classifier(config, model));
            }
        }