32 #ifndef MODULE_ANALYZER_ALGO_ASSOC_HPP_ 33 #define MODULE_ANALYZER_ALGO_ASSOC_HPP_ 35 #include "../Thread.hpp" 37 #include "../../../Data/Data.hpp" 38 #include "../../../Helper/DateTime.hpp" 39 #include "../../../Helper/Memory.hpp" 40 #include "../../../Main/Database.hpp" 41 #include "../../../Struct/QueryStruct.hpp" 42 #include "../../../Struct/StatusSetter.hpp" 43 #include "../../../Struct/TextMap.hpp" 44 #include "../../../Struct/ThreadOptions.hpp" 45 #include "../../../Struct/ThreadStatus.hpp" 53 #include <string_view> 54 #include <unordered_map> 98 using StringString = std::pair<std::string, std::string>;
118 std::string_view
getName()
const override;
143 struct Associations {
144 std::vector<std::uint64_t> keywordPositions;
145 std::vector<std::vector<std::uint64_t>> categoriesPositions;
146 std::uint64_t offset{};
150 std::string articleId;
152 std::uint64_t nOccurences{};
153 std::vector<std::uint64_t> catCounters;
156 using DateAssociationMap = std::unordered_map<std::string, std::unordered_map<std::string, Associations>>;
157 using DateAssociation = std::pair<std::string, std::unordered_map<std::string, Associations>>;
158 using ArticleAssociationMap = std::unordered_map<std::string, Associations>;
159 using ArticleAssociation = std::pair<std::string, Associations>;
163 std::vector<std::string> categoryLabels;
164 std::vector<std::uint64_t> categoryQueries;
165 bool combineSources{
true};
166 bool ignoreEmptyDate{
true};
167 std::uint64_t keyWordQuery{};
168 std::uint16_t windowSize{1};
172 QueryStruct queryKeyWord;
174 std::vector<QueryStruct> queriesCategories;
177 DateAssociationMap associations;
179 std::string previousDate;
181 std::size_t currentCorpus{};
182 std::size_t dateCounter{};
183 std::size_t firstDatePos{};
184 std::size_t dateMapSize{};
185 std::size_t articleIndex{};
186 std::size_t tokenIndex{};
187 std::size_t processedDates{};
189 bool dateSaved{
false};
193 void saveAssociations();
194 [[nodiscard]] std::vector<Result> processDates();
195 void saveResults(
const std::vector<Result>& results);
198 void initQueries()
override;
199 void deleteQueries()
override;
202 void addArticlesForDate(
204 DateAssociationMap::iterator& dateIt,
205 const TextMap& articleMap,
206 const std::vector<std::string>& tokens,
207 std::queue<std::string>& warningsTo
209 DateAssociationMap::iterator addDate(
const std::string& date);
210 ArticleAssociationMap::iterator addArticleToDate(
211 const std::string& article,
212 DateAssociationMap::iterator date
215 const std::string& token,
216 Associations& associationsTo,
217 std::queue<std::string>& warningsTo
220 const DateAssociation& date,
221 std::vector<Result>& resultsTo
224 const std::string& date,
225 const ArticleAssociation& article,
226 std::vector<Result>& resultsTo
228 void processTermOccurrence(
229 const ArticleAssociation& article,
230 std::uint64_t occurrence,
231 std::size_t& occurrencesTo,
232 std::vector<std::uint64_t>& catsCountersTo
234 void processCategory(
235 const ArticleAssociation& article,
236 std::uint64_t termOccurrence,
238 std::vector<std::uint64_t>& catsCountersTo
240 bool processCategoryOccurrence(
241 std::uint64_t termOccurrence,
242 std::uint64_t catOccurrence,
243 std::size_t catIndex,
244 std::vector<std::uint64_t>& catsCountersTo
248 const std::string& table,
249 const Result& dataSet,
250 std::size_t numColumns
void onAlgoInit() override
Generates the corpus.
Definition: Assoc.cpp:125
constexpr auto assocMinColumns
Minimum number of columns included in a dataset (including date).
Definition: Assoc.hpp:74
void parseAlgoOption() override
Parses a configuration option for the algorithm.
Definition: Assoc.cpp:204
Namespace for algorithm classes.
Definition: All.cpp:52
Abstract class providing thread functionality to algorithm (child) classes.
Definition: Thread.hpp:84
Thread status containing its ID, status message, pause state, and progress.
Definition: ThreadStatus.hpp:54
Text map entry.
Definition: TextMap.hpp:49
Empty algorithm template.
Definition: Assoc.hpp:87
Thread options containing the name of the module run, as well as the IDs of the website, URL list, and configuration used.
Definition: ThreadOptions.hpp:40
Class handling database access for the command-and-control and its threads.
Definition: Database.hpp:366
Class for analyzer exceptions to be used by algorithms.
Definition: Thread.hpp:242
void onAlgoUnpause() override
Does nothing.
Definition: Assoc.cpp:194
void onAlgoClear() override
Does nothing.
Definition: Assoc.cpp:197
Structure containing all the data needed to keep the status of a thread updated.
Definition: StatusSetter.hpp:57
std::vector< TextMapEntry > TextMap
A text map is defined as a vector of text map entries.
Definition: TextMap.hpp:280
void onAlgoInitTarget() override
Initializes the target table for the algorithm.
Definition: Assoc.cpp:89
std::string_view getName() const override
Returns the name of the algorithm.
Definition: Assoc.cpp:75
Structure to identify a query including its type and result type(s).
Definition: QueryStruct.hpp:40
constexpr auto assocAddColumns
Number of extra columns included in a dataset (except date).
Definition: Assoc.hpp:71
void checkAlgoOptions() override
Checks the configuration options for the algorithm.
Definition: Assoc.cpp:220
void onAlgoPause() override
Does nothing.
Definition: Assoc.cpp:191
void resetAlgo() override
Resets the algorithm.
Definition: Assoc.cpp:299
Assoc(Main::Database &dbBase, const ThreadOptions &threadOptions, const ThreadStatus &threadStatus)
Continues a previously interrupted algorithm run.
Definition: Assoc.cpp:44
void onAlgoTick() override
Calculates the associations in the text corpus.
Definition: Assoc.cpp:177
constexpr auto assocUpdateProgressEvery
Indicates, while saving, after how many articles the progress of the thread will be updated...
Definition: Assoc.hpp:68