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

commonMain.it.unibo.tuprolog.collections.AbstractMutableReteClauseCollection.kt Maven / Gradle / Ivy

Go to download

In-memory storage and indexing facilities for ordered and unordered knowledge bases composed by logic clauses

There is a newer version: 1.0.4
Show newest version
package it.unibo.tuprolog.collections

import it.unibo.tuprolog.collections.rete.custom.ReteTree
import it.unibo.tuprolog.core.Clause

internal abstract class AbstractMutableReteClauseCollection> :
    MutableClauseCollection, AbstractClauseCollection {
    @Suppress("ConvertSecondaryConstructorToPrimary")
    protected constructor(rete: ReteTree) : super(rete)

    override fun add(clause: Clause): Self {
        rete.assertZ(clause)
        return self
    }

    override fun addAll(clauses: Iterable): Self {
        clauses.forEach { rete.assertZ(it) }
        return self
    }

    override fun retrieve(clause: Clause): RetrieveResult {
        val retracted = rete.retractFirst(clause)
        return when {
            retracted.none() -> RetrieveResult.Failure(self)
            else -> RetrieveResult.Success(self, retracted.toList())
        }
    }

    override fun retrieveAll(clause: Clause): RetrieveResult {
        val retracted = rete.retractAll(clause)
        return when {
            retracted.none() -> RetrieveResult.Failure(self)
            else -> RetrieveResult.Success(self, retracted.toList())
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy