package iskra // Pattern encoding, pattern.mx: a pattern byte is either a content slot // (0x80 | role) or a marker ID below 0x80. const ( SlotNoun uint8 = 0x80 SlotVerb uint8 = 0x81 SlotModifier uint8 = 0x82 SlotScope uint8 = 0x83 SlotLiteral uint8 = 0x84 SlotExpr uint8 = 0x85 ) // IsSlot reports a content slot byte. func IsSlot(b uint8) bool { return b&0x80 != 0 } // SlotRole masks a slot byte down to its role. func SlotRole(b uint8) uint8 { return b & 0x7F } // Marker IDs, pattern.mx. const ( // JA particles. MkWa uint8 = 1 // は MkGa uint8 = 2 // が MkWo uint8 = 3 // を MkNi uint8 = 4 // に MkDe uint8 = 5 // で MkHe uint8 = 6 // へ MkMo uint8 = 7 // も MkNo uint8 = 8 // の MkTo uint8 = 9 // と MkKara uint8 = 10 // から MkMade uint8 = 11 // まで MkYori uint8 = 12 // より MkKedo uint8 = 13 // けど MkKa uint8 = 14 // か MkYo uint8 = 15 // よ MkNe uint8 = 16 // ね // EN structural words. MkThe uint8 = 17 MkA uint8 = 18 MkIn uint8 = 19 MkOn uint8 = 20 MkAt uint8 = 21 MkWith uint8 = 22 MkBy uint8 = 23 MkFor uint8 = 24 MkToEN uint8 = 25 MkOf uint8 = 26 MkFrom uint8 = 27 MkAs uint8 = 28 MkThat uint8 = 29 MkIs uint8 = 30 MkAre uint8 = 31 MkWas uint8 = 32 MkDo uint8 = 33 MkI uint8 = 34 MkYou uint8 = 35 MkPron3 uint8 = 36 MkItEN uint8 = 37 MkWeEN uint8 = 38 MkThey uint8 = 39 MkNot uint8 = 40 MkAnd uint8 = 41 MkBut uint8 = 42 MkThan uint8 = 47 // Synthetic morph markers. MkDef uint8 = 43 // ★ definiteness MkPlural uint8 = 44 // ☆ plural MkCopula uint8 = 45 // 〇 copula Mk3Sg uint8 = 46 // ◯ third person singular // EN possessive determiners. MkMy uint8 = 70 MkYour uint8 = 71 MkHis uint8 = 72 MkHerP uint8 = 73 MkIts uint8 = 74 MkOurP uint8 = 75 MkTheirP uint8 = 76 // Code structural keywords. MkIf uint8 = 49 MkElse uint8 = 50 MkForC uint8 = 51 MkReturn uint8 = 52 MkLBrace uint8 = 53 MkRBrace uint8 = 54 MkLParen uint8 = 55 MkRParen uint8 = 56 MkAssign uint8 = 57 MkDot uint8 = 58 MkComma uint8 = 59 MkColon uint8 = 60 MkArrow uint8 = 61 MkCase uint8 = 62 MkSelect uint8 = 63 MkSpawn uint8 = 64 MkChan uint8 = 65 ) // MarkerToOblRole maps a marker to its oblique role. ORNone means the marker // carries no thematic role. func MarkerToOblRole(mk uint8) uint8 { switch mk { case MkNi: return ORGoal case MkHe: return ORGoal case MkDe: return ORLoc case MkKara: return ORSource case MkMade: return ORLimit case MkYori: return ORCompare case MkTo: return ORComit case MkNo: return ORPart case MkToEN: return ORGoal case MkIn, MkOn, MkAt: return ORLoc case MkFrom: return ORSource case MkWith: return ORInstr case MkBy: return ORAgent case MkFor: return ORBenef case MkOf: return ORPart case MkAs: return ORNone case MkThan: return ORCompare } return ORNone } // MarkerToRole maps a marker to the role it assigns to the following slot (EN // prepositions) or the preceding slot (JA particles). func MarkerToRole(mk uint8) int32 { switch mk { case MkWa, MkMo: return HistTopic case MkGa: return HistSubject case MkWo: return HistObject case MkNi, MkHe: return HistScope case MkDe: return HistModifier case MkNo: return HistOperator case MkTo: return HistObject case MkKara, MkFrom: return HistScope case MkMade: return HistScope case MkYori, MkThan: return HistModifier case MkIn, MkOn, MkAt: return HistScope case MkWith: return HistModifier case MkBy: return HistModifier case MkFor: return HistModifier case MkOf: return HistOperator case MkToEN: return HistScope case MkI, MkYou, MkPron3, MkItEN, MkWeEN, MkThey: return HistSubject case MkIs, MkAre, MkWas, MkDo: return HistVerb case MkNot: return HistModifier case MkAnd, MkBut: return HistSubject } return HistComplement } // markerToJA maps marker IDs 1..49 to JA particle strings. 17..42 and 47..49 // are empty: those markers have no JA surface. var markerToJA = [50]string{ "", "は", "が", "を", "に", "で", "へ", "も", "の", "と", "から", "まで", "より", "けど", "か", "よ", "ね", "", "", "", "", "", "", "", "", "", "", // 17-26 "", "", "", "", "", "", "", "", "", "", // 27-36 "", "", "", "", "", "", // 37-42 "★", // 43 MkDef "☆", // 44 MkPlural "〇", // 45 MkCopula "◯", // 46 Mk3Sg "", "", "", // 47-49 } // jaParticleToMarker builds the JA particle string to marker ID map: the // sixteen particles plus the four synthetic morph markers. func jaParticleToMarker() map[string]uint8 { m := make(map[string]uint8, 20) for i := uint8(1); i <= 16; i++ { m[markerToJA[i]] = i } for _, mk := range []uint8{MkDef, MkPlural, MkCopula, Mk3Sg} { m[markerToJA[mk]] = mk } return m } // enWordToMarker is pattern.mx enWordToMarker: the English structural words // and what marker each becomes. func enWordToMarker() map[string]uint8 { return map[string]uint8{ "the": MkThe, "a": MkA, "an": MkA, "in": MkIn, "on": MkOn, "at": MkAt, "with": MkWith, "by": MkBy, "for": MkFor, "to": MkToEN, "of": MkOf, "from": MkFrom, "as": MkAs, "that": MkThat, "which": MkThat, "who": MkThat, "than": MkThan, "is": MkIs, "are": MkAre, "was": MkWas, "were": MkWas, "am": MkIs, "be": MkIs, "been": MkIs, "being": MkIs, "do": MkDo, "does": MkDo, "did": MkDo, "will": MkDo, "would": MkDo, "shall": MkDo, "should": MkDo, "can": MkDo, "could": MkDo, "may": MkDo, "might": MkDo, "must": MkDo, "have": MkDo, "has": MkDo, "had": MkDo, "i": MkI, "me": MkI, "mine": MkI, "myself": MkI, "my": MkMy, "you": MkYou, "yours": MkYou, "yourself": MkYou, "your": MkYour, "he": MkPron3, "him": MkPron3, "himself": MkPron3, "his": MkHis, "she": MkPron3, "hers": MkPron3, "herself": MkPron3, "her": MkHerP, "it": MkItEN, "itself": MkItEN, "its": MkIts, "we": MkWeEN, "us": MkWeEN, "ours": MkWeEN, "ourselves": MkWeEN, "our": MkOurP, "they": MkThey, "them": MkThey, "theirs": MkThey, "themselves": MkThey, "their": MkTheirP, "this": MkItEN, "these": MkThey, "those": MkThey, "not": MkNot, "n't": MkNot, "and": MkAnd, "or": MkAnd, "but": MkBut, "however": MkBut, "although": MkBut, "about": MkOf, "into": MkIn, "onto": MkOn, "through": MkIn, "over": MkOn, "under": MkAt, "after": MkFrom, "before": MkToEN, "between": MkAt, "among": MkAt, "during": MkAt, "until": MkToEN, "since": MkFrom, "without": MkWith, "within": MkIn, "around": MkAt, "behind": MkAt, "beside": MkAt, "toward": MkToEN, "towards": MkToEN, "across": MkIn, "along": MkIn, "against": MkWith, "upon": MkOn, } }