diff options
author | Paul Baltescu <pauldb89@gmail.com> | 2013-01-28 11:56:31 +0000 |
---|---|---|
committer | Paul Baltescu <pauldb89@gmail.com> | 2013-01-28 11:56:31 +0000 |
commit | 5530575ae0ad939e17f08d6bd49978acea388ab7 (patch) | |
tree | 4620a276c1c827d824e285148f4f4a5bf781ebfe /extractor/phrase_location.cc | |
parent | ce6937f136a38af93d9a5cd9628acc712da95543 (diff) |
Initial working commit.
Diffstat (limited to 'extractor/phrase_location.cc')
-rw-r--r-- | extractor/phrase_location.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/extractor/phrase_location.cc b/extractor/phrase_location.cc new file mode 100644 index 00000000..b5b68549 --- /dev/null +++ b/extractor/phrase_location.cc @@ -0,0 +1,35 @@ +#include "phrase_location.h" + +#include <cstdio> + +PhraseLocation::PhraseLocation(int sa_low, int sa_high) : + sa_low(sa_low), sa_high(sa_high), + matchings(shared_ptr<vector<int> >()), + num_subpatterns(0) {} + +PhraseLocation::PhraseLocation(shared_ptr<vector<int> > matchings, + int num_subpatterns) : + sa_high(0), sa_low(0), + matchings(matchings), + num_subpatterns(num_subpatterns) {} + +bool PhraseLocation::IsEmpty() { + return sa_low >= sa_high || (num_subpatterns > 0 && matchings->size() == 0); +} + +bool operator==(const PhraseLocation& a, const PhraseLocation& b) { + if (a.sa_low != b.sa_low || a.sa_high != b.sa_high || + a.num_subpatterns != b.num_subpatterns) { + return false; + } + + if (a.matchings == NULL && b.matchings == NULL) { + return true; + } + + if (a.matchings == NULL || b.matchings == NULL) { + return false; + } + + return *a.matchings == *b.matchings; +} |