concordia-library/concordia/matched_pattern_fragment.hpp
2019-01-22 14:07:28 +01:00

89 lines
2.5 KiB
C++

#ifndef MATCHED_PATTERN_FRAGMENT_HDR
#define MATCHED_PATTERN_FRAGMENT_HDR
#include "concordia/common/config.hpp"
#include "concordia/interval.hpp"
#include "concordia/substring_occurrence.hpp"
#include <vector>
#include <iostream>
#include <boost/foreach.hpp>
/*!
Class representing matched pattern fragment in concordia search.
This fragment can be seen as a word interval of the pattern.
This class holds information about:
- where the pattern fragment was matched (example id and example offset)
- where the fragment is located within the pattern
(patternOffset, matchedLength)
*/
class MatchedPatternFragment : public Interval {
public:
/*! Constructor.
\param patternOffset offset of the matched fragment in the pattern
\param matchedLength length of the matched pattern
*/
MatchedPatternFragment(const SUFFIX_MARKER_TYPE & patternOffset,
const SUFFIX_MARKER_TYPE & matchedLength);
/*! Destructor.
*/
virtual ~MatchedPatternFragment();
/*! Getter for occurrences.
\returns occurrences
*/
std::vector<SubstringOccurrence> getOccurrences() const {
return _occurrences;
}
/*! Adds an occurrence to the list.
\param fragment occurrence to be added
*/
void addOccurrence(const SubstringOccurrence & occurrence);
/*! Getter for pattern offset.
\returns pattern offset
*/
SUFFIX_MARKER_TYPE getPatternOffset() const {
return _patternOffset;
}
/*! Getter for matched length.
\returns matched fragment length
*/
SUFFIX_MARKER_TYPE getMatchedLength() const {
return _matchedLength;
}
/*! Operator for comparing fragments by their length.
\returns true if current pattern is longer than the other
*/
bool operator > (const MatchedPatternFragment & other) const {
return (_matchedLength > other.getMatchedLength());
}
friend std::ostream & operator << (std::ostream & o,
const MatchedPatternFragment & fragment) {
o << "fragment(patternOffset=" << fragment.getPatternOffset()
<< ", matchedLength=" << fragment.getMatchedLength() << ") {"
<< std::endl;
BOOST_FOREACH(SubstringOccurrence occurrence, fragment.getOccurrences()) {
o << "\t" << occurrence << std::endl;
}
o << "}";
return o;
}
private:
std::vector<SubstringOccurrence> _occurrences;
SUFFIX_MARKER_TYPE _patternOffset;
SUFFIX_MARKER_TYPE _matchedLength;
};
#endif