2014-03-11 14:32:10 +01:00
|
|
|
#ifndef INTERVAL_HDR
|
|
|
|
#define INTERVAL_HDR
|
|
|
|
|
2015-04-14 20:14:30 +02:00
|
|
|
#include "concordia/common/config.hpp"
|
2015-06-22 13:52:56 +02:00
|
|
|
#include <iostream>
|
2015-04-14 20:14:30 +02:00
|
|
|
|
2014-03-11 14:32:10 +01:00
|
|
|
/*!
|
2015-06-22 13:52:56 +02:00
|
|
|
Class representing interval of a sentence, i.e. a sequence of words or chars
|
2015-05-01 14:52:53 +02:00
|
|
|
coming from that sentence. An interval only has its start and end indexes,
|
|
|
|
where the start index is inclusive and end index is exclusive. For example,
|
2015-06-22 13:52:56 +02:00
|
|
|
an interval [2,5] of words of the sentence "This is just for
|
|
|
|
testing purposes" is: "just for testing".
|
2014-03-11 14:32:10 +01:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Interval {
|
|
|
|
public:
|
2015-05-01 14:52:53 +02:00
|
|
|
/*! Constructor.
|
|
|
|
\param start start index of the interval (0-based)
|
|
|
|
\param end end index of the interval (0-based)
|
|
|
|
*/
|
2015-04-15 14:14:10 +02:00
|
|
|
explicit Interval(const SUFFIX_MARKER_TYPE start,
|
|
|
|
const SUFFIX_MARKER_TYPE end);
|
2014-03-11 14:32:10 +01:00
|
|
|
|
|
|
|
/*! Destructor.
|
|
|
|
*/
|
|
|
|
virtual ~Interval();
|
|
|
|
|
2015-05-01 14:52:53 +02:00
|
|
|
/*! Checks if this interval intersects another.
|
|
|
|
\param interval another interval
|
|
|
|
\returns true if the two intervals intersect
|
|
|
|
*/
|
2014-04-29 14:46:04 +02:00
|
|
|
bool intersects(Interval & interval);
|
|
|
|
|
2015-05-01 14:52:53 +02:00
|
|
|
/*! Getter for interval length.
|
|
|
|
\returns end - start
|
|
|
|
*/
|
2015-04-14 20:14:30 +02:00
|
|
|
SUFFIX_MARKER_TYPE getLength();
|
2014-03-11 14:32:10 +01:00
|
|
|
|
2015-05-01 14:52:53 +02:00
|
|
|
/*! Getter for interval start.
|
|
|
|
\returns start
|
|
|
|
*/
|
2015-04-14 20:14:30 +02:00
|
|
|
SUFFIX_MARKER_TYPE getStart() const {
|
2014-03-11 14:32:10 +01:00
|
|
|
return _start;
|
|
|
|
}
|
|
|
|
|
2015-05-01 14:52:53 +02:00
|
|
|
/*! Getter for interval end.
|
|
|
|
\returns end
|
|
|
|
*/
|
2015-04-14 20:14:30 +02:00
|
|
|
SUFFIX_MARKER_TYPE getEnd() const {
|
2014-03-11 14:32:10 +01:00
|
|
|
return _end;
|
|
|
|
}
|
|
|
|
|
2015-06-27 12:40:24 +02:00
|
|
|
friend std::ostream & operator << (std::ostream & o,
|
|
|
|
const Interval & interval) {
|
|
|
|
return o << "[" << interval.getStart()
|
|
|
|
<< "," << interval.getEnd() << ")";
|
2015-06-22 13:52:56 +02:00
|
|
|
}
|
2015-06-27 12:40:24 +02:00
|
|
|
|
2015-04-21 15:14:48 +02:00
|
|
|
protected:
|
2015-04-14 20:14:30 +02:00
|
|
|
SUFFIX_MARKER_TYPE _start;
|
2014-04-29 14:46:04 +02:00
|
|
|
|
2015-04-14 20:14:30 +02:00
|
|
|
SUFFIX_MARKER_TYPE _end;
|
2014-03-11 14:32:10 +01:00
|
|
|
};
|
|
|
|
|
2015-04-21 15:14:48 +02:00
|
|
|
struct intervalEndComparator {
|
|
|
|
inline bool operator() (const Interval & lhs, const Interval & rhs) {
|
|
|
|
return (lhs.getEnd() < rhs.getEnd());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-11 14:32:10 +01:00
|
|
|
#endif
|