highlighter application  1.1
HCE project utils : highlighter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
HighlightComponent.cpp
Go to the documentation of this file.
1 
13 #include <exception>
14 #include <iostream>
15 #include <msgpack.hpp>
16 #include <Poco/Random.h>
17 #include <unistd.h>
18 
19 #include "InDataHighlight.hpp"
20 #include "HighlightComponent.hpp"
22 #include "OutDataHighlight.hpp"
23 #include "SerializeCacheData.hpp"
24 
25 using namespace HCE::exception;
26 
27 namespace HCE
28 {
29  namespace component
30  {
32  {
33  return highlightStringGenerator;
34  }
35 
36  Poco::SharedPtr<DataBase> HighlightComponent::process(Poco::SharedPtr<DataBase> inData)
37  {
38  Poco::SharedPtr<DataBase> ret = nullptr;
39  Poco::SharedPtr<InDataHighlight> inDataHiglight = inData.cast<InDataHighlight>();
40  if(!inDataHiglight.isNull())
41  {
42  ret = Poco::SharedPtr<DataBase>(new OutDataHighlight(HCE::CT_HIGHLIGHT));
43  if(!inDataHiglight->getCrossThreadBufPtr().isNull())
44  {
45  unsigned int index = 0;
46  unsigned int highlightCounter = 0;
47  unsigned long long id = 0llu;
48  unsigned long long resCrc = 0llu;
49  std::string outPutStr;
50  ContentsStorageBase::WordPosPtrType wordMapPtr = nullptr;
51  std::string &incomeContent = inDataHiglight->getCrossThreadBufPtr()->getIntData(index, id, resCrc);
52  Poco::SharedPtr<InDataStruct> inDataStructPtr = inDataHiglight->getInDataStructPtr();
53  Poco::SharedPtr<ContentsStorageBase> contentsStoragePtr = inDataHiglight->getContentsStorageBasePtr();
54  Poco::SharedPtr<std::string> contentStringPtr = nullptr;
55  if(!incomeContent.empty() && !inDataStructPtr.isNull() && !contentsStoragePtr.isNull() && inDataStructPtr->getParamsCount() > 0)
56  {
57  wordMapPtr = contentsStoragePtr->wordMapExctract(resCrc, incomeContent);
58  contentStringPtr = Poco::SharedPtr<std::string>(new std::string(incomeContent));
59  highlightStringGenerator.setHlBegin(inDataStructPtr->getParams(0).beginMarker);
60  highlightStringGenerator.setHlEnd(inDataStructPtr->getParams(0).endMarker);
61  highlightStringGenerator.setWordMapPtr(wordMapPtr);
62  highlightStringGenerator.setContent(contentStringPtr);
63  highlightStringGenerator.setMaxNumber(inDataStructPtr->getParams(0).maxNumber);
64  highlightStringGenerator.highlightStringStickerReinit(inDataStructPtr);
65  try
66  {
67  outPutStr = highlightStringGenerator.highlightStringGenerate(inDataStructPtr->getSearchStrings());
68  }
69  catch(HighlightAlgorithmException &excp)
70  {
71  }
72  catch(std::length_error &excp)
73  {
74  }
75  highlightCounter = highlightStringGenerator.getHighlightCounts();
76  if(inDataHiglight->getCrossThreadBufPtr()->getIsSendWordsMapBack())
77  {
78  SerializeCacheData serializeCacheData((*wordMapPtr), resCrc);
79  msgpack::sbuffer &localMsgPackBuff = inDataHiglight->getCrossThreadBufPtr()->getElem(index).getMsgPackBuff();
80  msgpack::pack(&localMsgPackBuff, serializeCacheData);
81  }
82  contentsStoragePtr->wordMapRelease(resCrc, wordMapPtr);
83  }
84  inDataHiglight->getCrossThreadBufPtr()->setOutData(outPutStr, highlightCounter, index);
85  inDataHiglight->getCrossThreadBufPtr()->signal();
86  }
87  }
88  return ret;
89  }
90  }
91 }