本文整理汇总了C++中Sentence::getStrPOS方法的典型用法代码示例。如果您正苦于以下问题:C++ Sentence::getStrPOS方法的具体用法?C++ Sentence::getStrPOS怎么用?C++ Sentence::getStrPOS使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sentence
的用法示例。
在下文中一共展示了Sentence::getStrPOS方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
/**
* Main function.
*/
int main(int argc, char* argv[])
{
const char* sysdict = TEST_JMA_DEFAULT_SYSTEM_DICT;
const char* stopdict = TEST_JMA_DEFAULT_STOPWORD_DICT;
for(int optIndex=1; optIndex+1<argc; optIndex+=2)
{
if(! strcmp(argv[optIndex], "--stop"))
stopdict = argv[optIndex+1];
else if(! strcmp(argv[optIndex], "--dict"))
sysdict = argv[optIndex+1];
else
{
cerr << "unknown option: " << argv[optIndex] << endl;
printUsage();
exit(1);
}
}
cout << "system dictionary: " << sysdict << endl;
cout << "stop word dictionary: " << stopdict << endl;
// create factory
JMA_Factory* factory = JMA_Factory::instance();
// create analyzer and knowledge
Analyzer* analyzer = factory->createAnalyzer();
Knowledge* knowledge = factory->createKnowledge();
// load dictioanry files
knowledge->setSystemDict(sysdict);
if(knowledge->loadDict() == 0)
{
cerr << "error: fail to load dictionary files" << endl;
exit(1);
}
cout << "encoding type of system dictionary: " << Knowledge::encodeStr(knowledge->getEncodeType()) << endl;
// load stop word dictionary
if(knowledge->loadStopWordDict(stopdict) == 0)
{
cerr << "error: fail to load stop word dictionary" << endl;
exit(1);
}
// set knowledge
if(analyzer->setKnowledge(knowledge) == 0)
{
cerr << "fail to set knowledge" << endl;
exit(1);
}
Sentence s;
string line;
while(getline(cin, line))
{
s.setString(line.c_str());
if(analyzer->runWithSentence(s) != 1)
{
cerr << "error: fail in Analyzer::runWithSentence()" << endl;
exit(1);
}
// get one-best result
int i= s.getOneBestIndex();
if(i == -1)
cout << "no one-best result exists." << endl;
else
{
for(int j=0; j<s.getCount(i); ++j)
cout << s.getLexicon(i, j) << "/" << s.getStrPOS(i, j) << " ";
cout << endl;
}
}
delete knowledge;
delete analyzer;
return 0;
}