Commit 95341e1a authored by Marc Duez's avatar Marc Duez

similarityMatric.cpp : use c++11 json lib

parent 42dc2250
......@@ -186,19 +186,20 @@ JsonArray &operator<<(JsonArray &out, const JsonOutputSimilarityMatrix &outputMa
/* Export Levenshtein distances matrix, for the edit distance distribution & DBSCAN algorithm
*/
JsonArray &operator<<(JsonArray &out, const JsonOutputWindowsMatrix &outputMatrix) {
json &operator<<(json &out, const JsonOutputWindowsMatrix &outputMatrix) {
SimilarityMatrix &matrix = outputMatrix.matrix;
for (int i = 0; i < matrix.size(); i++) {
for (int j = 0; j < matrix.size(); j++) {
if (i < j) {
//Creation of an edges objects array, which contains a source objet, a target object, and the length of the distance between them
JsonList lineEdge;
lineEdge.add("source", i);
lineEdge.add("target", j);
//absolute value of the score -> distance
lineEdge.add("len", fabs(matrix(i,j)));
out.add(lineEdge);
json lineEdge;
lineEdge = {
{"source", i},
{"target", j},
{"len", fabs(matrix(i,j))}
};
out.push_back(lineEdge);
}
}
}
......
......@@ -6,8 +6,10 @@
#include <iostream>
#include <iomanip>
#include "json.h"
#include "../lib/json.hpp"
using namespace std;
using json = nlohmann::json;
#define LIMIT_DISPLAY 15
......@@ -120,6 +122,6 @@ class JsonOutputWindowsMatrix: public OutputSimilarityMatrix {
ostream &operator<<(ostream &out, const RawOutputSimilarityMatrix &matrix);
ostream &operator<<(ostream &out, const HTMLOutputSimilarityMatrix &matrix);
JsonArray &operator<<(JsonArray &out, const JsonOutputSimilarityMatrix &matrix);
JsonArray &operator<<(JsonArray &out, const JsonOutputWindowsMatrix &matrix);
json &operator<<(json &out, const JsonOutputWindowsMatrix &matrix);
#endif
......@@ -365,8 +365,8 @@ int main (int argc, char **argv)
double expected_value = THRESHOLD_NB_EXPECTED;
//JsonArray which contains the Levenshtein distances
JsonArray jsonLevenshtein;
//json which contains the Levenshtein distances
json jsonLevenshtein;
//$$ options: getopt
......@@ -1359,13 +1359,13 @@ int main (int argc, char **argv)
SimilarityMatrix matrix = compare_all(first_representatives,
representatives_labels);
cout << RawOutputSimilarityMatrix(matrix, 90);
/*
//Compute all the edges
cout << "Compute distances" << endl ;
SimilarityMatrix matrixLevenshtein = compare_windows(*windowsStorage, Levenshtein, max_clones);
//Added distances matrix in the JsonTab
jsonLevenshtein << JsonOutputWindowsMatrix(matrixLevenshtein);
*/
//Compute all the edges
cout << "Compute distances" << endl ;
SimilarityMatrix matrixLevenshtein = compare_windows(*windowsStorage, Levenshtein, max_clones);
//Added distances matrix in the JsonTab
jsonLevenshtein << JsonOutputWindowsMatrix(matrixLevenshtein);
// delete scorer;
} // endif (clones_windows.size() > 0)
......@@ -1436,10 +1436,9 @@ int main (int argc, char **argv)
j["clusters"] = comp.toJson(clones_windows);
}
//Added edges in the json output file
//json->add("links", jsonLevenshtein);
//out_json << json->toString();
j["links"] = jsonLevenshtein;
out_json << j.dump(2);
delete multigermline ;
delete windowsStorage;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment