markers.go raw

   1  package iskra
   2  
   3  // Pattern encoding, pattern.mx: a pattern byte is either a content slot
   4  // (0x80 | role) or a marker ID below 0x80.
   5  const (
   6  	SlotNoun     uint8 = 0x80
   7  	SlotVerb     uint8 = 0x81
   8  	SlotModifier uint8 = 0x82
   9  	SlotScope    uint8 = 0x83
  10  	SlotLiteral  uint8 = 0x84
  11  	SlotExpr     uint8 = 0x85
  12  )
  13  
  14  // IsSlot reports a content slot byte.
  15  func IsSlot(b uint8) bool { return b&0x80 != 0 }
  16  
  17  // SlotRole masks a slot byte down to its role.
  18  func SlotRole(b uint8) uint8 { return b & 0x7F }
  19  
  20  // Marker IDs, pattern.mx.
  21  const (
  22  	// JA particles.
  23  	MkWa   uint8 = 1  // は
  24  	MkGa   uint8 = 2  // が
  25  	MkWo   uint8 = 3  // を
  26  	MkNi   uint8 = 4  // に
  27  	MkDe   uint8 = 5  // で
  28  	MkHe   uint8 = 6  // へ
  29  	MkMo   uint8 = 7  // も
  30  	MkNo   uint8 = 8  // の
  31  	MkTo   uint8 = 9  // と
  32  	MkKara uint8 = 10 // から
  33  	MkMade uint8 = 11 // まで
  34  	MkYori uint8 = 12 // より
  35  	MkKedo uint8 = 13 // けど
  36  	MkKa   uint8 = 14 // か
  37  	MkYo   uint8 = 15 // よ
  38  	MkNe   uint8 = 16 // ね
  39  
  40  	// EN structural words.
  41  	MkThe   uint8 = 17
  42  	MkA     uint8 = 18
  43  	MkIn    uint8 = 19
  44  	MkOn    uint8 = 20
  45  	MkAt    uint8 = 21
  46  	MkWith  uint8 = 22
  47  	MkBy    uint8 = 23
  48  	MkFor   uint8 = 24
  49  	MkToEN  uint8 = 25
  50  	MkOf    uint8 = 26
  51  	MkFrom  uint8 = 27
  52  	MkAs    uint8 = 28
  53  	MkThat  uint8 = 29
  54  	MkIs    uint8 = 30
  55  	MkAre   uint8 = 31
  56  	MkWas   uint8 = 32
  57  	MkDo    uint8 = 33
  58  	MkI     uint8 = 34
  59  	MkYou   uint8 = 35
  60  	MkPron3 uint8 = 36
  61  	MkItEN  uint8 = 37
  62  	MkWeEN  uint8 = 38
  63  	MkThey  uint8 = 39
  64  	MkNot   uint8 = 40
  65  	MkAnd   uint8 = 41
  66  	MkBut   uint8 = 42
  67  	MkThan  uint8 = 47
  68  
  69  	// Synthetic morph markers.
  70  	MkDef    uint8 = 43 // ★ definiteness
  71  	MkPlural uint8 = 44 // ☆ plural
  72  	MkCopula uint8 = 45 // 〇 copula
  73  	Mk3Sg    uint8 = 46 // ◯ third person singular
  74  
  75  	// EN possessive determiners.
  76  	MkMy     uint8 = 70
  77  	MkYour   uint8 = 71
  78  	MkHis    uint8 = 72
  79  	MkHerP   uint8 = 73
  80  	MkIts    uint8 = 74
  81  	MkOurP   uint8 = 75
  82  	MkTheirP uint8 = 76
  83  
  84  	// Code structural keywords.
  85  	MkIf     uint8 = 49
  86  	MkElse   uint8 = 50
  87  	MkForC   uint8 = 51
  88  	MkReturn uint8 = 52
  89  	MkLBrace uint8 = 53
  90  	MkRBrace uint8 = 54
  91  	MkLParen uint8 = 55
  92  	MkRParen uint8 = 56
  93  	MkAssign uint8 = 57
  94  	MkDot    uint8 = 58
  95  	MkComma  uint8 = 59
  96  	MkColon  uint8 = 60
  97  	MkArrow  uint8 = 61
  98  	MkCase   uint8 = 62
  99  	MkSelect uint8 = 63
 100  	MkSpawn  uint8 = 64
 101  	MkChan   uint8 = 65
 102  )
 103  
 104  // MarkerToOblRole maps a marker to its oblique role. ORNone means the marker
 105  // carries no thematic role.
 106  func MarkerToOblRole(mk uint8) uint8 {
 107  	switch mk {
 108  	case MkNi:
 109  		return ORGoal
 110  	case MkHe:
 111  		return ORGoal
 112  	case MkDe:
 113  		return ORLoc
 114  	case MkKara:
 115  		return ORSource
 116  	case MkMade:
 117  		return ORLimit
 118  	case MkYori:
 119  		return ORCompare
 120  	case MkTo:
 121  		return ORComit
 122  	case MkNo:
 123  		return ORPart
 124  	case MkToEN:
 125  		return ORGoal
 126  	case MkIn, MkOn, MkAt:
 127  		return ORLoc
 128  	case MkFrom:
 129  		return ORSource
 130  	case MkWith:
 131  		return ORInstr
 132  	case MkBy:
 133  		return ORAgent
 134  	case MkFor:
 135  		return ORBenef
 136  	case MkOf:
 137  		return ORPart
 138  	case MkAs:
 139  		return ORNone
 140  	case MkThan:
 141  		return ORCompare
 142  	}
 143  	return ORNone
 144  }
 145  
 146  // MarkerToRole maps a marker to the role it assigns to the following slot (EN
 147  // prepositions) or the preceding slot (JA particles).
 148  func MarkerToRole(mk uint8) int32 {
 149  	switch mk {
 150  	case MkWa, MkMo:
 151  		return HistTopic
 152  	case MkGa:
 153  		return HistSubject
 154  	case MkWo:
 155  		return HistObject
 156  	case MkNi, MkHe:
 157  		return HistScope
 158  	case MkDe:
 159  		return HistModifier
 160  	case MkNo:
 161  		return HistOperator
 162  	case MkTo:
 163  		return HistObject
 164  	case MkKara, MkFrom:
 165  		return HistScope
 166  	case MkMade:
 167  		return HistScope
 168  	case MkYori, MkThan:
 169  		return HistModifier
 170  	case MkIn, MkOn, MkAt:
 171  		return HistScope
 172  	case MkWith:
 173  		return HistModifier
 174  	case MkBy:
 175  		return HistModifier
 176  	case MkFor:
 177  		return HistModifier
 178  	case MkOf:
 179  		return HistOperator
 180  	case MkToEN:
 181  		return HistScope
 182  	case MkI, MkYou, MkPron3, MkItEN, MkWeEN, MkThey:
 183  		return HistSubject
 184  	case MkIs, MkAre, MkWas, MkDo:
 185  		return HistVerb
 186  	case MkNot:
 187  		return HistModifier
 188  	case MkAnd, MkBut:
 189  		return HistSubject
 190  	}
 191  	return HistComplement
 192  }
 193  
 194  // markerToJA maps marker IDs 1..49 to JA particle strings. 17..42 and 47..49
 195  // are empty: those markers have no JA surface.
 196  var markerToJA = [50]string{
 197  	"",
 198  	"は", "が", "を", "に", "で", "へ", "も", "の", "と",
 199  	"から", "まで", "より", "けど", "か", "よ", "ね",
 200  	"", "", "", "", "", "", "", "", "", "", // 17-26
 201  	"", "", "", "", "", "", "", "", "", "", // 27-36
 202  	"", "", "", "", "", "", // 37-42
 203  	"★",        // 43 MkDef
 204  	"☆",        // 44 MkPlural
 205  	"〇",        // 45 MkCopula
 206  	"◯",        // 46 Mk3Sg
 207  	"", "", "", // 47-49
 208  }
 209  
 210  // jaParticleToMarker builds the JA particle string to marker ID map: the
 211  // sixteen particles plus the four synthetic morph markers.
 212  func jaParticleToMarker() map[string]uint8 {
 213  	m := make(map[string]uint8, 20)
 214  	for i := uint8(1); i <= 16; i++ {
 215  		m[markerToJA[i]] = i
 216  	}
 217  	for _, mk := range []uint8{MkDef, MkPlural, MkCopula, Mk3Sg} {
 218  		m[markerToJA[mk]] = mk
 219  	}
 220  	return m
 221  }
 222  
 223  // enWordToMarker is pattern.mx enWordToMarker: the English structural words
 224  // and what marker each becomes.
 225  func enWordToMarker() map[string]uint8 {
 226  	return map[string]uint8{
 227  		"the":        MkThe,
 228  		"a":          MkA,
 229  		"an":         MkA,
 230  		"in":         MkIn,
 231  		"on":         MkOn,
 232  		"at":         MkAt,
 233  		"with":       MkWith,
 234  		"by":         MkBy,
 235  		"for":        MkFor,
 236  		"to":         MkToEN,
 237  		"of":         MkOf,
 238  		"from":       MkFrom,
 239  		"as":         MkAs,
 240  		"that":       MkThat,
 241  		"which":      MkThat,
 242  		"who":        MkThat,
 243  		"than":       MkThan,
 244  		"is":         MkIs,
 245  		"are":        MkAre,
 246  		"was":        MkWas,
 247  		"were":       MkWas,
 248  		"am":         MkIs,
 249  		"be":         MkIs,
 250  		"been":       MkIs,
 251  		"being":      MkIs,
 252  		"do":         MkDo,
 253  		"does":       MkDo,
 254  		"did":        MkDo,
 255  		"will":       MkDo,
 256  		"would":      MkDo,
 257  		"shall":      MkDo,
 258  		"should":     MkDo,
 259  		"can":        MkDo,
 260  		"could":      MkDo,
 261  		"may":        MkDo,
 262  		"might":      MkDo,
 263  		"must":       MkDo,
 264  		"have":       MkDo,
 265  		"has":        MkDo,
 266  		"had":        MkDo,
 267  		"i":          MkI,
 268  		"me":         MkI,
 269  		"mine":       MkI,
 270  		"myself":     MkI,
 271  		"my":         MkMy,
 272  		"you":        MkYou,
 273  		"yours":      MkYou,
 274  		"yourself":   MkYou,
 275  		"your":       MkYour,
 276  		"he":         MkPron3,
 277  		"him":        MkPron3,
 278  		"himself":    MkPron3,
 279  		"his":        MkHis,
 280  		"she":        MkPron3,
 281  		"hers":       MkPron3,
 282  		"herself":    MkPron3,
 283  		"her":        MkHerP,
 284  		"it":         MkItEN,
 285  		"itself":     MkItEN,
 286  		"its":        MkIts,
 287  		"we":         MkWeEN,
 288  		"us":         MkWeEN,
 289  		"ours":       MkWeEN,
 290  		"ourselves":  MkWeEN,
 291  		"our":        MkOurP,
 292  		"they":       MkThey,
 293  		"them":       MkThey,
 294  		"theirs":     MkThey,
 295  		"themselves": MkThey,
 296  		"their":      MkTheirP,
 297  		"this":       MkItEN,
 298  		"these":      MkThey,
 299  		"those":      MkThey,
 300  		"not":        MkNot,
 301  		"n't":        MkNot,
 302  		"and":        MkAnd,
 303  		"or":         MkAnd,
 304  		"but":        MkBut,
 305  		"however":    MkBut,
 306  		"although":   MkBut,
 307  		"about":      MkOf,
 308  		"into":       MkIn,
 309  		"onto":       MkOn,
 310  		"through":    MkIn,
 311  		"over":       MkOn,
 312  		"under":      MkAt,
 313  		"after":      MkFrom,
 314  		"before":     MkToEN,
 315  		"between":    MkAt,
 316  		"among":      MkAt,
 317  		"during":     MkAt,
 318  		"until":      MkToEN,
 319  		"since":      MkFrom,
 320  		"without":    MkWith,
 321  		"within":     MkIn,
 322  		"around":     MkAt,
 323  		"behind":     MkAt,
 324  		"beside":     MkAt,
 325  		"toward":     MkToEN,
 326  		"towards":    MkToEN,
 327  		"across":     MkIn,
 328  		"along":      MkIn,
 329  		"against":    MkWith,
 330  		"upon":       MkOn,
 331  	}
 332  }
 333