Example #1
0
        static void TestMergeXmlFile(string strAuthorize, string strOption, string strXMLlFile_Main, string strXMLlFile_Merge, string strXMLlFile_Out)
        {
            LTPService ltpService = new LTPService(strAuthorize);
            LTML       ltmlMain   = new LTML();

            ltmlMain.LoadFromXmlFile(strXMLlFile_Main);

            LTML ltmlMerge = new LTML();

            ltmlMerge.LoadFromXmlFile(strXMLlFile_Merge);

            for (int i = 0; i < ltmlMerge.ListParas.Count; i++)
            {
                foreach (SentIndex sentIndex in ltmlMerge.ListParas[i].SentenceList)
                {
                    ltmlMain.AddSentence(sentIndex.WordList, i);
                }
            }

            ltmlMain.SaveDom(strXMLlFile_Out + @".middle");
            LTML ltml = ltpService.Analyze(strOption, ltmlMain);

            ltml.SaveDom(strXMLlFile_Out);
            Console.WriteLine(ltml.GetXMLStr());
            int sentNum = ltml.CountSentence();

            for (int i = 0; i < sentNum; ++i)
            {
                string sentCont = ltml.GetSentenceContent(i);
                Console.WriteLine(sentCont);
                List <Word> wordList = ltml.GetWords(i);
                //按句子打印输出
                foreach (Word curWord in wordList)
                {
                    Console.Write(curWord.GetWS() + "\t" + curWord.GetID());
                    Console.Write("\t" + curWord.GetPOS());
                    Console.Write("\t" + curWord.GetNE());
                    Console.Write("\t" + curWord.GetParserParent() + "\t" + curWord.GetParserRelation());
                    Console.Write("\t" + curWord.GetWSD() + "\t" + curWord.GetWSDExplanation());
                    Console.WriteLine();

                    if (curWord.IsPredicate())
                    {
                        List <SRL> srls = curWord.GetSRLs();
                        Console.WriteLine(srls.Count);
                        foreach (SRL srl in srls)
                        {
                            Console.WriteLine(srl.ToString());
                        }
                    }
                }
            }
        }
Example #2
0
        static void TestMergeXmlFile(string strAuthorize, string strOption, string strXMLlFile_Main, string strXMLlFile_Merge, string strXMLlFile_Out)
        {
            LTPService ltpService = new LTPService(strAuthorize);
            LTML ltmlMain = new LTML();
            ltmlMain.LoadFromXmlFile(strXMLlFile_Main);

            LTML ltmlMerge = new LTML();
            ltmlMerge.LoadFromXmlFile(strXMLlFile_Merge);

            for (int i = 0; i < ltmlMerge.ListParas.Count; i++)
            {
                foreach (SentIndex sentIndex in ltmlMerge.ListParas[i].SentenceList)
                {
                    ltmlMain.AddSentence(sentIndex.WordList, i);
                }
            }

            ltmlMain.SaveDom(strXMLlFile_Out + @".middle");
            LTML ltml = ltpService.Analyze(strOption, ltmlMain);
            ltml.SaveDom(strXMLlFile_Out);
            Console.WriteLine(ltml.GetXMLStr());
            int sentNum = ltml.CountSentence();
            for (int i = 0; i < sentNum; ++i)
            {
                string sentCont = ltml.GetSentenceContent(i);
                Console.WriteLine(sentCont);
                List<Word> wordList = ltml.GetWords(i);
                //按句子打印输出
                foreach (Word curWord in wordList)
                {
                    Console.Write(curWord.GetWS() + "\t" + curWord.GetID());
                    Console.Write("\t" + curWord.GetPOS());
                    Console.Write("\t" + curWord.GetNE());
                    Console.Write("\t" + curWord.GetParserParent() + "\t" + curWord.GetParserRelation());
                    Console.Write("\t" + curWord.GetWSD() + "\t" + curWord.GetWSDExplanation());
                    Console.WriteLine();

                    if (curWord.IsPredicate())
                    {
                        List<SRL> srls = curWord.GetSRLs();
                        Console.WriteLine(srls.Count);
                        foreach (SRL srl in srls)
                        {
                            Console.WriteLine(srl.ToString());
                        }

                    }
                }
            }
        }
Example #3
0
        static void TestSentence(string strAuthorize, string strOption, string strSentFile, string strXMLFile)
        {
            LTPService ltpService = new LTPService(strAuthorize);
            LTML       ltmlOut    = new LTML();

            foreach (String strSentence in File.ReadAllLines(strSentFile, Encoding.UTF8))
            {
                String strSentence_new = strSentence.Trim();
                if (strSentence_new.Equals(String.Empty))
                {
                    continue;
                }
                LTML ltml = ltpService.Analyze(strOption, strSentence_new);
                for (int i = 0; i < ltml.ListParas.Count; i++)
                {
                    foreach (SentIndex sentIndex in ltml.ListParas[i].SentenceList)
                    {
                        ltmlOut.AddSentence(sentIndex.WordList, i);
                    }
                }
                int sentNum = ltml.CountSentence();
                for (int i = 0; i < sentNum; ++i)
                {
                    string sentCont = ltml.GetSentenceContent(i);
                    Console.WriteLine(sentCont);
                    List <Word> wordList = ltml.GetWords(i);
                    //按句子打印输出
                    foreach (Word curWord in wordList)
                    {
                        Console.Write(curWord.GetWS() + "\t" + curWord.GetID());
                        Console.Write("\t" + curWord.GetPOS());
                        Console.Write("\t" + curWord.GetNE());
                        Console.Write("\t" + curWord.GetParserParent() + "\t" + curWord.GetParserRelation());
                        Console.Write("\t" + curWord.GetWSD() + "\t" + curWord.GetWSDExplanation());
                        Console.WriteLine();

                        if (curWord.IsPredicate())
                        {
                            List <SRL> srls = curWord.GetSRLs();
                            Console.WriteLine(srls.Count);
                            foreach (SRL srl in srls)
                            {
                                Console.WriteLine(srl.ToString());
                            }
                        }
                    }
                }
            }
            ltmlOut.SaveDom(strXMLFile);
        }
