All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.it.unibo.tuprolog.datalog.visitors.HeadVariablesOutsideNonNegatedLiterals.kt Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
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