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.
  • Constructor Details

    • SimpleInMemoryGraphStore

      public SimpleInMemoryGraphStore()
      Creates a new SimpleInMemoryGraphStore
    • SimpleInMemoryGraphStore

      public SimpleInMemoryGraphStore(Collection<Atom> atoms)
      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:
      size in interface MaterializedData
      Returns:
      the number of atoms
    • 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)
      //////////////////////////////////////////////
      Specified by:
      addAll in interface Writable
      Parameters:
      atoms - to add
      Returns:
      true iff at least one atom is new
    • 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
    • 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
    • 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
    • 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
    • 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
    • getAtomsByPredicate

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

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

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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • 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
    • 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
    • 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