public List<Object[]> searchDocuments(String searchingTerm, bool checkedPairSearch_dist_0, bool checkedPairSearch_dist_1, bool radioAND) { var p = new Parser(); var listSearchTerms = (List<String>)p.Parse(searchingTerm)[1]; var listUnfullmeaningsTerms = fsHelper.getListUnfullmeaningWords(); var parser = new Parser(); var documents = new List<Object[]>(); var listTermsIDs = new List<int[]>(); var listTerms = new List<string>(); var dictSimilarTerms = new Dictionary<String, int>(); bool existUnknownTerm = false; foreach (var t in listSearchTerms) { if (!listUnfullmeaningsTerms.Contains(t)) { if (t.Length >= 2) { this.trySearchTermInDB(t, parser, listTermsIDs, listTerms, dictSimilarTerms, ref existUnknownTerm); } } } if (dictSimilarTerms.Count > 0) { this.saveSimilarWordsIntoDB(dictSimilarTerms); } if (listTermsIDs.Count > 0) { string stringListTerms = String.Join(", ", listTerms); if (!checkedPairSearch_dist_0 && !checkedPairSearch_dist_1) { if (radioAND) { if (!existUnknownTerm) { this.processSearchingWithAND(listTermsIDs, documents); } } else { documents = this.processSearchingWithOR(listTermsIDs); } } else { this.processSearchingWithPair(listTermsIDs, documents, checkedPairSearch_dist_0, checkedPairSearch_dist_1); } } return documents; }
public void saveTokensIntoDatabase(String document, int idExamination) { var p = new Parser(); var listCleanWords = new List<string>(); var listTokens = new List<string>(); int auxCounter = 0; var auxListCleanWordsWithVowel = p.getListCleanWords(document, ref auxCounter); var auxListCleanWords = p.removeEndsVowelFromWord(auxListCleanWordsWithVowel); var data = p.Parse(document); var listTokensOld = (List<String>)data[1]; var comparer = new StringComparer(); var listTokensWithVowel = listTokensOld.OrderBy(t => t.ToString(), comparer).ToList(); var listUnfullmeaningWords = fsHelper.getListUnfullmeaningWords(); foreach (var word in p.removeEndsVowelFromWord(listTokensWithVowel)) { if (!listTokens.Contains(word) && !listUnfullmeaningWords.Contains(word)) { listTokens.Add(word); } } foreach (string word in auxListCleanWords) { if (!listUnfullmeaningWords.Contains(word)) { listCleanWords.Add(word); } } var listIdsTerms = new List<int>(); var dictTerms = new Dictionary<string, int>(); foreach (var token in listTokens) { if (!listUnfullmeaningWords.Contains(token)) { if ((token.Length >= 2) || (Char.IsNumber(token[0]))) { this.saveToken(listIdsTerms, dictTerms, token); } else { if (!token.Equals(".")) { listCleanWords.Remove(token); } } } } this.insertPairsTermsWithExaminationInDB(listCleanWords, dictTerms, idExamination); this.insertTermsWithExaminationInDB(listIdsTerms, idExamination); }
private void trySearchTermInDB(String t, Parser parser, List<int[]> listTermsIDs, List<string> listTerms, Dictionary<String, int> dictSimilarTerms, ref bool existUnknownTerm) { string term = parser.removeEndsVowelFromWord(t); String query = "SELECT Id_vyraz FROM Vyrazy WHERE vyraz ='" + term + "'"; var dataReader = database.getRecords(query); if (dataReader.Read()) { listTermsIDs.Add(new[] { (int)dataReader[0] }); dataReader.Close(); listTerms.Add(term); } else { dataReader.Close(); String query2 = "SELECT Id_vyraz FROM Podobne_vyrazy WHERE Pod_vyraz = '" + term + "'"; dataReader = database.getRecords(query2); if (dataReader.Read()) { listTermsIDs.Add(new[] { (int)dataReader[0] }); dataReader.Close(); listTerms.Add(term); } else { dataReader.Close(); var findTerm = fsHelper.searchClosestTerm(term); if (findTerm != null) { var arr = new int[findTerm.Count]; dictSimilarTerms.Add(term, (int)findTerm[0][0]); for (int i = 0; i < findTerm.Count; i++) { arr[i] = (int)findTerm[i][0]; listTerms.Add(findTerm[i][1].ToString()); } listTermsIDs.Add(arr); } else { existUnknownTerm = true; } } } }