Class SimpleInMemoryGraphStore
java.lang.Object
fr.inria.rules.dlgpemodel.HasItemInfoImpl
fr.inria.rules.dlgpemodel.SentenceImpl
fr.inria.rules.integraal.storage.natives.SimpleInMemoryGraphStore
- 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 SimpleInMemoryGraphStore
extends fr.inria.rules.dlgpemodel.SentenceImpl
implements FactBase
This storage represents the atoms as a Graph in memory.
Nodes are Atoms
Vertices are Predicates and Terms used by the corresponding atoms.
There are also some indexes used to retrieve all the vertices corresponding to a given Predicate or Term.
-
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
ConstructorsConstructorDescriptionCreates a new SimpleInMemoryGraphStoreSimpleInMemoryGraphStore(Collection<Atom> atoms) Creates a new SimpleInMemoryGraphStore and adds all the given atoms to it -
Method Summary
Modifier and TypeMethodDescriptionbooleanStores the given atomsbooleanStores the given atombooleanaddAll(Collection<Atom> atoms) //////////////////////////////////////////////booleanTests whether a given atom is present in this data source.booleanestimateBound(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.getAtomsByTerm(Term term) Returns a stream over all atoms with the specified term.Returns a set of all the atoms in the sourceRecursively 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 variablesinthashCode()booleanAllows checking if this QueryableData provides the predicate pbooleanRemoves the given atomsbooleanRemoves the given atombooleanremoveAll(Collection<Atom> atoms) Removes the given atomslongsize()//////////////////////////////////////////////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 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
isEmpty, iteratorMethods inherited from interface QueryableData
estimateBound, evaluate, getSupportedOperationsMethods inherited from interface Sentence
getLabel, getPatterns, setLabelMethods inherited from interface TermCompound
getAllNestedTerms, getNestedTerms
-
Constructor Details
-
SimpleInMemoryGraphStore
public SimpleInMemoryGraphStore()Creates a new SimpleInMemoryGraphStore -
SimpleInMemoryGraphStore
Creates a new SimpleInMemoryGraphStore and adds all the given atoms to it- Parameters:
atoms- initial atoms of the graph
-
-
Method Details
-
size
public long size()//////////////////////////////////////////////- Specified by:
sizein interfaceMaterializedData- Returns:
- the number of atoms
-
add
-
addAll
////////////////////////////////////////////// -
add
-
removeAll
Description copied from interface:WritableRemoves the given atoms -
remove
-
remove
-
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
-
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
-
getAtomsByTerm
Description copied from interface:MaterializedDataReturns a stream over all atoms with the specified term.- Specified by:
getAtomsByTermin interfaceMaterializedData- Parameters:
term- to search- Returns:
- a stream over all atoms with the specified term
-
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
-
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
-
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.
-
contains
Description copied from interface:MaterializedDataTests whether a given atom is present in this data source.- Specified by:
containsin interfaceMaterializedData- Parameters:
atom- the atom to find- Returns:
- true iff this storage contains the given atom
-
equals
-
hashCode
-
toString
-
toDLGP
-
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. -
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
-