次の for ループがあります。この for ループでは、オブジェクト kw を作成します。
The class keywords (string, vector<pair<int,string>>, vector<string>)
for(size_t i = 0; i < names.size();i++)
{
Keywords kw (names[i].c_str(),vreg, stopWords);
Document d = kw.extractKeywords();
v_doc.push_back(d);
}
この for ループに問題があると思います。そのオブジェクトを一度作成するだけでよいので、for ループから Keywords を取り出した方がよいのではないかと考えました。
Keywords kw (vreg, stopWords);
for(size_t i = 0; i < names.size();i++)
{
Document d = kw.extractKeywords(names[i].c_str());
v_doc.push_back(d);
}
それを行うと、正しい出力が得られません。ヒントを教えてください よろしくお願いします。
ハニ。
このクラスは、xml ファイルからキーワードを抽出するために使用されています。私は以下を提供しました:
- クラス コンストラクター
- コンストラクターのコピー
- セッターとゲッター
- デストラクタ
コピーコンストラクタに問題があると思いますか
Keywords::Keywords(string xmlF,vector<pair<int, string>> re,vector<string> sw)
{
// Setter for string: the path of the xml File
setXml(xmlF);
// Setter for the vector<pair<int, string>> re
setRegularExpression(re);
//setter for vector<string> sw
setStopWords(sw);
}
//FREE MEMORY
Keywords::~Keywords()
{
sw.clear();
vreg.clear();
}
void Keywords::setRegularExpression(vector<pair<int, string>> re)
{
vreg = re;
}
vector<pair<int, string>> Keywords::getRegularExpression()
{
return vreg;
}
void Keywords::setStopWords(vector<string> s)
{
sw = s;
}
vector<string> Keywords::getStopWords()
{
return sw;
}
void Keywords::setXml(string xmlF)
{
xmlFile = xmlF;
}
///COPY CONSTRUCTOR
Keywords::Keywords(const Keywords& other):vreg(other.vreg),sw(other.sw)
{
}