Skip to content

Commit

Permalink
feat: quick evaluate in factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilbocc committed Dec 20, 2024
1 parent fb536c9 commit 4ae6322
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package it.unibo.tuprolog.argumentation.core

import it.unibo.tuprolog.argumentation.core.dsl.arg2pScope
import it.unibo.tuprolog.argumentation.core.libs.ArgLibrary
import it.unibo.tuprolog.argumentation.core.libs.basic.FlagsBuilder
import it.unibo.tuprolog.argumentation.core.mining.graph
import it.unibo.tuprolog.argumentation.core.model.Graph
import it.unibo.tuprolog.core.Struct
import it.unibo.tuprolog.core.parsing.parse
import it.unibo.tuprolog.solve.classic.ClassicSolverFactory
import it.unibo.tuprolog.solve.flags.FlagStore
import it.unibo.tuprolog.solve.flags.TrackVariables
Expand Down Expand Up @@ -35,4 +40,16 @@ object Arg2pSolverFactory {
staticKb = Theory.parse(theory, it.operators()),
)
}

fun evaluate(kb: String, flags: FlagsBuilder): Sequence<Graph> =
arg2pScope {
default(
theory = kb,
settings = flags.create(),
).let { solver ->
solver.solve(Struct.parse("buildLabelSetsSilent"))
.filter { it.isYes }
.map { solver.graph() }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import it.unibo.tuprolog.dsl.logicProgramming
import it.unibo.tuprolog.solve.Solver
import kotlin.js.JsName

@JsName("mineActiveGraph")
fun Solver.graph() =
logicProgramming {
this@graph.solve("context_active"(X))
.filter { it.isYes }
.map { it.substitution[X]!!.toString().toInt() }
.map { context -> this@graph.graph(context) }
.firstOrNull() ?: error("couldn't find a graph")
}

@JsName("mineGraph")
fun Solver.graph(context: Int) =
this.arguments(context).let {
Expand Down

0 comments on commit 4ae6322

Please sign in to comment.