DecideTemporalPredicate evaluates temporal interval predicates. Returns (ok, substitions, error). If ok is false with no error, the predicate failed.
(atom ast.Atom, subst *unionfind.UnionFind)
| 25 | // DecideTemporalPredicate evaluates temporal interval predicates. |
| 26 | // Returns (ok, substitions, error). If ok is false with no error, the predicate failed. |
| 27 | func DecideTemporalPredicate(atom ast.Atom, subst *unionfind.UnionFind) (bool, []*unionfind.UnionFind, error) { |
| 28 | if len(atom.Args) != 2 { |
| 29 | return false, nil, fmt.Errorf("temporal predicate %s requires 2 arguments, got %d", atom.Predicate.Symbol, len(atom.Args)) |
| 30 | } |
| 31 | |
| 32 | // Extract intervals from arguments |
| 33 | interval1, err := getIntervalValue(atom.Args[0]) |
| 34 | if err != nil { |
| 35 | return false, nil, err |
| 36 | } |
| 37 | interval2, err := getIntervalValue(atom.Args[1]) |
| 38 | if err != nil { |
| 39 | return false, nil, err |
| 40 | } |
| 41 | |
| 42 | var result bool |
| 43 | switch atom.Predicate.Symbol { |
| 44 | case symbols.IntervalBefore.Symbol: |
| 45 | result = intervalBefore(interval1, interval2) |
| 46 | case symbols.IntervalAfter.Symbol: |
| 47 | result = intervalAfter(interval1, interval2) |
| 48 | case symbols.IntervalMeets.Symbol: |
| 49 | result = intervalMeets(interval1, interval2) |
| 50 | case symbols.IntervalOverlaps.Symbol: |
| 51 | result = intervalOverlaps(interval1, interval2) |
| 52 | case symbols.IntervalDuring.Symbol: |
| 53 | result = intervalDuring(interval1, interval2) |
| 54 | case symbols.IntervalContains.Symbol: |
| 55 | result = intervalContains(interval1, interval2) |
| 56 | case symbols.IntervalStarts.Symbol: |
| 57 | result = intervalStarts(interval1, interval2) |
| 58 | case symbols.IntervalFinishes.Symbol: |
| 59 | result = intervalFinishes(interval1, interval2) |
| 60 | case symbols.IntervalEquals.Symbol: |
| 61 | result = intervalEquals(interval1, interval2) |
| 62 | default: |
| 63 | return false, nil, fmt.Errorf("unknown temporal predicate: %s", atom.Predicate.Symbol) |
| 64 | } |
| 65 | |
| 66 | if result { |
| 67 | return true, []*unionfind.UnionFind{subst}, nil |
| 68 | } |
| 69 | return false, nil, nil |
| 70 | } |
| 71 | |
| 72 | // getIntervalValue extracts an interval from a constant. |
| 73 | // Intervals are represented as pairs of timestamps (start, end). |