protected Dictionary <int, double> getSearchQueryVector() { Dictionary <int, double> result = new Dictionary <int, double>(); HashSet <string> uniqueWords = new HashSet <string>(); DeepMorphy.Model.MorphInfo[] searchInfo = Parser.getAllLemms(this.searchQuery); foreach (var lemmInfo in searchInfo) { uniqueWords.Add(lemmInfo.BestTag.Lemma); } List <Word> lemmas = DbConn.getInstance().getWordObjectsForLemms(uniqueWords.ToArray <string>()); foreach (var lem in lemmas) { result.Add(lem.id, 1.0d); } return(result); }
static bool getWordWeightInDocument(List <Word> docLemms, Word curLemm, int documentId, out double result) { try { double sqrtSumm = 0.0d; int amountOfDocuments = DbConn.getInstance().getAmountOfDocuments(); foreach (Word lem in docLemms) { sqrtSumm += Math.Pow(calcTDIDF(lem, documentId, amountOfDocuments), 2); } sqrtSumm = Math.Sqrt(sqrtSumm); result = calcTDIDF(curLemm, documentId, amountOfDocuments) / sqrtSumm; return(true); } catch { result = -1.0d; return(false); } }
private void search_Click(object sender, EventArgs e) { if (!Word.isCollectionUpToDate()) { this.setStatus("загрузка", Color.Orange); Word.setWordsCollection(DbConn.getInstance().getAllWords()); } this.setStatus("выполняется поиск", Color.Orange); int count = 0; Search searchQuery = new Search(textBox1.Text); List <Document> docs = DbConn.getInstance().GetAllFromDoc(); Dictionary <int, double> relevation = new Dictionary <int, double>(); double curRelevation; foreach (Document doc in docs) { curRelevation = searchQuery.scalarProduct(Document.getDocumentVector(doc.documentID)); relevation.Add(doc.documentID, curRelevation); if (curRelevation != 0) { count++; } } dataGridView1.DataSource = dt.ApplySort((r1, r2) => { var val1 = relevation[Int32.Parse(r1["documentid"].ToString())]; var val2 = relevation[Int32.Parse(r2["documentid"].ToString())]; return(val2.CompareTo(val1)); }); setOptionsDataGridView1(); HideIrrelevantRows(count); dataGridView1.Update(); dataGridView1.Refresh(); this.setStatus("поиск окончен", Color.ForestGreen); }
private void loadCollection_Click(object sender, EventArgs e) { this.setStatus("загрузка", Color.Orange); Word.setWordsCollection(DbConn.getInstance().getAllWords()); this.setStatus("загружено", Color.ForestGreen); }