UNPKG

ai-planning-val

Version:

Javascript/typescript wrapper for VAL (AI Planning plan validation and evaluation tools from KCL Planning department and the planning community around the ICAPS conference).

111 lines (109 loc) 4.35 kB
/* -------------------------------------------------------------------------------------------- * Copyright (c) Jan Dolejsi. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. * ------------------------------------------------------------------------------------------ */ 'use strict'; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Util = exports.PddlFactory = void 0; const tmp = __importStar(require("tmp-promise")); const fs = require("fs"); class PddlFactory { static createEmptyDomain(name) { return `(define (domain ${name}) (:requirements :strips ) )`; } static createEmptyProblem(name, domainName) { return `(define (problem ${name}) (:domain ${domainName}) (:objects ) (:init ) (:goal (and ) ) ) `; } } exports.PddlFactory = PddlFactory; class Util { /** * Saves the `text` to temporary file. * @param text file text * @param options file creation options */ static toFileSync(text, options) { const tempFile = tmp.fileSync(Util.toTmpFileOptions(options)); fs.writeSync(tempFile.fd, text, 0, 'utf8'); return tempFile.name; } /** * Saves the `text` to temporary file. * @param text file text * @param options file creation options */ static toFile(text, options) { return __awaiter(this, void 0, void 0, function* () { const tempFile = yield tmp.file(Util.toTmpFileOptions(options)); yield fs.promises.writeFile(tempFile.path, text, { encoding: 'utf8' }); return tempFile.path; }); } static toTmpFileOptions(options) { var _a; return { mode: 0o644, prefix: ((_a = options.prefix) !== null && _a !== void 0 ? _a : 'tmp') + '-', postfix: options.suffix, tmpdir: options.tmpdir }; } /** * Saves the text to a temporary .pddl file * @param text file text * @param options file name options */ static toPddlFileSync(text, options) { return Util.toFileSync(text, Object.assign(options, { suffix: '.pddl' })); } /** * Saves the text to a temporary .pddl file * @param text file text * @param options file name options */ static toPddlFile(text, options) { return __awaiter(this, void 0, void 0, function* () { return Util.toFile(text, Object.assign(options, { suffix: '.pddl' })); }); } } exports.Util = Util; //# sourceMappingURL=valUtils.js.map