Coverage Summary for Class: Arg2pSolverFactory (it.unibo.tuprolog.argumentation.core)

Class Class, % Method, % Branch, % Line, % Instruction, %
Arg2pSolverFactory 100% (1/1) 100% (6/6) 75% (3/4) 100% (20/20) 96.6% (142/147)


 package it.unibo.tuprolog.argumentation.core
 
 import it.unibo.tuprolog.argumentation.Arg2pException
 import it.unibo.tuprolog.argumentation.core.engine.Arg2pPrologSolverFactory
 import it.unibo.tuprolog.argumentation.core.model.Graph
 import it.unibo.tuprolog.argumentation.core.model.mining.graph
 import it.unibo.tuprolog.argumentation.core.modules.ArgLibrary
 import it.unibo.tuprolog.argumentation.core.runtime.Arg2pUnificator
 import it.unibo.tuprolog.argumentation.core.runtime.settings.FlagsBuilder
 import it.unibo.tuprolog.argumentation.core.runtime.theory.RuleAnnotations
 import it.unibo.tuprolog.core.Atom
 import it.unibo.tuprolog.solve.Solution
 import it.unibo.tuprolog.solve.channel.OutputChannel
 import it.unibo.tuprolog.solve.flags.FlagStore
 import it.unibo.tuprolog.solve.flags.Unknown
 import it.unibo.tuprolog.solve.library.Runtime
 import it.unibo.tuprolog.theory.parsing.parse
 
 object Arg2pSolverFactory {
     fun of(
         theory: String,
         settings: ArgLibrary,
         staticLibs: Iterable<ArgLibrary>,
         dynamicLibs: Iterable<ArgLibrary>,
     ) = solverOf(Arg2pSolver.of(staticLibs + listOf(settings), dynamicLibs), theory)
 
     fun default(
         theory: String = "",
         settings: ArgLibrary = FlagsBuilder().create(),
         staticLibs: Iterable<ArgLibrary> = emptyList(),
         dynamicLibs: Iterable<ArgLibrary> = emptyList(),
     ) = solverOf(Arg2pSolver.default(staticLibs + listOf(settings), dynamicLibs), theory)
 
     /**
      * A solver of the libraries of [arg2p], and the [extra] ones, for [theory] (its clauses tagged with the
      * identifiers of their comments, see RuleAnnotations): unknown predicates fail (the hooks a theory may define,
      * as conflict/2 and sup/2, are called whether it does or not), what it prints goes to [output] (the standard
      * output by default)
      */
     fun solverOf(
         arg2p: Arg2pSolver,
         theory: String,
         extra: Runtime = Runtime.empty(),
         output: OutputChannel<String> = OutputChannel.stdOut(),
     ) = Arg2pPrologSolverFactory.mutableSolverWithDefaultBuiltins(
         unificator = Arg2pUnificator,
         otherLibraries = arg2p.to2pLibraries() + extra,
         flags = FlagStore.DEFAULT.set(Unknown, Unknown.FAIL),
         staticKb = RuleAnnotations.parse(theory, arg2p.operators()),
         stdOut = output,
     )
 
     /**
      * The graph of each labelling of [kb] with [flags]: none if the theory has no labelling, an [Arg2pException] if
      * the evaluation halts (a theory its profile refuses, say)
      */
     fun evaluate(
         kb: String,
         flags: FlagsBuilder,
     ): Sequence<Graph> =
         default(theory = kb, settings = flags.create()).let { solver ->
             solver
                 .solve(Atom.of("buildLabelSetsSilent"))
                 .onEach { if (it is Solution.Halt) throw Arg2pException(it.exception.message ?: it.exception.toString()) }
                 .filter { it.isYes }
                 .map { solver.graph() }
         }
 }