Documentation ¶
Index ¶
- Variables
- func ExportDOT(name string, triples []Triple) string
- type Clause
- type Counter
- type Fabric
- func (f *Fabric) Count(ctx context.Context, query Query) (int, error)
- func (f *Fabric) Delete(ctx context.Context, query Query) (int, error)
- func (f *Fabric) Insert(ctx context.Context, tri Triple) error
- func (f *Fabric) Query(ctx context.Context, query Query) ([]Triple, error)
- func (f *Fabric) ReWeight(ctx context.Context, query Query, delta float64, replace bool) (int, error)
- type InMemoryStore
- func (mem *InMemoryStore) Count(ctx context.Context, query Query) (int, error)
- func (mem *InMemoryStore) Delete(ctx context.Context, query Query) (int, error)
- func (mem *InMemoryStore) Insert(ctx context.Context, tri Triple) error
- func (mem *InMemoryStore) Query(ctx context.Context, query Query) ([]Triple, error)
- func (mem *InMemoryStore) ReWeight(ctx context.Context, query Query, delta float64, replace bool) (int, error)
- type Query
- type ReWeighter
- type SQLStore
- func (ss *SQLStore) Count(ctx context.Context, query Query) (int, error)
- func (ss *SQLStore) Delete(ctx context.Context, query Query) (int, error)
- func (ss *SQLStore) Insert(ctx context.Context, tri Triple) error
- func (ss *SQLStore) Query(ctx context.Context, query Query) ([]Triple, error)
- func (ss *SQLStore) ReWeight(ctx context.Context, query Query, delta float64, replace bool) (int, error)
- func (ss *SQLStore) Setup(ctx context.Context) error
- type Store
- type Triple
Constants ¶
This section is empty.
Variables ¶
var ErrNotSupported = errors.New("not supported")
ErrNotSupported is returned when an operation is not supported.
Functions ¶
Types ¶
type Clause ¶
type Clause struct { // Type represents the operation that should be used. Examples include equal, // gt, lt etc. Supported operations are dictated by store implementations. Type string // Value that should be used as the right operand for the operation. Value string }
Clause represents a query clause. Zero value of this struct will be used as 'Any' clause which matches any value.
type Counter ¶
type Counter interface { // Count should return the number of triples in the store that match the // given query. Count(ctx context.Context, query Query) (int, error) }
Counter can be implemented by Store implementations to support count operations. In case, this interface is not implemented, count queries will not be supported.
type Fabric ¶
type Fabric struct {
// contains filtered or unexported fields
}
Fabric provides functions to query and manage triples.
func (*Fabric) Count ¶
Count returns the number of triples matching the query. If the store does not implement the Counter interface, standard Query method will be used to fetch all triples and the result set length is returned.
func (*Fabric) Delete ¶
Delete removes all the triples from the store matching the given query and returns the number of items deleted.
type InMemoryStore ¶
type InMemoryStore struct {
// contains filtered or unexported fields
}
InMemoryStore implements the Store interface using the golang map type.
func (*InMemoryStore) Count ¶
Count returns the number of triples in the store matching the given query.
func (*InMemoryStore) Insert ¶
func (mem *InMemoryStore) Insert(ctx context.Context, tri Triple) error
Insert stores the triple into the in-memory map.
type Query ¶
type Query struct { Source Clause `json:"source,omitempty"` Predicate Clause `json:"predicate,omitempty"` Target Clause `json:"target,omitempty"` Weight Clause `json:"weight,omitempty"` Limit int `json:"limit,omitempty"` }
Query represents a query to identify one or more triples.
type ReWeighter ¶
type ReWeighter interface { // ReWeight should update all the triples matching the query as described // by delta and replace flag. If replace is true, weight of all the triples // should be set to delta. Otherwise, delta should be added to the current // weights. ReWeight(ctx context.Context, query Query, delta float64, replace bool) (int, error) }
ReWeighter can be implemented by Store implementations to support weight updates. In case, this interface is not implemented, update queries will not be supported.
type SQLStore ¶
SQLStore implements Store interface using the Go standard library sql package.
func (*SQLStore) Query ¶
Query converts the given query object into SQL SELECT and fetches all the triples.
type Store ¶
type Store interface { // Insert should insert the given triple into the store. Insert(ctx context.Context, tri Triple) error // Query should return triples from store that match the given clauses. // Possible keys of the clauses map are: source, target, predicate, weight Query(ctx context.Context, q Query) ([]Triple, error) // Delete should delete triples from store that match the given clauses. // Clauses will follow same format as used in Query() method. Delete(ctx context.Context, q Query) (int, error) }
Store implementation should provide functions for managing persistence of triples.
type Triple ¶
type Triple struct { Source string `json:"source" yaml:"source" db:"source"` Predicate string `json:"predicate" yaml:"predicate" db:"predicate"` Target string `json:"target" yaml:"target" db:"target"` Weight float64 `json:"weight" yaml:"weight" db:"weight"` // extension field }
Triple represents a subject-predicate-object.