当前位置: 首页 > news >正文

go单词训练的通用结构体

本文摘要:代码展示了Go语言实现的单词训练系统核心数据结构。包含GroupResp响应结构体,管理6种训练模式(闪记、语境、二选一、三选一、消消乐、速筛);TrainRequest训练请求结构体,记录训练计划、状态、时间及模式配置;TrainModes定义训练模式基础属性和单词矩阵操作,支持复制、洗牌、计算轮次等功能;TrainModeWord描述单词训练项,包含基础信息、选项和关联句子。系统采用模块化设计,通过方法链式调用实现配置初始化、计算和状态管理,支持JSON序列化和文件存储。

package selectdto import ( "gitea.super-study.com/ys-study/gotrain/beapi/trainword/selectdto/trainmode" "gitee.com/gowebframe3/webframe.git/goconfig/base/basedto" ) type GroupResp struct { basedto.BaseEntitySingle *GroupRequest // 运行指针 Current Current `json:"current"` // 闪记模式1 FlashMode1 *trainmode.TrainModes `json:"flashMode1"` // 语境模式2 ContextMode2 *trainmode.TrainModes `json:"contextMode2"` // 二选一模式 3 Choice2Mode3 *trainmode.TrainModes `json:"choice2Mode3"` // 三选一模式 4 Choice3Mode4 *trainmode.TrainModes `json:"choice3Mode4"` // 消消乐模式 5 MatchMode5 *trainmode.TrainModes `json:"matchMode5"` // 速筛模式 ScreenMode6 *trainmode.TrainModes `json:"screenMode6"` } func NewGroupResp() *GroupResp { return &GroupResp{ FlashMode1: trainmode.FindBeanTrainModes().InitMode("mode1"), ContextMode2: trainmode.FindBeanTrainModes().InitMode("mode2"), Choice2Mode3: trainmode.FindBeanTrainModes().InitMode("mode3"), Choice3Mode4: trainmode.FindBeanTrainModes().InitMode("mode4"), MatchMode5: trainmode.FindBeanTrainModes().InitMode("mode5"), ScreenMode6: trainmode.FindBeanTrainModes().InitMode("mode6"), } } func (self *GroupResp) WithReq(req *GroupRequest) *GroupResp { self.GroupRequest = req return self } func (self *GroupResp) Compute() *GroupResp { self.FlashMode1.Compute() self.ContextMode2.Compute() self.Choice2Mode3.Compute() self.Choice3Mode4.Compute() self.MatchMode5.Compute() self.ScreenMode6.Compute() return self } type Current struct { // review or bulge CurrentFlow string `json:"currentFlow"` // groupIndex CurrentGroup int32 `json:"currentGroup"` // mode1-mode6 CurrentMode string `json:"currentMode"` // 1-3 轮次 CurrentRound int32 `json:"currentRound"` }
package trainmode import ( "time" "gitea.super-study.com/ys-study/gotrain/beapi/trainword/selectdto/trainreq" "gitee.com/gowebframe3/webframe.git/goconfig/base/basedto" "gitee.com/gowebframe3/webframe.git/goconfig/base/fileutils" "gitee.com/gowebframe3/webframe.git/goconfig/ichubconfig" "github.com/samber/lo" ) type Req struct { TrainPlanId int64 `json:"trainPlanId,string"` // 是否随机顺序 IfRandomSeq bool `json:"ifRandomSeq"` // 训练组编号 GroupIndex int32 `json:"groupIndex"` } // TrainRequest 训练请求(修复拼写错误:Resuest -> Request) type TrainRequest struct { basedto.BaseEntity `json:"-"` Id int64 `json:"id,string"` // OPC OpcId int64 `json:"opcId,string"` // 训练计划ID TrainPlanId int64 `json:"trainPlanId,string"` // 训练组ID GroupId int64 `json:"groupId"` // 训练组编号 GroupNo int32 `json:"groupNo"` // 当前模式 CurrentMode string `json:"currentMode"` // 状态, 0: 未开始, 1: 进行中, 2: 已完成 Status int `json:"status" gorm:"size:8;default:0"` // 训练开始时间 StartAt time.Time `json:"startAt"` // 训练结束时间 EndAt time.Time `json:"endAt"` // 单词列表 Words *TrainModes `json:"-"` // 上一次训练单词列表(用于筛查复习) LastWords *TrainModes `json:"lastWords"` // 是否随机顺序 IfRandomSeq bool `json:"ifRandomSeq"` TrainModesRequest TrainResult *TrainResult `json:"trainResult"` // 训练结果 } type TrainModesRequest struct { Req // 语境模式 ContextMode *TrainModes `json:"contextMode"` // 消消乐模式 3 MatchMode *TrainModes `json:"matchMode"` // 速筛模式 ScreenMode *TrainModes `json:"screenMode"` // 二选一模式 2 Choice2Mode *TrainModes `json:"choice2Mode"` // 三选一模式 2 Choice3Mode *TrainModes `json:"choice3Mode"` // 闪记模式 FlashMode *TrainModes `json:"flashMode"` } func (self *TrainModesRequest) Init() *TrainModesRequest { self.MatchMode = FindBeanTrainModes() self.ScreenMode = FindBeanTrainModes() self.ContextMode = FindBeanTrainModes() self.Choice2Mode = FindBeanTrainModes() self.Choice3Mode = FindBeanTrainModes() self.FlashMode = FindBeanTrainModes() return self } // reqOrRes 训练请求或结果 // NewTrainRequest 创建训练请求实例(直接初始化,简化Init方法) func NewTrainRequest() *TrainRequest { var req = &TrainRequest{ LastWords: FindBeanTrainModes(), Words: FindBeanTrainModes(), } req.TrainModesRequest.Init() return req } func (self *TrainRequest) InitDemo() *TrainRequest { self.LastWords.InitDemo() self.Words.InitDemo() self.MatchMode.InitDemo() self.ScreenMode.InitDemo() self.ContextMode.InitDemo() self.Choice2Mode.InitDemo() self.Choice3Mode.InitDemo() self.FlashMode.InitDemo() return self } func (self *TrainRequest) Save2File() *TrainRequest { fileutils.WriteBytesFile(ichubconfig.GetBathPath()+"/data/traindata/train_request.json", self.ToJsonBytes()) return self } // TrainModes 训练模式单词集合 type TrainModes struct { basedto.BaseEntity `json:"-" gorm:"-"` GroupNo int32 `json:"groupNo"` // 总轮次 RoundCount int `json:"roundCount"` WordCurrent int `json:"wordCurrent"` // 模式名称 mode1-7 pre last ModeName string `json:"modeName"` // 模式类型标识 ModeType string `json:"modeType"` // 是否为矩阵模式,二维 IfMatrix bool `json:"ifMatrix"` // 训练单词列表 Words [][]*trainreq.TrainModeWord `json:"words"` } // NewTrainModeWords 创建训练模式单词集合实例 func NewTrainModeWords() *TrainModes { return &TrainModes{ ModeType: "", Words: make([][]*trainreq.TrainModeWord, 0), } } func (self *TrainModes) Copy(data []*trainreq.TrainModeWord) []*trainreq.TrainModeWord { data = lo.Map(data, func(item *trainreq.TrainModeWord, index int) *trainreq.TrainModeWord { v := *item return &v }) return data } func (self *TrainModes) Shuffle(data []*trainreq.TrainModeWord) []*trainreq.TrainModeWord { return lo.Shuffle(data) } func (self *TrainModes) CopyShuffle(data []*trainreq.TrainModeWord) []*trainreq.TrainModeWord { return lo.Shuffle(self.Copy(data)) } func (self *TrainModes) Compute() *TrainModes { self.RoundCount = len(self.Words) self.IfMatrix = self.RoundCount > 1 return self } func DefaultModeContext() *TrainModes { var mode = FindBeanTrainModes() mode.ModeName = "语境模式" mode.ModeType = "mode2" return mode } func (self *TrainModes) InitMode(modetype string) *TrainModes { self.ModeType = modetype if modetype == "mode1" { self.ModeName = "闪记模式" } if modetype == "mode2" { self.ModeName = "语境模式" } if modetype == "mode3" { self.ModeName = "二选一模式" } if modetype == "mode4" { self.ModeName = "三选一模式" } if modetype == "mode5" { self.ModeName = "消消乐模式" } if modetype == "mode6" { self.ModeName = "速筛模式" } return self } func (self *TrainModes) AppendModeWord(words []*trainreq.TrainModeWord) *TrainModes { self.Words = append(self.Words, words) self.RoundCount = len(self.Words) self.IfMatrix = self.RoundCount > 1 return self } func (self *TrainModes) InitDemo() *TrainModes { self.Words = append(self.Words, []*trainreq.TrainModeWord{&trainreq.TrainModeWord{}}) return self } func (Self *TrainModes) GetWords(index ...int) []*trainreq.TrainModeWord { if Self.IfMatrix { return Self.GetMatrix(0) } if len(index) == 0 || index[0] >= Self.RoundCount { return []*trainreq.TrainModeWord{} } return Self.GetMatrix(index[0]) } func (Self *TrainModes) GetMatrix(index int) []*trainreq.TrainModeWord { return Self.Words[index] }
package trainreq import ( "gitea.super-study.com/ys-study/gotrain/beapi/dbview/viewentity" "gitee.com/gowebframe3/webframe.git/goconfig/base/basedto" ) type TrainModeWord struct { basedto.BaseEntity `json:"-"` // 单词基础信息 TrainDetail // 单词匹配选项列表 Options []TrainChoice `json:"options,omitempty"` // 关联句子 Sentences []*TrainSentence `json:"sentences,omitempty"` } type TrainModeWordResult struct { basedto.BaseEntity `json:"-"` // 单词基础信息 TrainDetail //消消乐选中 MatchSelected bool `json:"matchSelected"` //结果OK Passed bool `json:"passed"` } func NewTrainModeWordResult() *TrainModeWordResult { return &TrainModeWordResult{} } func NewTrainModeWord() *TrainModeWord { return &TrainModeWord{} } type TrainChoice struct { // 选项ID Id string `json:"id"` // 选项值 Val string `json:"val"` } type TrainSentence struct { // 关联句子id Id int64 `json:"id,string"` // 关联句子英文 En string `json:"en"` // 关联句子中文 Cn string `json:"cn"` // 单词等级 Level int `json:"level"` viewentity.WordMapper }
package trainreq import ( "gitee.com/gowebframe3/webframe.git/goconfig/base/jsonutils" "gitee.com/gowebframe3/webframe.git/goconfig/ichublog/golog" ) type TrainWord struct { TrainDetail Ok bool `json:"ok"` Selected bool `json:"selected"` } type TrainDetail struct { // 单词ID Id int64 `json:"id" form:"id,string" gorm:"autoIncrement;primaryKey"` // 单词内容 Word string `json:"word" form:"word" gorm:"size:256;not null;unique"` // 内容类型:word/choice/sentence WordType string `json:"wordType"` // 单词类型:word/choice/sentence // 词性 PartSpeech string `json:"partSpeech" form:"partSpeech" gorm:"size:32;column:part_speech"` // 单词含义 Meaning string `json:"meaning" form:"meaning" gorm:"size:256;not null"` // 国际音标 Ipa string `json:"ipa" form:"ipa" gorm:"size:128"` // 单词等级 Level int16 `json:"level" form:"level" gorm:"column:level"` // 单词音频 Audio *string `json:"audio,omitempty" gorm:"type:json;serializer:json"` // 单词音频 Audios []string `json:"audios" gorm:"-"` // 单词提示 Hint string `json:"hint" form:"hint" gorm:"size:256"` } func (self *TrainDetail) IfAudio() bool { return self.Audio != nil && *self.Audio != "" && *self.Audio != "[]" } func (self *TrainDetail) AudioTrans() { self.Audios = []string{} if self.IfAudio() { err := jsonutils.FromJson(*self.Audio, &self.Audios) if err != nil { golog.Error(err) } else { self.Audio = nil } } }

测试

func (self *TestSumService) Test008_wordsStartGroup() { var req = selectdto.FindBeanGroupRequest() req.TrainPlanId = 99 req.StudentId = ginctx.ID_USER_LEIJMDAS_137_STU req.GroupIndex = 1 req.WordIds = []string{ "100444", "101328", "101336", "101074", "101406", } var ret = trainflow.FindBeanTrainWordFlow().StartGroup(req) golog.Info(ret) fileutils.Save2File(ichubconfig.GetBathPath()+"/data/mode_all模式.json", ret) }
http://www.jsqmd.com/news/905452/

相关文章:

  • 从物理和优化理论看深度学习:动量(momentum)不只是加速,weight decay如何塑造模型‘体型’?
  • 对比直接使用原厂API体验Taotoken在多模型切换上的便捷性
  • 量子阱电荷陷阱突触晶体管:硅基神经形态计算的超低功耗硬件方案
  • 地平线x3使用vscode 远程调试linux虚拟机或者arm 开发板
  • 从宏命令到RuntimePlatform:深入理解Unity平台判断的底层逻辑与演进
  • 2026东莞寮步优质办公室装修企业盘点 专业力量赋能企业空间升级 - GrowthUME
  • 树莓派复古街机DIY全攻略:从硬件选型到RetroPie配置实战
  • 动效一致性崩塌预警!Sora 2中CSS @keyframes与JS Animation API协同失效的4层时序冲突(附Time Slicing修复补丁)
  • 微信 Bot 的“App Store”来了:从零搭建你的智能助手,全程不写代码
  • Arduino智能灌溉系统:从传感器到物联网的DIY实践
  • 干货合集:盘点2026年最受喜爱的的AI智能降重工具
  • WASM入门:开启高性能Web开发之旅
  • STM32H750+DCMI+OV2640实战:手把手教你用CubeIDE搞定JPEG图像采集(附源码)
  • 如何用免费AI工具将模糊照片变高清:Upscayl终极指南
  • 基于Arduino Mega 2560的金属探测器制作:从电磁感应原理到实战调试
  • 2026河南舞钢寄快递省钱指南|避坑科普+4款实测靠谱低价平台全推荐 - 时讯资讯
  • 猫抓浏览器扩展:一键捕获网页视频资源的终极免费工具
  • 保姆级教程:用NodeMediaClient-Android 2.8.4搞定Android RTSP低延迟播放(附完整配置代码)
  • AssemblyScript:TypeScript到WebAssembly的桥梁
  • DS18B20与Arduino温度监测:从单总线协议到多点测温实战
  • 2026年提示工程实战:7大技巧提升与大模型协作效率
  • 2026降AI率工具红黑榜:降AIGC网站怎么选?清单来了
  • 2026东莞麻涌全屋翻新整装实力品牌盘点 本土优质企业赋能人居升级 - GrowthUME
  • 2026东莞沙田局部翻新改造优选企业盘点 本土实力品牌赋能人居升级 - GrowthUME
  • 基于Arduino的智能小车:集成避障、巡线与遥控的机电一体化实践
  • AI项目成功之道:从业务痛点出发,定义可执行的技术规格
  • 告别手动打标!用Labelme命令行5分钟搞定图像分类和目标检测数据集
  • WASM性能对比:JavaScript vs WebAssembly
  • 基于NeuroLink与MCP协议构建企业级AI助手:从架构设计到生产部署
  • 完整的开发工具链是什么?