Пример #1
0
 public bool onSuggestionEvent(Suggestion suggestion)
 {
     return (bool)this.Invoke(new Func<bool>(()=>{
         listBox1.Items.Add(suggestion.suggestion);
         if ( listBox1.Items.Count == 1 ) listBox1.SelectedIndex = 0;
         return listBox1.Items.Count < Configurations.SUGGESTIONS_COUNT_LIMIT;
     }));
 }
Пример #2
0
 public bool onSuggestionEvent( Suggestion arg )
 {
     List<Suggester> names = arg.suggesters;
     var result = String.Join(", " , names);
     invoke(() => dataGridView1.Rows.Add(arg.suggestion , result , String.Format("{0:0.#####}" , arg.weight)));
     return true;
 }
Пример #3
0
        protected override void recomputeSuggestions()
        {
            if ( !isRelevant ) return;
            //Console.WriteLine("ofek starting recompute , D(the)="+currentDistances["the"]);
            index = 0;

            List<Node> suggestionsList = traveler.getAllPaths();
            Dictionary<string , Suggestion> suggestions = new Dictionary<string , Suggestion>();

            //foreach ( Node n in suggestionsList ) {
            //    string s = n.ToString();
            //    double currDistance = currentDistances[s];
            //    long allAppearances = 0;
            //    foreach ( Topic t in topics ) {
            //        Node nodeInTopicTrie = t.allwords.getNode(s);
            //        allAppearances += t.allwords.weight;
            //        double numApp = nodeInTopicTrie == null ? 0 : nodeInTopicTrie.getNumOfAppearances();
            //        double expectedDistance = t.historyDicti[s].getMedian();
            //        double distanceFactor = currDistance > expectedDistance ? expectedDistance / currDistance : currDistance / expectedDistance;
            //        double weight = distanceFactor * Math.Pow(numApp,2) * t.similiarity;
            //        Suggestion suggestion = null;
            //        if ( suggestions.TryGetValue(s , out suggestion) ) {
            //            suggestion.weight += weight;
            //        } else {
            //            suggestion = new Suggestion(s , weight , this);
            //            suggestions[s] = suggestion;
            //        }
            //    }
            //    Suggestion sggst = suggestions[s];
            //    sggst.weight /= topics.Count;
            //    sggst.weight = Math.Sqrt(sggst.weight);
            //    sggst.weight /= ((double)allAppearances/topics.Count);
            //}
            foreach ( Node n in suggestionsList ) {
                string s = n.ToString();
                double currDistance = currentDistances[s];
                //if ( s.Equals("the") ) Console.WriteLine("d(the)=" + currentDistances["the"]);
                foreach ( Topic t in topics ) {
                    Node nodeInTopicTrie = t.allwords.getNode(s);
                    double numApp = nodeInTopicTrie == null ? 0 : nodeInTopicTrie.getNumOfAppearances();
                    double distanceFactor = 1;
                    double lengthFactor = 1;
                    if (Configurations.SHOULD_CARE_FOR_STOP_WORDS_DISTANCE) {
                        Histogram h = t.historyDicti[s];
                        double expectedDistance = h.getSorted(h.n / 2);
                        double forgetDistance = h.getSorted(3 * h.n / 4);
                        if ( currDistance < expectedDistance ) {
                            distanceFactor = currDistance / expectedDistance;
                            distanceFactor = smoothingFunc(distanceFactor);
                        } else if ( currDistance > forgetDistance ) {
                            distanceFactor = forgetDistance / currDistance;
                            distanceFactor = smoothingFunc(distanceFactor);
                        } else distanceFactor = 1;
                        //if ( s.Equals("the") ) Console.WriteLine("D(the)=" + distanceFactor);
                    }
                    if ( Configurations.SHOULD_CARE_FOR_STOP_WORDS_LENGTH )
                        lengthFactor = s.Length * Configurations.LENGTH_CONSTANT_FACTOR;
                    double weight = distanceFactor * ( numApp / (double)t.allwords.weight ) * t.similiarity * lengthFactor;
                    Suggestion suggestion = null;
                    if ( suggestions.TryGetValue(s , out suggestion) ) {
                        suggestion.weight += weight;
                    } else {
                        suggestion = new Suggestion(s , weight , this);
                        suggestions[s] = suggestion;
                    }
                }
            }
            list = new List<Suggestion>(suggestions.Values);
            list.Sort(( s1 , s2 ) => {
                return Comparer<Double>.Default.Compare(s2.weight,s1.weight);
            });
            Stats.showOfekSuggestions(list);
        }
Пример #4
0
 /// <summary>
 /// recieve the suggestion and let the suggester know if it should get more suggestions by returnning true.
 /// if this method returnhs false the suggester will be stalled untill next time its runSuggester is called.
 /// </summary>
 /// <param name="suggestion"></param>
 /// <returns></returns>
 public abstract bool onSuggesterSuggestion( Suggestion suggestion );
Пример #5
0
 public override bool onSuggesterSuggestion( Suggestion s )
 {
     lock ( suggestions ) {
         if ( !running ) return false;
         Suggestion suggestion = null;
         if ( suggestions.TryGetValue(s.suggestion , out suggestion) ) {
             suggestion += s;
         } else {
             suggestion = s;
             suggestions[s.suggestion] = suggestion;
         }
         return true;
     }
 }
Пример #6
0
 public static Suggestion operator +( Suggestion s1 , Suggestion s2 )
 {
     if ( !s1.suggestion.Equals(s2.suggestion) ) throw new Exception("invalid operation - cant add suggestions that dont contain the same word");
     Suggestion res = new Suggestion(s1.suggestion , s1.weight + s2.weight);
     res.suggesters.AddRange(s1.suggesters);
     res.suggesters.AddRange(s2.suggesters);
     return res;
 }
Пример #7
0
 protected bool suggest( Suggestion suggestion )
 {
     return SuggestionEventHandler(suggestion);
 }