gpt4 book ai didi

c++ - 删除停用词然后应用大小写折叠(如何组合两个代码)

转载 作者:行者123 更新时间:2023-11-28 07:15:28 25 4
gpt4 key购买 nike

我有一个名为 aisha 的 txt 文件包含这个

This is a new file I did it for mediu.
Its about Removing stopwords fRom the file
and apply casefolding to it
I Tried doing that many Times
and finally now I could do

我写了两个代码,一个是从中删除一些停用词

#include <iostream>
#include <string>
#include <fstream>

int main()
{
using namespace std;

ifstream file("aisha.txt");
if(file.is_open())
{
string myArray[200];

for(int i = 0; i < 200; ++i)
{
file >> myArray[i];

if (myArray[i] !="is" && myArray[i]!="the" && myArray[i]!="that"&& myArray[i]!="it"&& myArray[i]!="to"){
cout<< myArray[i]<<" ";
}



}

}
system("PAUSE");
return 0;
}

还有一个是给四个ketters申请折叠

#include <iostream>
#include <string>
#include <fstream>

int main()
{
using namespace std;

ifstream file("aisha.txt");
if(file.is_open())
{
file >> std::noskipws;
char myArray[200];

for(int i = 0; i < 200; ++i)
{
file >> myArray[i];

if (myArray[i]=='I')
cout<<"i";
if (myArray[i]=='A')
cout<<"a";
if (myArray[i]=='T')
cout<<"t";
if (myArray[i]=='R')
cout<<"r";
else
if (myArray[i]!='I' && myArray[i]!='T' && myArray[i]!='R')
cout<<myArray[i];
}
file.close();

}

system("PAUSE");
return 0;
}

现在我需要将这两个代码组合成一个删除停用词的代码,然后应用大小写折叠我使用 string myArray[200]; 作为停用词代码和 char myArray[200]; 作为大小写折叠代码的问题我不能只使用字符串或只使用字符我能做什么?

最佳答案

将文本处理器放在单独的函数中,在main中一一调用。不会有名称和类型冲突。

这是一个粗略的例子

void removeStopWords(ifstream file) {
// put your code here for removing the stopwords
}

void applyCaseFolding(ifstream file) {
// put your code here for applying case folding
}

int main() {
ifstream file("aisha.txt");
if(file.is_open()) {
removeStopWords(file);
applyCaseFolding(file);
}

return 0;
}

关于c++ - 删除停用词然后应用大小写折叠(如何组合两个代码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20305106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com