コード例 #1
0
ファイル: Program.cs プロジェクト: koanse/Semantics
 public WordRu(string norm, string form, LinkTagRu lnkM, LinkTagRu lnkD, List <AttributeRu> lAt, List <WordRu> lCh, WordRu par)
 {
     this.norm = norm;
     this.form = form;
     this.prep = "";
     this.lnkM = lnkM;
     this.lnkD = lnkD;
     this.lAt  = lAt;
     this.lCh  = lCh;
     this.par  = par;
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: koanse/Semantics
        static public List <WordRu> Analize(string text)
        {
            StreamWriter sr = new StreamWriter("in.txt", false, System.Text.Encoding.Default);

            sr.Write(text);
            sr.Close();
            Process pr = Process.Start("bin\\wrf.exe", "i:in.txt o:out.xml lc:log.txt xml n");

            pr.WaitForExit();
            FileStream     fs     = new FileStream("out.xml", FileMode.Open);
            XmlReader      reader = XmlReader.Create(fs);
            List <WordRu>  lRoot  = new List <WordRu>();
            Stack <WordRu> st     = new Stack <WordRu>();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.XmlDeclaration:
                    break;

                case XmlNodeType.Element:
                    switch (reader.Name)
                    {
                    case "Node":
                        LinkTagRu lnkM = LinkTagRu.none, lnkD = LinkTagRu.none;
                        string    sign = reader.GetAttribute("Sign");
                        string    lTag = reader.GetAttribute("LeftTag"), rTag = reader.GetAttribute("RightTag");
                        if (sign == "<")
                        {
                            lnkM = (LinkTagRu)Enum.Parse(typeof(LinkTagRu), lTag.Substring(0, lTag.Length - 3));
                            lnkD = (LinkTagRu)Enum.Parse(typeof(LinkTagRu), rTag.Substring(0, rTag.Length - 3));
                        }
                        else if (sign == ">")
                        {
                            lnkD = (LinkTagRu)Enum.Parse(typeof(LinkTagRu), lTag.Substring(0, lTag.Length - 3));
                            lnkM = (LinkTagRu)Enum.Parse(typeof(LinkTagRu), rTag.Substring(0, rTag.Length - 3));
                        }
                        while (reader.Read() && reader.NodeType != XmlNodeType.Element)
                        {
                            ;
                        }
                        string             norm = reader.GetAttribute("Norm"), form = reader.GetAttribute("Form");
                        List <AttributeRu> lAt = new List <AttributeRu>();
                        while (true)
                        {
                            while (reader.Read() && reader.NodeType != XmlNodeType.Element &&
                                   reader.NodeType != XmlNodeType.EndElement)
                            {
                                ;
                            }
                            if (reader.NodeType == XmlNodeType.EndElement)
                            {
                                break;
                            }
                            while (reader.Read() && reader.NodeType != XmlNodeType.Text)
                            {
                                ;
                            }
                            lAt.Add((AttributeRu)int.Parse(reader.Value));
                            while (reader.Read() && reader.NodeType != XmlNodeType.EndElement)
                            {
                                ;
                            }
                        }
                        WordRu par = null;
                        if (st.Count > 0)
                        {
                            par = st.Peek();
                        }
                        WordRu w = new WordRu(norm, form, lnkM, lnkD, lAt, new List <WordRu>(), par);
                        if (par != null)
                        {
                            par.lCh.Add(w);
                        }
                        else
                        {
                            lRoot.Add(w);
                        }
                        st.Push(w);
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (reader.Name == "Node")
                    {
                        st.Pop();
                    }
                    break;
                }
            }
            fs.Close();
            return(lRoot);
        }