diff --git a/src/core/algorithms/ind/ind.cpp b/src/core/algorithms/ind/ind.cpp new file mode 100644 index 0000000000..1fc62c8d54 --- /dev/null +++ b/src/core/algorithms/ind/ind.cpp @@ -0,0 +1,13 @@ +#include "ind.h" + +#include + +namespace model { + +std::string IND::ToString() const { + std::stringstream ss; + ss << GetLhs().ToString() << " -> " << GetRhs().ToString(); + return ss.str(); +} + +} // namespace model diff --git a/src/core/algorithms/ind/ind.h b/src/core/algorithms/ind/ind.h new file mode 100644 index 0000000000..30b0682ede --- /dev/null +++ b/src/core/algorithms/ind/ind.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +#include "model/table/column_combination.h" + +namespace model { + +// Inclusion dependency is a relation between attributes of tables +// that indicates possible Primary Key–Foreign Key references. +class IND { +private: + std::shared_ptr lhs_; + std::shared_ptr rhs_; + +public: + IND(std::shared_ptr lhs, std::shared_ptr rhs) + : lhs_(std::move(lhs)), rhs_(std::move(rhs)) {} + + ColumnCombination const& GetLhs() const { + return *lhs_; + } + ColumnCombination const& GetRhs() const { + return *rhs_; + } + std::string ToString() const; +}; + +} // namespace model diff --git a/src/core/algorithms/ind/ind_algorithm.cpp b/src/core/algorithms/ind/ind_algorithm.cpp new file mode 100644 index 0000000000..4dc4245986 --- /dev/null +++ b/src/core/algorithms/ind/ind_algorithm.cpp @@ -0,0 +1,14 @@ +#include "ind_algorithm.h" + +#include "config/names_and_descriptions.h" +#include "config/tabular_data/input_tables/option.h" + +namespace algos { + +INDAlgorithm::INDAlgorithm(std::vector phase_names) + : Algorithm(std::move(phase_names)) { + RegisterOption(config::TablesOpt(&input_tables_)); + MakeOptionsAvailable({config::TablesOpt.GetName()}); +} + +} // namespace algos diff --git a/src/core/algorithms/ind/ind_algorithm.h b/src/core/algorithms/ind/ind_algorithm.h new file mode 100644 index 0000000000..9cc967bc25 --- /dev/null +++ b/src/core/algorithms/ind/ind_algorithm.h @@ -0,0 +1,50 @@ +#pragma once + +#include +#include +#include +#include + +#include "algorithms/algorithm.h" +#include "ind.h" +#include "tabular_data/input_tables_type.h" +#include "util/primitive_collection.h" + +namespace algos { + +class INDAlgorithm : public Algorithm { +public: + using IND = model::IND; + +private: + util::PrimitiveCollection ind_collection_; + + void ResetState() final { + ind_collection_.Clear(); + ResetINDAlgorithmState(); + } + + virtual void ResetINDAlgorithmState() = 0; + +protected: + constexpr static std::string_view kDefaultPhaseName = "IND mining"; + + config::InputTables input_tables_; + + explicit INDAlgorithm(std::vector phase_names); + + virtual void RegisterIND(std::shared_ptr lhs, + std::shared_ptr rhs) { + ind_collection_.Register(std::move(lhs), std::move(rhs)); + } + virtual void RegisterIND(IND ind) { + ind_collection_.Register(std::move(ind)); + } + +public: + std::list const& INDList() const noexcept { + return ind_collection_.AsList(); + } +}; + +} // namespace algos diff --git a/src/core/model/table/column_combination.cpp b/src/core/model/table/column_combination.cpp index e69de29bb2..956ce6912f 100644 --- a/src/core/model/table/column_combination.cpp +++ b/src/core/model/table/column_combination.cpp @@ -0,0 +1,19 @@ +#include "column_combination.h" + +#include + +namespace model { + +std::string ColumnCombination::ToString() const { + std::vector const& col_ids = GetColumnIndices(); + std::stringstream ss; + for (auto it = col_ids.begin(); it != col_ids.end(); ++it) { + if (it != col_ids.begin()) { + ss << ", "; + } + ss << GetTableIndex() << '.' << *it; + } + return ss.str(); +} + +} // namespace model diff --git a/src/core/model/table/column_combination.h b/src/core/model/table/column_combination.h index e69de29bb2..3b719fa075 100644 --- a/src/core/model/table/column_combination.h +++ b/src/core/model/table/column_combination.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include + +#include "column_index.h" + +namespace model { + +// Represents an index for a table within a set of tables +// As an example, this type is used in inclusion dependencies +using TableIndex = unsigned int; + +class ColumnCombination { +protected: + TableIndex table_index_; + std::vector column_indices_; + +public: + ColumnCombination(TableIndex table_index, std::vector col_indices) + : table_index_(table_index), column_indices_(std::move(col_indices)) {} + + TableIndex GetTableIndex() const { + return table_index_; + } + std::vector const& GetColumnIndices() const { + return column_indices_; + } + std::string ToString() const; +}; + +} // namespace model