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

Function Decide

builtin/builtin.go:216–433  ·  view source on GitHub ↗

Decide evaluates an atom of a built-in predicate. The atom must no longer contain any apply-expressions or variables.

(atom ast.Atom, subst *unionfind.UnionFind)

Source from the content-addressed store, hash-verified

214// Decide evaluates an atom of a built-in predicate. The atom must no longer contain any
215// apply-expressions or variables.
216func Decide(atom ast.Atom, subst *unionfind.UnionFind) (bool, []*unionfind.UnionFind, error) {
217 // Check for temporal predicates first
218 if IsTemporalPredicate(atom.Predicate) {
219 return DecideTemporalPredicate(atom, subst)
220 }
221
222 switch atom.Predicate.Symbol {
223 case symbols.StartsWith.Symbol:
224 fallthrough
225 case symbols.EndsWith.Symbol:
226 fallthrough
227 case symbols.Contains.Symbol:
228 fallthrough
229 case symbols.MatchPrefix.Symbol:
230 fallthrough
231 case symbols.MatchPair.Symbol:
232 fallthrough
233 case symbols.MatchCons.Symbol:
234 fallthrough
235 case symbols.MatchEntry.Symbol:
236 fallthrough
237 case symbols.MatchField.Symbol:
238 fallthrough
239 case symbols.MatchNil.Symbol:
240 ok, nsubst, err := match(atom, subst)
241 if err != nil {
242 return false, nil, err
243 }
244 if !ok {
245 return false, nil, nil
246 }
247 return ok, []*unionfind.UnionFind{nsubst}, nil
248 }
249 switch atom.Predicate.Symbol {
250 case symbols.Filter.Symbol:
251 if len(atom.Args) != 1 {
252 return false, nil, fmt.Errorf("wrong number of arguments for built-in predicate 'filter': %v", atom.Args)
253 }
254 evaluatedArg, err := functional.EvalExpr(atom.Args[0], subst)
255 if err != nil {
256 return false, nil, err
257 }
258 if evaluatedArg == ast.TrueConstant {
259 return true, []*unionfind.UnionFind{subst}, nil
260 }
261 return false, nil, nil
262
263 case symbols.Lt.Symbol:
264 if len(atom.Args) != 2 {
265 return false, nil, fmt.Errorf("wrong number of arguments for built-in predicate '<': %v", atom.Args)
266 }
267 nums, err := getNumberValues(atom.Args)
268 if err != nil {
269 return false, nil, err
270 }
271 return nums[0] < nums[1], []*unionfind.UnionFind{subst}, nil
272 case symbols.Le.Symbol:
273 if len(atom.Args) != 2 {

Callers 15

oneStepEvalPremiseMethod · 0.92
premiseAtomFunction · 0.92
premiseNegAtomFunction · 0.92
TestLessThanFunction · 0.85
TestLessThanErrorFunction · 0.85
TestLessThanOrEqualFunction · 0.85
TestLessThanOrEqualErrorFunction · 0.85
TestGreaterThanFunction · 0.85
TestGreaterThanErrorFunction · 0.85
TestGreaterThanOrEqualFunction · 0.85
TestWithinDistanceFunction · 0.85

Calls 12

EvalExprFunction · 0.92
UnifyTermsExtendFunction · 0.92
IsTemporalPredicateFunction · 0.85
DecideTemporalPredicateFunction · 0.85
matchFunction · 0.85
getNumberValuesFunction · 0.85
getTimeValuesFunction · 0.85
getDurationValuesFunction · 0.85
absFunction · 0.85
ListValuesMethod · 0.80
GetMethod · 0.65
EqualsMethod · 0.65

Tested by 15

TestLessThanFunction · 0.68
TestLessThanErrorFunction · 0.68
TestLessThanOrEqualFunction · 0.68
TestLessThanOrEqualErrorFunction · 0.68
TestGreaterThanFunction · 0.68
TestGreaterThanErrorFunction · 0.68
TestGreaterThanOrEqualFunction · 0.68
TestWithinDistanceFunction · 0.68
TestWithinDistanceErrorFunction · 0.68
TestMatchPrefixFunction · 0.68
TestStartsWithFunction · 0.68