Hi I want to create an object of ProfileComparator in another index.js file but I am getting an error.
strategy.js
var cosineUtils = require("./jscosine");
var ProfileComparator = function(algo, x, y, threshold) {
this.algo = algo;
this.x = x;
this.y = y;
this.threshold = threshold;
};
ProfileComparator.prototype.findMatches = function() {
return this.algo(this.x, this.y, this.threshold);
};
var cosineAlgoStrategy = function(x, y, threshold) {
var similarityCount = cosineUtils.cosineSimilarity(x, y);
if (similarityCount >= threshold) {
return y;
}
console.log("------------------------------------");
console.log("cosine");
console.log("------------------------------------");
};
var pearsonAlgoStrategy = function(x, y, threshold) {
console.log("------------------------------------");
console.log(threshold);
console.log("------------------------------------");
};
I am able to create object of ProfileComparator in strategy.js not in other javascript file like below
var cosineAlgo = new ProfileComparator(cosineAlgoStrategy, "x", "y", 0.9);
return cosineAlgo.findMatches();
index.js
I am trying to do same in index.js but I am getting an error here:
var strategyUtils = require("./strategy");
function computeSimilarity(x, user) {
var cosineAlgo = new ProfileComparator(cosineAlgoStrategy, x, y, 0.9);
return cosineAlgo.findMatches();
}
StackTrace:
ReferenceError: ProfileComparator is not defined
at computeSimilarity (/user_code/index.js:187:24)
at /user_code/index.js:232:16
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
Does anyone know how to resolve it ?
ProfileComparatorfromstrategy.jsfile.