2.建立VC工程
不要忘了添加stl的include路径和lib路径
以及开启异常支持 /GX 和多线程 /MT
3.稍微修改一点点代码
这个主要是因为VC对C++语言的支持不完善造成的.
这一点MS已经受了好多批评.
下面的修改临时弄的,有些地方很拙劣,可以修改得更漂亮一点.
model1.cc
原文
bool eindict[l + 1];
bool findict[m + 1];
bool indict[m + 1][l + 1];
改成
vector<bool> eindict;
vector<bool> findict;
bool* indict;
indict=(bool*)malloc(sizeof(bool)*(m + 1)*(l + 1));
原文
indict[dummy][dummy2] = false;
改成
indict[dummy*(l+1)+dummy2] = false;
原文
eindict[i] = findict[j] = indict[j][i] = true;
改成
eindict[i] = findict[j] = indict[j*(l+1)+i] = true;
原文
if(indict[j][i] || (!findict[j] && !eindict[i])){
改成
if(indict[j*(l+1)+i] || (!findict[j] && !eindict[i])){
model3.h
原文
void estimate_t_a_d(sentenceHandler& sHandler1, Perplexity& perp,
Perplexity& perp,bool simple, bool dump_files,bool updateT);
改成
void estimate_t_a_d(sentenceHandler& sHandler1, Perplexity& perp,
Perplexity& trainVPerp,bool simple, bool dump_files,bool updateT);
logprob.h
原文
return (logr * logb2 / log(2));
改成
return (logr * logb2 / log((double)2));
原文
//#define MAX(A,B) ((A) > (B) ? (A) : (B))
改成
#define max(A,B) ((A) > (B) ? (A) : (B))
增加一个文件 mystl.cc
#include <string.h>
#include <stdlib.h>
char *strlwr(char *s)
{
if (s != NULL)
{
char *p;
for (p = s; *p; ++p)
*p = tolower(*p);
}
return s;
}
int strcasecmp(const char *s1, const char *s2)
{
char *tmp1,*tmp2;
tmp1=(char *)malloc(strlen(s1)+1);
tmp2=(char *)malloc(strlen(s2)+1);
strcpy(tmp1,s1);
strcpy(tmp2,s2);
return strcmp( strlwr(tmp1), strlwr(tmp2) );
}
注意: 这只是编译成功,不保证运行没问题哦:-)