예제 #1
0
	bool LTPService::Analyze(const std::string& option, const std::string& analyzeString, LTML& ltml_out)
	{
		int flag = -1;
		ls.SetAnalysisOptions(option);
		ls.SetXmlOption(false);
		std::string resultStr;
		if(analyzeString.size() == 0)
		{
			std::cerr<<"Input analyzeString is null!"<<std::endl;
		}
		else
		{
			//		printf("analyzeString: \n%s\n", analyzeString.c_str());
			flag = ls.Analyze(analyzeString, resultStr);
			//		printf("result: \n%s\n", resultStr.c_str());
			ltml_out.ClearDOM();
			ltml_out.SetEncoding(ls.GetEncoding());
			ltml_out.LoadLtml(resultStr);
			ltml_out.SetOver();
		}
		if (flag==0)
		{
			return true;
		}
		return false;
	}
예제 #2
0
int main(){
    LTPService ls("email:token");
    LTML ltml;

    vector<Word> wordList;
    Word w;
    w.SetWS("我");      w.SetPOS("r");  wordList.push_back(w);
    w.SetWS("爱");      w.SetPOS("v");  wordList.push_back(w);
    w.SetWS("北京");    w.SetPOS("ns"); wordList.push_back(w);
    w.SetWS("天安门");  w.SetPOS("ns"); wordList.push_back(w);

    try{
        ltml.AddSentence(wordList, 0);

        if(!ls.Analyze(LTPOption.SRL, ltml, ltml)) {
            cerr<<"Authorization is denied!"<<endl;
            exit(EXIT_FAILURE);
        }
        int sentNum = ltml.CountSentence();
        for ( int i = 0; i<sentNum; ++i) { 
            string sentCont;
            ltml.GetSentenceContent(sentCont, i);
            cout<< sentCont <<endl;
            vector<Word> wordList;
            ltml.GetWords(wordList, i);
            for( vector<Word>::iterator iter = wordList.begin(); iter!= wordList.end(); ++iter ){
                if (ltml.HasWS()) {
                    cout<<iter->GetWS()<<"\t"<<iter->GetID();
                }
                if (ltml.HasPOS()) {
                    cout<<"\t"<<iter->GetPOS();
                }
                if (ltml.HasNE()) {
                    cout<<"\t"<<iter->GetNE();
                }
                if(ltml.HasParser()) {
                    cout<<"\t"<<iter->GetParserParent()<<"\t"<<iter->GetParserRelation();
                }
                cout<<endl;

                if( iter->IsPredicate() ){
                    vector<SRL> srls;
                    iter->GetSRLs(srls);
                    cout<<srls.size()<<endl;
                    for(vector<SRL>::iterator iter = srls.begin(); iter != srls.end(); ++iter){
                        cout<<"\t"<<iter->type
                            <<"\t"<<iter->beg
                            <<"\t"<<iter->end
                            <<endl;
                    }
                }

            }
        }
    } catch(exception& e) {
        std::cerr<<e.what();
    }
    return 0;
}
예제 #3
0
	bool LTPService::Analyze(const std::string& option, const LTML& ltml_in, LTML& ltml_out)
	{
		int flag = -1;
		ls.SetAnalysisOptions(option);
		ls.SetXmlOption(true);
		std::string resultStr;
		flag = ls.Analyze(ltml_in.GetXMLStr(), resultStr);
		ltml_out.ClearDOM();
		ltml_out.SetEncoding(ls.GetEncoding());
		ltml_out.LoadLtml(resultStr);
		ltml_out.SetOver();
		if (flag==0)
		{
			return true;
		}
		return false;
	}
예제 #4
0
int main2(){
	LTPService ls("username:password");
	LTML ltml;
	if (!ls.Analyze(LTPOption.ALL,"我们都是赛尔人。", ltml))
	{
		cerr<<"Authorization is denied!"<<endl;
		exit(EXIT_FAILURE);
	}
//	cout<<ltml.GetXMLStr()<<endl;
	int sentNum = ltml.CountSentence();
	for ( int i = 0; i<sentNum; ++i) { 
		string sentCont;
		ltml.GetSentenceContent(sentCont, i);
		cout<< sentCont <<endl;
		vector<Word> wordList;
		ltml.GetWords(wordList, i);
		//按句子打印输出
		for( vector<Word>::iterator iter = wordList.begin(); iter!= wordList.end(); ++iter ){
			cout<<iter->GetWS()<<"\t"<<iter->GetID();
			cout<<"\t"<<iter->GetPOS();
			cout<<"\t"<<iter->GetNE();
			cout<<"\t"<<iter->GetParserParent()<<"\t"<<iter->GetParserRelation();
			cout<<"\t"<<iter->GetWSD()<<"\t"<<iter->GetWSDExplanation();
			cout<<endl;

			if( iter->IsPredicate() ){
				vector<SRL> srls;
				iter->GetSRLs(srls);
//				cout<<srls.size()<<endl;
				for(vector<SRL>::iterator iter = srls.begin(); iter != srls.end(); ++iter){
					cout<<"\t"<<iter->type
						<<"\t"<<iter->beg
						<<"\t"<<iter->end
						<<endl;
				}
			}

		}
	}
	return 0;
}