Debian Codegraph @

FaCT++.JNI/FaCTPlusPlus.cpp

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2006-2015 Dmitry Tsarkov and The University of Manchester
3 Copyright (C) 2015-2017 Dmitry Tsarkov
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include <iostream>
21
22 #include "uk_ac_manchester_cs_factplusplus_FaCTPlusPlus.h"
23 #include "Kernel.h"
24 #include "tJNICache.h"
25 #include "JNIMonitor.h"
26 #include "configure.h"
27 #include "MemoryStat.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 //-------------------------------------------------------------
34 // Different fields/method IDs and their setup
35 //-------------------------------------------------------------
36
37 /// field for Kernel's ID
38 jfieldID KernelFID;
39
40 /*
41 * Class: uk_ac_manchester_cs_factplusplus_FaCTPlusPlus
42 * Method: initMethodsFieldsIDs
43 * Signature: ()V
44 */
45 JNIEXPORT void JNICALL Java_uk_ac_manchester_cs_factplusplus_FaCTPlusPlus_initMethodsFieldsIDs
46 (JNIEnv * env, jclass cls)
47 {
48 KernelFID = env->GetFieldID ( cls, "KernelId", "J" );
49
50 if ( KernelFID == nullptr )
51 {
52 Throw ( env, "Can't get 'KernelId' field" );
53 return;
54 }
55 MemoryStatistics MS("init JNI");
56 }
57
58 //-------------------------------------------------------------
59 // Kernel management (like newKB/curKB/releaseKB)
60 //-------------------------------------------------------------
61
62 /// try to load configuration from FILE; @return false if successful
63 bool loadConfiguration ( ReasoningKernel* K, const char* file )
64 {
65 Configuration Config;
66
67 if ( Config.Load(file) )
68 return true;
69 if ( K->getOptions()->initByConfigure ( Config, "Tuning" ) )
70 return true;
71 std::cerr << "Using options from file " << file << "\n";
72 return false;
73 }
74
75 /*
76 * Class: uk_ac_manchester_cs_factplusplus_FaCTPlusPlus
77 * Method: initKernel
78 * Signature: ()V
79 */
80 JNIEXPORT void JNICALL Java_uk_ac_manchester_cs_factplusplus_FaCTPlusPlus_initKernel
81 (JNIEnv * env, jobject obj)
82 {
83 MemoryStatistics MS("Create Reasoner");
84 // create new kernel and save it in an FaCTPlusPlus object
85 ReasoningKernel* Kernel = new ReasoningKernel();
86 env->SetLongField ( obj, KernelFID, (jlong)Kernel );
87
88 // try to load configuration
89 if ( loadConfiguration ( Kernel, ".fpp-options" ) )
90 loadConfiguration ( Kernel, "fpp-options.txt" );
91
92 // init dumping of the ontology
93 Kernel->setDumpOntology(Kernel->getOptions()->getBool("dumpOntology"));
94 // init incremental reasoning
95 Kernel->setUseIncrementalReasoning(Kernel->getOptions()->getBool("useIncrementalReasoning"));
96
97 // setup JNI cache
98 TJNICache* J = new TJNICache(env);
99 Kernel->setJNICache(J);
100 J->K = Kernel;
101 J->EM = Kernel->getExpressionManager();
102
103 TRACE_JNI("initKernel");
104
105 if ( USE_LOGGING )
106 {
107 // initialize LeveLogger
108 //LLM.initLogger ( 20, "reasoning.log" );
109 }
110 }
111
112 /*
113 * Class: uk_ac_manchester_cs_factplusplus_FaCTPlusPlus
114 * Method: deleteKernel
115 * Signature: ()V
116 */
117 JNIEXPORT void JNICALL Java_uk_ac_manchester_cs_factplusplus_FaCTPlusPlus_deleteKernel
118 (JNIEnv * env, jobject obj)
119 {
120 MemoryStatistics MS("Delete Reasoner");
121 TRACE_JNI("deleteKernel");
122 ReasoningKernel* Kernel = getK(env,obj);
123 delete Kernel->getJNICache();
124 delete Kernel;
125 // set to NULL
126 env->SetLongField ( obj, KernelFID, 0 );
127 }
128
129 /*
130 * Class: uk_ac_manchester_cs_factplusplus_FaCTPlusPlus
131 * Method: clearKernel
132 * Signature: ()V
133 */
134 JNIEXPORT void JNICALL Java_uk_ac_manchester_cs_factplusplus_FaCTPlusPlus_clearKernel
135 (JNIEnv * env, jobject obj)
136 {
137 MemoryStatistics MS("Clear Reasoner");
138 TRACE_JNI("clearKernel");
139 getK(env,obj)->clearKB();
140 }
141
142 /*
143 * Class: uk_ac_manchester_cs_factplusplus_FaCTPlusPlus
144 * Method: setTopBottomPropertyNames
145 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
146 */
147 JNIEXPORT void JNICALL Java_uk_ac_manchester_cs_factplusplus_FaCTPlusPlus_setTopBottomPropertyNames
148 (JNIEnv * env, jobject obj, jstring ton, jstring bon, jstring tdn, jstring bdn)
149 {
150 TRACE_JNI("setTopBottomPropertyNames");
151 TRACE_STR(env,ton);
152 TRACE_STR(env,bon);
153 TRACE_STR(env,tdn);
154 TRACE_STR(env,bdn);
155 JString topObjectName(env,ton);
156 JString botObjectName(env,bon);
157 JString topDataName(env,tdn);
158 JString botDataName(env,bdn);
159 getK(env,obj)->setTopBottomRoleNames ( topObjectName(), botObjectName(), topDataName(), botDataName() );
160 }
161
162 /*
163 * Class: uk_ac_manchester_cs_factplusplus_FaCTPlusPlus
164 * Method: setOperationTimeout
165 * Signature: (J)V
166 */
167 JNIEXPORT void JNICALL Java_uk_ac_manchester_cs_factplusplus_FaCTPlusPlus_setOperationTimeout
168 (JNIEnv * env, jobject obj, jlong delay)
169 {
170 TRACE_JNI("setOperationTimeout");
171 getK(env,obj)->setOperationTimeout(delay > 0 ? static_cast<unsigned long>(delay) : 0);
172 }
173
174 /*
175 * Class: uk_ac_manchester_cs_factplusplus_FaCTPlusPlus
176 * Method: setFreshEntityPolicy
177 * Signature: (Z)V
178 */
179 JNIEXPORT void JNICALL Java_uk_ac_manchester_cs_factplusplus_FaCTPlusPlus_setFreshEntityPolicy
180 (JNIEnv * env, jobject obj, jboolean value)
181 {
182 TRACE_JNI("setFreshEntityPolicy");
183 getK(env,obj)->setUseUndefinedNames(value);
184 }
185
186 /*
187 * Class: uk_ac_manchester_cs_factplusplus_FaCTPlusPlus
188 * Method: setProgressMonitor
189 * Signature: (Luk/ac/manchester/cs/factplusplus/FaCTPlusPlusProgressMonitor;)V
190 */
191 JNIEXPORT void JNICALL Java_uk_ac_manchester_cs_factplusplus_FaCTPlusPlus_setProgressMonitor
192 (JNIEnv * env, jobject obj, jobject monitor)
193 {
194 TRACE_JNI("setProgressMonitor");
195 getK(env,obj)->setProgressMonitor ( new JNIProgressMonitor ( env, monitor ) );
196 }
197
198 /*
199 * Class: uk_ac_manchester_cs_factplusplus_FaCTPlusPlus
200 * Method: startChanges
201 * Signature: ()V
202 */
203 JNIEXPORT void JNICALL Java_uk_ac_manchester_cs_factplusplus_FaCTPlusPlus_startChanges
204 (JNIEnv *, jobject)
205 {
206 }
207
208 /*
209 * Class: uk_ac_manchester_cs_factplusplus_FaCTPlusPlus
210 * Method: endChanges
211 * Signature: ()V
212 */
213 JNIEXPORT void JNICALL Java_uk_ac_manchester_cs_factplusplus_FaCTPlusPlus_endChanges
214 (JNIEnv * env ATTR_UNUSED, jobject obj ATTR_UNUSED)
215 {
216 TRACE_JNI("endChanges");
217 // do nothing
218 }
219
220 /*
221 * Class: uk_ac_manchester_cs_factplusplus_FaCTPlusPlus
222 * Method: needTracing
223 * Signature: ()V
224 */
225 JNIEXPORT void JNICALL Java_uk_ac_manchester_cs_factplusplus_FaCTPlusPlus_needTracing
226 (JNIEnv * env, jobject obj)
227 {
228 TRACE_JNI("needTracing");
229 getK(env,obj)->needTracing();
230 }
231
232 /*
233 * Class: uk_ac_manchester_cs_factplusplus_FaCTPlusPlus
234 * Method: getTrace
235 * Signature: ()[Luk/ac/manchester/cs/factplusplus/AxiomPointer;
236 */
237 JNIEXPORT jobjectArray JNICALL Java_uk_ac_manchester_cs_factplusplus_FaCTPlusPlus_getTrace
238 (JNIEnv * env, jobject obj)
239 {
240 TRACE_JNI("getTrace");
241 TJNICache* J = getJ(env,obj);
242 return J->buildArray ( J->K->getTrace(), J->AxiomPointer );
243 }
244
245 #ifdef __cplusplus
246 }
247 #endif