QueryInteractive parses query string, queries the interpreter's state, returns results formatted as strings.
(queryString string)
| 255 | // QueryInteractive parses query string, queries the interpreter's state, returns |
| 256 | // results formatted as strings. |
| 257 | func (i *Interpreter) QueryInteractive(queryString string) error { |
| 258 | query, err := i.ParseQuery(queryString) |
| 259 | if err != nil { |
| 260 | return err |
| 261 | } |
| 262 | facts, err := i.Query(query) |
| 263 | if err != nil { |
| 264 | return err |
| 265 | } |
| 266 | var results []string |
| 267 | for _, fact := range facts { |
| 268 | if atom, ok := fact.(ast.Atom); ok { |
| 269 | results = append(results, atom.DisplayString()) |
| 270 | } else if ta, ok := fact.(ast.TemporalAtom); ok { |
| 271 | results = append(results, ta.DisplayString()) |
| 272 | } else { |
| 273 | results = append(results, fact.String()) |
| 274 | } |
| 275 | } |
| 276 | sort.Strings(results) |
| 277 | fmt.Fprintf(i.out, "%s\n", strings.Join(results, "\n")) |
| 278 | if len(results) == 0 { |
| 279 | fmt.Fprintf(i.out, "No entries for %s.\n", query) |
| 280 | } else { |
| 281 | fmt.Fprintf(i.out, "Found %d entries for %s.\n", len(results), query) |
| 282 | } |
| 283 | return nil |
| 284 | } |
| 285 | |
| 286 | // Define adds rule definitions the interpreter's state. |
| 287 | func (i *Interpreter) Define(clauseText string) error { |
no test coverage detected