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

Method evalBoxPlus

engine/temporal.go:377–417  ·  view source on GitHub ↗

evalBoxPlus implements the box-plus operator ([+). It returns true if the atom will be true CONTINUOUSLY throughout the future interval. Syntax: [+[d1, d2] p(X) means "p(X) will be true for the entire period from d1 to d2 from now"

(
	atom ast.Atom,
	opInterval ast.Interval,
	interval *ast.Interval,
	subst unionfind.UnionFind,
)

Source from the content-addressed store, hash-verified

375// It returns true if the atom will be true CONTINUOUSLY throughout the future interval.
376// Syntax: [+[d1, d2] p(X) means "p(X) will be true for the entire period from d1 to d2 from now"
377func (te *TemporalEvaluator) evalBoxPlus(
378 atom ast.Atom,
379 opInterval ast.Interval,
380 interval *ast.Interval,
381 subst unionfind.UnionFind,
382) ([]unionfind.UnionFind, error) {
383 // Calculate the query interval based on the operator's interval
384 queryInterval, err := te.resolveFutureOperatorInterval(opInterval)
385 if err != nil {
386 return nil, err
387 }
388
389 var solutions []unionfind.UnionFind
390
391 // Query all facts matching the atom
392 err = te.temporalStore.GetAllFacts(atom, func(tf factstore.TemporalFact) error {
393 // Unify first to check if this fact matches
394 newSubst, err := unionfind.UnifyTermsExtend(atom.Args, tf.Atom.Args, subst)
395 if err != nil {
396 return nil // No match, continue
397 }
398
399 // For box-plus, the fact's interval must CONTAIN the query interval
400 // (the fact must be true throughout the entire future query period)
401 if te.intervalContains(tf.Interval, queryInterval) {
402 // Bind interval variables if present
403 if interval != nil {
404 newSubst = te.bindIntervalVariables(*interval, tf.Interval, newSubst)
405 }
406
407 solutions = append(solutions, newSubst)
408 }
409 return nil
410 })
411
412 if err != nil {
413 return nil, err
414 }
415
416 return solutions, nil
417}
418
419// resolveFutureOperatorInterval converts a future operator interval to absolute timestamps.
420func (te *TemporalEvaluator) resolveFutureOperatorInterval(interval ast.Interval) (ast.Interval, error) {

Callers 1

EvalTemporalLiteralMethod · 0.95

Calls 5

intervalContainsMethod · 0.95
bindIntervalVariablesMethod · 0.95
UnifyTermsExtendFunction · 0.92
GetAllFactsMethod · 0.65

Tested by

no test coverage detected