Example #4
0
        static void TestXmlFile(string strAuthorize, string strOption, string strXMLFileIn, string strXMLFileOut)
        {
            LTPService ltpService = new LTPService(strAuthorize);
            LTML       ltmlIn     = new LTML();

            ltmlIn.LoadFromXmlFile(strXMLFileIn);
            LTML ltml = ltpService.Analyze(strOption, ltmlIn);

            ltml.SaveDom(strXMLFileOut);
            Console.WriteLine(ltml.GetXMLStr());
            int sentNum = ltml.CountSentence();

            for (int i = 0; i < sentNum; ++i)
            {
                string sentCont = ltml.GetSentenceContent(i);
                Console.WriteLine(sentCont);
                List <Word> wordList = ltml.GetWords(i);
                //按句子打印输出
                foreach (Word curWord in wordList)
                {
                    Console.Write(curWord.GetWS() + "\t" + curWord.GetID());
                    Console.Write("\t" + curWord.GetPOS());
                    Console.Write("\t" + curWord.GetNE());
                    Console.Write("\t" + curWord.GetParserParent() + "\t" + curWord.GetParserRelation());
                    Console.Write("\t" + curWord.GetWSD() + "\t" + curWord.GetWSDExplanation());
                    Console.WriteLine();

                    if (curWord.IsPredicate())
                    {
                        List <SRL> srls = curWord.GetSRLs();
                        Console.WriteLine(srls.Count);
                        foreach (SRL srl in srls)
                        {
                            Console.WriteLine(srl.ToString());
                        }
                    }
                }
            }
        }
Example #5
0
        static void TestSentence(string strAuthorize, string strOption, string strSentFile, string strXMLFile)
        {
            LTPService ltpService = new LTPService(strAuthorize);
            LTML ltmlOut = new LTML();
            foreach(String strSentence in File.ReadAllLines(strSentFile,Encoding.UTF8))
            {
                String strSentence_new = strSentence.Trim();
                if (strSentence_new.Equals(String.Empty))
                {
                    continue;
                }
                LTML ltml = ltpService.Analyze(strOption, strSentence_new);
                for (int i = 0; i < ltml.ListParas.Count; i++)
                {
                    foreach (SentIndex sentIndex in ltml.ListParas[i].SentenceList)
                    {
                        ltmlOut.AddSentence(sentIndex.WordList, i);
                    }
                }
                int sentNum = ltml.CountSentence();
                for (int i = 0; i < sentNum; ++i)
                {
                    string sentCont = ltml.GetSentenceContent(i);
                    Console.WriteLine(sentCont);
                    List<Word> wordList = ltml.GetWords(i);
                    //按句子打印输出
                    foreach (Word curWord in wordList)
                    {
                        Console.Write(curWord.GetWS() + "\t" + curWord.GetID());
                        Console.Write("\t" + curWord.GetPOS());
                        Console.Write("\t" + curWord.GetNE());
                        Console.Write("\t" + curWord.GetParserParent() + "\t" + curWord.GetParserRelation());
                        Console.Write("\t" + curWord.GetWSD() + "\t" + curWord.GetWSDExplanation());
                        Console.WriteLine();

                        if (curWord.IsPredicate())
                        {
                            List<SRL> srls = curWord.GetSRLs();
                            Console.WriteLine(srls.Count);
                            foreach (SRL srl in srls)
                            {
                                Console.WriteLine(srl.ToString());
                            }

                        }
                    }
                }
            }
            ltmlOut.SaveDom(strXMLFile);
        }
Example #6
0
        static void TestXmlFile(string strAuthorize, string strOption, string strXMLFileIn, string strXMLFileOut)
        {
            LTPService ltpService = new LTPService(strAuthorize);
            LTML ltmlIn = new LTML();
            ltmlIn.LoadFromXmlFile(strXMLFileIn);
            LTML ltml = ltpService.Analyze(strOption, ltmlIn);
            ltml.SaveDom(strXMLFileOut);
            Console.WriteLine(ltml.GetXMLStr());
            int sentNum = ltml.CountSentence();
            for (int i = 0; i < sentNum; ++i)
            {
                string sentCont = ltml.GetSentenceContent(i);
                Console.WriteLine(sentCont);
                List<Word> wordList = ltml.GetWords(i);
                //按句子打印输出
                foreach (Word curWord in wordList)
                {
                    Console.Write(curWord.GetWS() + "\t" + curWord.GetID());
                    Console.Write("\t" + curWord.GetPOS());
                    Console.Write("\t" + curWord.GetNE());
                    Console.Write("\t" + curWord.GetParserParent() + "\t" + curWord.GetParserRelation());
                    Console.Write("\t" + curWord.GetWSD() + "\t" + curWord.GetWSDExplanation());
                    Console.WriteLine();

                    if (curWord.IsPredicate())
                    {
                        List<SRL> srls = curWord.GetSRLs();
                        Console.WriteLine(srls.Count);
                        foreach (SRL srl in srls)
                        {
                            Console.WriteLine(srl.ToString());
                        }

                    }
                }
            }
        }