目前做如下修改:
Preprocess.h文件中:
Preprocess类内:(只写明问题相关部分)
typedef vector<string>(Preprocess::*FUNCSEG)(string,set<string>);
int ConstructMap(map<string,vector<pair<int,int>>>&mymap,char *dbfield,FUNCSEG seg);
vector<string>goodWordsinPieceArticle(string rawtext,set<string> stopwords);
vector<string> mySplit(string s,set<string> stopwords);
void WriteTotalArff(int DFthreshlod,bool isbagOfwordsexsist);
Process.cpp中、
int Preprocess::ConstructMap(map<string,vector<pair<int,int>>>&mymap,char *dbfiled,Preprocess::FUNCSEG seg)
{
//set<string>MakeStopSet();
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString=dbconnection;
pConn->Open("","","",adConnectUnspecified);
pRst=pConn->Execute(dbselect,NULL,adCmdText);
set<string>stopwords=MakeStopSet();
while(!pRst->rsEOF)
{ vector<string>wordcollection;
//string keywordstr=(_bstr_t)pRst->GetCollect("CKeyWord");
string rawtext=(_bstr_t)pRst->GetCollect(dbfield);
if(rawtext!="")
{
wordcollection=seg(rawtext,stopwords);
string tempid=(_bstr_t)pRst->GetCollect("ArticleId");
int articleid=atoi(tempid.c_str());
for(vector<string>::iterator strit=wordcollection.begin();strit!=wordcollection.end();strit++)
{
vector<pair<int,int>>::iterator it;
if(mymap[*strit].empty())
{
pair<int,int>mytemppair=make_pair(articleid,1);
mymap[*strit].push_back(mytemppair);
}
else
{
for(it=mymap[*strit].begin();it!=mymap[*strit].end();it++)
{
if(it->first==articleid)
{
it->second=++(it->second);
break;
}
}
if(it==mymap[*strit].end())
{
pair<int,int>mytemppair=make_pair(articleid,1);
mymap[*strit].push_back(mytemppair);
}
}
}
}
pRst->MoveNext();
wordcollection.clear();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
return 0;
}
最后报错报在了:
在调用调用ConstructMap的函数里
报错如下Error 1 error C2064: term does not evaluate to a function taking 2 arguments e:\mycoding\wekapreprocess\wekapreprocess\preprocess.cpp 58 WekaPreprocess
错误指向ConstructMap中对应语句
wordcollection=seg(rawtext,stopwords)
调用ConstructMap的函数定义如下
void Preprocess::WriteTotalArff(int DFthreshold,bool isbagOfWordsExist)
{
char * dbfield="CAbstract";
FUNCSEG seg=&Preprocess::goodWordsinPieceArticle;
map<string,vector<pair<int,int>>> mymap;
if(!isbagOfWordsExist)
{
ConstructMap(mymap,dbfield,seg);
save(mymap);
cout<<"词袋子信息已经保存到硬盘"<<endl;
}
else
{
load(mymap);
}
DFcharicteristicWordSelection(mymap,DFthreshold);
WriteHeadArff();
VSMFormation(mymap);
cout<<"arff文件已经形成"<<endl;
string temp(infoFromWekaAddress);
cout<<"请您将使用weka聚类,并保存为"<<temp<<endl;
}
指向类成员函数的指针是个很蛋疼的东西。
class A{
public:
bool kk(int i){return i>1;}
};
typedef bool (A::* XXX)(int);
int main(){
XXX p = NULL;
p = &A::kk; // pointer to member function kk in class A;
A *pa = new A;
(pa->*p)(10); // to call a member function from pointer, must specific a pointer to class first
}
不能,静态函数可以.你申明友元函数时应该把 Preprocess* 作为参数传入.
class Preprocess
{
public:
Preprocess(void);
~Preprocess(void);
public:
typedef vector<string>(Preprocess::*FUNCSEG)(string,set<string>);
vector<string> goodWordsinPieceArticle(string rawtext,set<string> stopwords);
int ConstructMap(map<string,vector<pair<int,int>>>&mymap,char *dbfield,FUNCSEG seg)
{
string rawtext;
set<string>stopwords;
vector<string>wordcollection = (this->*seg)(rawtext,stopwords);
}
void WriteTotalArff(int DFthreshlod,bool isbagOfwordsexsist)
{
char * dbfield="CAbstract";
FUNCSEG seg=&Preprocess::goodWordsinPieceArticle;
map<string,vector<pair<int,int>>> mymap;
ConstructMap(mymap,dbfield,seg);
}
};
把你的代码简化了下,如上所示.