UNPKG

meta-log-db

Version:

Native database package for Meta-Log (ProLog, DataLog, R5RS)

68 lines 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PrologEngine = void 0; const resolution_js_1 = require("./resolution.js"); /** * ProLog Engine for Meta-Log Database */ class PrologEngine { constructor() { this.facts = []; this.rules = []; } /** * Add facts to the database */ addFacts(facts) { this.facts.push(...facts); } /** * Add a rule to the database */ addRule(rule) { this.rules.push(rule); } /** * Build database from facts */ buildDb(facts) { this.facts = [...facts]; } /** * Query the database */ async query(goal) { const results = resolution_js_1.Resolution.resolve(goal, this.facts, this.rules); // Convert results to bindings format const bindings = []; for (const resultBindings of results) { const binding = {}; for (const [key, value] of resultBindings) { binding[key] = value; } bindings.push(binding); } return { bindings }; } /** * Get all facts */ getFacts() { return [...this.facts]; } /** * Get all rules */ getRules() { return [...this.rules]; } /** * Clear database */ clear() { this.facts = []; this.rules = []; } } exports.PrologEngine = PrologEngine; //# sourceMappingURL=engine.js.map