#include <iostream>
#include <vector>
#include <cstddef>
#include <string>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <set>
#include <limits>
#include <functional>
#include <numeric> template <class DataType>
void ReadMatFromFile(std::string &filename, std::vector<std::vector<DataType> > &lines_feat) {
std::ifstream vm_info(filename.c_str());
std::string lines;
DataType var;
std::vector<DataType> row; lines_feat.clear(); while(!vm_info.eof()) {
getline(vm_info, lines);
if(lines.empty())
break;
std::stringstream stringin(lines);
row.clear(); while(stringin >> var) {
row.push_back(var);
}
lines_feat.push_back(row);
}
} void ReadStringFromFile(std::string &filename, std::vector<std::string> &in_string) {
std::ifstream vm_info(filename.c_str());
std::string lines, var; while(!vm_info.eof()) {
getline(vm_info, lines);
if(lines.empty())
break;
std::stringstream stringin(lines); while(stringin >> var) {
in_string.push_back(var);
}
}
} std::string lowerCase(const std::string& s) {
std::string lower(s);
for(size_t i=;i<s.length();++i) {
lower[i]=tolower(lower[i]);
}
return lower;
} std::string letters(const std::string& s) {
std::string letter;
for(size_t i=;i<s.length();++i) {
char ch=s.at(i);
bool flag=false;
if((ch>= && ch<=)) {
ch=ch+;
flag=true;
}
else if((ch>= && ch<=) || (ch>= && ch<=)) {
flag=true;
}
else {
;
}
if(flag) {
letter.push_back(ch);
}
}
letter.push_back('\0');
return letter;
} template <class T1, class T2>
int MatMultiply(const std::vector<std::vector<T1> > &Mata, const std::vector<std::vector<T2> > &Matb, std::vector<std::vector<T1> > &MatOut) {
if(Mata.at().size() != Matb.size()) {
std::cout<<"not match!\n";
return -;
}
for(size_t i=; i<Mata.size(); ++i) {
for(size_t j=; j<Matb.at().size(); ++j) {
std::vector<T2> col;
col.clear();
for(size_t k=; k<Matb.size(); ++k) {
col.push_back(Matb.at(k).at(j));
}
MatOut.at(i).at(j)=inner_product(Mata.at(i).begin(), Mata.at(i).end(), col.begin(), );
}
}
return ;
} template <class T1, class T2, class T3>
void outer_product(const std::vector<T1> &inst1, const std::vector<T2> &inst2, std::vector<std::vector<T3> > &out) {
std::vector<T3> temp_row(inst2.size()); for(typename::std::vector<T1>::const_iterator it=inst1.begin();it!=inst1.end();++it) {
transform(inst2.begin(), inst2.end(), temp_row.begin(), bind2nd(std::multiplies<T1>(), *it));
out.push_back(temp_row);
}
} void ReadDataFromFile(std::string &filename, std::vector<std::string> &lines_feat) {
std::ifstream vm_info(filename.c_str());
std::string lines; lines_feat.clear(); while(!vm_info.eof()) {
getline(vm_info, lines);
if(lines.empty())
break; lines_feat.push_back(lines);
}
} std::vector<std::string> split(const std::string& s, char delimiter) {
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s); while(std::getline(tokenStream, token, delimiter)) {
tokens.push_back(token);
}
return tokens;
} int stringtoint(const std::string& s) {
std::istringstream iss(s);
int num;
return iss>>num?num:;
} void printip(const std::string& s) {
std::vector<std::string> temp, ip_segment; temp=split(s, '-');
ip_segment=split(temp.front(), '.'); std::string ip_start=ip_segment.back(), ip_end=temp.back();
int start, end;
start=stringtoint(ip_start);
end=stringtoint(ip_end); for(size_t i=start;i<=end;++i) {
std::cout<<ip_segment[]<<"."<<ip_segment[]<<"."<<ip_segment[]<<"."<<i<<"\n";
}
} template <class T>
void Display2DVector(std::vector<std::vector<T> > &vv) {
for(size_t i=;i<vv.size();++i) {
for(typename::std::vector<T>::const_iterator it=vv.at(i).begin();it!=vv.at(i).end();++it) {
std::cout<<*it<<" ";
}
std::cout<<"\n";
}
std::cout<<"--------the total of the 2DVector is "<<vv.size()<<std::endl;
} int main() {
std::string filename("data");
std::vector<std::string> v_string;
std::string words;
std::set<std::string> s_string; ReadStringFromFile(filename, v_string); for(std::vector<std::string>::const_iterator it=v_string.begin(); it!=v_string.end(); ++it) {
std::cout<<*it<<" ";
words=letters(*it);
s_string.insert(words);
}
std::cout<<std::endl;
for(std::set<std::string>::const_iterator it=s_string.begin(); it!=s_string.end(); ++it) {
std::cout<<*it<<" ";
}
std::cout<<std::endl;
return ;
}

