- 项目介绍
- 文本查重的方式有很多,但都离不开分词这一项,所以在这里我选择jieba库来代替我分词;
- 相似度求法也很多,比如说余弦距离、欧几里得距离、曼哈顿距离等等,这里我选择余弦距离,比较容易理解。
- 项目规划
- 分词
- 统计词频
- 构建余弦向量
- 求余弦距离
- 项目过程
- 引入jieba库,这个库可以在网上直接找到,下载之后配置到项目中即可;
- 创建一个TestTextSimlarity类,构造函数这里根据jieba来写,以免文本链接不上;
class TestTextSimilarity { public: typedef std::unordered_map<std::string, int> wordFreq; typedef std::unordered_set<std::string> wordSet; TestTextSimilarity(std::string dict); void getStopWordTable(const char* stopWordFile); wordFreq getWordFreq(const char* filename); std::string UTF8TOGBK(std::string str); std::string GBKTOUTF8(std::string str); std::vector<std::pair<std::string, int>> sortByValueReverse(wordFreq& wf); void selectTopWords(std::vector<std::pair<std::string, int>>& wfvec, wordSet&a
文本相似度检测小项目
最新推荐文章于 2024-04-16 10:44:57 发布