Documentation ¶
Index ¶
- func MarshalTriple(triple IndexTriple) ([]byte, error)
- func UnmarshalTriple(dest *IndexTriple, src []byte) error
- type DiskEngine
- func (de DiskEngine[Label, Datum]) Data() (imap.KeyValueStore[imap.ID, Datum], error)
- func (de DiskEngine[Label, Datum]) Inverses() (imap.KeyValueStore[imap.ID, imap.ID], error)
- func (de DiskEngine[Label, Datum]) POSIndex() (ThreeStorage, error)
- func (de DiskEngine[Label, Datum]) PSOIndex() (ThreeStorage, error)
- func (de DiskEngine[Label, Datum]) Triples() (imap.KeyValueStore[imap.ID, IndexTriple], error)
- type Engine
- type IGraph
- func (index *IGraph[Label, Datum]) AddData(subject, predicate Label, object Datum) error
- func (index *IGraph[Label, Datum]) AddTriple(subject, predicate, object Label) error
- func (index *IGraph[Label, Datum]) Close() error
- func (index *IGraph[Label, Datum]) Finalize() error
- func (index *IGraph[Label, Datum]) IdentityMap(storage imap.KeyValueStore[Label, Label]) error
- func (index *IGraph[Label, Datum]) MarkIdentical(new, old Label) error
- func (index *IGraph[Label, Datum]) MarkInverse(left, right Label) error
- func (index *IGraph[Label, Datum]) PathsStarting(predicate, object Label) (*Paths[Label, Datum], error)
- func (index *IGraph[Label, Datum]) Reset(engine Engine[Label, Datum]) (err error)
- func (index *IGraph[Label, Datum]) Stats() Stats
- func (index *IGraph[Label, Datum]) Triple(id imap.ID) (triple Triple[Label, Datum], err error)
- func (index *IGraph[Label, Datum]) TripleCount() (count uint64, err error)
- type IndexTriple
- type MemoryEngine
- func (MemoryEngine[Label, Datum]) Data() (imap.KeyValueStore[imap.ID, Datum], error)
- func (MemoryEngine[Label, Datum]) Inverses() (imap.KeyValueStore[imap.ID, imap.ID], error)
- func (MemoryEngine[Label, Datum]) POSIndex() (ThreeStorage, error)
- func (MemoryEngine[Label, Datum]) PSOIndex() (ThreeStorage, error)
- func (MemoryEngine[Label, Datum]) Triples() (imap.KeyValueStore[imap.ID, IndexTriple], error)
- type Path
- func (path *Path[Label, Datum]) Datum() (datum Datum, ok bool, err error)
- func (path *Path[Label, Datum]) Edges() ([]Label, error)
- func (path *Path[Label, Datum]) Node(index int) (Label, error)
- func (path *Path[Label, Datum]) Nodes() ([]Label, error)
- func (result *Path[URI, Datum]) String() string
- func (path *Path[Label, Datum]) Triples() ([]Triple[Label, Datum], error)
- type Paths
- type Role
- type Stats
- type ThreeDiskHash
- func (tlm *ThreeDiskHash) Add(a, b, c imap.ID, l imap.ID, conflict func(old, new imap.ID) (imap.ID, error)) (conflicted bool, err error)
- func (tlm *ThreeDiskHash) Close() (err error)
- func (tlm *ThreeDiskHash) Count() (total int64, err error)
- func (tlm *ThreeDiskHash) Fetch(a, b imap.ID, f func(c imap.ID, l imap.ID) error) error
- func (tlm ThreeDiskHash) Finalize() error
- func (tlm *ThreeDiskHash) Has(a, b, c imap.ID) (id imap.ID, ok bool, err error)
- type ThreeHash
- func (tlm ThreeHash) Add(a, b, c imap.ID, l imap.ID, conflict func(old, new imap.ID) (imap.ID, error)) (conflicted bool, err error)
- func (tlm *ThreeHash) Close() error
- func (tlm ThreeHash) Count() (total int64, err error)
- func (tlm ThreeHash) Fetch(a, b imap.ID, f func(c imap.ID, l imap.ID) error) error
- func (tlm ThreeHash) Finalize() error
- func (tlm ThreeHash) Has(a, b, c imap.ID) (imap.ID, bool, error)
- type ThreeItem
- type ThreeStorage
- type Triple
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalTriple ¶
func MarshalTriple(triple IndexTriple) ([]byte, error)
func UnmarshalTriple ¶
func UnmarshalTriple(dest *IndexTriple, src []byte) error
Types ¶
type DiskEngine ¶
type DiskEngine[Label comparable, Datum any] struct { imap.DiskEngine[Label] MarshalDatum func(datum Datum) ([]byte, error) UnmarshalDatum func(dest *Datum, src []byte) error }
DiskEngine represents an engine that stores everything on disk
func (DiskEngine[Label, Datum]) Data ¶
func (de DiskEngine[Label, Datum]) Data() (imap.KeyValueStore[imap.ID, Datum], error)
func (DiskEngine[Label, Datum]) Inverses ¶
func (de DiskEngine[Label, Datum]) Inverses() (imap.KeyValueStore[imap.ID, imap.ID], error)
func (DiskEngine[Label, Datum]) POSIndex ¶
func (de DiskEngine[Label, Datum]) POSIndex() (ThreeStorage, error)
func (DiskEngine[Label, Datum]) PSOIndex ¶
func (de DiskEngine[Label, Datum]) PSOIndex() (ThreeStorage, error)
func (DiskEngine[Label, Datum]) Triples ¶
func (de DiskEngine[Label, Datum]) Triples() (imap.KeyValueStore[imap.ID, IndexTriple], error)
type Engine ¶
type Engine[Label comparable, Datum any] interface { imap.Engine[Label] Data() (imap.KeyValueStore[imap.ID, Datum], error) Triples() (imap.KeyValueStore[imap.ID, IndexTriple], error) Inverses() (imap.KeyValueStore[imap.ID, imap.ID], error) PSOIndex() (ThreeStorage, error) POSIndex() (ThreeStorage, error) }
Engine represents an object that creates storages for an IGraph
type IGraph ¶
type IGraph[Label comparable, Datum any] struct { // contains filtered or unexported fields }
IGraph represents a searchable index of a directed labeled graph with optionally attached Data.
Labels are used for nodes and edges. This means that the graph is defined by triples of the form (subject Label, predicate Label, object Label). See [AddTriple].
Datum is used for data associated with the specific nodes. See [AddDatum].
The zero value represents an empty index, but is otherwise not ready to be used. To fill an index, it first needs to be [Reset], and then [Finalize]d.
IGraph may not be modified concurrently, however it is possible to run several queries concurrently.
func (*IGraph[Label, Datum]) AddData ¶
AddData inserts a subject-predicate-data triple into the index. Adding multiple items to a specific subject with a specific predicate is supported.
Reset must have been called, or this function may panic. After all Add operations have finished, Finalize must be called.
func (*IGraph[Label, Datum]) AddTriple ¶
AddTriple inserts a subject-predicate-object triple into the index. Adding a triple more than once has no effect.
Reset must have been called, or this function may panic. After all Add operations have finished, Finalize must be called.
func (*IGraph[Label, Datum]) Finalize ¶
Finalize finalizes any adding operations into this graph.
Finalize must be called before any query is performed, but after any calls to the Add* methods. Calling finalize multiple times is valid.
func (*IGraph[Label, Datum]) IdentityMap ¶
func (index *IGraph[Label, Datum]) IdentityMap(storage imap.KeyValueStore[Label, Label]) error
IdentityMap writes all Labels for which has a semantically equivalent label. See imap.Storage.IdentityMap.
func (*IGraph[Label, Datum]) MarkIdentical ¶
MarkIdentical identifies the new and old labels. See imap.IMap.MarkIdentical.
func (*IGraph[Label, Datum]) MarkInverse ¶
MarkInverse marks the left and right Labels as inverse properties of each other. After calls to MarkInverse, no more calls to MarkIdentical should be made.
Each label is assumed to have at most one inverse. A label may not be it's own inverse.
This means that each call to AddTriple(s, left, o) will also result in a call to AddTriple(o, right, s).
func (*IGraph[Label, Datum]) PathsStarting ¶
func (index *IGraph[Label, Datum]) PathsStarting(predicate, object Label) (*Paths[Label, Datum], error)
PathsStarting creates a new [PathSet] that represents all one-element paths starting at a vertex which is connected to object with the given predicate
func (*IGraph[Label, Datum]) Reset ¶
Reset resets this index and prepares all internal structures for use.
func (*IGraph[Label, Datum]) TripleCount ¶
TripleCount returns the total number of (distinct) triples in this graph. Triples which have been identified will only count once.
type IndexTriple ¶
type IndexTriple struct { Role // Why was this triple stored? Items [3]imap.ID // What were the *original* items in this triple SItems [3]imap.ID // What were the *semantic* items in this triple }
IndexTriple represents a triple stored inside the index
type MemoryEngine ¶
type MemoryEngine[Label comparable, Datum any] struct { imap.MemoryEngine[Label] }
MemoryEngine represents an engine that stores everything in memory
func (MemoryEngine[Label, Datum]) Data ¶
func (MemoryEngine[Label, Datum]) Data() (imap.KeyValueStore[imap.ID, Datum], error)
func (MemoryEngine[Label, Datum]) Inverses ¶
func (MemoryEngine[Label, Datum]) Inverses() (imap.KeyValueStore[imap.ID, imap.ID], error)
func (MemoryEngine[Label, Datum]) POSIndex ¶
func (MemoryEngine[Label, Datum]) POSIndex() (ThreeStorage, error)
func (MemoryEngine[Label, Datum]) PSOIndex ¶
func (MemoryEngine[Label, Datum]) PSOIndex() (ThreeStorage, error)
func (MemoryEngine[Label, Datum]) Triples ¶
func (MemoryEngine[Label, Datum]) Triples() (imap.KeyValueStore[imap.ID, IndexTriple], error)
type Path ¶
type Path[Label comparable, Datum any] struct { // contains filtered or unexported fields }
Path represents a path inside a GraphIndex
func (*Path[Label, Datum]) Datum ¶
Datum returns the datum attached to the last node of this path, if any.
type Paths ¶
type Paths[Label comparable, Datum any] struct { // contains filtered or unexported fields }
Paths represents a set of paths in a related GraphIndex. It implements a very simple sparql-like query engine.
A Paths object is stateful. A Paths object should only be created from a GraphIndex; the zero value is invalid. It can be further refined using the [Connected] and [Ending] methods.
func (*Paths[Label, Datum]) Connected ¶
Connected extends the sets of in this PathSet by those which continue the existing paths using an edge labeled with predicate.
func (*Paths[URI, Datum]) Ending ¶
Ending restricts this set of paths to those that end in a node which is connected to object via predicate.
type Stats ¶
type Stats struct { DirectTriples int64 DatumTriples int64 InverseTriples int64 ConflictTriples int64 }
Stats holds statistics about triples in the index
type ThreeDiskHash ¶
ThreeHash implements ThreeStorage in memory
func (*ThreeDiskHash) Close ¶
func (tlm *ThreeDiskHash) Close() (err error)
func (*ThreeDiskHash) Count ¶
func (tlm *ThreeDiskHash) Count() (total int64, err error)
func (ThreeDiskHash) Finalize ¶
func (tlm ThreeDiskHash) Finalize() error
type ThreeHash ¶
ThreeHash implements ThreeStorage in memory
type ThreeStorage ¶
type ThreeStorage interface { io.Closer // Add adds a new mapping for the given (a, b, c). // // l acts as a label for the insert. // when the given edge already exists, the conflict function should be called to resolve the conflict Add(a, b, c imap.ID, l imap.ID, conflict func(old, new imap.ID) (imap.ID, error)) (conflicted bool, err error) // Count counts the overall number of entries in the index Count() (int64, error) // Finalize informs the storage that no more mappings will be made Finalize() error // Fetch iterates over all triples (a, b, c) in c-order. // l is the last label that was created for the triple. // If an error occurs, iteration stops and is returned to the caller Fetch(a, b imap.ID, f func(c imap.ID, l imap.ID) error) error // Has checks if the given mapping exists and returns the label (if any) Has(a, b, c imap.ID) (imap.ID, bool, error) }
func NewDiskHash ¶
func NewDiskHash(path string) (ThreeStorage, error)
type Triple ¶
type Triple[Label comparable, Datum any] struct { // ID uniquely identifies this triple. // Two Triples are identical iff their IDs are identical. ID imap.ID Role Role Subject, Predicate, Object Label SSubject, SPredicate, SObject Label // the "semantic" version of the datum Datum Datum }
Triple represents a triple found inside a graph