Skip to content

Commit

Permalink
feat(output): get formal concepts from inclose5 algo output
Browse files Browse the repository at this point in the history
  • Loading branch information
kalitine committed Sep 27, 2020
1 parent 1055d47 commit 0bb8715
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/inclose5
Submodule inclose5 updated 5 files
+27 −9 BicsUtils.cpp
+ InClose5
+2 −0 globalsv.cpp
+3 −0 globalsv.h
+10 −0 stdafx.h
39 changes: 35 additions & 4 deletions src/index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#include "../lib/inclose5/inclose.h"
#include "../lib/inclose5/BicsUtils.h"

static void ArrayConsumer(dataset_t &matrix, const uint8_t* array, size_t length, row_t row_size, col_t col_size ) {
static void readInputs(dataset_t &matrix, const uint8_t* array, size_t length, row_t row_size, col_t col_size ) {

//Allocating memory
matrix = new data_t*[row_size];
for (row_t i = 0; i < row_size; ++i)
matrix[i] = new data_t[col_size];

// Read intputs for the algo
row_t i = 0;
row_t j = 0;
for (size_t index = 0; index < length; index++) {
Expand Down Expand Up @@ -45,16 +46,46 @@ static Napi::Value Run(const Napi::CallbackInfo& info) {
col_t col_size = info[2].As<Napi::Number>().Int32Value();
Napi::ArrayBuffer buf = info[0].As<Napi::ArrayBuffer>();
dataset_t matrix;
ArrayConsumer(matrix, reinterpret_cast<uint8_t*>(buf.Data()),
readInputs(matrix, reinterpret_cast<uint8_t*>(buf.Data()),
buf.ByteLength() / sizeof(uint8_t), row_size, col_size);

double duration = runInClose(matrix, row_size, col_size, 2, 1);
Napi::Number durationN = Napi::Number::New(env, duration);

return durationN;
// Perparing the output
Napi::Object result = Napi::Object::New(env);
result.Set("duration", duration);
result.Set("nbClusters", g_cont);

Napi::Array formalConcepts = Napi::Array::New(env);
int j = 0;

clusters_t cluster;
while (!clusters.empty()) {
cluster = clusters.front();
Napi::Object formalConcept = Napi::Object::New(env);
Napi::Array objects = Napi::Array::New(env, cluster->sizeA);
Napi::Array attributs = Napi::Array::New(env, cluster->sizeB);
formalConcept.Set("objects", objects);
formalConcept.Set("attributs", attributs);

for (row_t i = 0; i < cluster->sizeA; ++i)
objects[i] = Napi::Number::New(env, cluster->A[i]);

for (col_t i = 0; i < cluster->sizeB; ++i)
attributs[i] = Napi::Number::New(env, cluster->B[i]);


formalConcepts[j++] = formalConcept;
clusters.pop();
}
result.Set("clusters", formalConcepts);


return result;
}

static Napi::Object Init(Napi::Env env, Napi::Object exports) {
isNode = true;
exports.Set(Napi::String::New(env, "run"), Napi::Function::New(env, Run));
return exports;
}
Expand Down
4 changes: 2 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const inclose5 = require('../src/index.js')

const dataset = new Uint8Array([0,0,0,1,1,1,0,0,0,1,1,1,0,1,1,0,0,0,0,1,1,0,0,0])
const duration = inclose5.run(dataset.buffer, 4, 6)
console.log(`Algorithm run time = ${duration} seconds`)
const result = inclose5.run(dataset.buffer, 4, 6)
console.log(`Algorithm result: `, JSON.stringify(result))

0 comments on commit 0bb8715

Please sign in to comment.