在VS2003下编译 GIZA++.2003-09-30

5 views
Skip to first unread message

Jacky

unread,
Sep 21, 2006, 9:08:13 AM9/21/06
to 语言技术中心论坛
1.安装STLPORT
Giza++是在GNU C++的环境要求下写的.
采用了其中的标准模版库.
GNU C++的标准模版库是采用目前公认的最好的SGI STL.
由于STL有很多个实现版本,关于这方面的说明,请看http://jjhou.csdn.net/myan-stlport.htm
各个版本之间存在差异,为了减少麻烦,我们不采用VC自带的STL,
而安装SGI STL的VC版本
具体做法参见http://jjhou.csdn.net/myan-stlport.htm
其中描述的是VC6.0的方法,VS2003大同小异.
更详细的说明请参见stlport自带的readme和install文件
我采用的是stlport-4.6.2(http://www.stlport.org/download.html),
用其中的src\vc71.mak 进行编译和安装

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) );
}

注意: 这只是编译成功,不保证运行没问题哦:-)

Reply all
Reply to author
Forward
0 new messages