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.Map;
29  
30  /**
31   * Converter for convert {@code PrologTerm} to the equivalent native {@code T}
32   * term representation.
33   * 
34   * @author Jose Zalacain
35   * @since 1.0
36   * @param <T> native Term Representation
37   */
38  public interface PrologConverter<T> extends PrologMapper {
39  
40  	/**
41  	 * Create an equivalent Prolog terms map array using the given native terms map
42  	 * array representation. The resulting map array contains map that have the same
43  	 * string key and the value for every key is a conversion from native term to
44  	 * Prolog term.
45  	 * 
46  	 * @param map native terms map array to be converted in Prolog terms map array.
47  	 * @return an equivalent Prolog terms map array using the given native terms map
48  	 *         array representation.
49  	 * @since 1.0
50  	 */
51  	public Map<String, PrologTerm>[] toTermMapArray(Map<String, T>[] map);
52  
53  	/**
54  	 * Create an equivalent Prolog terms map using the given native terms map
55  	 * representation. The resulting map have the same string key and the value for
56  	 * every key is a conversion from native term to Prolog term.
57  	 * 
58  	 * @param map native terms map representation to be converted
59  	 * @return an equivalent Prolog terms map using the given native terms map
60  	 *         representation.
61  	 * @since 1.0
62  	 */
63  	public Map<String, PrologTerm> toTermMap(Map<String, T> map);
64  
65  	/**
66  	 * Create an equivalent Prolog terms matrix using the given native terms matrix
67  	 * representation.
68  	 * 
69  	 * @param terms native terms matrix representation to be converted
70  	 * @return an equivalent Prolog terms matrix using the given native terms matrix
71  	 *         representation.
72  	 * @since 1.0
73  	 */
74  	public PrologTerm[][] toTermMatrix(T[][] terms);
75  
76  	/**
77  	 * Create an equivalent Prolog terms array using the given native terms array
78  	 * representation.
79  	 * 
80  	 * @param terms native terms array representation to be converted
81  	 * @return an equivalent Prolog terms array using the given native terms array
82  	 *         representation.
83  	 * @since 1.0
84  	 */
85  	public PrologTerm[] toTermArray(T[] terms);
86  
87  	/**
88  	 * Create an equivalent Prolog term using the given native term representation.
89  	 * 
90  	 * @param prologTerm native term representation to be converted
91  	 * @return an equivalent Prolog term using the given native term representation.
92  	 * @since 1.0
93  	 */
94  	public PrologTerm toTerm(T prologTerm);
95  
96  	/**
97  	 * Create a native term representation from given Prolog term.
98  	 * 
99  	 * @param term Prolog term to be converted to native prolog term
100 	 * @return native term from given Prolog term.
101 	 * @since 1.0
102 	 */
103 	public T fromTerm(PrologTerm term);
104 
105 	/**
106 	 * Create a native term array representation from given Prolog term array.
107 	 * 
108 	 * @param terms Prolog term array to be converted to native array.
109 	 * @return native term array representation from given Prolog term array.
110 	 * @since 1.0
111 	 */
112 	public T[] fromTermArray(PrologTerm[] terms);
113 
114 	/**
115 	 * Create a native rule representation term from given head and body.
116 	 * 
117 	 * @param head rule head
118 	 * @param body rule body
119 	 * @return rule representation from given head and body.
120 	 * @since 1.0
121 	 */
122 	public T fromTerm(PrologTerm head, PrologTerm[] body);
123 
124 	/**
125 	 * Get the generic class for the current Prolog converter at runtime.
126 	 * 
127 	 * @return the converter generic class
128 	 * @since 1.0
129 	 */
130 	public Class<T> getGenericClass();
131 
132 	/**
133 	 * Create a Prolog provider instance.
134 	 * 
135 	 * @return a Prolog provider instance.
136 	 * @since 1.0
137 	 */
138 	public PrologProvider createProvider();
139 
140 }