Ejemplo n.º 1
0
        public void main(string path)
        {
            XmlNodeList N2;

            Xml_reader xml_reader = new Xml_reader();
            N2 = xml_reader.xml_reader_N2(path);

            Xml_writer xml_writer = new Xml_writer();
            xml_writer.setpath(".\\xml\\exam_withKey.xml");

            Xml_find_key xml_find_key = new Xml_find_key();

            foreach(XmlNode n2 in N2)
            {
                XmlDocument xmldocument = new XmlDocument();
                XmlNode new_n2 = xmldocument.ImportNode(n2, true);
                List<string> key;
                key = xml_find_key.findkey(new_n2);
                xml_writer.write_key(new_n2, key);
            }

            xml_writer.save();

            MessageBox.Show("f");
        }
Ejemplo n.º 2
0
        //經由nlp分析出的ner將單字組合為有意義的key組裝
        private List<string> ner(string path)
        {
            List<string> return_key = new List<string>();

            Xml_reader xml_reader = new Xml_reader();
            XmlDocument xmldocument = new XmlDocument();

            //讀出Relay.xml中nlp分析結果
            XmlNodeList nlp_tokens = xml_reader.xml_reader_nlp(path);

            string selectKey = "";
            Boolean iskey = true;

            foreach (XmlNode nlp_token in nlp_tokens)
            {
                //將nlpNode轉換為本地物件
                XmlNode local_nlp_token = xmldocument.ImportNode(nlp_token, true);

                //取得nlp_token中word資料
                XmlNode nlp_word = xml_reader.xml_reader_nlp_word(local_nlp_token);

                //取得nlp_token中ner資料
                XmlNode nlp_ner = xml_reader.xml_reader_nlp_ner(local_nlp_token);

                //組合key
                if (nlp_ner.InnerText == "DATE")
                {
                    selectKey += (" " + nlp_word.InnerText);
                    iskey = false;
                }
                else if (nlp_ner.InnerText == "LOCATION")
                {
                    selectKey += (" " + nlp_word.InnerText);
                    iskey = false;
                }
                else if (nlp_ner.InnerText == "ORGANIZATION")
                {
                    selectKey += (" " + nlp_word.InnerText);
                    iskey = false;
                }
                else if (nlp_ner.InnerText == "MONEY")
                {
                    selectKey += (" " + nlp_word.InnerText);
                    iskey = false;
                }
                else if (nlp_ner.InnerText == "PERSON")
                {
                    selectKey += (" " + nlp_word.InnerText);
                    iskey = false;
                }
                else if (nlp_ner.InnerText == "PERCENT")
                {
                    selectKey += (" " + nlp_word.InnerText);
                    iskey = false;
                }
                else if (nlp_ner.InnerText == "TIME")
                {
                    selectKey += (" " + nlp_word.InnerText);
                    iskey = false;
                }
                else
                {
                    if (iskey != true)
                    {
                        return_key.Add(selectKey);
                        selectKey = "";
                        iskey = true;
                    }
                }
            }

            return return_key;
        }
Ejemplo n.º 3
0
        public List<string> findkey(XmlNode N2)
        {
            string type = "";
            string mainKey = "Nu11";
            XmlNodeList N3D,N3I,N4IR,N4QI,N4DU,N5QIR;
            List<string> Key = new List<string>();

            Xml_reader xml_reader = new Xml_reader();

            N3D = xml_reader.xml_reader_N3_data(N2);
            N3I = xml_reader.xml_reader_N3_instruction(N2);

            //Analytics question
            if (N2.Attributes["minimal"].Value == "yes")
            {
                //type1,2
                //Analytics instruction
                foreach (XmlNode N3 in N3I)
                {
                    //set type
                    if (N3.HasChildNodes)
                    {
                        //type1
                        type = "1";
                        N4IR = xml_reader.xml_reader_N4_instruction_ref(N2);
                        foreach (XmlNode N4 in N4IR)
                        {
                            mainKey = N4.Attributes["target"].Value.Trim();
                        }
                    }
                    else
                    {
                        //type2
                        type = "2";
                    }

                    //Analytics instruction by nlp
                    String instruction = N3.InnerText;
                    foreach (string k in nlp(instruction))
                    {
                        Key.Add("#/" + k.Trim());
                    }
                }

                //Analytics data
                foreach (XmlNode N3 in N3D)
                {
                    if (N3.Attributes["id"].Value.Trim() == mainKey )
                    {
                        //all main key
                        String data = N3.InnerText;
                        string[] datalist = data.Split(',');
                        foreach(string d in datalist)
                        {
                            Key.Add("@/" + d.Trim());
                        }
                    }
                    else
                    {
                        //Analytics data by nlp
                        foreach (string k in nlp(N3.InnerText))
                        {
                            Key.Add("#/" + k.Trim());
                        }
                    }
                }
            }
            else
            {
                //type3,4
                //Analytics instruction
                foreach (XmlNode N3 in N3I)
                {
                    //set type
                    if (N3.HasChildNodes)
                    {
                        //type3
                        type = "3";
                    }
                    else
                    {
                        //type4
                        type = "4";
                    }

                    //Analytics instruction by nlp
                    foreach (string k in nlp(N3.InnerText))
                    {
                        Key.Add("#/" + k.Trim());
                    }
                }

                //Analytics data
                foreach (XmlNode N3 in N3D)
                {
                    //Analytics data by nlp
                    foreach (string k in nlp(N3.InnerText))
                    {
                        Key.Add("#/" + k.Trim());
                    }
                }

                //Analytics question_instruction
                N4QI = xml_reader.xml_reader_N4_question_instruction(N2);
                N4DU = xml_reader.xml_reader_N4_data_utext(N2);
                N5QIR = xml_reader.xml_reader_N5_question_instruction_ref(N2);
                foreach (XmlNode N4 in N4QI)
                {
                    //have ref target
                    if (N5QIR != null)
                    {
                        foreach (XmlNode N5 in N5QIR)
                        {
                            try
                            {
                                string tager = N5.Attributes["target"].Value;
                                foreach (XmlNode N4_5 in N4DU)
                                {
                                    if (N4_5.Attributes["id"].Value == tager)
                                    {
                                        string[] w = N4_5.InnerText.Split(')');
                                        Key.Add("@/" + w[1].Trim());
                                        break;
                                    }
                                }
                            }catch(Exception e)
                            {

                            }
                        }

                    }

                    //Analytics question_instruction by nlp
                    foreach (string k in nlp(N4.InnerText))
                    {
                        Key.Add("#/"+k.Trim());
                    }
                }
            }

            Key = delete_repeat_key(Key);

            return Key;
        }