/// <summary> /// 为当前用户猜测其最可能喜欢的产品 /// </summary> /// <param name="user">用户id</param> /// <param name="query">用户输入的查询</param> /// <param name="click_time">用户点击产品的时间</param> /// <returns></returns> static string GuessBestSku(string user, string query, DateTime click_time) { string[] games = WordProcessor.skuKeywords.Keys.ToArray(); Tuple <string, double, double>[] matchResults = new Tuple <string, double, double> [games.Length]; for (int i = 0; i < games.Length; ++i) { double wordsScore = SkuMatcher.GetSkuQuerySim(games[i], query); double cfScore = CF.GetCFValue(games[i], user, click_time); if (userHist.ContainsKey(user) && userHist[user].Contains(games[i])) { //用户不太可能点击一个他之前点击过的产品 wordsScore = 0; cfScore = 0; } //打分结果由两部分构成,分别是查询词得分和协同过滤得分。 matchResults[i] = new Tuple <string, double, double>(games[i], wordsScore, cfScore); } Sort(matchResults); string skus = matchResults[0].Item1; for (int i = 1; i < DISP_NUM; ++i) { skus = skus + " " + matchResults[i].Item1; } return(skus); }
static void Main(string[] args) { Console.WriteLine("Loading queries..."); WordProcessor.BuildWordGraph("train"); Console.WriteLine("Building words connections..."); ////WordProcessor.FindConnections(); WordProcessor.BuildGlobalEquGraph(); WordProcessor.BuildLocalEquGraph(); Console.WriteLine("Initializing CF model..."); CF.Initialize(); Console.WriteLine("Initialization finishd!"); Console.WriteLine("Begin Query"); SkuSelector.Query(); Console.WriteLine("All things have been done!"); Console.ReadLine(); }