Esempio n. 1
0
        public training(int lang_id, int category_id, string langauge, string stemming, bool addtur, int n, bool punctuation, int nov)
        {
            _cr = new classifier(langauge, stemming, addtur, n, punctuation, nov);//classifier hazır
            _category_sentence_count = new Dictionary <int, int>();
            all_sentence_count       = 0;

            word_dic _wd = new word_dic();
            comment  _c  = new comment();

            DataTable _dt = _c.select_comment(lang_id.ToString(), category_id.ToString());

            int id      = 1;
            int yuzde50 = _dt.Rows.Count / 2;

            foreach (DataRow row in _dt.Rows) // Loop over the rows.
            {
                var    type      = row[0];
                string _sentence = row[1].ToString().ToLower();
                int    _type     = Convert.ToInt32(type);

                _cr.AddSentenceforTraining(_sentence, _type);
                AddASentence(_type);//kategorideki cümle sayısı
                all_sentence_count++;
                id++;
                if (id == yuzde50)
                {
                    break;
                }
            }
        }
Esempio n. 2
0
        public classifier(string _langauge, string _stemming, bool _addtur, int _n, bool _punctuation, int _nov)
        {
            _cat_dic = new Dictionary <int, catDictionary>();

            _wd         = new word_dic();
            language    = _langauge;
            stemming    = _stemming;
            addtur      = _addtur;
            n           = _n;
            punctuation = _punctuation;
            nov         = _nov;
        }
Esempio n. 3
0
        public int[,] ConfusionMatrix(int lang_id, int category_id)
        {
            int[,] _cm = new int[_cat_dic.Count, _cat_dic.Count];
            for (int x = 0; x < _cat_dic.Count; x++)
            {
                for (int y = 0; y < _cat_dic.Count; y++)
                {
                    _cm[x, y] = 0;
                }
            }

            Hashtable _categoriler = new Hashtable();
            int       i            = 0;

            foreach (var _cat in _cat_dic)
            {
                _categoriler.Add((int)_cat.Key, i);
                i++;
            }

            word_dic  _wd = new word_dic();
            comment   _c  = new comment();
            DataTable _dt = _c.select_comment(lang_id.ToString(), category_id.ToString());

            int id = 1;

            foreach (DataRow row in _dt.Rows) // Loop over the rows.
            {
                var    type      = row[0];
                string _sentence = row[1].ToString().ToLower();
                int    _type     = Convert.ToInt32(type);
                int    x         = (int)_categoriler[_type];
                int    y         = (int)_categoriler[Estimate_Category(_sentence)];
                _cm[x, y]++;
                id++;
            }

            return(_cm);
        }
Esempio n. 4
0
        public void CalculateScore(string _sentence)
        {
            _cat_score = new Dictionary <int, double>();

            word_dic _new_wd = new word_dic();

            _new_wd.update_hashtables(_sentence, 0, language, stemming, addtur, n, punctuation, nov);

            foreach (DictionaryEntry _word in _new_wd._words_in_sentence)
            {
                foreach (var _cat in _cat_dic)
                {
                    catDictionary _cd                   = (catDictionary)_cat.Value;
                    double        _countofword          = Convert.ToDouble(_cd.Search((string)_word.Key));
                    double        _totalWords           = Convert.ToDouble(_cd.CountofWordsinCategory);
                    double        _countofsentenceincat = (int)_category_sentence_count[(int)_cat.Key];

                    double _score = 0;
                    if (_countofword > 0)
                    {
                        _score = System.Math.Log(((double)_countofword + 1) / ((double)_totalWords + _all_sentence_count));
                    }
                    else
                    {
                        _score = 0;
                    }

                    if (!_cat_score.ContainsKey((int)_cat.Key))
                    {
                        _cat_score.Add((int)_cat.Key, _score + System.Math.Log((double)_countofsentenceincat / (double)_all_sentence_count));
                    }
                    else
                    {
                        _cat_score[(int)_cat.Key] = (double)_cat_score[(int)_cat.Key] + _score;
                    }
                }
            }
        }