Ejemplo n.º 1
0
 //Add new topic trie
 public void addTopicTrie(string topic,Trie trie)
 {
     if (TriesByTopic.ContainsKey(topic))
         TriesByTopic[topic].Merge(trie);
     else
         TriesByTopic.Add(topic, trie);
 }
Ejemplo n.º 2
0
 public DataBase(string connStr)
 {
     StopWordsTrie = new Trie();
     TriesByTopic = new Dictionary<string, Trie>();
     conn = new SqlCeConnection(connStr);//new SqlConnection(connStr);
     globalTrie = new TextPredict.Base.Trie();
     //Utils.initTrieFromString(Resources.worms , globalTrie);
     //Utils.initTrieFromString(Resources.stop_words , globalTrie);
     //Utils.initTrieFromString(Resources.stopWordsConversation , globalTrie);
     //Utils.initTrieFromString(Resources.bicycle , globalTrie);
     //Utils.initTrieFromString(Resources.science , globalTrie);
     //Utils.initTrieFromString(Resources.how_to_play_fotbool , globalTrie);
     //Utils.initTrieFromString(Resources.how_to_play_basketball , globalTrie);
     //Utils.initTrieFromString(Resources.Cardiovascular_disease , globalTrie);
     //Utils.initTrieFromString(Resources.calories , globalTrie);
     try
     {
         if (!load())
             Initialize();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
         if (conn.State == ConnectionState.Open) conn.Close();
     }
 }
Ejemplo n.º 3
0
        public MsgError LoadFile( string fileName, out Trie trie, string topic )
        {
            bool isFileEmpty = true, isTrieEmptyOfFringeWord = true;
            trie = new Trie(topic);

            try
            {
                using (var reader = new StreamReader(fileName))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        string[] words = line.Split(' ','?','!','.','(',')','"',',',':');
                        foreach (string word in words)
                        {
                            //check if the word is not a stop word
                            if (String.IsNullOrEmpty(word)) continue;
                            if (false == MainControl.dataBase.isStopWord(word))
                            {
                                trie.Add(word);
                                isTrieEmptyOfFringeWord = false;
                            }
                            else
                            {
                                MainControl.dataBase.StopWordsTrie.Add(word);
                            }
                            isFileEmpty = false;
                        }
                    }
                }
            }
            catch (Exception errorMsg) { MessageBox.Show(errorMsg.Message); }

            if (isFileEmpty == false && isTrieEmptyOfFringeWord == false)
                return MsgError.OK;
            else
                if (isFileEmpty == false)
                    return MsgError.NOT_VALID;
                else
                    return MsgError.ERROR;
        }
Ejemplo n.º 4
0
        public Trie LoadStopWordFile(string fileName )
        {
            Trie trie = new Trie();
            bool isFileEmpty = true;

            try
            {
                using (var reader = new StreamReader(fileName))
                {
                    string word;
                    while ((word = reader.ReadLine()) != null)
                    {   
                        trie.Add(word);
                        isFileEmpty = false;              
                    }
                }
            }
            catch (Exception errorMsg ) { MessageBox.Show(errorMsg.Message); }

            if (isFileEmpty == false)
                return trie;
            else
                return null;
        }
Ejemplo n.º 5
0
        private bool load()
        {
            /*Load Application settings*/
            MainControl.WINDOW_SIZE = Settings.Default.WindowSize;
            MainControl.numberOfFringe = Settings.Default.numOfFringe;
            MainControl.numberOfStop = Settings.Default.numOfStop;
            MainControl.numberOfMostRelevntTries = Settings.Default.numOfMostRelevant;
            MainControl.ConsiderSuffixLength = Settings.Default.ConsiderSuffixLength;
            MainControl.Sigma = Settings.Default.Sigma;
            MainControl.demoIntervals = Settings.Default.demoIntervals;

            Word word;
            Trie tempTrie = null;
            string curTopic = "general";
            conn.Open();
            var cmd = new SqlCeCommand("SELECT * FROM Words WHERE Topic='general' ORDER BY Word", conn);
            var dr = cmd.ExecuteReader();

            while (dr.Read()) //add words to stop words trie
            {
                word = new Word(dr["Word"].ToString(),long.Parse(dr["Weight"].ToString()));
                StopWordsTrie.Add(word);
            }

            dr.Close();
            cmd.CommandText = "SELECT * FROM Words WHERE Topic<>'general' ORDER BY Topic,Word";
            dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                if (!curTopic.Equals(dr["Topic"].ToString()))
                {
                    try
                    {
                        if (tempTrie != null) TriesByTopic.Add(curTopic, tempTrie);
                        curTopic = dr["Topic"].ToString();
                        tempTrie = new Trie(curTopic);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }
                }
                word = new Word(dr["Word"].ToString(), long.Parse(dr["Weight"].ToString()));
                tempTrie.Add(word);
            }
            if (tempTrie != null) TriesByTopic.Add(curTopic, tempTrie);

            dr.Close();
            conn.Close();
            return (StopWordsTrie.Count > 0) || (TriesByTopic.Count > 0);
        }
Ejemplo n.º 6
0
        public void Merge(Trie t)
        {
            if (t == null) return;

            var suffs = t.root.getSuffixes(t.Count);
            foreach (var w in suffs)
                this.Add(w);
        }