summaryrefslogtreecommitdiff
path: root/extractor/matchings_trie.h
diff options
context:
space:
mode:
authorPaul Baltescu <pauldb89@gmail.com>2013-03-10 01:01:01 +0000
committerPaul Baltescu <pauldb89@gmail.com>2013-03-10 01:01:01 +0000
commite6181c89ab8f29d8bd0fc6a3a8a359cb50c2304c (patch)
treec05eaae595c711605e6ccb596b8b634756a95c5b /extractor/matchings_trie.h
parent65a67c6921ee6da0477531224effe38559739455 (diff)
Added comments. Hooray!
Diffstat (limited to 'extractor/matchings_trie.h')
-rw-r--r--extractor/matchings_trie.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/extractor/matchings_trie.h b/extractor/matchings_trie.h
index f3dcc075..1fb29693 100644
--- a/extractor/matchings_trie.h
+++ b/extractor/matchings_trie.h
@@ -11,20 +11,27 @@ using namespace std;
namespace extractor {
+/**
+ * Trie node containing all the occurrences of the corresponding phrase in the
+ * source data.
+ */
struct TrieNode {
TrieNode(shared_ptr<TrieNode> suffix_link = shared_ptr<TrieNode>(),
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<TrieNode> 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<TrieNode> GetChild(int key) {
return children[key];
}
@@ -35,15 +42,20 @@ struct TrieNode {
unordered_map<int, shared_ptr<TrieNode> > 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<TrieNode> GetRoot() const;
private:
+ // Recursively deletes a subtree of the trie.
void DeleteTree(shared_ptr<TrieNode> root);
shared_ptr<TrieNode> root;