package transdb import ( "git.mleku.dev/iskra" "git.smesh.lol/iskradb/lattice" ) // Language domain codes. const ( LangEN uint8 = 0x01 LangJA uint8 = 0x02 LangUnknown uint8 = 0x00 ) // Coord layout constants — re-exported from iskra for package-internal use. const ( CoordSemanticShift = iskra.CoordSemanticShift CoordGrammaticalShift = iskra.CoordGrammaticalShift CoordCooccurShift = iskra.CoordCooccurShift CoordMorphShift = iskra.CoordMorphShift CoordPragmaticShift = iskra.CoordPragmaticShift CoordValencyShift = iskra.CoordValencyShift CoordRegisterShift = iskra.CoordRegisterShift ) // Semantic bitfield constants — re-exported from iskra. const ( SemanticHumanSubj = iskra.SemanticHumanSubj SemanticHumanObj = iskra.SemanticHumanObj SemanticAnimSubj = iskra.SemanticAnimSubj SemanticAnimObj = iskra.SemanticAnimObj SemanticAbstSubj = iskra.SemanticAbstSubj SemanticAbstObj = iskra.SemanticAbstObj SemanticPlaceSubj = iskra.SemanticPlaceSubj SemanticPlaceObj = iskra.SemanticPlaceObj SemanticArtiSubj = iskra.SemanticArtiSubj SemanticArtiObj = iskra.SemanticArtiObj SemanticNatSubj = iskra.SemanticNatSubj SemanticNatObj = iskra.SemanticNatObj SemanticEventSubj = iskra.SemanticEventSubj SemanticEventObj = iskra.SemanticEventObj SemanticCollSubj = iskra.SemanticCollSubj SemanticCollObj = iskra.SemanticCollObj ) // Co-occurrence type constants — re-exported from iskra. const ( CooccurNone = iskra.CooccurNone CooccurNominal = iskra.CooccurNominal CooccurVerbal = iskra.CooccurVerbal CooccurFunction = iskra.CooccurFunction ) // Coord functions delegated to iskra. func PackCoord(semantic, grammatical, cooccur, morph, pragmatic, valency, register uint64) uint64 { return iskra.PackCoord(semantic, grammatical, cooccur, morph, pragmatic, valency, register) } func RelaxCoord(coord uint64) []uint64 { return iskra.RelaxCoord(coord) } func CoordSemantic(coord uint64) uint64 { return iskra.CoordSemantic(coord) } func CoordMorph(coord uint64) uint8 { return iskra.CoordMorph(coord) } func CoordCooccur(prevType, nextType uint8) uint64 { return iskra.CoordCooccur(prevType, nextType) } func CoordPrevType(coord uint64) uint8 { return iskra.CoordPrevType(coord) } func CoordNextType(coord uint64) uint8 { return iskra.CoordNextType(coord) } // MakeKey returns the 128-bit SipHash key for (lang, coord, word). // Delegates to iskra.MakeKey with lang as the domain byte. func MakeKey(lang uint8, coord uint64, word string) lattice.Key { return iskra.MakeKey(lang, coord, word) } // ActiveBranches are the 3 branches used for JA/EN lattice data. var ActiveBranches = [3]lattice.Branch{lattice.Bnoun, lattice.Bverb, lattice.Bmodifier} // POSForWord returns the POS type of a word at coord=0 (JMdict baseline). // Returns 1=nominal, 2=verbal, 3=modifier, 0=unknown. func POSForWord(tree *lattice.Tree, lang uint8, word string) uint8 { key := MakeKey(lang, 0, word) for i, b := range ActiveBranches { if tree.LookupRecIdx(b, key) != lattice.NullRec { return uint8(i + 1) } } return 0 } // POSTypeFor maps POSForWord result to CooccurNominal/Verbal/Function. func POSTypeFor(posResult uint8) uint8 { switch posResult { case 1: return CooccurNominal case 2: return CooccurVerbal case 3: return CooccurFunction } return CooccurNone } // branchOrderJA returns branch search order from coord's cooccurrence axis. func branchOrderJA(coord uint64) [3]uint8 { bMod := uint8(lattice.Bmodifier) bNou := uint8(lattice.Bnoun) bVer := uint8(lattice.Bverb) prevType := CoordPrevType(coord) nextType := CoordNextType(coord) switch { case prevType == CooccurNominal: return [3]uint8{bMod, bNou, bVer} case prevType == CooccurVerbal: return [3]uint8{bMod, bVer, bNou} case nextType == CooccurVerbal: return [3]uint8{bNou, bMod, bVer} default: return [3]uint8{bNou, bVer, bMod} } } // PackCtx — legacy wrapper kept for callers during migration. func PackCtx(prev, cur, next uint8) uint8 { return (prev << 4) | (cur << 2) | next } // CtxToCoord converts old 6-bit ctx to new coord cooccurrence field. func CtxToCoord(ctx uint8) uint64 { prevPOS := (ctx >> 4) & 3 nextPOS := ctx & 3 return CoordCooccur(prevPOS, nextPOS) << CoordCooccurShift } func KeyLang(key lattice.Key) uint8 { return LangUnknown } func LangName(lang uint8) string { switch lang { case LangEN: return "EN" case LangJA: return "JA" } return "?" }