Example #1
0
        public static void GetOpcorporaWords()
        {
            bool   previousWasVerb    = false;
            string previousVerbLexeme = "";

            string xmlFolderName = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\Documentation\\dict.opcorpora.xml";

            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(xmlFolderName);

            XmlElement xRoot = xDoc.DocumentElement;

            XmlNodeList lemmataLvl = xRoot.SelectNodes("lemmata");

            XmlNode lemmata = lemmataLvl[0];                     // Уровень lemmata

            XmlNodeList lemmaLvl = lemmata.SelectNodes("lemma"); // Уровень lemma

            OpcorporaWords = new List <OpcorporaWord>();


            foreach (XmlNode xmlNode in lemmaLvl)
            {
                XmlNode lNode = xmlNode.FirstChild;                // Уровень l
                XmlNode gNode = lNode.FirstChild;                  // Уровень g
                XmlNode fNode = xmlNode.ChildNodes[1];             // f подуровень

                string str   = gNode.SelectSingleNode("@v").Value; // Значение "INFN"
                string value = lNode.SelectSingleNode("@t").Value; // лексема глагола

                OpcorporaWord opcorporaWord = new OpcorporaWord();
                opcorporaWord.AditionalWords = new List <string>();

                if (str != null)
                {
                    if (str == "INFN" && previousWasVerb == true)
                    {
                        foreach (XmlNode chilnode in xmlNode.ChildNodes)
                        {
                            string aditionalWord = chilnode.SelectSingleNode("@t").Value;
                            if (!opcorporaWord.AditionalWords.Contains(aditionalWord))
                            {
                                opcorporaWord.AditionalWords.Add(aditionalWord);
                            }
                        }

                        opcorporaWord.Lexeme       = previousVerbLexeme;
                        opcorporaWord.PartOfSpeech = "VERB";

                        previousWasVerb    = false;
                        previousVerbLexeme = "";

                        OpcorporaWords.Add(opcorporaWord);
                    }

                    if (MainWindow.activeTypes.Contains(str) == true)
                    {
                        if (str == "VERB")
                        {
                            previousVerbLexeme = value;
                            previousWasVerb    = true;
                        }
                        else
                        {
                            foreach (XmlNode chilnode in xmlNode.ChildNodes)
                            {
                                string aditionalWord = chilnode.SelectSingleNode("@t").Value;
                                if (!opcorporaWord.AditionalWords.Contains(aditionalWord))
                                {
                                    opcorporaWord.AditionalWords.Add(aditionalWord);
                                }
                            }

                            opcorporaWord.Lexeme       = value;
                            opcorporaWord.PartOfSpeech = str;

                            OpcorporaWords.Add(opcorporaWord);
                        }
                    }
                }
            }
        }
Example #2
0
        public static List <OpcorporaWord> MatchWordsFromOpcorporaAndDictationary(List <string> singleWords)
        {
            //CloseWindow();

            //ShowWindow("Выолняется сопоставление слов из диктанта c Opcorpora...");

            List <OpcorporaWord> words = new List <OpcorporaWord>();

            foreach (var sWord in singleWords)
            {
                foreach (var oWord in OpcorporaWords)
                {
                    if (oWord.Lexeme == sWord)
                    {
                        OpcorporaWord newWord = new OpcorporaWord();

                        if (oWord.PartOfSpeech == "VERB")
                        {
                            newWord.Lexeme       = oWord.AditionalWords[0];
                            newWord.PartOfSpeech = oWord.PartOfSpeech;
                        }
                        else
                        {
                            newWord.Lexeme       = sWord;
                            newWord.PartOfSpeech = oWord.PartOfSpeech;
                        }

                        if (words.Exists(x => x.Lexeme == oWord.Lexeme) == false)
                        {
                            if (newWord.Lexeme.Length > 2)
                            {
                                words.Add(newWord);
                            }
                        }
                    }
                    else
                    {
                        foreach (var aWord in oWord.AditionalWords)
                        {
                            if (aWord == sWord)
                            {
                                if (words.Exists(x => x.Lexeme == oWord.Lexeme) == false)
                                {
                                    if (oWord.Lexeme.Length > 2)
                                    {
                                        OpcorporaWord newWord = new OpcorporaWord();

                                        if (oWord.PartOfSpeech == "VERB")
                                        {
                                            newWord.Lexeme       = aWord; //oWord.Lexeme;
                                            newWord.PartOfSpeech = oWord.PartOfSpeech;
                                        }
                                        else
                                        {
                                            newWord.Lexeme       = oWord.AditionalWords[0];
                                            newWord.PartOfSpeech = oWord.PartOfSpeech;
                                        }

                                        words.Add(newWord);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(words);
        }