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

commonMain.it.unibo.tuprolog.solve.library.impl.ExtensionLibrary.kt Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package it.unibo.tuprolog.solve.library.impl

import it.unibo.tuprolog.core.Clause
import it.unibo.tuprolog.core.operators.Operator
import it.unibo.tuprolog.core.operators.OperatorSet
import it.unibo.tuprolog.solve.Signature
import it.unibo.tuprolog.solve.function.FunctionWrapper
import it.unibo.tuprolog.solve.function.LogicFunction
import it.unibo.tuprolog.solve.library.Library
import it.unibo.tuprolog.solve.library.Library.Companion.toMapEnsuringNoDuplicates
import it.unibo.tuprolog.solve.primitive.Primitive
import it.unibo.tuprolog.solve.primitive.PrimitiveWrapper
import it.unibo.tuprolog.solve.rule.RuleWrapper

@Suppress("MemberVisibilityCanBePrivate")
abstract class ExtensionLibrary(
    private val extended: Library,
) : AbstractLibrary() {
    override val alias: String
        get() = extended.alias

    override val operators: OperatorSet by lazy {
        extended.operators + OperatorSet(additionalOperators)
    }

    open val additionalOperators: Iterable
        get() = emptyList()

    final override val clauses: List by lazy {
        (extended.clauses.asSequence() + additionalRules.asSequence().map { it.implementation }).toList()
    }

    protected open val additionalRules: Iterable>
        get() = emptyList()

    override val primitives: Map by lazy {
        val initial = extended.primitives.asSequence().map { it.toPair() }
        val additional = additionalPrimitives.asSequence().map { it.descriptionPair }
        (initial + additional).toMapEnsuringNoDuplicates()
    }

    protected open val additionalPrimitives: Iterable>
        get() = emptyList()

    override val functions: Map by lazy {
        val initial = extended.functions.asSequence().map { it.toPair() }
        val additional = additionalFunctions.asSequence().map { it.descriptionPair }
        (initial + additional).toMapEnsuringNoDuplicates()
    }

    protected open val additionalFunctions: Iterable>
        get() = emptyList()

    override fun hasRule(signature: Signature): Boolean {
        return super.hasRule(signature)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy