50 m_sentenceBreaks.clear();
51 m_topicShifts.clear();
60 m_sentenceBreaks.clear();
61 m_topicShifts.clear();
72 std::map<BoWText::const_iterator, BoWText::const_iterator> iteratorMap;
73 BoWText::const_iterator thisIt=this->begin();
74 BoWText::const_iterator it = d.begin();
75 while (it != d.end() && thisIt != this->end()) {
76 iteratorMap[it] = thisIt;
80 if (thisIt != this->end() || it != d.end()) {
81 throw std::runtime_error(
"cannot build iterator map in BoWDocumentST copy");
85 for (std::vector<BoWText::const_iterator>::const_iterator
86 it=d.m_sentenceBreaks.begin(); it!=d.m_sentenceBreaks.end(); it++) {
87 m_sentenceBreaks.push_back(iteratorMap[*it]);
89 for (std::vector<BoWText::const_iterator>::const_iterator
90 it=d.m_topicShifts.begin(); it!=d.m_topicShifts.end(); it++) {
91 m_topicShifts.push_back(iteratorMap[*it]);
97 m_sentenceBreaks.clear();
98 m_topicShifts.clear();
136 os << static_cast<BoWDocument>(d);
139 os <<
"## sentence breaks" << std::endl;
140 std::vector<BoWText::const_iterator>::const_iterator itSentBrk;
141 for (itSentBrk = d.m_sentenceBreaks.begin();
142 itSentBrk != d.m_sentenceBreaks.end(); itSentBrk ++) {
143 os << (**itSentBrk)->getOutputUTF8String() << std::endl;
147 os <<
"## topic shifts" << std::endl;
151 std::vector<BoWText::const_iterator>::const_iterator itTopSht;
152 for (itTopSht = d.m_topicShifts.begin();
153 itTopSht != d.m_topicShifts.end(); itTopSht ++) {
154 os << (**itTopSht)->getOutputUTF8String() << std::endl;
175 std::map<uint64_t, BoWText::const_iterator> indexToIterator;
176 uint64_t tokenCounter = 1;
177 for (BoWText::const_iterator itTok = this->begin();
178 itTok != this->end(); itTok ++) {
179 indexToIterator[tokenCounter] = itTok;
187 for (uint64_t sentBrkInd = 1; sentBrkInd <= sentBrkNb; sentBrkInd ++) {
189 std::map<uint64_t, BoWText::const_iterator>::const_iterator itMap =
190 indexToIterator.find(sentBrkIndex);
191 if (itMap != indexToIterator.end()) {
192 m_sentenceBreaks.push_back(itMap->second);
195 throw std::runtime_error(
"invalid sentence break reference\n");
203 for (uint64_t topShtInd = 1; topShtInd <= topShtNb; topShtInd ++) {
205 std::map<uint64_t, BoWText::const_iterator>::const_iterator itMap =
206 indexToIterator.find(topShtIndex);
207 if (itMap != indexToIterator.end()) {
208 m_topicShifts.push_back(itMap->second);
211 throw std::runtime_error(
"invalid topic shift reference\n");
233 std::vector<uint64_t> sentenceBreaks;
234 std::vector<uint64_t> topicShifts;
235 uint64_t tokenCounter = 1;
236 std::vector<BoWText::const_iterator>::const_iterator itSentBrk = m_sentenceBreaks.begin();
237 std::vector<BoWText::const_iterator>::const_iterator itTopSht = m_topicShifts.begin();
238 for (BoWText::const_iterator itTok = this->begin();
239 itTok != this->end(); itTok ++) {
240 if ((itSentBrk != m_sentenceBreaks.end()) && (*itTok == **itSentBrk)) {
241 sentenceBreaks.push_back(tokenCounter);
244 if ((itTopSht != m_topicShifts.end()) && (*itTok == **itTopSht)) {
247 topicShifts.push_back(tokenCounter);
252 if (itTopSht != m_topicShifts.end()) {
254 std::ostringstream oss;
256 oss << (**itTopSht)->getOutputUTF8String() <<
" "; itTopSht++;
257 }
while (itTopSht != m_topicShifts.end());
258 LERROR <<
"Write BoWDocumentST: missing topic shifts on tokens "
261 if (itSentBrk != m_sentenceBreaks.end()) {
263 std::ostringstream oss;
265 oss << (**itSentBrk)->getOutputUTF8String() <<
" "; itSentBrk++;
266 }
while (itSentBrk != m_sentenceBreaks.end());
267 LERROR <<
"Write BoWDocumentST: missing sentence breaks on tokens "
275 for (std::vector<uint64_t>::const_iterator itSent = sentenceBreaks.begin();
276 itSent != sentenceBreaks.end(); itSent ++) {
283 for (std::vector<uint64_t>::const_iterator itTop = topicShifts.begin();
284 itTop != topicShifts.end(); itTop ++) {
BoWDocumentST & operator=(const BoWDocumentST &)
void read(std::istream &file) override
specialization of read/write functions for taking into account sentence breaks and topic shifts
void writeSTData(std::ostream &file) const
void write(std::ostream &file) const
represent a document as a Bag Of Word, with associated document properties.
virtual void reinit() override
BoWText & operator=(const BoWText &)
virtual void read(std::istream &file)
void write(std::ostream &file) const
T & operator<<(T &qd, const BoWType &bt)
uint64_t readCodedInt(std::istream &file)
read a integer coded in variable-byte format in a file
void writeCodedInt(std::ostream &file, const uint64_t number)
write a integer coded in variable-byte format in a file