#ifndef _MATCHINGS_TRIE_ #define _MATCHINGS_TRIE_ #include #include #include "phrase.h" #include "phrase_location.h" using namespace std; namespace extractor { /** * Trie node containing all the occurrences of the corresponding phrase in the * source data. */ struct TrieNode { TrieNode(shared_ptr suffix_link = shared_ptr(), Phrase phrase = Phrase(), PhraseLocation matchings = PhraseLocation()) : suffix_link(suffix_link), phrase(phrase), matchings(matchings) {} // Adds a trie node as a child of the current node. void AddChild(int key, shared_ptr child_node) { children[key] = child_node; } // Checks if a child exists for a given key. bool HasChild(int key) { return children.count(key); } // Gets the child corresponding to the given key. shared_ptr GetChild(int key) { return children[key]; } shared_ptr suffix_link; Phrase phrase; PhraseLocation matchings; unordered_map> children; }; /** * Trie containing all the phrases that can be obtained from a sentence. */ class MatchingsTrie { public: MatchingsTrie(); virtual ~MatchingsTrie(); // Returns the root of the trie. shared_ptr GetRoot() const; private: // Recursively deletes a subtree of the trie. void DeleteTree(shared_ptr root); shared_ptr root; }; } // namespace extractor #endif