View Javadoc

1   /*
2    * #%L
3    * prolobjectlink-jpi
4    * %%
5    * Copyright (C) 2019 Prolobjectlink Project
6    * %%
7    * Permission is hereby granted, free of charge, to any person obtaining a copy
8    * of this software and associated documentation files (the "Software"), to deal
9    * in the Software without restriction, including without limitation the rights
10   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11   * copies of the Software, and to permit persons to whom the Software is
12   * furnished to do so, subject to the following conditions:
13   * 
14   * The above copyright notice and this permission notice shall be included in
15   * all copies or substantial portions of the Software.
16   * 
17   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23   * THE SOFTWARE.
24   * #L%
25   */
26  package io.github.prolobjectlink.prolog;
27  
28  import java.util.Iterator;
29  
30  /**
31   * <p>
32   * Prolog clause is composed by two prolog terms that define a prolog clause,
33   * the head and the body. This representation consider the prolog clause body
34   * like a single term. If the body is a conjunctive set of terms, the body is an
35   * structure with functor/arity (,/2) and the first argument is the first
36   * element in the conjunction and the rest is a recursive functor/arity (,/2).
37   * </p>
38   * <p>
39   * The functor and arity for the clause is given from head term functor and
40   * arity.
41   * </p>
42   * <p>
43   * This class define some properties for commons prolog clause implementations.
44   * They are boolean flags that indicate if the prolog clause is dynamic
45   * multifile and discontiguos.
46   * </p>
47   * <p>
48   * This class have several methods to access to the clause components and
49   * retrieve some clause properties and information about it.
50   * </p>
51   * <p>
52   * Additionally this class contains a prolog provider reference for build terms
53   * in some operations.
54   * </p>
55   * 
56   * @author Jose Zalacain
57   * @since 1.0
58   */
59  public interface PrologClause extends PrologElement, PrologDocumentable {
60  
61  	/**
62  	 * Integer number that represent the arguments number in the clause head. The
63  	 * arity for this clause can be implemented like {@code getHead().getArity()}.
64  	 * 
65  	 * @return the arguments number in the clause head.
66  	 * @since 1.0
67  	 */
68  	public int getArity();
69  
70  	/**
71  	 * String that represent the functor in the clause head. The functor for this
72  	 * clause can be implemented like {@code getHead().getFunctor()}.
73  	 * 
74  	 * @return the functor in the clause head
75  	 * @since 1.0
76  	 */
77  	public String getFunctor();
78  
79  	/**
80  	 * Term arguments present in the clause head.
81  	 * 
82  	 * @return Term arguments present in the clause head.
83  	 * @since 1.0
84  	 */
85  	public PrologTerm[] getArguments();
86  
87  	/**
88  	 * Term located at some given index position in the clause head arguments.
89  	 * 
90  	 * @param index position to retrieve the correspondent term.
91  	 * @return Term located at some given index position.
92  	 * @throws ArrayIndexOutOfBoundsException if the index value is out of term
93  	 *                                        array bound.
94  	 * @since 1.0
95  	 */
96  	public PrologTerm getArgument(int index);
97  
98  	/**
99  	 * Prolog term representation of the current clause. This prolog term is a
100 	 * structure with functor/arity (:-/2) and the arguments head and body.
101 	 * 
102 	 * @return term representation of the current clause.
103 	 * @since 1.0
104 	 */
105 	public PrologTerm getTerm();
106 
107 	/**
108 	 * Prolog term that represent the clause head.
109 	 * 
110 	 * @return the clause head.
111 	 * @since 1.0
112 	 */
113 	public PrologTerm getHead();
114 
115 	/**
116 	 * Prolog term that represent the clause body. If the clause body representation
117 	 * it's not the term itself, the prolog term should be created and returned.
118 	 * 
119 	 * @return the clause body.
120 	 * @since 1.0
121 	 */
122 	public PrologTerm getBody();
123 
124 	/**
125 	 * Clause family functor/arity based indicator. The clause family indicator is
126 	 * the same indicator for all clauses head in the clause family.
127 	 * 
128 	 * @return functor/arity based indicator of the current clause family.
129 	 * @since 1.0
130 	 */
131 	public String getIndicator();
132 
133 	/**
134 	 * Check if the current clause have functor/arity based indicator specified by
135 	 * arguments, false in otherwise.
136 	 * 
137 	 * @param functor clause functor to be checked
138 	 * @param arity   clause arity to be checked
139 	 * @return true if the current clause have functor/arity based indicator
140 	 *         specified by arguments, false in otherwise.
141 	 * @since 1.0
142 	 */
143 	public boolean hasIndicator(String functor, int arity);
144 
145 	/**
146 	 * True if this clause is a directive, false in other case. The implementation
147 	 * for this method can be {@code getHead()==null && getBody()!=null}.
148 	 * 
149 	 * @return whether this clause is a directive.
150 	 * @since 1.0
151 	 */
152 	public boolean isDirective();
153 
154 	/**
155 	 * True if this clause is a fact, false in other case. The implementation for
156 	 * this method can be {@code getHead()!=null && getBody()==null}.
157 	 * 
158 	 * @return whether this clause is a fact.
159 	 * @since 1.0
160 	 */
161 	public boolean isFact();
162 
163 	/**
164 	 * True if this clause is a rule, false in other case. The implementation for
165 	 * this method can be {@code getHead()!=null && getBody()!=null}.
166 	 * 
167 	 * @return whether this clause is a rule.
168 	 * @since 1.0
169 	 */
170 	public boolean isRule();
171 
172 	/**
173 	 * True if this clause is a rule, false in other case. The implementation for
174 	 * this method can be {@code getHead()!=null && getBody()!=null}.
175 	 * 
176 	 * @return whether this clause is a rule.
177 	 * @since 1.1
178 	 */
179 	public boolean isMethod();
180 
181 	/**
182 	 * True if this clause is a function, false in other case. The implementation
183 	 * for this method can be {@code getHead()!=null && getBody()!=null}.
184 	 * 
185 	 * @return whether this clause is a rule.
186 	 * @since 1.1
187 	 */
188 	public boolean isFunction();
189 
190 	/**
191 	 * Check that two clauses unify. Prolog clauses unify if and only if the head
192 	 * and the body for both clauses unify.
193 	 * 
194 	 * @param clause the clause to unify with the current clause
195 	 * @return true if the given clause unify whit the current clause, false
196 	 *         otherwise
197 	 * @since 1.0
198 	 */
199 	public boolean unify(PrologClause clause);
200 
201 	/**
202 	 * True if this clause is a dynamic, false in other case
203 	 * 
204 	 * @deprecated Natives engine don't offer information about that.
205 	 * @return whether this clause is a dynamic
206 	 * @since 1.0
207 	 */
208 	@Deprecated
209 	public boolean isDynamic();
210 
211 	/**
212 	 * True if this clause is a multifile, false in other case
213 	 * 
214 	 * @deprecated Natives engine don't offer information about that.
215 	 * @return whether this clause is a multifile
216 	 * @since 1.0
217 	 */
218 	@Deprecated
219 	public boolean isMultifile();
220 
221 	/**
222 	 * True if this clause is a discontiguos, false in other case
223 	 * 
224 	 * @deprecated Natives engine don't offer information about that.
225 	 * @return whether this clause is a discontiguos.
226 	 * @since 1.0
227 	 */
228 	@Deprecated
229 	public boolean isDiscontiguous();
230 
231 	/**
232 	 * Clause family PrologIndicator based indicator. The clause family indicator is
233 	 * the same indicator for all clauses head in the clause family.
234 	 * 
235 	 * @return PrologIndicator based indicator of the current clause family.
236 	 * @since 1.0
237 	 */
238 	public PrologIndicator getPrologIndicator();
239 
240 	/**
241 	 * Iterator to iterate over all body terms.
242 	 * 
243 	 * @return Iterator to iterate over all body terms.
244 	 * @since 1.0
245 	 */
246 	public Iterator<PrologTerm> getBodyIterator();
247 
248 	/**
249 	 * Get the clause body as terms array.
250 	 * 
251 	 * @return clause terms body array.
252 	 * @since 1.0
253 	 */
254 	public PrologTerm[] getBodyArray();
255 
256 	/**
257 	 * Casts the current PrologClause to the class or interface represented by this
258 	 * {@code Class} object.
259 	 *
260 	 * @return the PrologTerm after casting, or null if term is null
261 	 *
262 	 * @throws ClassCastException if the object is not null and is not assignable to
263 	 *                            the type T.
264 	 * @since 1.1
265 	 */
266 	public <T extends PrologClause> T cast();
267 
268 }