@graperank/interpreter
Version:
The GrapeRank Interpreter module generates normalized ratings from ingested network data. It requires one or more Protocols plugins.
45 lines (44 loc) • 1.63 kB
JavaScript
;
// Export ALL module instances of Interpreter interface
// as this[source][protocol]
Object.defineProperty(exports, "__esModule", { value: true });
exports.Protocols = void 0;
const util_1 = require("@graperank/util");
class Protocols extends Map {
constructor(factories) {
super();
factories.forEach((protocolfactory) => {
protocolfactory.forEach((initializer, protocol) => {
if (!this.has(protocol))
this.set(protocol, initializer());
});
});
}
setRequest(request) {
this.get(request.protocol).request = request;
}
getParams(protocol) {
return this.get(protocol).params;
}
getInterpreted(protocol) {
return this.get(protocol).interpreted;
}
async fetchData(protocol, raters) {
return await this.get(protocol).fetchData(raters);
}
async interpret(protocol, dos) {
let instance = this.get(protocol);
// let numzero = 0
let newratings = await instance.interpret(dos);
let numtargetratings = 0;
for (let r in newratings) {
// if(newratings[r].score == 0) numzero ++
// DEBUG
if (newratings[r].ratee == util_1.DEBUGTARGET)
console.log('DEBUGTARGET : interpret : rating ', numtargetratings, ' returned by protocolInterpret() ', newratings[r]);
}
// console.log("GrapeRank : interpret : "+protocol+" protocol : number of zero scored ratings = "+numzero+" of "+newratings.length+" ratings")
return newratings;
}
}
exports.Protocols = Protocols;