Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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;
                    }
                }
            }
        }