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
-
Field Summary
Fields inherited from interface fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo
IDENTFields inherited from interface fr.inria.rules.dlgpemodel.api.sentences.IPrintable
WRITER -
Constructor Summary
ConstructorsConstructorDescriptionFactBaseDelAtomsWrapper(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. -
Method Summary
Modifier and TypeMethodDescriptionbooleanStores the given atomsbooleanStores the given atombooleanaddAll(Collection<Atom> atoms) Stores the given atomsbooleanStores the given atomsvoidConcrete the virtual deletions by permanently removing all atoms currently marked as removed in the underlying fact base.booleanTests whether a given atom is present in this data source.estimateBound(BasicQuery query) 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.evaluate(BasicQuery query) Try to evaluate a basic querygetAtomicPattern(Predicate predicate) Get the basic pattern for a given predicategetAtomsByPredicate(Predicate predicate) Returns an iterator over all atoms with the specified predicate.Returns a stream over all atoms with the specified term.Returns a set of all the atoms in the sourcegetColumnsType(Predicate viewPredicate) Returns the column types used to expose a predicate.Recursively list all constantsgetDescription(Predicate viewPredicate) Returns the storage description associated with a predicate.Recursively list all literalsReturns a collection of all predicates in this Readable.getTerms()Streams the first-level terms contained in this object.getTermsByPredicatePosition(Predicate p, int position) Returns a stream over terms which are in a specific position in at least one atom with the given predicate.Returns the storage type associated with a predicate.Recursively list all variablesbooleanAllows checking if this QueryableData provides the predicate pbooleanRemoves the given atomsbooleanRemoves the given atombooleanremoveAll(Collection<Atom> atoms) Removes the given atomsbooleanRemoves the given atomslongsize()Counts the atoms contained in this data source.stream()Streams every atom contained in this data source.toDLGP()Renders this object in DLGP form.toString()Methods inherited from class fr.inria.rules.dlgpemodel.SentenceImpl
getPatterns, setPatternsMethods inherited from class fr.inria.rules.dlgpemodel.HasItemInfoImpl
getItemInfo, setItemInfoMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo
getIdentifier, getInfo, getItemInfo, setIdentifier, setInfo, setItemInfoMethods inherited from interface fr.inria.rules.dlgpemodel.api.sentences.IPrintable
toDLGPEMethods inherited from interface fr.inria.rules.dlgpemodel.api.sentences.ISentence
setPatternsMethods inherited from interface Iterable
forEach, spliteratorMethods inherited from interface MaterializedData
isEmpty, iteratorMethods inherited from interface QueryableData
estimateBound, evaluate, getSupportedOperationsMethods inherited from interface Sentence
getLabel, getPatterns, setLabelMethods inherited from interface TermCompound
getAllNestedTerms, getNestedTerms
-
Constructor Details
-
FactBaseDelAtomsWrapper
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 wrapremovedAtoms- 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
Description copied from interface:MaterializedDataStreams every atom contained in this data source.- Specified by:
streamin interfaceMaterializedData- Returns:
- a stream over all the atoms of the source
-
getAtomSet
Description copied from interface:MaterializedDataReturns a set of all the atoms in the source- Specified by:
getAtomSetin interfaceMaterializedData- Returns:
- a set containing all the atoms of the source
-
getVariables
Description copied from interface:TermCompoundRecursively list all variables- Specified by:
getVariablesin interfaceTermCompound- Returns:
- the set of variables included in this term
-
getTerms
Description copied from interface:TermCompoundStreams the first-level terms contained in this object.- Specified by:
getTermsin interfaceTermCompound- 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
Description copied from interface:TermCompoundRecursively list all constants- Specified by:
getConstantsin interfaceTermCompound- Returns:
- the set of constants included in this term
-
getLiterals
Description copied from interface:TermCompoundRecursively list all literals- Specified by:
getLiteralsin interfaceTermCompound- Returns:
- the set of literals included in this term
-
getAtomsByPredicate
Description copied from interface:MaterializedDataReturns an iterator over all atoms with the specified predicate.- Specified by:
getAtomsByPredicatein interfaceMaterializedData- Parameters:
predicate- to search- Returns:
- an iterator over all atoms with the specified predicate
-
getPredicates
Description copied from interface:QueryableDataReturns a collection of all predicates in this Readable.- Specified by:
getPredicatesin interfaceQueryableData- Returns:
- a collection of all predicates.
-
hasPredicate
Description copied from interface:QueryableDataAllows checking if this QueryableData provides the predicate p- Specified by:
hasPredicatein interfaceQueryableData- Parameters:
p- the predicate to look up- Returns:
- boolean that is true iff the QueryableData provides this predicate
-
getTermsByPredicatePosition
Description copied from interface:MaterializedDataReturns a stream over terms which are in a specific position in at least one atom with the given predicate.- Specified by:
getTermsByPredicatePositionin interfaceMaterializedData- Parameters:
p- predicateposition- 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
Description copied from interface:MaterializedDataReturns a stream over all atoms with the specified term.- Specified by:
getAtomsByTermin interfaceMaterializedData- Parameters:
t- to search- Returns:
- a stream over all atoms with the specified term
-
contains
Description copied from interface:MaterializedDataTests whether a given atom is present in this data source.- Specified by:
containsin interfaceMaterializedData- Parameters:
a- the atom to find- Returns:
- true iff this storage contains the given atom
-
size
public long size()Description copied from interface:MaterializedDataCounts the atoms contained in this data source.- Specified by:
sizein interfaceMaterializedData- Returns:
- the number of atoms
-
getDescription
Description copied from interface:FactBaseReturns the storage description associated with a predicate.- Specified by:
getDescriptionin interfaceFactBase- Parameters:
viewPredicate- a predicate- Returns:
- the description of the storage
-
getType
Description copied from interface:FactBaseReturns the storage type associated with a predicate. -
getColumnsType
Description copied from interface:FactBaseReturns the column types used to expose a predicate.- Specified by:
getColumnsTypein interfaceFactBase- Parameters:
viewPredicate- a predicate- Returns:
- the type of the columns for the given predicate
-
evaluate
Description copied from interface:QueryableDataTry to evaluate a basic query- Specified by:
evaluatein interfaceQueryableData- 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
Description copied from interface:QueryableDataEstimate 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:
estimateBoundin interfaceQueryableData- 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
Description copied from interface:QueryableDataGet the basic pattern for a given predicate- Specified by:
getAtomicPatternin interfaceQueryableData- Parameters:
predicate- the predicate for which we want to know the basic pattern- Returns:
- a basic pattern for predicate
-
add
-
add
-
addAll
Description copied from interface:WritableStores the given atoms -
addAll
-
remove
-
remove
-
removeAll
Description copied from interface:WritableRemoves the given atoms -
removeAll
-
toString
-
toDLGP
-