TuPrologIDEModel
The model layer of the tuProlog IDE: it owns the it.unibo.tuprolog.solve.Solver driving the GUI, the set of open in-memory files (a file is just an in-memory String associated to a File handle until saveFile is called), the currently selected query, and the resolution state machine (TuPrologIDEModel.State.IDLE ->TuPrologIDEModel.State.COMPUTING ->TuPrologIDEModel.State.SOLUTION -> ...).
The model exposes no direct getters for solutions, errors, or solver internals: instead, every observable change is published as an org.reactfx.EventStream (the onXxx properties below), which TuPrologIDEController subscribes to in order to keep the JavaFX views in sync. This mirrors the MVC pattern: TuPrologIDEController wires FXML widgets to this model, while this interface (and its default implementation, TuPrologIDEModelImpl) contains all the actual parsing/solving logic, built on top of it.unibo.tuprolog.solve.classic.ClassicSolverFactory-backed solvers loaded with it.unibo.tuprolog.solve.libs.oop.OOPLib and it.unibo.tuprolog.solve.libs.io.IOLib.
Example (headless-ish usage, as done by TuPrologIDEController):
val model = TuPrologIDEModel.of()
model.onNewSolution.subscribe { println(it.event) }
model.onError.subscribe { println("error: ${it.message}") }
val file = model.newFile()
model.setCurrentFile("father(tom, jerry).")
model.query = "father(tom, X)"
model.solveAll()Types
The three phases a TuPrologIDEModel cycles through while resolving a query.
Properties
The File whose in-memory content is used as the static knowledge base for the next resolution, if any.
The ExecutorService used to run resolution steps (solve, solveAll, next, nextAll) off the calling thread.
Fired for every TuPrologException that surfaces while parsing the current file/query or, more generally, driving the solver; used in place of throwing, since resolution happens asynchronously.
Fired by closeFile with the file that was closed.
Fired by newFile with the freshly created temporary file.
Fired by loadFile with the loaded file and its content.
Fired by selectFile (and indirectly by loadFile/newFile) with the newly selected file.
Fired every time the solver is rebuilt (by reset or customizeSolver), carrying a fresh solver snapshot.
Fired whenever the static knowledge base loaded into the solver changes (by reset or before a new resolution).
Fired once the whole resolution for a query is over (solutions exhausted, or stop was invoked).
Fired by reset, carrying a snapshot of the freshly rebuilt solver.
Fired right after a resolution step finishes computing, carrying the 1-based index of the solution just produced.
Fired right before a resolution step starts computing, carrying the 1-based index of the solution being sought.
Fired whenever solveOptions is reassigned to a different value.
Fired with every chunk of text written by the solver to its standard error channel.
Fired with every chunk of text written by the solver to its standard output channel.
The SolveOptions (e.g. timeout, it.unibo.tuprolog.solve.flags.TrackVariables flag) used by future resolutions.
The current phase of the resolution state machine; see State.
Functions
Forgets the in-memory content associated with file (without touching the file on disk) and fires onFileClosed.
Rebuilds the underlying solver applying customizer to it, e.g. to load extra it.unibo.tuprolog.solve.library.Library instances (as done by TuPrologIDEBuilder.customLibraries). The next resolution will run against the customized solver.
Reads file from disk, registers its content as an in-memory theory (see setFile), fires onFileLoaded, and selects it (see selectFile).
Creates a new empty temporary .pl file, registers it as the currently open/selected file (firing onFileCreated and, through loadFile, onFileLoaded and onFileSelected), and returns its handle.
Computes and publishes (via onNewSolution) the next solution of the resolution started by solve/solveAll.
Requests termination of the IDE by firing onQuit; this model does not exit the JVM itself, it is up to an onQuit subscriber (e.g. TuPrologIDEController) to do so.
Rebuilds the solver from scratch (discarding the dynamic knowledge base accumulated by previous resolutions), re-parses currentFile as the static knowledge base, and fires onReset followed by onNewStaticKb. Parsing errors in currentFile are reported through onError rather than thrown.
Marks file as currentFile and fires onFileSelected.
Shorthand for setFile(currentFile, theory).
Parses currentFile as the static knowledge base and query as the goal, then computes and publishes (via onNewSolution) only the first solution, leaving state as State.SOLUTION if more solutions may exist.
Like solve, but keeps computing and publishing every solution (via repeated onNewSolution events) until the resolution is exhausted or stop is called.
Interrupts an in-progress State.SOLUTION resolution, firing onQueryOver and bringing state back to State.IDLE.