当前位置: 首页>>代码示例>>C++>>正文


C++ Sentence::getToken方法代码示例

本文整理汇总了C++中Sentence::getToken方法的典型用法代码示例。如果您正苦于以下问题:C++ Sentence::getToken方法的具体用法?C++ Sentence::getToken怎么用?C++ Sentence::getToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sentence的用法示例。


在下文中一共展示了Sentence::getToken方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: buildIndices

void Indices::buildIndices(Corpus* pCorpus){
	cout << "Building indices using: " << pCorpus->getCorpusFile() << endl << std::flush;
	int sentenceNum = pCorpus->getSentenceNum();
	int colNum = pCorpus->getSentence(0)->getToken(0)->getColumnNum();
	m_vecMapString2IntCol = new MyVector<unordered_map <string, int>>;
	m_vecMapInt2StringCol = new MyVector<vector<string>>;
	for(int i = 0; i < colNum; ++ i){
		unordered_map <string, int>* p = new unordered_map <string, int>;
		m_vecMapString2IntCol->push_back(p);
		vector<string>* pv = new vector<string>;
		m_vecMapInt2StringCol->push_back(pv);
	}

	for(int i = 0; i < sentenceNum; ++ i){
		Sentence* pSentence = pCorpus->getSentence(i);
		int tokenNum = pSentence->getTokenNum();
		for(int j = 0; j < tokenNum; ++ j){
			Token* pToken = pSentence->getToken(j);

			//column
			for(int k = 0; k < colNum; ++ k){
				MyString* pCol = pToken->getColumn(k);

				unordered_map <string, int>* string2int = m_vecMapString2IntCol->getItem(k);
				vector<string>* int2string = m_vecMapInt2StringCol->getItem(k);

				unordered_map <string, int>::const_iterator got = string2int->find(pCol->getString());
				if(got == string2int->end()){// not found
					std::pair<string, int> newIndex (pCol->getString(), int2string->size());
					string2int->insert(newIndex);
					int2string->push_back(pCol->getString());
				}
			}

			//unigram tag
			MyString* pTag = pToken->getTag();
			unordered_map <string, int>::const_iterator got = m_mapString2IntTag.find(pTag->getString());
			if(got == m_mapString2IntTag.end()){// not found
					std::pair<string, int> newIndex (pTag->getString(), m_mapInt2StringTag.size());
					m_mapString2IntTag.insert(newIndex);
					m_mapInt2StringTag.push_back(pTag->getString());
			}

		}

	}

	for(int i = 0; i < sentenceNum; ++ i){
			Sentence* pSentence = pCorpus->getSentence(i);
			int tokenNum = pSentence->getTokenNum();
			for(int j = 1; j < tokenNum; ++ j){
				Token* pPreToken = pSentence->getToken(j - 1);
				Token* pCurrToken = pSentence->getToken(j);
				int preTag = m_mapString2IntTag.find(pPreToken->getTag()->getString())->second;
				int curTag = m_mapString2IntTag.find(pCurrToken->getTag()->getString())->second;
				string strBitag = BiTag::mergeTag(preTag, curTag);
				unordered_map <string, int>::const_iterator got = m_mapString2IntBiTag.find(strBitag);
				if(got == m_mapString2IntBiTag.end()){// not found
					std::pair<string, int> newIndex (strBitag, m_mapInt2StringBiTag.size());
					m_mapString2IntBiTag.insert(newIndex);
					m_mapInt2StringBiTag.push_back(strBitag);
				}
			}
	}

	//unigram feature index
	m_mapUnigramFeature = new std::tr1::unordered_map<string, Feature*>;
	m_vecUnigramFeatures = new MyVector<Feature>;

	//bigram feature index
	m_mapBigramFeature = new std::tr1::unordered_map<string, Feature*>;
	m_vecBigramFeatures = new MyVector<Feature>;
	printColCardinalities();
	cout << "Building indices finished!" << endl << endl << std::flush;
}
开发者ID:djoerd,项目名称:Co-occurrence-Rate-Networks,代码行数:75,代码来源:Indices.cpp


注:本文中的Sentence::getToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。