Rab*_*bit 17 c++ full-text-search tokenize
这应该是不重新发明轮子的理想情况,但到目前为止,我的搜索一直是徒劳的.
我不想自己写一个,而是想使用现有的C++标记器.令牌将用于全文搜索的索引中.性能非常重要,我将解析许多千兆字节的文本.
编辑:请注意,令牌将用于搜索索引.创建这样的令牌并不是一门精确的科学(afaik),需要一些启发式方法.这已经做了一千次,可能有千种不同的方式,但我甚至找不到其中一个:)
有什么好的指针吗?
谢谢!
小智 16
在C++字符串工具箱库(StrTk)具有以下问题的解决方案:
#include <iostream>
#include <string>
#include <deque>
#include "strtk.hpp"
int main()
{
std::deque<std::string> word_list;
strtk::for_each_line("data.txt",
[&word_list](const std::string& line)
{
const std::string delimiters = "\t\r\n ,,.;:'\""
"!@#$%^&*_-=+`~/\\"
"()[]{}<>";
strtk::parse(line,delimiters,word_list);
});
std::cout << strtk::join(" ",word_list) << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
更多例子可以在这里找到