package lattice // Rotation is the transition between two positions on the ternary lattice // triangle, or a punctuation operator. Values 1-3 rotate, 4+ punctuate. // This is the go-ref rotation model; no iskra .mx file defines it. // // noun (1) // / \ // left right // / \ // mod (3) -------- verb (2) // // Right = clockwise N->V, V->M, M->N // Left = counterwise N->M, M->V, V->N // Stay = same branch N->N, V->V, M->M type Rotation uint8 const ( RotUnknown Rotation = 0 RotRight Rotation = 1 RotLeft Rotation = 2 RotStay Rotation = 3 RotList Rotation = 4 RotDefine Rotation = 5 RotRelate Rotation = 6 RotStop Rotation = 7 RotExclaim Rotation = 8 RotQuestion Rotation = 9 RotQuoteOpen Rotation = 10 RotQuoteClose Rotation = 11 ) // BranchRotation returns the rotation from one primary branch to another, or // RotUnknown if either branch is TritEnd. func BranchRotation(from, to uint8) Rotation { if from < BranchType || from > BranchData || to < BranchType || to > BranchData { return RotUnknown } if from == to { return RotStay } if to == (from%3)+1 { return RotRight } return RotLeft } // IsPunctuation reports whether the rotation is a structural operator. func (r Rotation) IsPunctuation() bool { return r >= RotList } // IsBreak reports whether the punctuation ends a phrase (. ! ?). func (r Rotation) IsBreak() bool { return r == RotStop || r == RotExclaim || r == RotQuestion } // String returns the operator's surface form. func (r Rotation) String() string { switch r { case RotRight: return "right" case RotLeft: return "left" case RotStay: return "stay" case RotList: return "," case RotDefine: return ":" case RotRelate: return ";" case RotStop: return "." case RotExclaim: return "!" case RotQuestion: return "?" case RotQuoteOpen, RotQuoteClose: return "\"" default: return "?" } } // RuneToRotation maps punctuation to its operator, or RotUnknown. func RuneToRotation(r rune) Rotation { switch r { case ',': return RotList case ':': return RotDefine case ';': return RotRelate case '.': return RotStop case '!': return RotExclaim case '?': return RotQuestion case '"', '\u201C', '\u00AB': return RotQuoteOpen case '\u201D', '\u00BB': return RotQuoteClose default: return RotUnknown } } // TritPathDistance is the lattice distance between two coordinates. -1 when // either is unassigned. This is Distance over TritPath; the moxie source keeps // both names. func TritPathDistance(a, b TritPath) int { return Distance(a, b) } // SetBigramTransition stores the target coordinate and the rotation on a // bigram's MetaEntry. func (m *MetaEntry) SetBigramTransition(rot Rotation, target TritPath) { m.SetTritPath(target) m.SetRotation(rot) } // GetBigramTransition reads the rotation and target coordinate back. func (m *MetaEntry) GetBigramTransition() (Rotation, TritPath) { return m.Rotation(), m.TritPath() }