Exemple #1
0
 public Topic( String topic,Trie fringeTrie ,Trie allwords , Dictionary<string , Distance.Histogram> dict )
 {
     this.topic = topic;
     this.fringeTrie = fringeTrie;
     this.historyDicti = dict;
     this.allwords = allwords;
 }
Exemple #2
0
 public static void initTrieFromString( String s , Trie t )
 {
     string[] words = s.Replace("\r" , "").Split(' ' , '\n' , ',' , '.');
     foreach ( var w in words ) {
         bool valid = true;
         foreach ( char c in w )
             valid &= Char.IsLetter(c);
         if ( !valid ) continue;
         t.add(w);
     }
 }
 static Topic createTopic( string topic,string text )
 {
     Trie t = new Trie(text);
      t.removeAll(stopWords);
      Trie t2 = new Trie(text);
     Dictionary<string , Histogram>  dict = new Dictionary<string , Histogram>();
     foreach ( Node wordNode in stopWords.getAll() ) {
         string word = wordNode.ToString();
         Histogram h = new Histogram(word , text);
         dict.Add(word , h);
     }
     return new Topic(topic, t ,t2, dict);
 }
Exemple #4
0
        public static Trie readTrie(string fileName) {
            Trie trie=new Trie();
            StreamReader reader=null;
            try {
                reader=new StreamReader(fileName);
                string word;
                while ((word=reader.ReadLine())!=null) 
                    trie.addAll(word);
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
            } finally {
                if (reader!=null) reader.Close();
            }
            return trie;

        }
Exemple #5
0
 public static Trie readTrie(string fileName , Filter<String> filter) {
     Trie trie=new Trie();
     StreamReader reader = null;
     try {
         reader = new StreamReader(fileName);
         string word;
         while ((word=reader.ReadLine())!=null) {
             string[] words = word.Replace("\r" , "").Split(' ' , '\n' , ',' , '.');
             foreach ( var w in words ) {
                 bool valid = true;
                 foreach ( char c in w )
                     valid &= Char.IsLetter(c);
                 if ( !valid ) continue;
                 if ( !filter(w) )
                     trie.add(w);
             }
         }
     } catch (Exception e) {
         Console.WriteLine(e.ToString());
     } finally {
         if (reader!=null) reader.Close();
     }
     return trie;
 }
Exemple #6
0
 public TrieTraveler( TrieTraveler trieTraveler )
 {
     current = trieTraveler.current;
     currentPosition = trieTraveler.currentPosition;
     trie = trieTraveler.trie;
     sb = new StringBuilder(trieTraveler.sb.ToString());
 }
Exemple #7
0
 public TrieTraveler( Trie t )
 {
     trie = t;
     current = trie.root;
     sb = new StringBuilder();
 }
Exemple #8
0
 public void removeAll( Trie t )
 {
     foreach ( Node n in t.getAll() ) {
         remove(n.ToString());
     }
 }
 public TrieSuggester( Trie trie )
 {
     this.trie = trie;
     traveler = new TrieTraveler(trie);
 }
Exemple #10
0
 private void calculateSimiliarity( Trie window )
 {
     List<Node> windowWords = window.getAll();
     List<string> windowVector = new List<string>();
     Distribution X = new Distribution();
     double xmax = 0;
     foreach ( Node n in windowWords ) {
         string s = n.ToString();
         windowVector.Add(s);
         double x = window.weight > 0 ? n.getNumOfAppearances() / (double)window.weight : 0;
         X.add(s , x );
         xmax += x * x;
     }
     double rmin = 0;
     foreach ( Topic t in SuggestionUtils.fringeTopics.Values ) {
         Distribution Y = t.topicVector;
         t.rtmin = 0;
         for ( int i = 0 ; i < Math.Max(Y.count , X.count) ; i++ )
             t.rtmin += Math.Pow(Y[i] - X[i] , 2);
         rmin = Math.Min(rmin,t.rtmin);
         t.rtmax = xmax;
         for ( int i = 0 ; i < Y.count ; i++ )
             t.rtmax += Math.Pow(Y[i], 2);
         List<string> union = new List<string>(windowVector);
         foreach (object o in Y.keys )
             if (union.Contains((string)o))
                 union.Add((string)o);
         t.rt = 0;
         for ( int i = 0 ; i < union.Count ; i++ ) {
             string s = union[i];
             double xs = X[s];
             double ys = Y[s];
             t.rt += Math.Pow(xs - ys , 2);
         }
     }
     foreach ( Topic t in SuggestionUtils.fringeTopics.Values ) {
         double frt = ( t.rt - rmin ) / ( t.rtmax - rmin );
         t.similiarity = similiarity1(frt);
         if ( onTopicReady != null ) onTopicReady(t);
         Form3.updateChartForTopic(t.topic , frt);
         Stats.updateChartForTopic(t.topic , frt);
     }
     Form2.showPlots(1);
 }
Exemple #11
0
 private WindowHandler()
 {
     stopWords = SuggestionUtils.stopWords;
     bw = new Worker("WindowHandlerThread");
 }