Class FactBaseDelAtomsWrapper

java.lang.Object
fr.inria.rules.dlgpemodel.HasItemInfoImpl
fr.inria.rules.dlgpemodel.SentenceImpl
fr.inria.rules.integraal.storage.natives.FactBaseDelAtomsWrapper
All Implemented Interfaces:
fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo, fr.inria.rules.dlgpemodel.api.sentences.IFact, fr.inria.rules.dlgpemodel.api.sentences.IPrintable, fr.inria.rules.dlgpemodel.api.sentences.ISentence, Labeled, Printable, Sentence, MaterializedData, QueryableData, Writable, FactBase, TermCompound, Iterable<Atom>

public class FactBaseDelAtomsWrapper extends fr.inria.rules.dlgpemodel.SentenceImpl implements FactBase
This class is a wrapper around a fact base that allows virtual deletions of atoms. Atoms are not physically removed from the wrapped fact base, but are virtually marked as removed. When querying the fact base through this wrapper, any atom marked as removed will be excluded from the results.

This class is useful for scenarios where you want to simulate the removal of facts from a knowledge base without actually deleting the data, allowing flexible "undo" operations or temporary filters.

Additionally, this class provides a method to permanently remove atoms from the underlying fact base after they have been marked for virtual deletion.

Author:
Guillaume Pérution-Kihli
  • Constructor Details

    • FactBaseDelAtomsWrapper

      public FactBaseDelAtomsWrapper(FactBase factBase, Set<Atom> removedAtoms)
      Constructs a new FactBaseDelAtomsWrapper instance, wrapping the provided fact base and initializing the set of atoms to be virtually removed.
      Parameters:
      factBase - the underlying fact base to wrap
      removedAtoms - the set of atoms to be virtually removed
  • Method Details

    • concreteDeletions

      public void concreteDeletions()
      Concrete the virtual deletions by permanently removing all atoms currently marked as removed in the underlying fact base. After this method, the set of removed atoms will be cleared.
    • stream

      public Stream<Atom> stream()
      Description copied from interface: MaterializedData
      Streams every atom contained in this data source.
      Specified by:
      stream in interface MaterializedData
      Returns:
      a stream over all the atoms of the source
    • getAtomSet

      public Set<Atom> getAtomSet()
      Description copied from interface: MaterializedData
      Returns a set of all the atoms in the source
      Specified by:
      getAtomSet in interface MaterializedData
      Returns:
      a set containing all the atoms of the source
    • getVariables

      public Stream<Variable> getVariables()
      Description copied from interface: TermCompound
      Recursively list all variables
      Specified by:
      getVariables in interface TermCompound
      Returns:
      the set of variables included in this term
    • getTerms

      public Stream<Term> getTerms()
      Description copied from interface: TermCompound
      Streams the first-level terms contained in this object.
      Specified by:
      getTerms in interface TermCompound
      Returns:
      a stream over all the non-nested terms (i.e., all terms that are not themselves in a compound term) For instance, for p(a,g(b)), it returns a and g(b) but not b.
    • getConstants

      public Stream<Constant> getConstants()
      Description copied from interface: TermCompound
      Recursively list all constants
      Specified by:
      getConstants in interface TermCompound
      Returns:
      the set of constants included in this term
    • getLiterals

      public Stream<Literal<?>> getLiterals()
      Description copied from interface: TermCompound
      Recursively list all literals
      Specified by:
      getLiterals in interface TermCompound
      Returns:
      the set of literals included in this term
    • getAtomsByPredicate

      public Stream<Atom> getAtomsByPredicate(Predicate predicate)
      Description copied from interface: MaterializedData
      Returns an iterator over all atoms with the specified predicate.
      Specified by:
      getAtomsByPredicate in interface MaterializedData
      Parameters:
      predicate - to search
      Returns:
      an iterator over all atoms with the specified predicate
    • getPredicates

      public Stream<Predicate> getPredicates()
      Description copied from interface: QueryableData
      Returns a collection of all predicates in this Readable.
      Specified by:
      getPredicates in interface QueryableData
      Returns:
      a collection of all predicates.
    • hasPredicate

      public boolean hasPredicate(Predicate p)
      Description copied from interface: QueryableData
      Allows checking if this QueryableData provides the predicate p
      Specified by:
      hasPredicate in interface QueryableData
      Parameters:
      p - the predicate to look up
      Returns:
      boolean that is true iff the QueryableData provides this predicate
    • getTermsByPredicatePosition

      public Stream<Term> getTermsByPredicatePosition(Predicate p, int position)
      Description copied from interface: MaterializedData
      Returns a stream over terms which are in a specific position in at least one atom with the given predicate.
      Specified by:
      getTermsByPredicatePosition in interface MaterializedData
      Parameters:
      p - predicate
      position - the position of the term in atoms, positions starts from 0.
      Returns:
      a stream over terms which appear in the specified position of the specified predicate.
    • getAtomsByTerm

      public Stream<Atom> getAtomsByTerm(Term t)
      Description copied from interface: MaterializedData
      Returns a stream over all atoms with the specified term.
      Specified by:
      getAtomsByTerm in interface MaterializedData
      Parameters:
      t - to search
      Returns:
      a stream over all atoms with the specified term
    • contains

      public boolean contains(Atom a)
      Description copied from interface: MaterializedData
      Tests whether a given atom is present in this data source.
      Specified by:
      contains in interface MaterializedData
      Parameters:
      a - the atom to find
      Returns:
      true iff this storage contains the given atom
    • size

      public long size()
      Description copied from interface: MaterializedData
      Counts the atoms contained in this data source.
      Specified by:
      size in interface MaterializedData
      Returns:
      the number of atoms
    • getDescription

      public FactBaseDescription getDescription(Predicate viewPredicate)
      Description copied from interface: FactBase
      Returns the storage description associated with a predicate.
      Specified by:
      getDescription in interface FactBase
      Parameters:
      viewPredicate - a predicate
      Returns:
      the description of the storage
    • getType

      public FactBaseType getType(Predicate viewPredicate)
      Description copied from interface: FactBase
      Returns the storage type associated with a predicate.
      Specified by:
      getType in interface FactBase
      Parameters:
      viewPredicate - a predicate
      Returns:
      the type of storage used for the given predicate
    • getColumnsType

      public List<ColumnType> getColumnsType(Predicate viewPredicate)
      Description copied from interface: FactBase
      Returns the column types used to expose a predicate.
      Specified by:
      getColumnsType in interface FactBase
      Parameters:
      viewPredicate - a predicate
      Returns:
      the type of the columns for the given predicate
    • evaluate

      public Stream<List<Term>> evaluate(BasicQuery query) throws EvaluationException
      Description copied from interface: QueryableData
      Try to evaluate a basic query
      Specified by:
      evaluate in interface QueryableData
      Parameters:
      query - the query to evaluate
      Returns:
      Empty if the query is not evaluable, otherwise a stream containing substitutions that are the answers to the query
      Throws:
      EvaluationException - if query evaluation fails
    • estimateBound

      public Optional<Long> estimateBound(BasicQuery query)
      Description copied from interface: QueryableData
      Estimate the number of answers to a query The estimation is the upper bound, meaning the actual number of answers will not exceed this number. Implementations may return an empty Optional if they cannot provide an estimation.
      Specified by:
      estimateBound in interface QueryableData
      Parameters:
      query - the query for which we want to know the upper bound
      Returns:
      an Optional containing the estimated upper bound of answers, or an empty Optional if estimation is not possible
    • getAtomicPattern

      public AtomicPattern getAtomicPattern(Predicate predicate)
      Description copied from interface: QueryableData
      Get the basic pattern for a given predicate
      Specified by:
      getAtomicPattern in interface QueryableData
      Parameters:
      predicate - the predicate for which we want to know the basic pattern
      Returns:
      a basic pattern for predicate
    • add

      public boolean add(Atom atom)
      Description copied from interface: Writable
      Stores the given atom
      Specified by:
      add in interface Writable
      Parameters:
      atom - to add
      Returns:
      true iff the atom is new
    • add

      public boolean add(FOFormula atoms)
      Description copied from interface: Writable
      Stores the given atoms
      Specified by:
      add in interface Writable
      Parameters:
      atoms - to add
      Returns:
      true iff at least one atom is new
    • addAll

      public boolean addAll(Collection<Atom> atoms)
      Description copied from interface: Writable
      Stores the given atoms
      Specified by:
      addAll in interface Writable
      Parameters:
      atoms - to add
      Returns:
      true iff at least one atom is new
    • addAll

      public boolean addAll(Stream<Atom> atoms)
      Description copied from interface: Writable
      Stores the given atoms
      Specified by:
      addAll in interface Writable
      Parameters:
      atoms - to add
      Returns:
      true iff at least one atom is new
    • remove

      public boolean remove(Atom atom)
      Description copied from interface: Writable
      Removes the given atom
      Specified by:
      remove in interface Writable
      Parameters:
      atom - to remove
      Returns:
      true iff the atom is removed
    • remove

      public boolean remove(FOFormula atoms)
      Description copied from interface: Writable
      Removes the given atoms
      Specified by:
      remove in interface Writable
      Parameters:
      atoms - to remove
      Returns:
      true iff at least one atom is removed
    • removeAll

      public boolean removeAll(Collection<Atom> atoms)
      Description copied from interface: Writable
      Removes the given atoms
      Specified by:
      removeAll in interface Writable
      Parameters:
      atoms - to remove
      Returns:
      true iff at least one atom is removed
    • removeAll

      public boolean removeAll(Stream<Atom> atoms)
      Description copied from interface: Writable
      Removes the given atoms
      Specified by:
      removeAll in interface Writable
      Parameters:
      atoms - to remove
      Returns:
      true iff at least one atom is removed
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toDLGP

      public String toDLGP()
      Description copied from interface: Printable
      Renders this object in DLGP form.
      Specified by:
      toDLGP in interface Printable
      Returns:
      the DLGP serialization