1 /* 2 * #%L 3 * prolobjectlink-jpi-jtrolog 4 * %% 5 * Copyright (C) 2012 - 2018 WorkLogic Project 6 * %% 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU Lesser General Public License as 9 * published by the Free Software Foundation, either version 2.1 of the 10 * License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Lesser Public License for more details. 16 * 17 * You should have received a copy of the GNU General Lesser Public 18 * License along with this program. If not, see 19 * <http://www.gnu.org/licenses/lgpl-2.1.html>. 20 * #L% 21 */ 22 /* 23 * tuProlog - Copyright (C) 2001-2002 aliCE team at deis.unibo.it 24 * 25 * This library is free software; you can redistribute it and/or 26 * modify it under the terms of the GNU Lesser General Public 27 * License as published by the Free Software Foundation; either 28 * version 2.1 of the License, or (at your option) any later version. 29 * 30 * This library is distributed in the hope that it will be useful, 31 * but WITHOUT ANY WARRANTY; without even the implied warranty of 32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 33 * Lesser General Public License for more details. 34 * 35 * You should have received a copy of the GNU Lesser General Public 36 * License along with this library; if not, write to the Free Software 37 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 38 */ 39 package jTrolog.lib; 40 41 import jTrolog.engine.Prolog; 42 import jTrolog.terms.Term; 43 44 import java.io.Serializable; 45 46 /** 47 * 48 * This abstract class is the base class for developing built-in libraries, 49 * which can be dynamically loaded by prolog objects. 50 * <p> 51 * Each library can expose to engine: 52 * <ul> 53 * <li>a theory (as a string assigned to theory field) 54 * <li>primitives: methods whose signature is boolean|void|Term 55 * name_arity(BindingsTable bt, Term arg0, Term arg1, ...) is considered a 56 * built-in primitive provided by the library 57 * <li>synonyms for primitives 58 * </ul> 59 */ 60 @SuppressWarnings({ "serial" }) 61 public abstract class Library implements Serializable { 62 63 /** prolog core which loaded the library */ 64 protected Prolog engine; 65 66 /** 67 * @return the library name (Library class name is default) 68 */ 69 public String getName() { 70 return getClass().getName(); 71 } 72 73 /** 74 * @return the theory provided with the library (an empty theory is 75 * default). 76 */ 77 public String getTheory() { 78 return ""; 79 } 80 81 /** 82 * Defines a map for synonyms for primitives. String primitive name = 83 * String[]{synonym name, another synonym name, ..}. 84 */ 85 public String[] getSynonym(String primitiveName) { 86 return null; 87 } 88 89 public void setEngine(Prolog en) { 90 engine = en; 91 } 92 93 /** 94 * method invoked by prolog engine when library is going to be removed 95 */ 96 public void dismiss() { 97 } 98 99 /** 100 * method invoked when the engine is going to demonstrate a goal 101 */ 102 public void onSolveBegin(Term goal) { 103 } 104 105 /** 106 * method invoked when the engine has finished a demostration 107 */ 108 public void onSolveEnd() { 109 } 110 }