MCPcopy
hub / github.com/google/mangle / GetAllFacts

Method GetAllFacts

factstore/temporal.go:224–259  ·  view source on GitHub ↗

GetAllFacts returns all facts matching the query with their intervals.

(query ast.Atom, fn func(TemporalFact) error)

Source from the content-addressed store, hash-verified

222
223// GetAllFacts returns all facts matching the query with their intervals.
224func (s *TemporalStore) GetAllFacts(query ast.Atom, fn func(TemporalFact) error) error {
225 if query.Predicate.Symbol == "" {
226 for _, predMap := range s.facts {
227 for hash, tree := range predMap {
228 atom := s.atoms[hash]
229 err := tree.All(func(interval ast.Interval) error {
230 return fn(TemporalFact{Atom: atom, Interval: interval})
231 })
232 if err != nil {
233 return err
234 }
235 }
236 }
237 return nil
238 }
239
240 predMap, ok := s.facts[query.Predicate]
241 if !ok {
242 return nil
243 }
244
245 for hash, tree := range predMap {
246 atom := s.atoms[hash]
247 if !Matches(query.Args, atom.Args) {
248 continue
249 }
250
251 err := tree.All(func(interval ast.Interval) error {
252 return fn(TemporalFact{Atom: atom, Interval: interval})
253 })
254 if err != nil {
255 return err
256 }
257 }
258 return nil
259}
260
261// ContainsAt returns true if the atom is valid at the given time.
262func (s *TemporalStore) ContainsAt(atom ast.Atom, t time.Time) bool {

Calls 2

MatchesFunction · 0.85
AllMethod · 0.80