首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >删除停用词,然后应用案例折叠(如何组合两个代码)

删除停用词,然后应用案例折叠(如何组合两个代码)
EN

Stack Overflow用户
提问于 2013-12-01 04:11:43
回答 1查看 481关注 0票数 0

我有一个名为aisha的txt文件,其中包含以下内容

代码语言:javascript
复制
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

我写了两个代码,一个是去掉一些停用的单词

代码语言:javascript
复制
#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;
}

另一个是用于四个水壶的应用案例折叠

代码语言:javascript
复制
#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];用于案例折叠代码,并且我不能只使用字符串或字符,我该怎么办?

EN

回答 1

Stack Overflow用户

发布于 2013-12-01 04:28:58

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

下面是一个粗略的例子

代码语言:javascript
复制
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;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20305106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档