From 098feac0c18a4fd72c5cfc92a9415779b47e07fe Mon Sep 17 00:00:00 2001 From: anan02-admin Date: Thu, 9 Mar 2023 14:08:21 +0100 Subject: [PATCH] reading out pyclingo output in a proper way --- .../aspplugin/extensions/ClingoConfig.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pluginsystem/plugins/ASPPlugin/src/main/java/de/dfki/asr/ajan/pluginsystem/aspplugin/extensions/ClingoConfig.java b/pluginsystem/plugins/ASPPlugin/src/main/java/de/dfki/asr/ajan/pluginsystem/aspplugin/extensions/ClingoConfig.java index 29ffcce4..0fbae5cf 100644 --- a/pluginsystem/plugins/ASPPlugin/src/main/java/de/dfki/asr/ajan/pluginsystem/aspplugin/extensions/ClingoConfig.java +++ b/pluginsystem/plugins/ASPPlugin/src/main/java/de/dfki/asr/ajan/pluginsystem/aspplugin/extensions/ClingoConfig.java @@ -141,7 +141,10 @@ private boolean executeInternalSolver(Problem problem, final int i) { private boolean extractFactsFormSolverResult(final BufferedReader in, Problem problem) throws IOException, ClingoException { ArrayList factsFromSolver = new ArrayList(); + ArrayList factsFromPyClingo = new ArrayList(); boolean stat = true; + boolean pyclingo = false; + boolean readPyclingo = false; String line; /* example output of the solver: * ... more stupid stuff, looking for the Answer line @@ -153,12 +156,23 @@ private boolean extractFactsFormSolverResult(final BufferedReader in, Problem pr while ( (line = in.readLine()) != null) { LOG.info(line); if (line.startsWith("SATISFIABLE")) { - problem.setFacts(factsFromSolver); + if (pyclingo) { + problem.setFacts(factsFromPyClingo); + break; + } else { + problem.setFacts(factsFromSolver); + } } else if (line.startsWith("UNSATISFIABLE")) { stat = false; break; } else if (line.toLowerCase().contains("error") || line.startsWith("UNKNOWN") ) { throw new ClingoException("Solver error:" + line, null); + } else if (line.startsWith("pyclingo")) { + pyclingo = true; + } else if (pyclingo && line.startsWith("Answer")) { + readPyclingo = true; + } else if (readPyclingo) { + factsFromPyClingo.add(line); } else { // preemptively read all other lines. // they may be facts or error messages, but we won't know that