2015-04-17 14:17:59 +02:00
|
|
|
#ifndef MATCHED_PATTERN_FRAGMENT_HDR
|
|
|
|
#define MATCHED_PATTERN_FRAGMENT_HDR
|
|
|
|
|
|
|
|
#include "concordia/common/config.hpp"
|
2015-04-21 15:14:48 +02:00
|
|
|
#include "concordia/interval.hpp"
|
2019-01-22 14:07:28 +01:00
|
|
|
#include "concordia/substring_occurrence.hpp"
|
2017-04-21 14:51:58 +02:00
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include <boost/foreach.hpp>
|
2015-04-17 14:17:59 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Class representing matched pattern fragment in concordia search.
|
2015-06-27 12:40:24 +02:00
|
|
|
This fragment can be seen as a word interval of the pattern.
|
2017-04-21 14:51:58 +02:00
|
|
|
|
2015-05-01 14:52:53 +02:00
|
|
|
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)
|
2015-04-17 14:17:59 +02:00
|
|
|
*/
|
|
|
|
|
2015-04-21 15:14:48 +02:00
|
|
|
class MatchedPatternFragment : public Interval {
|
2015-04-17 14:17:59 +02:00
|
|
|
public:
|
2015-05-01 14:52:53 +02:00
|
|
|
/*! Constructor.
|
|
|
|
\param patternOffset offset of the matched fragment in the pattern
|
|
|
|
\param matchedLength length of the matched pattern
|
|
|
|
*/
|
2017-04-21 14:51:58 +02:00
|
|
|
MatchedPatternFragment(const SUFFIX_MARKER_TYPE & patternOffset,
|
2015-04-17 14:17:59 +02:00
|
|
|
const SUFFIX_MARKER_TYPE & matchedLength);
|
|
|
|
/*! Destructor.
|
|
|
|
*/
|
|
|
|
virtual ~MatchedPatternFragment();
|
|
|
|
|
2019-01-22 14:07:28 +01:00
|
|
|
/*! Getter for occurrences.
|
|
|
|
\returns occurrences
|
2015-05-01 14:52:53 +02:00
|
|
|
*/
|
2019-01-22 14:07:28 +01:00
|
|
|
std::vector<SubstringOccurrence> getOccurrences() const {
|
|
|
|
return _occurrences;
|
2015-04-17 14:17:59 +02:00
|
|
|
}
|
|
|
|
|
2019-01-22 14:07:28 +01:00
|
|
|
/*! Adds an occurrence to the list.
|
|
|
|
\param fragment occurrence to be added
|
2015-05-01 14:52:53 +02:00
|
|
|
*/
|
2019-01-22 14:07:28 +01:00
|
|
|
void addOccurrence(const SubstringOccurrence & occurrence);
|
2015-04-17 14:17:59 +02:00
|
|
|
|
2015-05-01 14:52:53 +02:00
|
|
|
/*! Getter for pattern offset.
|
|
|
|
\returns pattern offset
|
|
|
|
*/
|
2015-04-17 14:17:59 +02:00
|
|
|
SUFFIX_MARKER_TYPE getPatternOffset() const {
|
|
|
|
return _patternOffset;
|
|
|
|
}
|
|
|
|
|
2015-05-01 14:52:53 +02:00
|
|
|
/*! Getter for matched length.
|
|
|
|
\returns matched fragment length
|
|
|
|
*/
|
2015-04-17 14:17:59 +02:00
|
|
|
SUFFIX_MARKER_TYPE getMatchedLength() const {
|
|
|
|
return _matchedLength;
|
|
|
|
}
|
|
|
|
|
2015-05-01 14:52:53 +02:00
|
|
|
/*! Operator for comparing fragments by their length.
|
|
|
|
\returns true if current pattern is longer than the other
|
|
|
|
*/
|
2015-04-17 14:17:59 +02:00
|
|
|
bool operator > (const MatchedPatternFragment & other) const {
|
|
|
|
return (_matchedLength > other.getMatchedLength());
|
|
|
|
}
|
|
|
|
|
2017-04-21 14:51:58 +02:00
|
|
|
friend std::ostream & operator << (std::ostream & o,
|
|
|
|
const MatchedPatternFragment & fragment) {
|
|
|
|
o << "fragment(patternOffset=" << fragment.getPatternOffset()
|
|
|
|
<< ", matchedLength=" << fragment.getMatchedLength() << ") {"
|
|
|
|
<< std::endl;
|
2019-01-22 14:07:28 +01:00
|
|
|
BOOST_FOREACH(SubstringOccurrence occurrence, fragment.getOccurrences()) {
|
|
|
|
o << "\t" << occurrence << std::endl;
|
2017-04-21 14:51:58 +02:00
|
|
|
}
|
2015-04-17 14:17:59 +02:00
|
|
|
|
2017-04-21 14:51:58 +02:00
|
|
|
o << "}";
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2019-01-22 14:07:28 +01:00
|
|
|
std::vector<SubstringOccurrence> _occurrences;
|
2015-04-17 14:17:59 +02:00
|
|
|
|
|
|
|
SUFFIX_MARKER_TYPE _patternOffset;
|
|
|
|
|
|
|
|
SUFFIX_MARKER_TYPE _matchedLength;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|