コード例 #1
0
        private void Button_change_TXT_Click(object sender, EventArgs e)
        {
            Hide();
            while (true)
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog
                {
                    InitialDirectory = DirectoryManager.GetSpecifiedDirectory("PlainTexts"),
                    Filter           = "Formát txt (*.txt)|*.txt|Všechny formáty (*.*)|*.*",
                    RestoreDirectory = true
                };


                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        if (openFileDialog1.FileName.EndsWith(".txt"))
                        {
                            TransformTXTFile.TransformFile(openFileDialog1.FileName);
                            MakeResultsVisible(true, ".txt", openFileDialog1.FileName);
                            break;
                        }
                        else
                        {
                            MakeResultsVisible(false, ".txt", openFileDialog1.FileName);
                            Show();
                        }
                    }
                    catch (SecurityException)
                    {
                        MessageBox.Show("Chyba při načítání souboru.");
                    }
                }
                else
                {
                    ResetWindow();
                    Show();
                    break;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Morphological table
        ///
        /// No.	 Name   Description
        ///1     POS Part of Speech
        ///2     SUBPOS Detailed Part of Speech
        ///3     GENDER Gender
        ///4     NUMBER Number
        ///5     CASE Case
        ///6     POSSGENDER Possessor's Gender
        ///7     POSSNUMBER Possessor's Number
        ///8     PERSON Person
        ///9     TENSE Tense
        ///10    GRADE Degree of comparison
        ///11    NEGATION Negation
        ///12    VOICE Voice
        ///13    RESERVE1 Unused
        ///14    RESERVE2 Unused
        ///15    VAR Variant, Style, Register, Special Usage

        /// </summary>

        /// <summary>
        ///
        /// </summary>
        /// <param name="sentence"></param>
        /// <param name="wordsForReplacement">
        ///     This param is a Dictionary that conatins word and the word
        ///         thhat was chosen for exchange by Word2Vec
        /// </param>
        /// <returns></returns>
        public static string UseMorphoDiTa(string sentence, Dictionary <string, string> wordsForReplacement)
        {
            if (wordsForReplacement.Count == 0)
            {
                return(sentence);
            }
            Dictionary <string, string[]> dict = AnalyzeSentenceAndReturnDictionary(sentence);

            Dictionary <string, string> dictOfMorphCOmbinations = new Dictionary <string, string>();

            foreach (var selectedWord in dict.Keys)
            {
                if (wordsForReplacement.ContainsKey(selectedWord))
                {
                    if (!dictOfMorphCOmbinations.ContainsKey(selectedWord))
                    {
                        dictOfMorphCOmbinations.Add(selectedWord, dict[selectedWord][1]);
                    }
                }
            }

            StringBuilder basicFormOfWOrdsRequest = new StringBuilder();

            foreach (var word in wordsForReplacement)
            {
                basicFormOfWOrdsRequest.Append(word.Value + "%20");
            }

            var basicForms = AnalyzeSentenceAndReturnDictionary(basicFormOfWOrdsRequest.ToString());

            string[]      keys = basicForms.Keys.ToArray();
            StringBuilder sb   = new StringBuilder();

            foreach (string line in basicForms.Keys)
            {
                sb.Append(basicForms[line][0] + "%0A");
            }
            var DictionaryOfDictionariesOfGeneratedWords = GenerateFormsOfWord(sb.ToString(), keys);

            Dictionary <string, string> basicFormOfGeneratedWord = new Dictionary <string, string>();

            foreach (string line in basicForms.Keys)
            {
                if (!basicFormOfGeneratedWord.ContainsKey(line))
                {
                    basicFormOfGeneratedWord.Add(line, basicForms[line][0]);
                }
            }



            StringBuilder resultSentence = new StringBuilder();

            string[] words = TransformTXTFile.TransformString(sentence).Split(' ');
            foreach (string word in words)
            {
                if (wordsForReplacement.ContainsKey(word.ToLower()))
                {
                    try
                    {
                        string resultWord           = wordsForReplacement[word.ToLower()];
                        string resultWordMorphology = dictOfMorphCOmbinations[word.ToLower()];
                        //send normalize form


                        string result = GetMorphoDiTaWord(basicFormOfGeneratedWord[resultWord], DictionaryOfDictionariesOfGeneratedWords, resultWordMorphology);
                        if (result == null)
                        {
                            if (word.Length > 2 || TransformTXTFile.ContainsDangerousChar(word) == 'n')
                            {
                                resultSentence.Append(" " + word);
                            }
                            else
                            {
                                resultSentence.Append(word);
                            }
                        }
                        else
                        {
                            if (result.Length > 2 || TransformTXTFile.ContainsDangerousChar(result) == 'n')
                            {
                                resultSentence.Append(" " + result);
                            }
                            else
                            {
                                resultSentence.Append(result);
                            }
                        }
                    }
                    catch (KeyNotFoundException)
                    {
                        resultSentence.Append(" " + word);
                        continue;
                    }
                }
                else
                {
                    if (word.Length > 2 || TransformTXTFile.ContainsDangerousChar(word) == 'n')
                    {
                        resultSentence.Append(" " + word);
                    }
                    else
                    {
                        resultSentence.Append(word);
                    }
                }
            }
            return(resultSentence.ToString().Trim());
        }
コード例 #3
0
        public static string Paraphrase(string input, string model, bool morphoDiTa)
        {
            string output = "";

            string normalizeString = TransformTXTFile.TransformString(input);

            string[]      words      = normalizeString.Split(' ');
            List <string> rightWords = new List <string>();

            // in this section I choose
            foreach (string word in words)
            {
                if (word.Length > 3)
                {
                    rightWords.Add(word);
                }
            }
            Dictionary <string, string> replacedWords = Word2Vec.UseWord2Vec(model, rightWords.ToArray());

            //   window.clear();

            if (morphoDiTa)
            {
                output = MorphoDiTa.UseMorphoDiTa(input, replacedWords);
            }
            else
            {
                StringBuilder sb = new StringBuilder();

                foreach (string word in words)
                {
                    if (replacedWords.ContainsKey(word))
                    {
                        string tempWord = replacedWords[word];
                        char   c        = TransformTXTFile.ContainsDangerousChar(tempWord);
                        if ((word.Length <= 1) || (c == 'n'))
                        {
                            sb.Append(replacedWords[word] + " ");
                        }
                        else
                        {
                            string[] tempWords = tempWord.Split(c);
                            if (tempWords[0].Length > tempWords[1].Length)
                            {
                                sb.Append(tempWords[0] + " ");
                            }
                            else
                            {
                                sb.Append(tempWords[1] + " ");
                            }
                        }
                    }
                    else
                    {
                        sb.Append(word + " ");
                    }
                }
                output = sb.ToString();
            }
            output = TransformTXTFile.TransformStringBack(output);

            return(output);
        }