项目作者: james-dow

项目描述 :
Implementation of Aho-Corasick Trie.
高级语言: C++
项目地址: git://github.com/james-dow/aho-corasick-trie.git
创建时间: 2018-05-29T20:13:11Z
项目社区:https://github.com/james-dow/aho-corasick-trie

开源协议:

下载


Aho-Corasick trie

Easy to use implementation of Aho-Corasick Trie.
Constructed of the desired patterns, then it can process the text, finding all the samples included in the text.

Example compilation:

  1. g++ common.cpp ../Trie/Trie.cpp -o common

Usage example

  1. #include "Trie/Trie.hpp"
  2. ...
  3. Trie trie;
  4. set<int> found;
  5. char* patternsChar[] = {
  6. "Lorem",
  7. "lorem",
  8. "five centuries",
  9. "since the 1500s, when an unknown printer",
  10. "containing the Lorem"
  11. };
  12. vector<string> patterns(patternsChar, patternsChar + sizeof(patternsChar) / sizeof(patternsChar[0]));
  13. string text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
  14. for (size_t i = 0; i < patterns.size(); ++i) {
  15. trie.addPattern(patterns[i], i);
  16. }
  17. trie.processText(text, found);
  18. for (set<int>::iterator it = found.begin(); it != found.end(); it++) {
  19. cout << "Found pattern (" << *it + 1 << "): " << patterns[*it] << "." << endl;
  20. }