⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 factorcollection.cpp.svn-base

📁 moses开源的机器翻译系统
💻 SVN-BASE
字号:
// $Id$/***********************************************************************Moses - factored phrase-based language decoderCopyright (C) 2006 University of EdinburghThis library is free software; you can redistribute it and/ormodify it under the terms of the GNU Lesser General PublicLicense as published by the Free Software Foundation; eitherversion 2.1 of the License, or (at your option) any later version.This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNULesser General Public License for more details.You should have received a copy of the GNU Lesser General PublicLicense along with this library; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA***********************************************************************/#include <iostream>#include <fstream>#include <string>#include <vector>#include "FactorCollection.h"#include "LanguageModel.h"#include "Util.h"using namespace std;FactorCollection FactorCollection::s_instance;void FactorCollection::LoadVocab(FactorDirection direction, FactorType factorType, const string &filePath){	ifstream 	inFile(filePath.c_str());	string line;		while( !getline(inFile, line, '\n').eof())	{		vector<string> token = Tokenize( line );		if (token.size() < 2) 		{			continue;		}				// looks like good line		AddFactor(direction, factorType, token[1]);	}}bool FactorCollection::Exists(FactorDirection direction, FactorType factorType, const string &factorString){	// find string id	const string *ptrString=&(*m_factorStringCollection.insert(factorString).first);	FactorSet::const_iterator iterFactor;	Factor search(direction, factorType, ptrString); // id not used for searching	iterFactor = m_collection.find(search);	return iterFactor != m_collection.end();}const Factor *FactorCollection::AddFactor(FactorDirection direction																				, FactorType 			factorType																				, const string 		&factorString){	// find string id	const string *ptrString=&(*m_factorStringCollection.insert(factorString).first);	pair<FactorSet::iterator, bool> ret = m_collection.insert( Factor(direction, factorType, ptrString, m_factorId) );	if (ret.second)		++m_factorId; // new factor, make sure next new factor has diffrernt id			const Factor *factor = &(*ret.first);	return factor;}FactorCollection::~FactorCollection(){	//FactorSet::iterator iter;	//for (iter = m_collection.begin() ; iter != m_collection.end() ; iter++)	//{	//	delete (*iter);	//}}TO_STRING_BODY(FactorCollection);// friendostream& operator<<(ostream& out, const FactorCollection& factorCollection){	FactorSet::const_iterator iterFactor;	for (iterFactor = factorCollection.m_collection.begin() ; iterFactor != factorCollection.m_collection.end() ; ++iterFactor)	{		const Factor &factor 	= *iterFactor;		out << factor;	}	return out;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -