fastMatch是一个用于大规模精确字符串匹配的c++库,主要解决以下几个问题:
单模式串 - 单文本串匹配
单模式串 - 多文本串匹配
多模式串 - 单文本串匹配
多模式串 - 多文本串匹配
最大正向匹配分词
代码:https://github.com/zejunwang1/fastMatch
fastMatch库实际上仅包含头文件,我们提供了一个可执行程序fastMatch用于大规模字符串匹配。
Usage
使用make进行编译:
git clone https://github.com/zejunwang1/fastMatch
cd fastMatch
make
Multiple texts
./fastMatch --help
Large-scale Exact String Matching Tool! Usage:
--input text string file path
--pattern pattern string or pattern string file path
--num_threads number of threads
--num_patterns number of matching patterns returned
--fast enable fast matching mode
--hit enable hit matching mode
--seg enable maximum forward matching word segmentation
--N total number of text strings
--M total number of pattern strings
--help -h show help information
# match all patterns
./fastMatch --input data/query.txt --pattern data/disease.txt
# return a fixed number of matched patterns
./fastMatch --input data/query.txt --pattern data/disease.txt --num_patterns 2
# search only once for each position of the text string
./fastMatch --input data/query.txt --pattern data/disease.txt --fast
# return only one hit pattern for each text string
./fastMatch --input data/query.txt --pattern data/disease.txt --hit
# maximum forward matching word segmentation
./fastMatch --input data/query.txt --pattern data/disease.txt --seg
部分匹配结果如下:
婴幼儿肺炎咳喘 肺炎
右眼外伤性白内障右眼完全看不清怎么办?怎么才能怀上宝宝 白内障
怀孕后痔疮会加重吗 痔疮
如何治疗焦虑症都是哪些办法 焦虑症
在检查白癜风要多少钱 白癜风
宫颈息肉了怎么样治 宫颈息肉 息肉
子宫内膜息肉手术后注意事项 子宫内膜息肉 息肉
小儿癫痫要注意哪些饮食呢 小儿癫痫 癫痫
合肥女性多囊卵巢综合症能怀孕吗 多囊卵巢综合症 囊卵巢综合症
急性非淋巴白血病m2a这个病该如何治疗这个病该如何治疗 非淋 白血病
Single text
#include <fastMatch.h>
int main() {
string disease_path = "data/disease.txt";
FastMatch fastMatch(disease_path);
string query = "乙肝大三阳抗病毒治疗需要多长时间?";
// Single-pattern matching
string pattern = "抗病毒治疗";
int pos = match(query, pattern);
if (pos >= 0)
cout << "Find pattern at position: " << pos << endl;
// Multi-pattern matching
auto result = fastMatch.parse(query);
cout << "\nMulti-pattern matching result:\n";
for (int i = 0; i < result.size(); i++)
cout << result[i].first << " " << result[i].second << endl;
// Maximum forward matching word segmentation
cout << "\nMaximum forward matching word segmentation result:\n";
auto words = fastMatch.maxForwardMatch(query);
for (auto& word : words)
cout << word << " ";
cout << endl;
return 0;
}
运行 ./singleExample
fastMatch是基于MIT许可证的。
往期精彩回顾
适合初学者入门人工智能的路线及资料下载(图文+视频)机器学习入门系列下载机器学习及深度学习笔记等资料打印《统计学习方法》的代码复现专辑
交流群
欢迎加入机器学习爱好者微信群一起和同行交流,目前有机器学习交流群、博士群、博士申报交流、CV、NLP等微信群,请扫描下面的微信号加群,备注:”昵称-学校/公司-研究方向“,例如:”张小明-浙大-CV“。请按照格式备注,否则不予通过。添加成功后会根据研究方向邀请进入相关微信群。请勿在群内发送广告,否则会请出群,谢谢理解~(也可以加入机器学习交流qq群772479961)