Example #1
0
 public static Word getWordFor(String s)
 {
     Word output;
     if (stringToWord.TryGetValue(s, out output) )
         return output;
     stringToWord.Add(s, output = new Word(s));
     return output;
 }
Example #2
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);
        }