static void TryAddRelation(Dictionary <string, WordNode> dict, string a, string b) { WordNode x = GetOrAddNode(dict, a), y = GetOrAddNode(dict, b); x.TryAddNeighbour(b); y.TryAddNeighbour(a); }
static WordNode GetOrAddNode(Dictionary <string, WordNode> dict, string word) { WordNode node = null; if (dict.ContainsKey(word)) { return(dict[word]); } else { node = new WordNode(word); dict.Add(word, node); } return(node); }
public static Dictionary <string, int> skuMaxWordCnt; //每个产品keyword中出现次数最多的单词的出现次数 #region Spell check static void OutputConnections(Dictionary <string, WordNode> dict, string filename, string sku) { string[] words = dict.Keys.ToArray(); for (int i = 0; i < words.Length - 1; ++i) { if (words[i].Length >= Tools.MIN_WORD_LENGTH) { for (int j = i + 1; j < words.Length; ++j) { if (words[j].Length < Tools.MIN_WORD_LENGTH) { continue; } if (Tools.ISEditDistOK(words[i], words[j])) { WordNode x = GetOrAddNode(dict, words[i]), y = GetOrAddNode(dict, words[j]); int t = Tools.GetWordSim(x, y); File.AppendAllLines(filename, new string[] { sku + " " + words[i] + " " + words[j] + " " + t + " " + x.cnt + " " + y.cnt }); } } } } }
/// <summary> /// 返回单词相似度 /// </summary> /// <param name="x">单词x对应节点</param> /// <param name="y">单词y对应节点</param> /// <returns></returns> public static int GetWordSim(WordNode x, WordNode y) { return WordNode.CountOverlap(x.pre, y.pre) + WordNode.CountOverlap(x.next, y.next); }
static WordNode GetOrAddNode(Dictionary<string, WordNode> dict, string word) { WordNode node = null; if (dict.ContainsKey(word)) return dict[word]; else { node = new WordNode(word); dict.Add(word, node); } return node; }
/// <summary> /// 返回单词相似度 /// </summary> /// <param name="x">单词x对应节点</param> /// <param name="y">单词y对应节点</param> /// <returns></returns> public static int GetWordSim(WordNode x, WordNode y) { return(WordNode.CountOverlap(x.pre, y.pre) + WordNode.CountOverlap(x.next, y.next)); }