public Statistic(oneUrl item) { initDict(); output = new StatisticOutput(); output.time = item.time; output.feat = item.feat; output.discount = 100 - Convert.ToInt32(10 * Convert.ToDouble(item.discount)); output.title = item.seller + "-" + item.deal_title; output.description = item.description; output.keywordList = new Hashtable(); splitwords(output.title, TITLE_WEIGHT); splitwords(item.other, OTHER_WEIGHT); splitwords(item.description, DESCRIPTION_WEIGHT); }
public StatisticOutput statistic(oneUrl item) {//统计item中存储的团购条目信息 Console.WriteLine("Computing the statisitc data of the item..."); StatisticOutput oneOutput = new StatisticOutput(); oneOutput.url = item.url; oneOutput.time = item.time; oneOutput.feat = item.feat; oneOutput.discount = 100 - Convert.ToInt32(10 * Convert.ToDouble(item.discount)); oneOutput.title = item.seller + "-" + item.deal_title; oneOutput.description = item.description; oneOutput.keywordList = new Hashtable(); splitwords(ref oneOutput, oneOutput.title, TITLE_WEIGHT); splitwords(ref oneOutput, item.other, OTHER_WEIGHT); splitwords(ref oneOutput, item.description, DESCRIPTION_WEIGHT); Console.WriteLine("Statistic ready."); return(oneOutput); }
private bool addOneUrl(int pos) {//添加第pos条团购条目信息 string query; int link_id; MD5 md5 = new MD5CryptoServiceProvider();; //XmlNode oneUrl = lashouDocument.DocumentElement.ChildNodes[pos]; oneUrl oneUrl = xmlparse.getOneUrl(pos); StatisticOutput sta = staContext.statistic(oneUrl); Console.WriteLine("Insert the data to the database...."); query = "insert into links (site_id, url, title, description) values(5, \"" + sta.url + "\",\"" + sta.title + "\",\"" + sta.description + "\")"; cmd = new MySQLDriverCS.MySQLCommand(query, conn); cmd.ExecuteNonQuery(); cmd.Dispose(); query = "select link_id from links where url = \"" + sta.url + "\""; cmd = new MySQLDriverCS.MySQLCommand(query, conn); IDataReader dt = cmd.ExecuteReader(); link_id = Convert.ToInt32(dt.GetSchemaTable().Rows[0]["link_id"]); foreach (DictionaryEntry de in sta.keywordList) { int keyword_id = 0; query = "select keyword_id from keywords where keyword = \"" + de.Key + "\""; cmd = new MySQLDriverCS.MySQLCommand(query, conn); dt = cmd.ExecuteReader(); if (dt.GetSchemaTable().Rows.Count == 0) { query = "insert into keywords (keyword) values (\"" + de.Key + "\")"; cmd = new MySQLDriverCS.MySQLCommand(query, conn); cmd.ExecuteNonQuery(); cmd.Dispose(); query = "select keyword_id from keywords where keyword = \"" + de.Key + "\""; cmd = new MySQLDriverCS.MySQLCommand(query, conn); dt = cmd.ExecuteReader(); keyword_id = Convert.ToInt32(dt.GetSchemaTable().Rows[0]["keyword_id"]); } else { keyword_id = Convert.ToInt32(dt.GetSchemaTable().Rows[0]["keyword_id"]); } byte[] hash = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(de.Key.ToString())); string flag; switch (hash[0] >> 4) { case 10: flag = "a"; break; case 11: flag = "b"; break; case 12: flag = "c"; break; case 13: flag = "d"; break; case 14: flag = "e"; break; case 15: flag = "f"; break; default: flag = (hash[0] >> 4).ToString(); break; } query = "insert into link_keyword" + flag + "(link_id, keyword_id, weight, time, feat, discount) values (" + link_id + "," + keyword_id + "," + de.Value + "," + sta.time + "," + sta.feat + "," + sta.discount + ")"; cmd = new MySQLDriverCS.MySQLCommand(query, conn); cmd.ExecuteNonQuery(); cmd.Dispose(); } Console.WriteLine("Write one link sucessfully!"); return(true); }