/// <summary> /// Generates the indexed data. /// </summary> /// <param name="UserId">The user identifier.</param> /// <returns>List<WordClouds>.</returns> public List <WordClouds> GenerateIndexedData() { var indexedResults = new List <WordClouds>(); var indexedResult = new WordClouds(); var relatedWords = new List <RelatedWord>(); indexedResult.Date = this.newDate.Date; indexedResult.Word = "ALL"; double score; foreach (var d in this.WordDoc) { var relatedWord = new RelatedWord(); if (d.Value.Count < 1) { continue; } relatedWord.Word = d.Key; relatedWord.Count = 0; relatedWord.Score = 0; foreach (var v in d.Value) { this.DocScore.TryGetValue(v.Key, out score); relatedWord.Score = (relatedWord.Count * relatedWord.Score + v.Value * score) / (relatedWord.Count + v.Value); relatedWord.Count = relatedWord.Count + v.Value; } relatedWords.Add(relatedWord); } IEnumerable <RelatedWord> relatedWordssort1 = from relatedWord in relatedWords orderby relatedWord.Count descending select relatedWord; relatedWords = relatedWordssort1.ToList(); var wordlist = ""; foreach (var rword in relatedWords) { wordlist = wordlist + rword.Word + "," + rword.Count + "," + rword.Score + ";"; } indexedResult.RelatedWords = wordlist; indexedResults.Add(indexedResult); foreach (var word in relatedWords) { var indexedResult1 = new WordClouds(); indexedResult1.Date = this.newDate.Date; indexedResult1.Word = word.Word; var relatedWords2 = new List <RelatedWord>(); foreach (var d in this.DocWord) { //double score; this.DocScore.TryGetValue(d.Key, out score); if (d.Value.ContainsKey(word.Word)) { foreach (var v in d.Value) { if (relatedWords2.Exists(x => x.Word == v.Key)) { var rWord = relatedWords2.Find( delegate(RelatedWord rWord2) { return(rWord2.Word.Equals(v.Key)); }); rWord.Score = (rWord.Count * rWord.Score + v.Value * score) / (rWord.Count + v.Value); rWord.Count = rWord.Count + v.Value; } else { var rWord3 = new RelatedWord(); rWord3.Word = v.Key; rWord3.Score = score; rWord3.Count = v.Value; relatedWords2.Add(rWord3); } } } } IEnumerable <RelatedWord> relatedWordssort2 = from relatedWord in relatedWords2 orderby relatedWord.Count descending select relatedWord; relatedWords2 = relatedWordssort2.ToList(); wordlist = ""; foreach (var rword in relatedWords2) { wordlist = wordlist + rword.Word + "," + rword.Count + "," + rword.Score + ";"; } indexedResult1.RelatedWords = wordlist; indexedResults.Add(indexedResult1); } return(indexedResults); }
protected void btnSearch_Click(object sender, EventArgs e) { lb1.Text = ""; lb2.Text = ""; lb3.Text = ""; lb4.Text = ""; RelatedWord rw = new RelatedWord(); query = @"select * from tbl_formsofword where NOUN like '%" + txtSearch.Text + "%' or VERB like '%" + txtSearch.Text + "%' or ADJECTIVE like '%" + txtSearch.Text + "%' or ADVERB like '%" + txtSearch.Text + "%'"; SqlDataReader dr = connection.GetRow(query); DataTable dt; if (dr.Read()) { rw.noun = dr["NOUN"].ToString().Split(new char[] { '/', '\\' }); rw.verb = dr["VERB"].ToString().Split(new char[] { '/', '\\' }); rw.adj = dr["ADJECTIVE"].ToString().Split(new char[] { '/', '\\' }); rw.adv = dr["ADVERB"].ToString().Split(new char[] { '/', '\\' }); } else { string[] temp = new string[1]; temp[0] = txtSearch.Text; rw.noun = temp; } connection.conn.Close(); for (int i = 0; i < rw.noun?.Length; i++) { query = "select detail from tbl_edict where word = '" + rw.noun[i] + "'"; dt = connection.GetTable(query); foreach (DataRow row in dt.Rows) { lb1.Text += row["detail"]?.ToString(); } } for (int i = 0; i < rw.verb?.Length; i++) { query = "select detail from tbl_edict where word = '" + rw.verb[i] + "'"; dt = connection.GetTable(query); foreach (DataRow row in dt.Rows) { lb2.Text += row["detail"]?.ToString(); } } for (int i = 0; i < rw.adj?.Length; i++) { query = "select detail from tbl_edict where word = '" + rw.adj[i] + "'"; dt = connection.GetTable(query); foreach (DataRow row in dt.Rows) { lb3.Text += row["detail"]?.ToString(); } } for (int i = 0; i < rw.adv?.Length; i++) { query = "select detail from tbl_edict where word = '" + rw.adv[i] + "'"; dt = connection.GetTable(query); foreach (DataRow row in dt.Rows) { lb4.Text += row["detail"]?.ToString(); } } }