The bag of words model ignores grammar and order of words.

运行结果如下,第一行为原始数据,第二行为提取后的数据:

bag of words in c++的更多相关文章

  1. 【ros】.bag文件

    Bags are typically created by a tool like rosbag They store the serialized message data in a file as ...

  2. MATLAB 图像分类 Image Category Classification Using Bag of Features

    使用MATLAB实现图像的识别,这是MATLAB官网上面的例子,学习一下. http://cn.mathworks.com/help/vision/examples/image-category-cl ...

  3. Bag标签之中的一个行代码实行中文分词实例2

    例1: 分词(返回以逗号隔开每一个词带上引號的词组.gap=",",quotes="'"或quotes='"') 单引號 <bag id=pPa ...

  4. Bag Problem

    Bag Problem Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/131072 K (Java/Others) Total ...

  5. Bag of mice(CodeForces 148D )

    D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  6. Hibernate的集合映射(Set、List、Array、Map、Bag)

    POJOs如下: Customer类------>customer表   Order类对应---------->orders表  customer(1)<-------------- ...

  7. Bag of Words/Bag of Features的Matlab源码发布

    2010年11月19日 ⁄ 技术, 科研 ⁄ 共 1296字 ⁄ 评论数 26 ⁄ 被围观 4,150 阅读+ 由于自己以前发过一篇文章讲bow特征的matlab代码的优化的<Bag-Of-Wo ...

  8. Bag of Words(BOW)模型

    原文来自:http://www.yuanyong.org/blog/cv/bow-mode 重复造轮子并不是完全没有意义的. 这几天忙里偷闲看了一些关于BOW模型的知识,虽然自己做图像检索到目前为止并 ...

  9. Hibernate 多表关联映射- Hibernate中使用的集合类型(set,list,array,bag,map)

    Set类型的使用: <hibernate-mapping package="cn.model"> <class name="Department&quo ...

  10. CF 148D. Bag of mice (可能性DP)

    D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. freemarker使用map替换ftl中相关值

    ftl文件demo01.ftl <html> <head> <title>Welcome!</title> </head> <body ...

  2. 关于SPFA的双端队列优化

    7.11 Update 我做题的时候发现这样写会RE 因为在使用双端队列优化SPFA的时候 在将一个点加入队列的时候,如果队列已经空了 那么一旦出现dis[Q.front()]就会RE 可以这样修改 ...

  3. [LNOI2014]LCA(树链剖分)

    BZOJ传送门 Luogu传送门 题目:给你一棵树,给你n个询问,每个询问要求输出$\sum_{i=l}^{r}depth(LCA(i,z))$ 细看看其实没有想象的那么难 大体思路: 1.对于每个询 ...

  4. python 使用time / datetime进行时间、时间戳、日期转换

    python 使用time 进行时间.时间戳.日期格式转换 #!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2017/11/7 15:53 # ...

  5. eclipse 中导入 MyBatis 的源码

    (1)选中 Mybatis-3.2.2.jar ,右击,在弹出的快捷菜单中选择 “Properties” 选项,进入属性界面. (2)进入属性界面后,选中 “Java  Source Attachme ...

  6. 微信小程序 导航 4种页面跳转 详解

    1.wx.navigateTo   保留当前页面,跳转到应用内的某个页面,目前页面路径最多只能十层.  参数:url(可携带参数) .success .fail .complete 可用wxml代替: ...

  7. Python爬虫入门教程: 半次元COS图爬取

    半次元COS图爬取-写在前面 今天在浏览网站的时候,忽然一个莫名的链接指引着我跳转到了半次元网站 https://bcy.net/ 打开之后,发现也没有什么有意思的内容,职业的敏感让我瞬间联想到了 c ...

  8. intel compiler的表现

    好久没弄这个东西,今天突然想试下,代码没写完,以后补. #include <stdio.h> #include <stdlib.h> #include <time.h&g ...

  9. 1031. Hello World for U

    Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. ...

  10. 【Codeforces 1037D】Valid BFS?

    [链接] 我是链接,点我呀:) [题意] 让你判断一个序列是否可能为一个bfs的序列 [题解] 先dfs出来每一层有多少个点,以及每个点是属于哪一层的. 每一层的bfs如果有先后顺序的话,下一层的节点 ...