@@ -138,30 +138,27 @@ public static void main(String[] args) {
138138 // Set SPARQL Endpoit
139139 endpoint = new SparqlEndpoint (Global .SPARQL_ENDPOINT , PREFIXES );
140140
141- // Create an empty json object which will be fill with our results
142- JSONObject json = new JSONObject ();
143-
144- try {
145- output = new FileWriter (Global .OUTPUT_PATH + parameters .resultFile + ".json" );
146- } catch (/* JAXBException | */ IOException e ) {
147- logger .error (e .getMessage ());
148- e .printStackTrace ();
149- System .exit (1 );
150- }
151-
152141 AxiomGenerator generator = null ;
153142 BufferedReader axiomFile = null ;
154143
144+ // Create an empty JSON object which will be fill with our results
145+ JSONObject json = new JSONObject ();
146+
155147 if (parameters .axiomFile == null ) {
156- if (parameters .useRandomAxiomGenerator ) {
157- logger .info ("Initializing the random axiom generator with grammar " + parameters .grammarFile + "..." );
158- generator = new RandomAxiomGenerator (parameters .grammarFile );
159- } else if (parameters .subclassList != null ) {
160- logger .info ("Initializing the increasing TP axiom generator..." );
161- generator = new IncreasingTimePredictorAxiomGenerator (parameters .subclassList );
148+ if (parameters .axiom == null ) {
149+ if (parameters .useRandomAxiomGenerator ) {
150+ logger .info (
151+ "Initializing the random axiom generator with grammar " + parameters .grammarFile + "..." );
152+ generator = new RandomAxiomGenerator (parameters .grammarFile );
153+ } else if (parameters .subclassList != null ) {
154+ logger .info ("Initializing the increasing TP axiom generator..." );
155+ generator = new IncreasingTimePredictorAxiomGenerator (parameters .subclassList );
156+ } else {
157+ logger .info ("Initializing the candidate axiom generator..." );
158+ generator = new CandidateAxiomGenerator (parameters .grammarFile );
159+ }
162160 } else {
163- logger .info ("Initializing the candidate axiom generator..." );
164- generator = new CandidateAxiomGenerator (parameters .grammarFile );
161+ logger .info ("launch test on a single axiom" );
165162 }
166163 } else {
167164 logger .info ("Reading axioms from file " + parameters .axiomFile + "..." );
@@ -176,6 +173,19 @@ public static void main(String[] args) {
176173
177174 executor = Executors .newSingleThreadExecutor ();
178175
176+ if (parameters .axiom == null ) {
177+ // as the test of a single axiom is return on standard output, we don't need to
178+ // write
179+ // file of the results
180+ try {
181+ output = new FileWriter (Global .OUTPUT_PATH + parameters .resultFile + ".json" );
182+ } catch (IOException e ) {
183+ logger .error (e .getMessage ());
184+ e .printStackTrace ();
185+ System .exit (1 );
186+ }
187+ }
188+
179189 while (true ) {
180190
181191 Axiom a = null ;
@@ -201,7 +211,14 @@ public static void main(String[] args) {
201211 }
202212 } else {
203213 try {
204- axiomName = axiomFile .readLine ();
214+ if (axiomFile == null && parameters .axiom != null ) {
215+ axiomName = parameters .axiom ;
216+ } else if (axiomFile != null && parameters .axiom == null ) {
217+ axiomName = axiomFile .readLine ();
218+ } else {
219+ logger .error ("'-a' and '-sa' are used at the same time" );
220+ System .exit (1 );
221+ }
205222 if (axiomName == null )
206223 break ;
207224 if (axiomName .isEmpty ())
@@ -232,32 +249,40 @@ public static void main(String[] args) {
232249 reportJSON .confirmations = a .confirmations ;
233250 if (a .numExceptions > 0 && a .numExceptions < 100 )
234251 reportJSON .exceptions = a .exceptions ;
252+
253+ // fill json results
254+ json .append (axiomName , reportJSON .toJSON ());
235255
236256 // print useful results
237257 logger .info ("Num. confirmations: " + a .numConfirmations );
238258 logger .info ("Num. exceptions: " + a .numExceptions );
239- logger .info ("Possibility = " + reportJSON .possibility );
240- logger .info ("Necessity = " + reportJSON .necessity );
259+ logger .info ("Possibility = " + a .possibility (). doubleValue () );
260+ logger .info ("Necessity = " + a .necessity (). doubleValue () );
241261
242- if (a instanceof SubClassOfAxiom && reportJSON .necessity > 1.0 / 3.0 ) {
262+ if (a instanceof SubClassOfAxiom && a .necessity (). doubleValue () > 1.0 / 3.0 ) {
243263 SubClassOfAxiom sa = (SubClassOfAxiom ) a ;
244- SubClassOfAxiom .maxTestTime .maxput (sa .timePredictor (), reportJSON . elapsedTime );
264+ SubClassOfAxiom .maxTestTime .maxput (sa .timePredictor (), t - t0 );
245265 }
246266
247- json .append (axiomName , reportJSON .toJSON ());
248-
267+ if (parameters .axiom != null ) {
268+ System .out .println ("[RES]" + json .toString ());
269+ break ;
270+ }
271+
249272 } else
250273 logger .warn ("Axiom type not supported yet!" );
251274 logger .info ("Test completed in " + (t - t0 ) + " ms." );
252275 }
253276 logger .info ("Done testing axioms. Exiting." );
254- try {
255- output .write (json .toString ());
256- output .close ();
257- } catch (IOException e ) {
258- logger .error ("I/O error while closing CSV writer: " + e .getMessage ());
259- e .printStackTrace ();
260- System .exit (1 );
277+ if (parameters .axiom == null ) {
278+ try {
279+ output .write (json .toString ());
280+ output .close ();
281+ } catch (IOException e ) {
282+ logger .error ("I/O error while closing CSV writer: " + e .getMessage ());
283+ e .printStackTrace ();
284+ System .exit (1 );
285+ }
261286 }
262287 System .exit (0 );
263288 }
0 commit comments