//refine the candidate set based on the questions and answers provided func refine(answers *rx.BitSet, qns []string, cand []*rx.DFA, expns []*rx.RegExParsed, dex []int) ([]*rx.DFA, []*rx.RegExParsed, []int) { remain := make([]*rx.DFA, 0, len(cand)) express := make([]*rx.RegExParsed, 0, len(expns)) index := make([]int, 0, len(expns)) //iterate through all candidates for i := 0; i < len(cand); i++ { test := new(rx.BitSet) //initialize new bitset for j := 0; j < len(qns); j++ { //ask all the questions if cand[i].Accepts(qns[j]) != nil { test.Set(j) //record answers } } if test.Equals(answers) { //if test matches answers, keep this DFA remain = append(remain, cand[i]) express = append(express, expns[i]) if len(dex) == 0 { index = append(index, i) } else { index = append(index, dex[i]) if len(cand) < 20 { fmt.Printf("%d ", dex[i]) } } } } fmt.Printf("\n") return remain, express, index }
//find the expression that corresponds to the question word func findExpr(nextQn *rx.BitSet, e []*RegEx) string { b := new(rx.BitSet) for i := 0; i < len(e); i++ { b.Set(e[i].Index) if b.Equals(nextQn) { return e[i].Rexpr } b.Clear(e[i].Index) } return "" }