commonMain.it.unibo.tuprolog.datalog.visitors.HeadVariablesOutsideNonNegatedLiterals.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datalog-jvm Show documentation
Show all versions of datalog-jvm Show documentation
Datalog-compliant utilities for knowledge representation
package it.unibo.tuprolog.datalog.visitors
import it.unibo.tuprolog.core.Clause
import it.unibo.tuprolog.core.Struct
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.core.Var
object HeadVariablesOutsideNonNegatedLiterals : AbstractClauseVisitor>() {
override fun reduce(results: Sequence>): Set =
buildSet {
for (vars in results.filter { it.isNotEmpty() }) {
addAll(vars)
}
}
override fun defaultValue(term: Term): Set = emptySet()
override fun visitClause(term: Clause): Set {
val positiveVariables = reduce(dispatchBody(term))
val headVariables = reduce(dispatchHead(term))
return headVariables.asSequence().filter { it !in positiveVariables }.toSet()
}
override fun visitVar(term: Var): Set = setOf(term)
override fun visitNegatedLiteral(literal: Struct): Set = emptySet()
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy