diff --git a/querying/src/calculation/Space.cpp b/querying/src/calculation/Space.cpp index 77c608da9d27e97a1075894f4c8ec683858aebc3..6b05dbf5ffeb656262bb67e5d3a25e33086980c0 100644 --- a/querying/src/calculation/Space.cpp +++ b/querying/src/calculation/Space.cpp @@ -17,15 +17,3 @@ const InvertedIndex &Space::operator[](const string &key) const { InvertedIndex &Space::getInvertedIndexByKey(const string &key) { return terms.at(key); } - -const map<string, double> Space::getTermsAndWeightsByID(Database & database, int document_id) { - map<string, double> terms; - vector<string> dummy = database.getTermsByDocumentID(document_id); - - for (const string & term : dummy) { - InvertedIndex tmp = getInvertedIndexByKey(term); - terms[term] = tmp.getDocumentWeightByID(document_id); - } - - return terms; -} diff --git a/querying/src/calculation/Space.h b/querying/src/calculation/Space.h index d3e643aa2f5be8f73879216a87db8b3c8dad9233..f7eeadba1f872bc18b9586a7352dbfbde211e552 100644 --- a/querying/src/calculation/Space.h +++ b/querying/src/calculation/Space.h @@ -3,7 +3,6 @@ #include <string> -#include <set> #include <map> #include "InvertedIndex.h" @@ -35,13 +34,6 @@ public: */ InvertedIndex &getInvertedIndexByKey(const std::string &key); - /** - * @brief Finds all terms in DB which occurs in specific document - * @param database, document_id Instance of DB connection and document_id to process - * @return Map with terms as keys and weights as their values - */ - const std::map<std::string, double> getTermsAndWeightsByID(Database & database, int document_id); - /** * @brief Gets an element from @ref Space::terms with key @ref key * @param key Key of the element to find diff --git a/querying/src/database/Database.cpp b/querying/src/database/Database.cpp index 26887a4638428689edc6ca745a18e255b2649fcd..6439c7fdf3ab8f9addc8b283a10fb911e14dce63 100644 --- a/querying/src/database/Database.cpp +++ b/querying/src/database/Database.cpp @@ -24,17 +24,18 @@ Document Database::getDocumentByID(int id) { return {id, query.getColumn(0)}; } -vector<string> Database::getTermsByDocumentID(int document_id) { - vector<string> terms; - SQLite::Statement query(db, "SELECT Term.value FROM Term " +map<string, double> Database::getTermsAndWightsByDocumentID(int document_id) { + map<string, double> termsAndWeights; + SQLite::Statement query(db, "SELECT Term.value, TermDocumentOccurrence.weight FROM Term " "JOIN TermDocumentOccurrence ON Term.id = TermDocumentOccurrence.Term_id " "WHERE TermDocumentOccurrence.Document_id = :id"); query.bind(":id", document_id); - while(query.executeStep()) - terms.emplace_back(query.getColumn(0)); + while(query.executeStep()) { + termsAndWeights[query.getColumn(0)] = query.getColumn(1); + } - return terms; + return termsAndWeights; } map<int, double> Database::getVectorSizes() { diff --git a/querying/src/database/Database.h b/querying/src/database/Database.h index 8e759c6f631b14416b28c6078c08174a8de7ebc5..2bb4a667a60a82ef74978a40882130219548006a 100644 --- a/querying/src/database/Database.h +++ b/querying/src/database/Database.h @@ -31,11 +31,11 @@ public: Document getDocumentByID(int id); /** - * @brief Finds all terms from specified document + * @brief Finds all terms and their weights from specified document * @param document_id to process - * @return Vector with strings which are in specified document + * @return Map with terms as keys and weights as their values */ - std::vector<std::string> getTermsByDocumentID(int document_id); + std::map<std::string, double> getTermsAndWightsByDocumentID(int document_id); /** * @brief Computes size of vector for every document in database diff --git a/querying/src/ui/MainPage.cpp b/querying/src/ui/MainPage.cpp index 716e4b7bc3e8b25da1dbed2d2de00d13056b7abb..03075caa5f871cf3e9f5f7bb937e267ba3ce5024 100644 --- a/querying/src/ui/MainPage.cpp +++ b/querying/src/ui/MainPage.cpp @@ -75,7 +75,7 @@ void MainPage::displayDetail(Space space, Wt::WContainerWidget * container, int Document document = database.getDocumentByID(document_id); // threshold je nyni nastaven na -1 --> ve vysledku budou i uplne rozdilne dokumenty - Query query(space.getTermsAndWeightsByID(database, document.id), -1); + Query query(database.getTermsAndWightsByDocumentID(document_id), -1); auto result = Computor(space, query).compute(database); // dodelat proklikavani na zobrazene podobne dokumenty