diff options
| author | Christine Dodrill <me@christine.website> | 2019-01-26 09:48:28 -0800 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2019-01-26 09:48:28 -0800 |
| commit | a0b5fc1c39e9aba464a9178da150cf0da863a47f (patch) | |
| tree | e86f6af56089215c29660dc464e495fa5d2c3a49 | |
| parent | cfbbdb4130b89b3caae91dc0bf6a1bf736d527bd (diff) | |
| download | x-a0b5fc1c39e9aba464a9178da150cf0da863a47f.tar.xz x-a0b5fc1c39e9aba464a9178da150cf0da863a47f.zip | |
tokipona: add very dumb relex
| -rw-r--r-- | tokipona/TokiPonaRelex.csv | 125 | ||||
| -rw-r--r-- | tokipona/doc.go | 6 | ||||
| -rw-r--r-- | tokipona/generate.go | 50 | ||||
| -rw-r--r-- | tokipona/relex.go | 27 | ||||
| -rw-r--r-- | tokipona/relex_gen.go | 130 | ||||
| -rw-r--r-- | tokipona/relex_test.go | 27 | ||||
| -rw-r--r-- | tokipona/tokipona.go | 22 | ||||
| -rw-r--r-- | tokipona/tokipona.yaml | 323 |
8 files changed, 359 insertions, 351 deletions
diff --git a/tokipona/TokiPonaRelex.csv b/tokipona/TokiPonaRelex.csv new file mode 100644 index 0000000..d885e51 --- /dev/null +++ b/tokipona/TokiPonaRelex.csv @@ -0,0 +1,125 @@ +,a,ah,
+,akesi,frog,
+,ala,not,
+,alasa,hunt,
+,ale,all,
+,ali,all,
+,anpa,down,
+,ante,other,
+,anu,or,
+,awen,keep,
+,e,eh,
+,en,and,
+,esun,store,
+,ijo,thing,
+,ike,bad,
+,ilo,tool,
+,insa,inside,
+,jaki,yucky,
+,jan,human,
+,jelo,yellow,
+,jo,have,
+,kala,fish,
+,kalama,sound,
+,kama,come,
+,kasi,plant,
+,ken,can,
+,kepeken,with,
+,kipisi,cut,
+,kili,fruit,
+,kin,indeed,
+,kiwen,rock,
+,ko,muck,
+,kon,air,
+,kule,color,
+,kute,ear,
+,kulupu,group,
+,la,if,
+,lape,sleep,
+,laso,blue,
+,lawa,head,
+,len,cloth,
+,lete,cold,
+,li,is,
+,lili,little,
+,linja,wave,
+,lipu,sheet,
+,loje,red,
+,lon,at,
+,luka,hand,
+,lukin,see,
+,lupa,hole,
+,ma,land,
+,mama,mom,
+,mani,money,
+,meli,girl,
+,mi,me,
+,mije,man,
+,moku,eat,
+,moli,die,
+,monsi,rear,
+,mu,moo,
+,mun,moon,
+,musi,play,
+,mute,many,
+,namako,extra,
+,nanpa,number,
+,nasa,crazy,
+,nasin,path,
+,nena,bump,
+,ni,this,
+,nimi,name,
+,noka,leg,
+,o,oh,
+,oko,eye,
+,olin,love,
+,ona,they,
+,open,open,
+,pakala,break,
+,pali,work,
+,palisa,stick,
+,pan,bread,
+,pana,give,
+,pata,brother,
+,pi,of,
+,pilin,feel,
+,pimeja,black,
+,pini,end,
+,pipi,bug,
+,poka,with,
+,poki,box,
+,pona,good,
+,sama,same,
+,seme,what,
+,seli,hot,
+,selo,skin,
+,sewi,high,
+,sike,circle,
+,sijelo,body,
+,sin,new,
+,sina,you,
+,sinpin,face,
+,sitelen,drawing,
+,sona,know,
+,soweli,beast,
+,suli,great,
+,suno,sun,
+,supa,couch,
+,suwi,sweet,
+,tan,from,
+,taso,but,
+,tawa,go,
+,telo,water,
+,tenpo,time,
+,toki,speak,
+,tomo,room,
+,tu,two,
+,unpa,fuck,
+,uta,mouth,
+,utala,fight,
+,walo,white,
+,wan,one,
+,waso,bird,
+,weka,drop,
+,wawa,power,
+,wile,want,
diff --git a/tokipona/doc.go b/tokipona/doc.go deleted file mode 100644 index 5038499..0000000 --- a/tokipona/doc.go +++ /dev/null @@ -1,6 +0,0 @@ -// Package tokipona is a simple package to walk tokiponatokens sentences and -// decompose them into their component subject, verb and object. -// -// Sorry, most of the type and member names are going to be in Toki Pona so I -// don't have to code switch between English and Toki Pona so much. -package tokipona diff --git a/tokipona/generate.go b/tokipona/generate.go new file mode 100644 index 0000000..f23ef07 --- /dev/null +++ b/tokipona/generate.go @@ -0,0 +1,50 @@ +//+build ignore + +package main + +import ( + "encoding/csv" + "io" + "os" + + . "github.com/dave/jennifer/jen" +) + +func main() { + fin, err := os.Open("./TokiPonaRelex.csv") + if err != nil { + panic(err) + } + defer fin.Close() + relexFile := NewFile("tokipona") + _ = relexFile + r := csv.NewReader(fin) + + fout, err := os.Create("relex_gen.go") + if err != nil { + panic(err) + } + defer fout.Close() + + relexFile.Comment("generated by generate.go; DO NOT EDIT") + + d := Dict{} + + for { + record, err := r.Read() + if err == io.EOF { + break + } + if err != nil { + panic(err) + } + + d[Lit(record[1])] = Lit(record[2]) + } + + relexFile.Var().Id("relexMap").Op("=").Map(String()).String().Values(d) + err = relexFile.Render(fout) + if err != nil { + panic(err) + } +} diff --git a/tokipona/relex.go b/tokipona/relex.go new file mode 100644 index 0000000..6810943 --- /dev/null +++ b/tokipona/relex.go @@ -0,0 +1,27 @@ +package tokipona + +import ( + "strings" + "unicode" +) + +// Relex does a very literal translation of Toki Pona to English. See http://tokipona.net/tp/Relex.aspx for the idea. +func Relex(inp string) string { + f := func(c rune) bool { + return !unicode.IsLetter(c) + } + + words := strings.FieldsFunc(inp, f) + result := []string{} + + for _, word := range words { + if en, ok := relexMap[word]; ok { + result = append(result, en) + } else { + result = append(result, word) + } + + } + + return strings.Join(result, " ") +} diff --git a/tokipona/relex_gen.go b/tokipona/relex_gen.go new file mode 100644 index 0000000..c9722c0 --- /dev/null +++ b/tokipona/relex_gen.go @@ -0,0 +1,130 @@ +package tokipona + +// generated by generate.go; DO NOT EDIT +var relexMap = map[string]string{ + "a": "ah", + "akesi": "frog", + "ala": "not", + "alasa": "hunt", + "ale": "all", + "ali": "all", + "anpa": "down", + "ante": "other", + "anu": "or", + "awen": "keep", + "e": "eh", + "en": "and", + "esun": "store", + "ijo": "thing", + "ike": "bad", + "ilo": "tool", + "insa": "inside", + "jaki": "yucky", + "jan": "human", + "jelo": "yellow", + "jo": "have", + "kala": "fish", + "kalama": "sound", + "kama": "come", + "kasi": "plant", + "ken": "can", + "kepeken": "with", + "kili": "fruit", + "kin": "indeed", + "kipisi": "cut", + "kiwen": "rock", + "ko": "muck", + "kon": "air", + "kule": "color", + "kulupu": "group", + "kute": "ear", + "la": "if", + "lape": "sleep", + "laso": "blue", + "lawa": "head", + "len": "cloth", + "lete": "cold", + "li": "is", + "lili": "little", + "linja": "wave", + "lipu": "sheet", + "loje": "red", + "lon": "at", + "luka": "hand", + "lukin": "see", + "lupa": "hole", + "ma": "land", + "mama": "mom", + "mani": "money", + "meli": "girl", + "mi": "me", + "mije": "man", + "moku": "eat", + "moli": "die", + "monsi": "rear", + "mu": "moo", + "mun": "moon", + "musi": "play", + "mute": "many", + "namako": "extra", + "nanpa": "number", + "nasa": "crazy", + "nasin": "path", + "nena": "bump", + "ni": "this", + "nimi": "name", + "noka": "leg", + "o": "oh", + "oko": "eye", + "olin": "love", + "ona": "they", + "open": "open", + "pakala": "break", + "pali": "work", + "palisa": "stick", + "pan": "bread", + "pana": "give", + "pata": "brother", + "pi": "of", + "pilin": "feel", + "pimeja": "black", + "pini": "end", + "pipi": "bug", + "poka": "with", + "poki": "box", + "pona": "good", + "sama": "same", + "seli": "hot", + "selo": "skin", + "seme": "what", + "sewi": "high", + "sijelo": "body", + "sike": "circle", + "sin": "new", + "sina": "you", + "sinpin": "face", + "sitelen": "drawing", + "sona": "know", + "soweli": "beast", + "suli": "great", + "suno": "sun", + "supa": "couch", + "suwi": "sweet", + "tan": "from", + "taso": "but", + "tawa": "go", + "telo": "water", + "tenpo": "time", + "toki": "speak", + "tomo": "room", + "tu": "two", + "unpa": "fuck", + "uta": "mouth", + "utala": "fight", + "walo": "white", + "wan": "one", + "waso": "bird", + "wawa": "power", + "weka": "drop", + "wile": "want", +} diff --git a/tokipona/relex_test.go b/tokipona/relex_test.go new file mode 100644 index 0000000..ac1166c --- /dev/null +++ b/tokipona/relex_test.go @@ -0,0 +1,27 @@ +package tokipona + +import "testing" + +func TestRelex(t *testing.T) { + cases := []struct { + tokiPona, english string + }{ + { + tokiPona: "sina sona", + english: "you know", + }, + { + tokiPona: "butt", + english: "butt", + }, + } + + for _, cs := range cases { + t.Run(cs.tokiPona, func(t *testing.T) { + get := Relex(cs.tokiPona) + if get != cs.english { + t.Fatalf("wanted: %q got: %q", cs.english, get) + } + }) + } +} diff --git a/tokipona/tokipona.go b/tokipona/tokipona.go deleted file mode 100644 index 7d72fdb..0000000 --- a/tokipona/tokipona.go +++ /dev/null @@ -1,22 +0,0 @@ -package tokipona - -// Toki li wan toki. -// -// Toki is a sentence. -type Toki struct { - Subject []Nimi - Verb []Nimi - Object []Nimi -} - -// Nimi is a single word in Toki Pona. -type Nimi struct { - Nimi string `json:"nimi"` - - Particle string `json:"particle"` - Nouns []string `json:"nouns"` - Adjectives []string `json:"adjectives"` - PreVerbs []string `json:"preverbs"` - Verbs []string `json:"verbs"` - Prepositions []string `json:"prepositions"` -} diff --git a/tokipona/tokipona.yaml b/tokipona/tokipona.yaml deleted file mode 100644 index 3f804c6..0000000 --- a/tokipona/tokipona.yaml +++ /dev/null @@ -1,323 +0,0 @@ -# This is a synthesis for a dictionary in toki pona. The following roles are -# supposed to be interepreted as the following: -# -# xultabangu: # metalanguage -# adjective: -# - describes a trait or quality of a noun -# - x is $ENTRY -# - passive -# noun: -# - explains a thing's identity -# - singular -# number: -# - a quantity -# particle: -# - explains the grammatical role in the sentence -# preposition: -# - expresses spatial or temporal relationships between words -# preverb: -# - gives additional context to a verb -# verb: -# - explains an action, occurance or existence -# - $SUBJECT $VERB $OBJECT -# - plural - -# taken from pu and https://en.wikibooks.org/wiki/Toki_Pona/WordTpEn - -a: - particle: - - emphasis - - emotion - - confirmation - -akesi: - noun: - - non-cute animal - - reptile - - amphibian - -ala: - adjective: - - negated - -alasa: - verb: - - hunts - - forages - -ale: - adjective: - - all - - abundant - - countless - - infinite - - bountiful - - every - - plentiful - - noun: - - abundance - - everything - - life - - universe - - number: - - 100 - -anpa: - adjective: - - bowing down - - downward - - humble - - lowly - - dependent - -ante: - adjective: - - different - - altered - - changed - - other - -anu: - particle: - - or - -awen: - adjective: - - enduring - - kept - - protected - - safe - - waiting - - staying - - preverb: - - continuing to x - -e: - particle: - - marks direct object - -en: - particle: - - combines multiple subjects into one subject (semanticalyl similar but not identical to and in English) - -esun: - noun: - - market - - shop - - fair - - bazarr - - buisiness transaction - -ijo: - noun: - - thing - - phenomenon - - object - - matter - -ike: - adjective: - - bad - - negative - - non-essential - - irrelevant - -ilo: - noun: - - tool - - implement - - machine - - device - -insa: - noun: - - center - - content - - inside - - between - - internal organ - - stomach - -jaki: - adjective: - - disgusting - - obscene - - sickly - - toxic - - unclean - - unsanitary - -jelo: - adjective: - - the color yellow - - similar to the color yellow - -jo: - verb: - - has - - contains - - carries - - holds - -kala: - noun: - - fish - - marine animal - - sea creature - -kalama: - verb: - - produces sound - - recite - - utter aloud - -kama: - adjective: - - arriving - - coming - - in the future - - summoned - - preverb: - - becoming x - - managing to x - - succeeding in x - -kasi: - noun: - - plant - - vegetation - - herb - - leaf - -ken: - adjective: - - possible - - preverb: - - able to x - - allowed to x - - can x - - may x - -kepeken: - preposition: - - to use - - with - - by means - -kili: - noun: - - fruit - - vegetable - - mushroom - -kiwen: - noun: - - hard object - - metal - - rock - - stone - -ko: - noun: - - clay - - clinging form - - dough - - semi-solid - - paste - - powder - -kon: - noun: - - air - - breath - - essence - - spirit - - hidden reality - - unseen agent - -kule: - adjective: - - colorful - - pigmented - - noun: - - color - - paint - - verb: - - color - - paint - -kulupu: - noun: - - community - - company - - group - - nation - - society - - tribe - -kute: - noun: - - ear - - verb: - - hear - - listen - - pay attention to - - obey - -la: - particle: - - separates context phrase and main sentence - -lape: - adjective: - - sleeping - - resting - - noun: - - sleep - - rest - - verb: - - sleeps - - rests - -laso: - adjective: - - blue - - green - -lawa: - noun: - - head - - mind - - adjective: - - - - verb: - - controls - - directs - - guides - - leads - - owns - - plans - - regulates - - rules - -len: - noun: - - cloth - - clothing - - fabric - - textile - - cover - - layer of privacy - |
