conjugate.mx raw

   1  package ingest
   2  
   3  import (
   4  	"git.smesh.lol/iskradb/lattice"
   5  	"git.smesh.lol/transdb"
   6  )
   7  
   8  // GenerateConjugations inserts MorphState 1+ records for a Bverb entry.
   9  // Uses BuildVerbForms from transdb.morph.mx — single source for conjugation tables.
  10  // State 0 (base form) must already be in the lattice. firstEN is the EN record index.
  11  func GenerateConjugations(db *DB, dictForm, verbClass string,
  12  	branch lattice.Branch, branchByte uint8, firstEN uint32) {
  13  
  14  	if firstEN == lattice.NullRec || verbClass == "" {
  15  		return
  16  	}
  17  
  18  	forms := transdb.BuildVerbForms(dictForm, verbClass)
  19  	if len(forms) == 0 {
  20  		return
  21  	}
  22  
  23  	for state, form := range forms {
  24  		if form == "" || form == dictForm || state == 0 {
  25  			continue
  26  		}
  27  		// Insert at coord with morphological axis set — enables direct coord lookup.
  28  		// DataFile MorphState redundantly encodes state for post-lookup applyMorphEN.
  29  		coord := transdb.PackCoord(0, 0, 0, uint64(state), 0, 0, 0)
  30  		key := transdb.MakeKey(transdb.LangJA, coord, form)
  31  		if db.Tree.LookupRecIdx(branch, key) != lattice.NullRec {
  32  			continue
  33  		}
  34  		var rec lattice.Record
  35  		transdb.SetFormOnRecord(&rec, form, &db.StringPool)
  36  		rec.Branch = branchByte
  37  		transdb.SetMorphState(&rec, state)
  38  		newRI := db.Tree.InsertRec(branch, key, rec)
  39  		if r := db.Tree.GetRecord(newRI); r != nil {
  40  			r.Link[0] = firstEN
  41  		}
  42  	}
  43  }
  44