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
 public LTML Analyze(String strOption, LTML ltmlIn)
 {
     if (strOption == null || ltmlIn == null)
     {
         throw new Exception(String.Format("{0}: LTPService.Analyze(strOption, ltmlIn)", LtpServiceError.ParameterNullError));
     }
     m_cirServ.SetAnalysisOptions(strOption);
     m_cirServ.SetXmlOption(true);
     String resultStr = m_cirServ.Analyze(ltmlIn.GetXMLStr());
     LTML ltml_out = new LTML();
     ltml_out.LoadFromXmlStr(resultStr);
     return ltml_out;
 }
Example #3
0
        public LTML Analyze(String strOption, LTML ltmlIn)
        {
            if (strOption == null || ltmlIn == null)
            {
                throw new Exception(String.Format("{0}: LTPService.Analyze(strOption, ltmlIn)", LtpServiceError.ParameterNullError));
            }
            m_cirServ.SetAnalysisOptions(strOption);
            m_cirServ.SetXmlOption(true);
            String resultStr = m_cirServ.Analyze(ltmlIn.GetXMLStr());
            LTML   ltml_out  = new LTML();

            ltml_out.LoadFromXmlStr(resultStr);
            return(ltml_out);
        }
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());
                        }
                    }
                }
            }
        }