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

Link copied to clipboard
object Companion
Link copied to clipboard

The three phases a TuPrologIDEModel cycles through while resolving a query.

Properties

Link copied to clipboard
abstract val currentFile: File?

The File whose in-memory content is used as the static knowledge base for the next resolution, if any.

Link copied to clipboard

The ExecutorService used to run resolution steps (solve, solveAll, next, nextAll) off the calling thread.

Link copied to clipboard
abstract val onError: EventStream<TuPrologException>

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.

Link copied to clipboard
abstract val onFileClosed: EventStream<File>

Fired by closeFile with the file that was closed.

Link copied to clipboard
abstract val onFileCreated: EventStream<File>

Fired by newFile with the freshly created temporary file.

Link copied to clipboard
abstract val onFileLoaded: EventStream<Pair<File, String>>

Fired by loadFile with the loaded file and its content.

Link copied to clipboard
abstract val onFileSelected: EventStream<File>

Fired by selectFile (and indirectly by loadFile/newFile) with the newly selected file.

Link copied to clipboard
abstract val onNewQuery: EventStream<SolverEvent<Struct>>

Fired by solve/solveAll with the parsed goal, right before the first solution is requested.

Link copied to clipboard
abstract val onNewSolution: EventStream<SolverEvent<Solution>>

Fired every time a new Solution (yes/no/halt) is produced by solve, solveAll, next, or nextAll.

Link copied to clipboard
abstract val onNewSolver: EventStream<SolverEvent<Unit>>

Fired every time the solver is rebuilt (by reset or customizeSolver), carrying a fresh solver snapshot.

Link copied to clipboard
abstract val onNewStaticKb: EventStream<SolverEvent<Unit>>

Fired whenever the static knowledge base loaded into the solver changes (by reset or before a new resolution).

Link copied to clipboard
abstract val onQueryChanged: EventStream<String>
Link copied to clipboard
abstract val onQueryOver: EventStream<SolverEvent<Struct>>

Fired once the whole resolution for a query is over (solutions exhausted, or stop was invoked).

Link copied to clipboard
abstract val onQuit: EventStream<Unit>

Fired by quit; see quit for why acting on it is the subscriber's responsibility.

Link copied to clipboard
abstract val onReset: EventStream<SolverEvent<Unit>>

Fired by reset, carrying a snapshot of the freshly rebuilt solver.

Link copied to clipboard
abstract val onResolutionOver: EventStream<SolverEvent<Int>>

Fired right after a resolution step finishes computing, carrying the 1-based index of the solution just produced.

Link copied to clipboard
abstract val onResolutionStarted: EventStream<SolverEvent<Int>>

Fired right before a resolution step starts computing, carrying the 1-based index of the solution being sought.

Link copied to clipboard
abstract val onSolveOptionsChanged: EventStream<SolveOptions>

Fired whenever solveOptions is reassigned to a different value.

Link copied to clipboard
abstract val onStderrPrinted: EventStream<String>

Fired with every chunk of text written by the solver to its standard error channel.

Link copied to clipboard
abstract val onStdoutPrinted: EventStream<String>

Fired with every chunk of text written by the solver to its standard output channel.

Link copied to clipboard
abstract val onWarning: EventStream<Warning>

Fired for every Warning emitted by the solver while solving.

Link copied to clipboard
abstract var query: String

The Prolog goal (as unparsed text) that solve/solveAll will parse and resolve against the current solver.

Link copied to clipboard

The SolveOptions (e.g. timeout, it.unibo.tuprolog.solve.flags.TrackVariables flag) used by future resolutions.

Link copied to clipboard

The current phase of the resolution state machine; see State.

Functions

Link copied to clipboard
abstract fun closeFile(file: File)

Forgets the in-memory content associated with file (without touching the file on disk) and fires onFileClosed.

Link copied to clipboard
abstract fun customizeSolver(customizer: (MutableSolver) -> MutableSolver)

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.

Link copied to clipboard
abstract fun getFile(file: File): String

Returns the in-memory content currently associated with file.

Link copied to clipboard
abstract fun loadFile(file: File)

Reads file from disk, registers its content as an in-memory theory (see setFile), fires onFileLoaded, and selects it (see selectFile).

Link copied to clipboard
abstract fun newFile(): File

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.

Link copied to clipboard
abstract fun next()

Computes and publishes (via onNewSolution) the next solution of the resolution started by solve/solveAll.

Link copied to clipboard
abstract fun nextAll()

Like next, but keeps computing and publishing solutions until exhaustion or stop.

Link copied to clipboard
abstract fun quit()

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.

Link copied to clipboard
abstract fun renameFile(file: File, newFile: File)

Moves the in-memory content associated with file to newFile, e.g. after a "save as" operation.

Link copied to clipboard
abstract fun reset()

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.

Link copied to clipboard
abstract fun saveFile(file: File)

Writes the in-memory content associated with file (see getFile) back to disk.

Link copied to clipboard
abstract fun selectFile(file: File)

Marks file as currentFile and fires onFileSelected.

Link copied to clipboard
abstract fun setCurrentFile(theory: String)

Shorthand for setFile(currentFile, theory).

Link copied to clipboard
abstract fun setFile(file: File, theory: String)

Registers or updates the in-memory content associated with file, without touching the file on disk.

Link copied to clipboard
abstract fun setStdin(content: String)

Sets the content of the solver's standard input channel, consumed by input-reading built-ins (e.g. read/1).

Link copied to clipboard
abstract fun solve()

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.

Link copied to clipboard
abstract fun solveAll()

Like solve, but keeps computing and publishing every solution (via repeated onNewSolution events) until the resolution is exhausted or stop is called.

Link copied to clipboard
abstract fun stop()

Interrupts an in-progress State.SOLUTION resolution, firing onQueryOver and bringing state back to State.IDLE.