public override bool Equals(object obj) { WordPair other = obj as WordPair; if (null != other) { return(ToString().Equals(other.ToString())); } return(false); }
public double Get(WordPair word) { double result = 0; if (_matrix.ContainsKey(word)) { result = _matrix[word]; } else { result = 0; } return(result); }
public double GetNormalized(WordPair word) { double absolute = Get(word); int n1 = GetOccurances(word.Word1); int n2 = GetOccurances(word.Word2); int totalOccurances = n1 * n2; if (totalOccurances > 0) { return(absolute / totalOccurances); } else { return(0); } }
public void Add(string[] words) { //int totalAddOccuranceCount = 0; //int totalAddFrequencyCount = 0; //long totalAddOccuranceTime = 0; //long totalAddFrequencyTime = 0; for (int i = 0; i < words.Length; i++) { //using (MonitoredScope scope = new MonitoredScope("AddOccurance")) { AddOccurance(WordPair.Normalize(words[i])); //totalAddOccuranceTime += scope.ElapsedMilliseconds; //totalAddOccuranceCount++; } for (int j = i + 1; j < words.Length; j++) { //using (MonitoredScope scope = new MonitoredScope("AddFrequency")) { if (string.Compare(words[i], words[j], ignoreCase: true, culture: CultureInfo.InvariantCulture) < 0) { //Add(GetWordIndex(words[i]), GetWordIndex(words[j]), 1.0 / (j - i + 1)); Add2(GetWordIndex2(words[i]), GetWordIndex2(words[j]), 1.0 / (j - i + 1)); } else { //Add(GetWordIndex(words[j]), GetWordIndex(words[i]), 1.0 / (j - i + 1)); Add2(GetWordIndex2(words[j]), GetWordIndex2(words[i]), 1.0 / (j - i + 1)); } //totalAddFrequencyTime += scope.ElapsedMilliseconds; //totalAddFrequencyCount++; } } } //Logger.Log("Average AddOccuranceTime: " + (double)totalAddOccuranceTime / totalAddOccuranceCount); //Logger.Log("Average AddFrequencyTime: " + (double)totalAddFrequencyTime / totalAddFrequencyCount); }
public void Add(string word1, string word2, double value) { //if (word1.CompareTo(word2) > 0) //{ // Add(word2, word1, value); //} //else //{ // if (_matrix2.ContainsKey(word1)) // { // Dictionary<string, double> word2Dictionary = _matrix2[word1]; // if (word2Dictionary.ContainsKey(word2)) // { // word2Dictionary[word2] += value; // } // else // { // word2Dictionary[word2] = value; // } // } // else // { // Dictionary<string, double> word2Dictionary = _matrix2[word1] = new Dictionary<string, double>(); // word2Dictionary[word2] = value; // } //} WordPair word = new WordPair(word1, word2); double existingValue; if (_matrix.TryGetValue(word, out existingValue)) { _matrix[word] = value + existingValue; } else { _matrix[word] = value; } }