Skip to content
Snippets Groups Projects
Commit df54b988 authored by Lukáš Paukert's avatar Lukáš Paukert
Browse files

Improved getting query

parent 2ab633fd
No related branches found
No related tags found
No related merge requests found
...@@ -17,15 +17,3 @@ const InvertedIndex &Space::operator[](const string &key) const { ...@@ -17,15 +17,3 @@ const InvertedIndex &Space::operator[](const string &key) const {
InvertedIndex &Space::getInvertedIndexByKey(const string &key) { InvertedIndex &Space::getInvertedIndexByKey(const string &key) {
return terms.at(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;
}
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
   
   
#include <string> #include <string>
#include <set>
#include <map> #include <map>
   
#include "InvertedIndex.h" #include "InvertedIndex.h"
...@@ -35,13 +34,6 @@ public: ...@@ -35,13 +34,6 @@ public:
*/ */
InvertedIndex &getInvertedIndexByKey(const std::string &key); 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 * @brief Gets an element from @ref Space::terms with key @ref key
* @param key Key of the element to find * @param key Key of the element to find
......
...@@ -24,17 +24,18 @@ Document Database::getDocumentByID(int id) { ...@@ -24,17 +24,18 @@ Document Database::getDocumentByID(int id) {
return {id, query.getColumn(0)}; return {id, query.getColumn(0)};
} }
   
vector<string> Database::getTermsByDocumentID(int document_id) { map<string, double> Database::getTermsAndWightsByDocumentID(int document_id) {
vector<string> terms; map<string, double> termsAndWeights;
SQLite::Statement query(db, "SELECT Term.value FROM Term " SQLite::Statement query(db, "SELECT Term.value, TermDocumentOccurrence.weight FROM Term "
"JOIN TermDocumentOccurrence ON Term.id = TermDocumentOccurrence.Term_id " "JOIN TermDocumentOccurrence ON Term.id = TermDocumentOccurrence.Term_id "
"WHERE TermDocumentOccurrence.Document_id = :id"); "WHERE TermDocumentOccurrence.Document_id = :id");
query.bind(":id", document_id); query.bind(":id", document_id);
   
while(query.executeStep()) while(query.executeStep()) {
terms.emplace_back(query.getColumn(0)); termsAndWeights[query.getColumn(0)] = query.getColumn(1);
}
   
return terms; return termsAndWeights;
} }
   
map<int, double> Database::getVectorSizes() { map<int, double> Database::getVectorSizes() {
......
...@@ -31,11 +31,11 @@ public: ...@@ -31,11 +31,11 @@ public:
Document getDocumentByID(int id); 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 * @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 * @brief Computes size of vector for every document in database
......
...@@ -75,7 +75,7 @@ void MainPage::displayDetail(Space space, Wt::WContainerWidget * container, int ...@@ -75,7 +75,7 @@ void MainPage::displayDetail(Space space, Wt::WContainerWidget * container, int
Document document = database.getDocumentByID(document_id); Document document = database.getDocumentByID(document_id);
   
// threshold je nyni nastaven na -1 --> ve vysledku budou i uplne rozdilne dokumenty // 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); auto result = Computor(space, query).compute(database);
   
// dodelat proklikavani na zobrazene podobne dokumenty // dodelat proklikavani na zobrazene podobne dokumenty
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment