func (self *RuleEngine) GetFiredExpressions(data *facts.FactCollection) []string { counter := make(map[int]int) for _, k := range data.Keys() { ids, ok := self.expressionIndex[k] if ok { for _, id := range ids { v, exist := counter[id] if !exist { counter[id] = 1 } else { counter[id] = v + 1 } } } } firedExpressions := []string{} for k, v := range counter { if v == self.varCountInExpressions[k] { fmt.Println(self.expressions[k]) ret := expression.CalcReversePolishNotation(self.expressions[k], data) if ret == "true" { fmt.Println("fire expression", self.expressionNames[k], self.expressions[k]) firedExpressions = append(firedExpressions, self.expressionNames[k]) } } } return firedExpressions }
func VariableValue(a, b string, data *facts.FactCollection) (interface{}, interface{}) { va, oka := data.Get(a) vb, okb := data.Get(b) if oka && okb { return va, vb } else if oka && !okb { { na, ok := va.(int) if ok { nb, err := strconv.Atoi(b) if err != nil { panic(err) } return na, nb } } { na, ok := va.(float64) if ok { nb, err := strconv.ParseFloat(b, 64) if err != nil { panic(err) } return na, nb } } { na, ok := va.(string) if ok { return na, b } } } else if !oka && okb { { nb, ok := vb.(int) if ok { na, err := strconv.Atoi(a) if err != nil { panic(err) } return na, nb } } { nb, ok := vb.(float64) if ok { na, err := strconv.ParseFloat(a, 64) if err != nil { panic(err) } return na, nb } } { nb, ok := vb.(string) if ok { return a, nb } } } else { { na, err_na := strconv.Atoi(a) nb, err_nb := strconv.Atoi(b) if err_na == nil && err_nb == nil { return na, nb } } { na, err_na := strconv.ParseFloat(a, 64) nb, err_nb := strconv.ParseFloat(b, 64) if err_na == nil && err_nb == nil { return na, nb } } } return a, b }