Class TripleStoreStore

java.lang.Object
fr.inria.rules.dlgpemodel.HasItemInfoImpl
fr.inria.rules.dlgpemodel.SentenceImpl
fr.inria.rules.integraal.storage.external.triplestore.TripleStoreStore
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, DatalogDelegable, MaterializedData, QueryableData, Writable, FactBase, TermCompound, Iterable<Atom>

public class TripleStoreStore extends fr.inria.rules.dlgpemodel.SentenceImpl implements FactBase, DatalogDelegable
This wrapper represents Triplestores handled by InteGraal. They are accessed by translating atoms, queries and even some rules into SPARQL queries or simple Statement if possible
  • Constructor Details

    • TripleStoreStore

      public TripleStoreStore()
      Creates a new Triple store kept in memory
    • TripleStoreStore

      public TripleStoreStore(org.eclipse.rdf4j.repository.Repository repo)
      Creates a new wrapper over the given repository
      Parameters:
      repo - the SPARQL repository from RDF4J
    • TripleStoreStore

      public TripleStoreStore(TermFactory tf, PredicateFactory pf)
      Creates a new Triple store kept in memory with the user-given factories
      Parameters:
      tf - the term factory
      pf - the predicate factory
    • TripleStoreStore

      public TripleStoreStore(String endpointUrl)
      Creates a new Triple store over the given endpoint url
      Parameters:
      endpointUrl - the url of the endpoint
    • TripleStoreStore

      public TripleStoreStore(String endpointUrl, TermFactory tf, PredicateFactory pf)
      Creates a new Triple store over the given endpoint url with user-given factories
      Parameters:
      endpointUrl - the url of the endpoint
      tf - the term factory
      pf - the predicate factory
  • Method Details

    • 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
    • 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
    • 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
    • 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.
    • 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
    • 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
    • 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
    • delegate

      public boolean delegate(Collection<FORule> rules)
      Description copied from interface: DatalogDelegable
      Apply all the given (datalog) rules.
      Specified by:
      delegate in interface DatalogDelegable
      Parameters:
      rules - the rules to apply
      Returns:
      true iff at least one atom have been produced by the application of the rules
    • delegate

      public Iterator<Substitution> delegate(FOQuery<?> query, boolean countAnswersOnly)
      Description copied from interface: DatalogDelegable
      Evaluate the given (conjunctive) query
      Specified by:
      delegate in interface DatalogDelegable
      Parameters:
      query - the query to evaluate
      countAnswersOnly - true iff the query has to return only the number of answers
      Returns:
      an Iterator of Substitution over all the answers of the given query with respect to the query answer variables.
    • getAtomsByTerm

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