// ops.js BAYES STAR (c) coppola.ai const { Proposition, FirstOrderArgument, RoleMap } = require("./predicate"); function ConvertToQuantified(proposition, roles) { const roleSet = new Set(roles) var result = [] for (let i = 0; i < proposition.roles.length; i++) { const crole = proposition.roles[i] const role_name = crole.role_name if (roleSet.has(role_name)) { const converted = crole.ConvertToQuantified() result.push(converted) } else { result.push(crole) } } return new Proposition(result) } function ConvertToProposition(predicate, roleMap) { var result = [] for (let i = 0; i < predicate.roles.length; i++) { const role = predicate.roles[i] const IsVariable = role.argument.IsVariable() if (IsVariable) { const substitute = roleMap.Get(role.role_name) const newRole = role.DoSubstitution(substitute) result.push(newRole) } else { result.push(role) } } return new Proposition(result) } function ExtractPremiseRoleMap(proposition, roleMap) { var result = {} for (let i = 0; i < proposition.roles.length; i++) { const crole = proposition.roles[i] const role_name = crole.role_name const premise_role_name = roleMap.Get(role_name) if (premise_role_name) { result[premise_role_name] = crole.argument } } const rval = new RoleMap(result) return rval } module.exports = { ConvertToQuantified, ConvertToProposition, ExtractPremiseRoleMap}