eliza-core
Version:
A rendition of ELIZA program engine by Weizenbaum sharable for all javascript environments
37 lines (36 loc) • 1.26 kB
JavaScript
import { NoReassemblyRuleException } from './exceptions';
var Decomp = (function () {
function Decomp(pattern, mem, reassembles) {
this.pattern = pattern;
this.mem = mem;
this.reassembles = reassembles;
this.currReasmb = 100;
}
Decomp.prototype.getPattern = function () {
return this.pattern;
};
Decomp.prototype.isMemoryKey = function () {
return this.mem;
};
Decomp.prototype.getReasemb = function () {
return this.reassembles.filter(function (r) { return !r.isAnnotated(); });
};
Decomp.prototype.getAnnotates = function () {
return this.reassembles.filter(function (r) { return r.isAnnotated(); });
};
Decomp.prototype.nextRule = function () {
var reassembles = this.reassembles.filter(function (r) { return !r.isAnnotated(); });
if (this.isMemoryKey()) {
this.currReasmb = Math.floor(Math.random() * reassembles.length);
}
if (++this.currReasmb >= reassembles.length) {
this.currReasmb = 0;
}
if (reassembles.length < 1) {
throw new NoReassemblyRuleException();
}
return reassembles[this.currReasmb];
};
return Decomp;
}());
export { Decomp };