highlighter application  1.1
HCE project utils : highlighter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
HighlightStringGenerator.hpp
Go to the documentation of this file.
1 
13 #ifndef HIGHLIGHT_STRING_GENERATOR_HPP
14 #define HIGHLIGHT_STRING_GENERATOR_HPP
15 
16 #include <Poco/SharedPtr.h>
17 #include <Poco/UTF8String.h>
18 #include <map>
19 #include <string>
20 #include <vector>
21 
22 #include "ContentsStorageBase.hpp"
23 #include "CRC64.h"
24 #include "CWords.hpp"
25 #include "InDataRefine.hpp"
26 #include "InDataStruct.hpp"
29 #include "OutDataRefine.hpp"
30 #include "Refine.hpp"
31 #include "WordPos.hpp"
32 
34 {
35  protected:
36  unsigned int maxNumber;
38  Poco::SharedPtr<std::string> contentPtr;
39  std::string hlBegin;
40  std::string hlEnd;
41  std::vector<Poco::SharedPtr<HighlightingAlgorithmBase> > highlightingAlgorithms;
42  Poco::SharedPtr<HighlightStringStickerBase> highlightStringStickerPtr;
43  protected:
44  std::vector<WordPos> stickWordOffsetMaps(std::vector<std::map<unsigned int, WordPos> > &wordOffsetMaps);
45 // cppcheck-suppress *
46  void joinOverlapElements(std::map<unsigned int, WordPos> &resultingMap, std::vector<WordPos> &ret);
47  public:
49  inline void setMaxNumber(unsigned int _maxNumber);
50  inline void setWordMapPtr(ContentsStorageBase::WordPosPtrType _wordMapPtr);
51  inline void setContent(Poco::SharedPtr<std::string> _contentPtr);
52  inline void setHlBegin(std::string _hlBegin);
53  inline void setHlEnd(std::string _hlEnd);
54  inline void addHighlightingAlgorithm(Poco::SharedPtr<HighlightingAlgorithmBase> _highlightingAlgorithm);
55  inline void setHighlightStringSticker(Poco::SharedPtr<HighlightStringStickerBase> _highlightStringStickerPtr);
56  std::string highlightStringGenerate(std::vector<std::vector<std::pair<SearchType, std::string> > > &vecSearchStrings);
57  inline unsigned int getHighlightCounts();
58  inline void highlightStringStickerReinit(Poco::SharedPtr<InDataStruct> inDataStructPtr);
59  std::string generateHighlightingAlgorithmsString(const std::string &separator);
61 };
62 
63 void HighlightStringGenerator::setMaxNumber(unsigned int _maxNumber)
64 {
65  maxNumber = _maxNumber;
66 }
67 
69 {
70  wordMapPtr = _wordMapPtr;
71 }
72 
73 void HighlightStringGenerator::setContent(Poco::SharedPtr<std::string> _contentPtr)
74 {
75  contentPtr = _contentPtr;
76 }
77 
78 void HighlightStringGenerator::setHlBegin(std::string _hlBegin)
79 {
80  hlBegin = _hlBegin;
81 }
82 
83 void HighlightStringGenerator::setHlEnd(std::string _hlEnd)
84 {
85  hlEnd = _hlEnd;
86 }
87 
88 void HighlightStringGenerator::addHighlightingAlgorithm(Poco::SharedPtr<HighlightingAlgorithmBase> _highlightingAlgorithm)
89 {
90  highlightingAlgorithms.push_back(_highlightingAlgorithm);
91 }
92 
93 void HighlightStringGenerator::setHighlightStringSticker(Poco::SharedPtr<HighlightStringStickerBase> _highlightStringStickerPtr)
94 {
95  highlightStringStickerPtr = _highlightStringStickerPtr;
96 }
97 
99 {
100  if(!highlightStringStickerPtr.isNull())
101  {
102  return highlightStringStickerPtr->getHighlightedCounter();
103  }
104  else
105  {
106  return 0;
107  }
108 }
109 
110 void HighlightStringGenerator::highlightStringStickerReinit(Poco::SharedPtr<InDataStruct> inDataStructPtr)
111 {
112  if(!highlightStringStickerPtr.isNull())
113  {
114  highlightStringStickerPtr->reinitialize(inDataStructPtr);
115  }
116 }
117 
118 #endif