【问题标题】:Way to get word frequency from string?从字符串中获取词频的方法?
【发布时间】:2016-05-31 19:40:02
【问题描述】:

大家好,我有以下问题。我一直在使用 C++ 来抓取网站,用于在 outputHTML 中找到 5 个最常见的单词,它是字符串。目前我有以下代码。任何提示都会很棒。

curl = curl_easy_init();
if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &htmlOutput);
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);

    std::cout << htmlOutput << std::endl;
}

【问题讨论】:

  • 提示:使用std::map&lt;std::string, unsigned int&gt;
  • 提示:Frequency

标签: c++ curl


【解决方案1】:

这里有一些更棒的提示:

std::istringstream awsome_stream(web_text);
std::string word;
std::map<std::string, unsigned int> kewl_words;
while (awsome_stream >> word)
{
  kewl_words[word]++;
}
std::cout << "Occurances of 'div': " << kewl_words["div"] << "\n";

【讨论】:

    猜你喜欢
    • 2020-08-20
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 2011-06-10
    • 1970-01-01
    • 2021-02-12
    • 2012-11-25
    • 1970-01-01
    相关资源
    最近更新 更多