Interface StorageRDF

  • All Known Implementing Classes:
    StorageSimpleMem, StorageTuples

    public interface StorageRDF
    A minimal interface for RDF storage. This is less that DatasetGraph or any of it's derived classes and it just concerned with Triples and Quads, not Graphs nor prefixes.

    Storage is split into the triples for the default graph and quads for the named graphs. In find(Node, Node, Node, Node) (find on the named graphs), null for the graph slot does not match the default graph.

    Concrete and Pattern Operations.

    Various API operations work on "concrete" terms. For example, add. These are marked "concrete operation" in their javadoc. They are not matching operations. A concrete term is one of a URI, blank node or literal. It is not null, Node.ANY nor a named variable. Any Triple or Quad must be composed of concrete terms.

    A pattern operation is one where the arguments are concrete terms or wildcard ANY. Such an operation will match zero or more triples or quads. Any Triple or Quad can use ANY.

    Pattern operations do not match named variables. Using Node.ANY rather than null is preferred in pattern operations but both are acceptable.

    • Method Detail

      • add

        default void add​(Triple triple)
        Add a triple to the default graph.

        Concrete operation.

      • add

        default void add​(Quad quad)
        Add a quad.

        Concrete operation.

      • delete

        default void delete​(Triple triple)
        Delete a triple from the default graph.

        Concrete operation.

      • delete

        default void delete​(Quad quad)
        Delete a quad from the default graph. All terms are concrete, and not Node#ANY. For delete-by-pattern, see removeAll(Node, Node, Node, Node).

        Concrete operation.

      • add

        void add​(Node s,
                 Node p,
                 Node o)
        Add a triple to the default graph.

        Concrete operation.

      • add

        void add​(Node g,
                 Node s,
                 Node p,
                 Node o)
        Add to a named graph.

        Concrete operation.

      • removeAll

        default void removeAll​(Node s,
                               Node p,
                               Node o)
        Delete all triples matching a find-like pattern.

        Pattern operation.

      • removeAll

        default void removeAll​(Node g,
                               Node s,
                               Node p,
                               Node o)
        Delete all quads matching a find-like pattern.

        Pattern operation.

      • findUnionGraph

        default java.util.Iterator<Triple> findUnionGraph​(Node s,
                                                          Node p,
                                                          Node o)
        Find in the union graph (union of all named graphs, not the default graph). An RDF graph is a set of triples - the union graph does not shows duplicates even if more than one named graph contains a given triple.
        Implementation Note:
        The default implementation of this operation involves the use of Stream.distinct() which is a stateful intermediate operation. Without additional internal knowledge, it is necessary to remember all triples in the stream so far to know whether the next triple is a duplicate or not. This can be a significant amount of intermediate space.

        An implementation may be able to exploit its internal representation to means that this operation can be implemented more efficient, for example, knowing that duplicate triples (same triple, from different graphs) will be adjacent in the stream so not requires the full cost of distinct to remove duplicates.

        Pattern operation.

      • find

        default java.util.Iterator<Quad> find​(Quad quad)
        Find in named graphs: does not look in the default graph.

        Pattern operation.

      • find

        java.util.Iterator<Quad> find​(Node g,
                                      Node s,
                                      Node p,
                                      Node o)
        Find in named graphs: does not look in the default graph.

        Pattern operation.

      • find

        default java.util.Iterator<Triple> find​(Triple triple)
        Find in the default graph.

        Pattern operation.

      • find

        java.util.Iterator<Triple> find​(Node s,
                                        Node p,
                                        Node o)
        Find in the default graph.

        Pattern operation.

      • stream

        default java.util.stream.Stream<Quad> stream​(Quad quad)
        Find in named graphs: does not look in the default graph.

        Pattern operation.

      • stream

        default java.util.stream.Stream<Quad> stream​(Node g,
                                                     Node s,
                                                     Node p,
                                                     Node o)
        Find in named graphs: does not look in the default graph.

        Pattern operation.

      • stream

        default java.util.stream.Stream<Triple> stream​(Triple triple)
        Find in the default graph.

        Pattern operations.

      • stream

        default java.util.stream.Stream<Triple> stream​(Node s,
                                                       Node p,
                                                       Node o)
        Find in the default graph.

        Pattern operation.

      • contains

        default boolean contains​(Triple triple)
        Test whether the default graph contains the triple.

        Pattern operation.

        Equivalent to find(triple).hasNext() or stream(triple).findAny().isPresent().

      • contains

        boolean contains​(Node s,
                         Node p,
                         Node o)
        Test whether the default graph contains the triple.

        Pattern operation.

        Equivalent to find(s,p,o).hasNext().

      • contains

        default boolean contains​(Quad quad)
        Test whether any named graph matches the quad.

        Pattern operation.

        Equivalent to find(quad).hasNext() or stream(quad).findAny().isPresent().

      • contains

        boolean contains​(Node g,
                         Node s,
                         Node p,
                         Node o)
        Test whether any named graph matches the quad.

        Pattern operation.

        Equivalent to find(g,s,p,o).hasNext().