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

Improved generation of JSON file

parent a6269f75
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,6 @@ bool calculateWeight(SQLite::Database & db, std::ofstream & ostream, const json
uint32_t occurrences;
double weight;
maxOccurrences[term].get_to(occurrences);
bool firstOccurrence = true;
 
try
{
......@@ -26,14 +25,12 @@ bool calculateWeight(SQLite::Database & db, std::ofstream & ostream, const json
ostream << "\"" << term << "\":{";
while(query.executeStep())
{
if (!firstOccurrence)
ostream << ",";
firstOccurrence = false;
weight = query.getColumn("count").getInt() / (occurrences*1.0);
ostream << "\"" << query.getColumn("Document_id") << "\":" << std::setprecision(20) << weight;
ostream << "\"" << query.getColumn("Document_id") << "\":" << std::setprecision(20) << weight << ",";
}
ostream << "}";
ostream.seekp(-1, std::ios_base::end);
ostream << "},";
}
 
catch(const std::exception& e)
......@@ -51,19 +48,13 @@ bool process(std::ofstream & ostream, const json & maxOccurrences)
{
SQLite::Database db("./../data/persistance/db", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);
SQLite::Statement query(db, "SELECT value FROM Term");
bool firstTerm = true;
 
ostream << "{";
while (query.executeStep())
{
if(!firstTerm)
ostream << ",";
firstTerm = false;
if(!calculateWeight(db, ostream, maxOccurrences, query.getColumn("value")))
return false;
}
 
ostream.seekp(-1, std::ios_base::end);
ostream << "}";
}
 
......
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