Documentation ¶
Overview ¶
Package infer implements fact inference by traversing transitive predicates. If the predicate defines a heirarchy, and an entity has a fact relating it to an item in the heirarchy, then this can infer that the entity also has facts to each parent item in the herirachy path.
For exampe, given facts that describe a type classification ¶
[cell phone] -type-> [electronics] -type-> [product]
and a fact that says
[iphone]-type-> [cell phone]
then we can infer that these additional facts are also true
[iphone] -type -> [electronics]
[iphone] -type -> [product]
This package supports inference in both directions, i.e. start at <subject> and follow predicate -> object -> predicate -> object and start at <object> and follow backwards <- predicate <- subject <- predicate <- subject
Index ¶
- func PO(ctx context.Context, lookup lookups.PO, inferReq *PORequest, ...) error
- func SP(ctx context.Context, lookup lookups.SP, req *SPRequest, ...) error
- func SPO(ctx context.Context, lookup lookups.SP, cache cache.FactCache, req *SPORequest, ...) error
- type PORequest
- type PORequestItem
- type SPORequest
- type SPORequestItem
- type SPRequest
- type SPRequestItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PO ¶
func PO(ctx context.Context, lookup lookups.PO, inferReq *PORequest, resCh chan<- *rpc.LookupChunk) error
PO will iteratively walk backwards from the starting object following the predicate and collect up all the relevant facts. Results with chunks of facts are generated into the supplied results channel. This function will block until all results have been generate, or an error occurs. resCh will always be closed before this function returns. All the Lookups in the request aggregate their RPC lookup requests and execute them in bulk for efficiency
func SP ¶
func SP(ctx context.Context, lookup lookups.SP, req *SPRequest, resCh chan<- *rpc.LookupChunk) error
SP will perform a breadth first graph traversal to infer facts for each of the supplied subject & predicate pairs chunks of results will be written to the supplied result channel, when the traversal is successfully completed this function returns nil. In the event of an error, the error will be returned, in either case 'resCh' will be closed.
The returned facts are all the static & infered facts from the subject following the predicate e.g. given facts
<iPhone> <type> <smartPhone> <smartPhone> <type> <consumerElectronics> <consumerElectronics> <type> <product>
running infer.SP(<iPhone><type>) would return results
<iPhone> <type> <smartPhone> <iPhone> <type> <consumerElectronics> <iPhone> <type> <product>
We currently assume all predicates are transitive, however we expect that in the future the predicate schema can indicate that predicates are/are not transitive. the request can specify a list of infers to run, and these are execute efficiently in bulk. If there's more than one lookup in the request, the generated LookupChunks indicate which lookup they are for via the Lookup field which specifies the index into req.Lookups that that result is for
func SPO ¶
func SPO(ctx context.Context, lookup lookups.SP, cache cache.FactCache, req *SPORequest, resCh chan<- *rpc.LookupChunk) error
SPO runs a graph traversal to determine if a particular fact can be inferred to exist, by finding a path between the subject and target KIDs using the predicate.
If it finds a path the inferred fact is sent as part of a result chunk on the supplied resCh, if it can't find that item, no result is generated with that lookup offset.
Currently we assume all predicates are transitive, for example if <a> <type> <b> is true and <b> <type> <c> is true, then we infer that <a> <type> <c> is also true. Its expected that a future version will allow for non-transitive predicates.
Types ¶
type PORequest ¶
type PORequest struct { Index uint64 Lookups []PORequestItem }
PORequest describes 1 or more inference lookups on Predicate,Object to perform all are performed as of the indicated log index, which must be set
type PORequestItem ¶
PORequestItem describes a single infer PO starting point
type SPORequest ¶
type SPORequest struct { Index uint64 Lookups []SPORequestItem }
SPORequest defines 1..N lookups to be executed at the supplied index
type SPORequestItem ¶
SPORequestItem descibes a single SPO infer lookup to perform
type SPRequest ¶
type SPRequest struct { Index uint64 Lookups []SPRequestItem }
SPRequest describes a request to infer 1 or more (S,P) lookups all inference is performed as of the supplied index, which must be set
type SPRequestItem ¶
SPRequestItem describes a single Subject, Predicate lookup to perform as part of a larger SP request.