diff options
| author | Christine Dodrill <me@christine.website> | 2019-09-11 13:45:34 +0000 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2019-09-11 13:45:44 +0000 |
| commit | 0d58fcab795a0307996f0b0e7ec5aa36ca27641f (patch) | |
| tree | 76ce7687a23f313ebb1f1214289e9125486d2156 /cmd | |
| parent | 3263cceb69b2ab47248fdeffb04d1e0e6fc2bf07 (diff) | |
| download | x-0d58fcab795a0307996f0b0e7ec5aa36ca27641f.tar.xz x-0d58fcab795a0307996f0b0e7ec5aa36ca27641f.zip | |
cmd/la-baujmi: .i mi cu mencre
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/la-baujmi/fact.go | 18 | ||||
| -rw-r--r-- | cmd/la-baujmi/main.go | 23 |
2 files changed, 29 insertions, 12 deletions
diff --git a/cmd/la-baujmi/fact.go b/cmd/la-baujmi/fact.go index 3a92357..86563a4 100644 --- a/cmd/la-baujmi/fact.go +++ b/cmd/la-baujmi/fact.go @@ -7,20 +7,20 @@ import ( "within.website/x/web/tokiponatokens" ) -// Selbri is a predicate relationship between its arguments. The name comes from +// Bridi is a predicate relationship between its arguments. The name comes from // the lojban term selbri: http://jbovlaste.lojban.org/dict/selbri. -type Selbri struct { +type Bridi struct { Predicate string Arguments []string } // Fact converts a selbri into a prolog fact. -func (s Selbri) Fact() string { +func (s Bridi) Fact() string { var sb strings.Builder var varCount byte - sb.WriteString("selbri(verb(") + sb.WriteString("bridi(verb(") if s.Predicate == "seme" { sb.WriteByte(byte('A') + varCount) @@ -61,9 +61,9 @@ var ( ErrNoPredicate = errors.New("la-baujmi: sentence must have a verb to function as the logical predicate") ) -// SentenceToSelbris creates logical facts derived from toki pona sentences. +// SentenceToBridis creates logical facts derived from toki pona sentences. // This is intended to be the first step in loading them into prolog. -func SentenceToSelbris(s tokiponatokens.Sentence) ([]Selbri, error) { +func SentenceToBridis(s tokiponatokens.Sentence) ([]Bridi, error) { var ( subjects []string verbs []string @@ -167,7 +167,7 @@ func SentenceToSelbris(s tokiponatokens.Sentence) ([]Selbri, error) { return nil, ErrNoPredicate } - var result []Selbri + var result []Bridi for _, v := range verbs { for _, s := range subjects { @@ -179,7 +179,7 @@ func SentenceToSelbris(s tokiponatokens.Sentence) ([]Selbri, error) { } sumti = append(sumti, s) - r := Selbri{ + r := Bridi{ Predicate: v, Arguments: sumti, } @@ -196,7 +196,7 @@ func SentenceToSelbris(s tokiponatokens.Sentence) ([]Selbri, error) { sumti = append(sumti, s) sumti = append(sumti, o) - r := Selbri{ + r := Bridi{ Predicate: v, Arguments: sumti, } diff --git a/cmd/la-baujmi/main.go b/cmd/la-baujmi/main.go index cf37b17..edc4bff 100644 --- a/cmd/la-baujmi/main.go +++ b/cmd/la-baujmi/main.go @@ -2,8 +2,10 @@ package main import ( + "flag" "log" "os" + "path/filepath" "strings" "github.com/mndrix/golog" @@ -13,13 +15,23 @@ import ( "within.website/x/web/tokiponatokens" ) +var ( + historyFname = flag.String("history-file", filepath.Join(os.Getenv("HOME"), ".la-baujmi-history"), "location of history file") +) + func main() { internal.HandleStartup() var m golog.Machine m = golog.NewMachine() + l := line.NewLiner() + + fin, err := os.Open(*historyFname) + if err == nil { + l.ReadHistory(fin) + fin.Close() + } for { - l := line.NewLiner() if inp, err := l.Prompt("|toki: "); err == nil { if inp == "" { return @@ -34,7 +46,7 @@ func main() { } for _, sentence := range parts { - sbs, err := SentenceToSelbris(sentence) + sbs, err := SentenceToBridis(sentence) if err != nil { log.Printf("can't derive facts: %v", err) continue @@ -67,5 +79,10 @@ func main() { } } - os.Exit(0) + fout, err := os.Create(*historyFname) + if err != nil { + panic(err) + } + l.WriteHistory(fout) + fout.Close() } |
