aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/shell
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2025-06-19 01:22:19 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2025-06-19 01:22:19 -0400
commit21d72b2f67fb065d9071907c5c3307434aad3795 (patch)
tree9313ca1091d0f4c9b3252639d33b582c58f72d87 /pkg/shell
parent649bbdf8d3fdda4423f2f30bbf98698e8f2faa07 (diff)
Add multiple clause and tree level optimizations
Implement optimizations that can be called in parallel or serial. Optimizations occur mostly in place and result in a logically equivalent tree when used correctly. Optimizations ============= * Sort - sort all statements within a clause tree * Simplify - apply negation rules to all statements * Flatten - merge child clauses with parents * Compact - merge equivalent statements * Tidy^ - remove zero statements * Contradictions - zero contradicting statements and clauses * StrictEquality - zero fuzzy statements when exact statements are within clause * Tighten - combine multiple fuzzy statements to the least (AND) or most (OR) restrictive bounds ^: when used incorrectly can turn an invalid clause tree into a valid one
Diffstat (limited to 'pkg/shell')
-rw-r--r--pkg/shell/interpreter.go39
1 files changed, 29 insertions, 10 deletions
diff --git a/pkg/shell/interpreter.go b/pkg/shell/interpreter.go
index 45dbecf..87b7748 100644
--- a/pkg/shell/interpreter.go
+++ b/pkg/shell/interpreter.go
@@ -19,6 +19,7 @@ import (
type Interpreter struct {
State State
Scanner *bufio.Scanner
+ Workers uint
}
type ITokType int
@@ -54,10 +55,11 @@ type IToken struct {
Text string
}
-func NewInterpreter(initialState State, inputSource io.Reader) *Interpreter {
+func NewInterpreter(initialState State, inputSource io.Reader, workers uint) *Interpreter {
return &Interpreter{
initialState,
bufio.NewScanner(inputSource),
+ workers,
}
}
@@ -184,12 +186,24 @@ func (interpreter *Interpreter) Eval(tokens []IToken) (bool, error) {
return true, errors.New("Type corruption during flatten, expected *query.Clause")
}
- o := query.Optimizer{}
+ o := query.NewOptimizer(clause, interpreter.Workers)
switch t.Text {
+ case "simplify":
+ o.Simplify()
+ case "tighten":
+ o.Tighten()
case "flatten":
- o.Flatten(clause)
+ o.Flatten()
+ case "sortStatements":
+ o.SortStatements()
+ case "tidy":
+ o.Tidy()
+ case "contradictions":
+ o.Contradictions()
case "compact":
- o.Compact(clause)
+ o.Compact()
+ case "strictEq":
+ o.StrictEquality()
default:
return false, fmt.Errorf("Unrecognized optimization: %s", t.Text)
}
@@ -292,7 +306,7 @@ func (interpreter Interpreter) Tokenize(line string) []IToken {
tokens = append(tokens, IToken{Type: ITOK_CMD_TOKENIZE})
} else if trimmedWord == "parse" {
tokens = append(tokens, IToken{Type: ITOK_CMD_PARSE})
- } else if l := len("optimize_"); len(trimmedWord) > l && trimmedWord[:l] == "optimize_" {
+ } else if l := len("opt_"); len(trimmedWord) > l && trimmedWord[:l] == "opt_" {
tokens = append(tokens, IToken{ITOK_CMD_OPTIMIZE, trimmedWord[l:]})
} else if prevType == ITOK_CMD_LET {
tokens = append(tokens, IToken{ITOK_VAR_NAME, trimmedWord})
@@ -357,11 +371,11 @@ func (interpreter Interpreter) Run() error {
}(lineCh, exitCh)
for {
- fmt.Print("> ")
+ fmt.Print("atlasi> ")
select {
case <-signalCh:
- // TODO: log info to output
+ fmt.Println("Recieved Ctrl-C, exitting")
return nil
case err := <-exitCh:
return err
@@ -391,8 +405,13 @@ func printHelp() {
fmt.Println("tokenize (string|name) - tokenize a string")
fmt.Println(" ex. tokenize `author:me")
fmt.Println("parse (tokens|name) - parse tokens into a clause")
- fmt.Println("optimize_<subcommand> (clause|name) - optimize clause tree")
- fmt.Println(" flatten - flatten clauses")
- fmt.Println(" compact - compact equivalent statements")
+ fmt.Println("opt_<subcommand> (clause|name) - optimize clause tree")
+ fmt.Println(" sortStatements - sort statements")
+ fmt.Println(" flatten - flatten clauses")
+ fmt.Println(" compact - compact equivalent statements")
+ fmt.Println(" tidy - remove zero statements and `AND` clauses containing any")
+ fmt.Println(" contradictions - zero contradicting statements and clauses")
+ fmt.Println(" strictEq - zero fuzzy/range statements when an eq is present")
+ fmt.Println(" tighten - zero redundant fuzzy/range statements when another mathes the same values")
fmt.Println("\nBare commands which return a value assign to an implicit variable _")
}