Class DefaultInMemoryAtomSet
java.lang.Object
fr.inria.rules.dlgpemodel.HasItemInfoImpl
fr.inria.rules.dlgpemodel.SentenceImpl
fr.inria.rules.integraal.storage.natives.DefaultInMemoryAtomSet
- 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 DefaultInMemoryAtomSet
extends fr.inria.rules.dlgpemodel.SentenceImpl
implements FactBase
The DefaultInMemoryAtomSet is a simple in memory atom set based on a java
set. It is a wrapper for any Collection that implements the Set interface.
Recommended sets: - By default, use a HashSet<Atom> - If you want an
ordered set, you can use a TreeSet<Atom> - If you want to access
elements in the order there are added into the set, use
LinkedHashSet<Atom> that combine a HashSet and a Linked List
/!\ Disclaimer: this class should not be used with a big set, there are no indexes!
- 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
ConstructorsConstructorDescriptionDefault constructor By default, we use a HashSet<Atom>DefaultInMemoryAtomSet(Atom... atoms) A copy constructor using a variable number of AtomsDefaultInMemoryAtomSet(Collection<Atom> collection) A copy constructor that can copy any Collection<Atom>DefaultInMemoryAtomSet(Set<Atom> javaAtomSet) This constructor allows you to use any Collection that implements the Set<Atom> interface -
Method Summary
Modifier and TypeMethodDescriptionbooleanStores the given atomsbooleanStores the given atombooleanaddAll(Collection<Atom> atoms) Stores the given atomsestimateBound(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 predicateReturns an iterator over all atoms with the specified predicate.Returns a set of all the atoms in the sourcegetDescription(Predicate viewPredicate) Returns the storage description associated with a predicate.Returns 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.booleanAllows checking if this QueryableData provides the predicate pbooleanRemoves the given atomsbooleanRemoves the given atombooleanremoveAll(Collection<Atom> atoms) Removes the given atomsbooleanRemoves the given atomsstream()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 FactBase
clear, getColumnsType, getHeadMethods 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
contains, getAtomsByTerm, isEmpty, iterator, sizeMethods inherited from interface QueryableData
estimateBound, evaluate, getSupportedOperationsMethods inherited from interface Sentence
getLabel, getPatterns, setLabelMethods inherited from interface TermCompound
getAllNestedTerms, getConstants, getLiterals, getNestedTerms, getVariables
-
Constructor Details
-
DefaultInMemoryAtomSet
public DefaultInMemoryAtomSet()Default constructor By default, we use a HashSet<Atom> -
DefaultInMemoryAtomSet
-
DefaultInMemoryAtomSet
A copy constructor that can copy any Collection<Atom>- Parameters:
collection- the collection to copy
-
DefaultInMemoryAtomSet
A copy constructor using a variable number of Atoms- Parameters:
atoms- the atoms to initialize the storage with
-
-
Method Details
-
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
-
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
-
getAtomsByPredicate
Description copied from interface:MaterializedDataReturns an iterator over all atoms with the specified predicate.- Specified by:
getAtomsByPredicatein interfaceMaterializedData- Parameters:
p- 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.
-
add
-
addAll
Description copied from interface:WritableStores the given atoms -
add
-
remove
-
remove
-
removeAll
Description copied from interface:WritableRemoves the given atoms -
removeAll
-
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
-
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. -
toString
-
toDLGP
-
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.
-