01: /*
02: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18: package org.mandarax.lib;
19:
20: import org.mandarax.kernel.Predicate;
21: import org.mandarax.util.PredicateUtils;
22: import org.mandarax.util.logging.LogCategories;
23:
24: /**
25: * Abstract super class mandarax lib predicates.
26: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
27: * @version 3.4 <7 March 05>
28: * @since 1.6
29: */
30: public abstract class AbstractPredicate extends LibObject implements
31: Predicate {
32:
33: public final static String[] SLOT_NAMES_0 = {};
34: public final static String[] SLOT_NAMES_1 = { "slot1" };
35: public final static String[] SLOT_NAMES_2 = { "slot1", "slot2" };
36: public final static String[] SLOT_NAMES_3 = { "slot1", "slot2",
37: "slot3" };
38:
39: /**
40: * Indicates whether the object (usually a term or a clause set) can be performed
41: * using the java semantics. All Mandarax lib predicates support this.
42: * @return true
43: */
44: public boolean isExecutable() {
45: return true;
46: }
47:
48: /**
49: * Convert the object to a string.
50: * @return a string
51: */
52: public String toString() {
53: return (getName() == null) ? super .toString() : getName();
54: }
55:
56: /**
57: * Get the slot names.
58: * @return an array of strings, the length of the array is the same as
59: * the length of the array of terms (the structure of the predicate)
60: */
61: public String[] getSlotNames() {
62: int structLength = getStructure().length;
63: if (structLength == 0)
64: return SLOT_NAMES_0;
65: else if (structLength == 1)
66: return SLOT_NAMES_1;
67: else if (structLength == 2)
68: return SLOT_NAMES_2;
69: else if (structLength == 3)
70: return SLOT_NAMES_3;
71: else {
72: String[] slotNames = new String[getStructure().length];
73: for (int i = 0; i < slotNames.length; i++)
74: slotNames[i] = PredicateUtils.getSlotName(this , i);
75: return slotNames;
76: }
77:
78: }
79:
80: /**
81: * Set the slot names.
82: * @param names an array of strings, the length of the array is the same as
83: * the length of the array of terms (the structure of the predicate)
84: */
85: public void setSlotNames(String[] names) {
86: LogCategories.LOG_KB
87: .debug("Ignore attempt to set slot names for lib predicate");
88: // ignored
89: }
90:
91: /**
92: * Indicates whether the slot names can be modified.
93: * @return a boolean
94: */
95: public boolean slotNamesCanBeEdited() {
96: return false;
97: }
98:
99: }
|