Documentation ¶
Overview ¶
package igraph provides Index
Index ¶
- Variables
- func MarshalTriple(triple IndexTriple) ([]byte, error)
- func UnmarshalTriple(dest *IndexTriple, src []byte) error
- type DiskEngine
- func (de DiskEngine) Data() (imap.HashMap[impl.ID, impl.Datum], error)
- func (de DiskEngine) Inverses() (imap.HashMap[impl.ID, impl.ID], error)
- func (de DiskEngine) Language() (imap.HashMap[impl.ID, impl.Language], error)
- func (de DiskEngine) POSIndex() (ThreeStorage, error)
- func (de DiskEngine) PSOIndex() (ThreeStorage, error)
- func (de DiskEngine) Triples() (imap.HashMap[impl.ID, IndexTriple], error)
- type Engine
- type Index
- func (index *Index) AddData(subject, predicate impl.Label, object impl.Datum) error
- func (index *Index) AddLangData(subject, predicate impl.Label, object impl.Datum, lang impl.Language) error
- func (index *Index) AddTriple(subject, predicate, object impl.Label) error
- func (index *Index) Close() error
- func (index *Index) Compact() error
- func (index *Index) Finalize() error
- func (index *Index) IdentityMap(storage imap.HashMap[impl.Label, impl.Label]) error
- func (index *Index) MarkIdentical(new, old impl.Label) error
- func (index *Index) MarkInverse(left, right impl.Label) error
- func (index *Index) PathsStarting(predicate, object impl.Label) (*Paths, error)
- func (index *Index) Reset(engine Engine) (err error)
- func (index *Index) SetDataMask(predicates map[impl.Label]struct{}) error
- func (index *Index) SetPredicateMask(predicates map[impl.Label]struct{}) error
- func (index *Index) Stats() Stats
- func (index *Index) Triple(id impl.ID) (triple Triple, err error)
- func (index *Index) TripleCount() (count uint64, err error)
- type IndexTriple
- type MemoryEngine
- func (MemoryEngine) Data() (imap.HashMap[impl.ID, impl.Datum], error)
- func (MemoryEngine) Inverses() (imap.HashMap[impl.ID, impl.ID], error)
- func (MemoryEngine) Language() (imap.HashMap[impl.ID, impl.Language], error)
- func (MemoryEngine) POSIndex() (ThreeStorage, error)
- func (MemoryEngine) PSOIndex() (ThreeStorage, error)
- func (MemoryEngine) Triples() (imap.HashMap[impl.ID, IndexTriple], error)
- type Path
- type Paths
- type Role
- type Stats
- type ThreeDiskHash
- func (tlm *ThreeDiskHash) Add(a, b, c impl.ID, l impl.ID, conflict func(old, new impl.ID) (impl.ID, error)) (conflicted bool, err error)
- func (tlm *ThreeDiskHash) Close() (err error)
- func (tlm ThreeDiskHash) Compact() error
- func (tlm *ThreeDiskHash) Count() (total int64, err error)
- func (tlm *ThreeDiskHash) Fetch(a, b impl.ID, f func(c impl.ID, l impl.ID) error) error
- func (tlm ThreeDiskHash) Finalize() error
- func (tlm *ThreeDiskHash) Has(a, b, c impl.ID) (id impl.ID, ok bool, err error)
- type ThreeHash
- func (tlm ThreeHash) Add(a, b, c impl.ID, l impl.ID, conflict func(old, new impl.ID) (impl.ID, error)) (conflicted bool, err error)
- func (tlm *ThreeHash) Close() error
- func (th *ThreeHash) Compact() error
- func (tlm ThreeHash) Count() (total int64, err error)
- func (tlm ThreeHash) Fetch(a, b impl.ID, f func(c impl.ID, l impl.ID) error) error
- func (tlm ThreeHash) Finalize() error
- func (tlm ThreeHash) Has(a, b, c impl.ID) (impl.ID, bool, error)
- type ThreeItem
- type ThreeStorage
- type Triple
Constants ¶
This section is empty.
Variables ¶
var ErrFinalized = errors.New("IGraph: Finalized")
Functions ¶
func MarshalTriple ¶
func MarshalTriple(triple IndexTriple) ([]byte, error)
func UnmarshalTriple ¶
func UnmarshalTriple(dest *IndexTriple, src []byte) error
Types ¶
type DiskEngine ¶
DiskEngine represents an engine that stores everything on disk
func (DiskEngine) POSIndex ¶
func (de DiskEngine) POSIndex() (ThreeStorage, error)
func (DiskEngine) PSOIndex ¶
func (de DiskEngine) PSOIndex() (ThreeStorage, error)
func (DiskEngine) Triples ¶
func (de DiskEngine) Triples() (imap.HashMap[impl.ID, IndexTriple], error)
type Engine ¶
type Engine interface { imap.Map Data() (imap.HashMap[impl.ID, impl.Datum], error) Language() (imap.HashMap[impl.ID, impl.Language], error) Triples() (imap.HashMap[impl.ID, IndexTriple], error) Inverses() (imap.HashMap[impl.ID, impl.ID], error) PSOIndex() (ThreeStorage, error) POSIndex() (ThreeStorage, error) }
Engine represents an object that creates storages for an IGraph
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index 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.
Index may not be modified concurrently, however it is possible to run several queries concurrently.
func (*Index) AddData ¶
AddData inserts a non-language 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 (*Index) AddLangData ¶ added in v0.0.3
func (index *Index) AddLangData(subject, predicate impl.Label, object impl.Datum, lang impl.Language) error
AddLangData inserts a language-specific 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 (*Index) 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 (*Index) 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 invalid.
func (*Index) IdentityMap ¶
IdentityMap writes all Labels for which has a semantically equivalent label. See imap.Storage.IdentityMap.
func (*Index) MarkIdentical ¶
MarkIdentical identifies the new and old labels. See imap.IMap.MarkIdentical.
func (*Index) 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 (*Index) PathsStarting ¶
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 (*Index) SetDataMask ¶
SetDataMask sets the masks for data
func (*Index) SetPredicateMask ¶
SetPredicateMask sets the masks for predicates
func (*Index) TripleCount ¶
TripleCount returns the total number of (distinct) triples in this graph. Triples which have been identified will only count once.
type IndexTriple ¶
IndexTriple represents a triple stored inside the index
type MemoryEngine ¶
MemoryEngine represents an engine that stores everything in memory
func (MemoryEngine) POSIndex ¶
func (MemoryEngine) POSIndex() (ThreeStorage, error)
func (MemoryEngine) PSOIndex ¶
func (MemoryEngine) PSOIndex() (ThreeStorage, error)
func (MemoryEngine) Triples ¶
func (MemoryEngine) Triples() (imap.HashMap[impl.ID, IndexTriple], error)
type Path ¶
type Path struct { Datum impl.Datum Language impl.Language Nodes []impl.Label Edges []impl.Label Triples []Triple HasDatum bool }
Path represents a path inside a GraphIndex
func (Path) String ¶
String turns this result into a string
NOTE(twiesing): This is for debugging only, and ignores all errors. It should not be used in production code.
type Paths ¶
type Paths 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) Connected ¶
Connected extends the sets of in this PathSet by those which continue the existing paths using an edge labeled with predicate.
func (*Paths) 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 uint64 DatumTriples uint64 MaskedPredTriples uint64 MaskedDataTriples uint64 InverseTriples uint64 ConflictTriples uint64 }
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) Compact ¶
func (tlm ThreeDiskHash) Compact() 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 impl.ID, l impl.ID, conflict func(old, new impl.ID) (impl.ID, error)) (conflicted bool, err error) // Count counts the overall number of entries in the index Count() (int64, error) // Compact indicates to the caller to perform internal optimizations of all data structures. Compact() error // Finalize informs the storage that no more mutable calls will be made. // A mutable call is one to Compact or Add. 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 impl.ID, f func(c impl.ID, l impl.ID) error) error // Has checks if the given mapping exists and returns the label (if any) Has(a, b, c impl.ID) (impl.ID, bool, error) }
func NewDiskHash ¶
func NewDiskHash(path string) (ThreeStorage, error)
type Triple ¶
type Triple struct { // the literal SPO for this triple, as found in the original data. Subject impl.Label Predicate impl.Label Object impl.Label // the canonical (normalized for sameAs) for this triple. // FIXME: change this to say canonical in the name SSubject impl.Label SPredicate impl.Label SObject impl.Label // Datum and Language hold the data value of this triple and the corresponding language Datum impl.Datum Language impl.Language // ID uniquely identifies this triple. // Two triples are identical iff their IDs are identical. ID impl.ID // Why was this triple inserted? Role Role }
Triple represents a triple found inside a graph