话术制作,上一句、下一句关联
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
#Region ;**** 参数创建于 ACNWrapper_GUI **** #PRE_Icon=bender_favicon.ico #PRE_Outfile_x64=huashumaker.exe #PRE_UseUpx=n #PRE_Res_Comment=www.gaohaiyan.com #PRE_Res_Description=autoit语言开发的 #PRE_Res_LegalCopyright=www.gaohaiyan.com #PRE_Res_requestedExecutionLevel=None #PRE_Res_Field=site|www.gaohaiyan.com #EndRegion ;**** 参数创建于 ACNWrapper_GUI **** #include <File.au3> #include <Array.au3> #include <SQLite.au3> #include <WinAPI.au3> #include <Process.au3> #include <GUIEdit.au3> #include <GuiMenu.au3> #Include <WinAPIEx.au3> #include <SQLite.dll.au3> #include <WinAPIFiles.au3> #include <GuiListView.au3> #include <FileConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $guiWelcome Global $selectMorePopupWindow Global $selectedItems Global $windowWidth = @DesktopWidth / 4 * 3 Global $windowHeight = @DesktopHeight / 3 * 2 Global $editWidth = 360 Global $widgetHeight = 25 Global $meEdit Global $otherEdit Global $otherItemListLabel Global $listView Global Enum $menuDeleteListViewItem,$menuInsertAnswerListViewItem Global $db Global $listViewItemIndex = -1 Global $chatIndex = -1 Global $lastIndex = -1 Global $nextIndex = -1 _SQLite_Startup() If @error Then MsgBox($MB_SYSTEMMODAL, "SQLite 错误", "SQLite3.dll 不能加载!") ; @echo 开始注册 ; copy sqlite3.dll 64位版 %windir%\SysWOW64\ ; regsvr32 %windir%\SysWOW64\sqlite3.dll 64位版 /s ; @echo sqlite3.dll 64位版注册成功 ; @pause Exit -1 Else $db = _SQLite_Open(@ScriptDir&"/jiuren.db") ; 打开一个永久的磁盘数据库 If @error Then MsgBox($MB_SYSTEMMODAL, "SQLite 错误", "无法打开或创建一个永久性的数据库!") Exit -1 EndIf EndIf $guiWelcome = GUICreate("话术制作工具", $windowWidth,$windowHeight) GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_EVENT_CLOSE") $load = GUICtrlCreateButton("加载话术",4,6,60,$widgetHeight) GUICtrlSetOnEvent($load, "_LoadButtonEvent") $export = GUICtrlCreateButton("导出话术",70,6,60,$widgetHeight) GUICtrlSetOnEvent($export, "_ExportButtonEvent") GUICtrlCreateGraphic(0, 34, $windowWidth, 5, 0) GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, 2) ; 起始点 GUICtrlSetGraphic(-1, $GUI_GR_LINE, $windowWidth, 2) $resetOtherBtn = GUICtrlCreateButton("重置",4,41,30,$widgetHeight-5) GUICtrlSetOnEvent($resetOtherBtn, "_ResetOtherButtonEvent") GUICtrlCreateLabel("【对方话术】",34,44,80,$widgetHeight) $selectMoreBtn = GUICtrlCreateButton("选择相似话术",$editWidth-80-6,41,90,$widgetHeight-5) GUICtrlSetOnEvent($selectMoreBtn,"_SelectMoreButtonEvent") $otherItemListLabel = GUICtrlCreateLabel("",106,44,$editWidth-200,$widgetHeight) $otherEdit = GUICtrlCreateEdit("", 4, 64, $editWidth, 120, BitOR($ES_AUTOVSCROLL,$ES_READONLY,$WS_HSCROLL,$WS_VSCROLL)) GUICtrlCreateLabel("【回答话术】([对方话术]为空时,此为双方沟通第一句)",6,200,$editWidth,20) $meEdit = GUICtrlCreateEdit("", 4, 220, $editWidth, 120) $saveBtn = GUICtrlCreateButton("输入",$editWidth-56,355,60,$widgetHeight) GUICtrlSetOnEvent($saveBtn,"_OnSaveButtonEvent") Local $heightOfListView = $windowHeight - 80 $listView = GUICtrlCreateListView ( "索引|话术|上一句|下一句", $editWidth+8, 44, $windowWidth-$editWidth-12, $heightOfListView) _GUICtrlListView_SetExtendedListViewStyle($listView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER,$LVS_SHOWSELALWAYS, $LVS_REPORT)) GUICtrlSetBkColor($listView, 0xFCFEFC) GUICtrlSetBkColor($listView, $GUI_BKCOLOR_LV_ALTERNATE) _GUICtrlListView_RegisterSortCallBack($listView, True, False) $clearBtn = GUICtrlCreateButton("清除列表",$windowWidth - 90 - 3,50+$heightOfListView,90,$widgetHeight) GUICtrlSetOnEvent($clearBtn, "_ClearButtonEvent") GUIRegisterMsg($WM_CONTEXTMENU, "_WM_CONTEXTMENU") GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") ; 显示界面 GUISetState(@SW_SHOW, $guiWelcome) While 1 Sleep(200) WEnd Func _GUI_EVENT_CLOSE () _SQLite_Close($db) _SQLite_Shutdown() Exit EndFunc Func _OnSaveButtonEvent() $otherText = GUICtrlRead($otherEdit) $meText = StringStripWS(StringStripCR(GUICtrlRead($meEdit)),$STR_STRIPALL) ConsoleWrite("------------------" & $otherText & @CRLF) ConsoleWrite("------------------" & $meText & @CRLF) If 0=StringLen($meText) Then MsgBox($MB_SYSTEMMODAL, "提示", "请输入话术", 10) Return EndIf $chatIndex = $chatIndex+1 ; 全局的话术索引 ; “上一条” If 0=StringLen($otherText) Then ; "对方话术为空",则本话术为对话第一条,上一条为-1 $lastIndex = -1 Else ; 取上一条的全局索引 Local $str = StringSplit($otherText, "|") $lastIndex = "," & $str[1] ; 索引 EndIf Local $listCount = _GUICtrlListView_GetItemCount($listView) _GUICtrlListView_BeginUpdate($listView) ;i|话术|上一句|下一句 GUICtrlCreateListViewItem( $chatIndex & "|" & $meText & "|" & $lastIndex & "|" & $nextIndex, $listView) ; 插入新的话术 _GUICtrlListView_EndUpdate($listView) ; 更新上一条话术的“下一条” If -1 <> $listViewItemIndex Then ; 根据当前“上一条”话术的listview索引操作 Local $item = _GUICtrlListView_GetItemTextString (GUICtrlGetHandle($listView), $listViewItemIndex) ConsoleWrite("父条目:" & $listViewItemIndex & "," & $item & @CRLF) Local $arrItemStr = StringSplit($item,"|") Local $childIndex = $arrItemStr[4] $childIndex = StringReplace($childIndex,"-1","") & "," & $chatIndex ConsoleWrite("父条目的子对话:" & $childIndex & @CRLF) _GUICtrlListView_SetItemText($listView, $listViewItemIndex, $childIndex, 3 ) ; 直接更新“下一条”这一列的内容 EndIf ; 更新相似语义话术的下一条 Local $labelText22 = GUICtrlRead($otherItemListLabel) If(StringLen($labelText22)>0) Then Local $arrLabelText = StringSplit($labelText22,",") ConsoleWrite("相似话术列表数量:"&_ArrayToString($arrLabelText)&@CRLF) Local $itemCount2 = _GUICtrlListView_GetItemCount ( $listView ) For $i = 1 To $arrLabelText[0] ; 遍历上一条话术,更新其“下一条” Local $itemI = $arrLabelText[$i] ConsoleWrite("附加的父条目:" & $itemI & @CRLF) For $jjj = 0 To $itemCount2 Step 1 Local $item2 = _GUICtrlListView_GetItemTextString (GUICtrlGetHandle($listView), $jjj) Local $arrItemStr2 = StringSplit($item2,"|") If $itemI = $arrItemStr2[1] Then ; 索引项 ConsoleWrite("附加的父条目匹配:" & $itemI & @CRLF) Local $childIndex2 = $arrItemStr2[4] $childIndex2 = StringReplace($childIndex2,"-1","") If Not StringInStr($childIndex2, $chatIndex) Then $childIndex2 = $childIndex2 & "," & $chatIndex _GUICtrlListView_SetItemText($listView, $jjj, $childIndex2, 3 ) EndIf EndIf Next Next If Not StringInStr($labelText22, $listViewItemIndex) Then Local $tmpLastIndex = $listViewItemIndex & "," & $labelText22 _GUICtrlListView_SetItemText($listView, $itemCount2-1, $tmpLastIndex, 2 ) EndIf EndIf GUICtrlSetData($meEdit, "") EndFunc Func _WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam) ConsoleWrite("$hWnd:"&$hWnd&@CRLF) ConsoleWrite("$iMsg:"&$iMsg&@CRLF) ConsoleWrite("$iwParam:"&$iwParam&@CRLF) ConsoleWrite("$ilParam:"&$ilParam&@CRLF) ConsoleWrite("$listView:"&GUICtrlGetHandle($listView)&@CRLF) ; 匹配ListView Switch $iwParam Case GUICtrlGetHandle($listView) If _GUICtrlListView_GetSelectedIndices ( $iwParam ) <> "" Then Local $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hMenu, 0, "删除本条话术", $menuDeleteListViewItem) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "", 0) _GUICtrlMenu_InsertMenuItem($hMenu, 2, "添加回复话术", $menuInsertAnswerListViewItem) _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd) _GUICtrlMenu_DestroyMenu($hMenu) EndIf Return True EndSwitch EndFunc Func _WM_COMMAND($hWnd, $msg, $wParam, $lParam) Switch $wParam Case $menuDeleteListViewItem $listViewItemIndex = _GUICtrlListView_GetSelectedIndices ( GUICtrlGetHandle($listView)) Local $item = _GUICtrlListView_GetItemTextString (GUICtrlGetHandle($listView), $listViewItemIndex) ConsoleWrite("选择要删除的item"&$item&@CRLF) Local $confirmDel = MsgBox($MB_OKCANCEL, "提示", "删除选择item:"&$listViewItemIndex) If $confirmDel = 1 Then _DeleteSpeechcraft($listView,$listViewItemIndex) EndIf Case $menuInsertAnswerListViewItem ;If $lastIndex <> -1 Then ; Local $confirmDel = MsgBox($MB_OKCANCEL, "提示", "当前正在发生对话") ;Else $listViewItemIndex = _GUICtrlListView_GetSelectedIndices ( GUICtrlGetHandle($listView)) Local $item = _GUICtrlListView_GetItemTextString (GUICtrlGetHandle($listView), $listViewItemIndex) ConsoleWrite("选择增加话术的item "&$listViewItemIndex&@CRLF) _InsertSpeechcraft($item) ;EndIf EndSwitch EndFunc Func _DeleteSpeechcraft($hWnd, $iIndex) $isDeleteSuccess = _GUICtrlListView_DeleteItem ( $hWnd, $iIndex ) If($isDeleteSuccess) Then ;根据$iIndex更新相关话术 $listViewItemIndex = -1 Local $itemCount = _GUICtrlListView_GetItemCount ( $hWnd ) For $i = 0 To $itemCount Step 1 Local $item = _GUICtrlListView_GetItemTextString (GUICtrlGetHandle($hWnd), $i) Local $arrItemStr = StringSplit($item,"|") Local $parentIndex = $arrItemStr[3] Local $childIndex = $arrItemStr[4] If StringInStr($parentIndex, $iIndex) Then $parentIndex = StringReplace($parentIndex, "," & $iIndex, "") If 0 = StringLen($parentIndex) Then $parentIndex = -1 EndIf _GUICtrlListView_SetItemText($hWnd, $i, $parentIndex, 2 ) EndIf If StringInStr($childIndex, $iIndex) Then $childIndex = StringReplace($childIndex, "," & $iIndex, "") If 0 = StringLen($childIndex) Then $childIndex = -1 EndIf _GUICtrlListView_SetItemText($hWnd, $i, $childIndex, 3 ) EndIf Next EndIf EndFunc Func _InsertSpeechcraft($item) GUICtrlSetData($otherEdit, $item) EndFunc Func _SelectMoreButtonEvent() If $listViewItemIndex = -1 Then Return EndIf $selectMorePopupWindow = GUICreate("", 500, 100, Default, Default, $WS_CAPTION, BitOR($WS_EX_TOPMOST, $GUI_WS_EX_PARENTDRAG)) WinSetTitle($selectMorePopupWindow, "", "直接输入相似语义话术的索引") GUICtrlCreateLabel("多个索引时用单个空格分开", 20, 18, 200, 20 ) $selectedItems = GUICtrlCreateInput ("", 20, 35, 460, 20) $btnOK = GUICtrlCreateButton("确定", 4, 74, 60, 22) GUICtrlSetOnEvent($btnOK, "_CancelPopwinowBtn") $btnNO = GUICtrlCreateButton("取消", 435, 74, 60, 22) GUICtrlSetOnEvent($btnNO, "_CancelPopwinowBtn") GUISetState(@SW_SHOW, $selectMorePopupWindow) GUISetState(@SW_DISABLE, $guiWelcome) EndFunc Func _CancelPopwinowBtn () Local $selectedStrs = GUICtrlRead($selectedItems) $selectedStrs = StringReplace($selectedStrs," ",",") GUICtrlSetData($otherItemListLabel,$selectedStrs) GUIDelete ($selectMorePopupWindow ) GUISetState(@SW_ENABLE, $guiWelcome) GUISetState(@SW_RESTORE, $guiWelcome) EndFunc Func _ResetOtherButtonEvent () GUICtrlSetData($otherEdit,"") GUICtrlSetData($otherItemListLabel,"") $listViewItemIndex = -1 EndFunc Func _LoadButtonEvent() Local $fileDir = FileOpenDialog("选择话术文件", "", "文本文件 (*.txt)", $FD_FILEMUSTEXIST ) If @error Then Else $lineCount = _FileCountLines($fileDir) ConsoleWrite("读取的话术:" & $lineCount & @CRLF) If($lineCount > 0) Then ; 解析,加载到listview Local $file = FileOpen($fileDir) _GUICtrlListView_BeginUpdate($listView) For $i = 1 To $lineCount Local $line = FileReadLine($file, $i) ConsoleWrite("读取的话术:" & $line & @CRLF) Local $arrLine = StringSplit($line, "|") ConsoleWrite("读取的话术:" & _ArrayToString($arrLine) & @CRLF) GUICtrlCreateListViewItem( $arrLine[1] & "|" & $arrLine[2] & "|" & $arrLine[3] & "|" & $arrLine[4], $listView) ; 插入新的话术 Next _GUICtrlListView_EndUpdate($listView) FileClose($file) Else MsgBox($MB_SYSTEMMODAL, "提示", "文件为空", 3) EndIf EndIf EndFunc Func _ExportButtonEvent() Local $itemCount = _GUICtrlListView_GetItemCount ( $listView ) If $itemCount < 1 Then MsgBox($MB_SYSTEMMODAL, "提示", "请先编辑话术", 3) Return EndIf ConsoleWrite("保存的话术数量:" & $itemCount & @CRLF) Local $fileDir = FileSaveDialog("保存话术文件", "", "文本文档 (*.txt)", 2+16, "话术.txt") If @error Then Else Local $file = FileOpen($fileDir, 2) For $i = 0 To $itemCount-1 Local $item = _GUICtrlListView_GetItemTextString (GUICtrlGetHandle($listView), $i) ConsoleWrite("保存的话术item:" & $item & @CRLF) FileWriteLine($file, $item) ConsoleWrite("保存的话术item完毕:" & $i & @CRLF) Next FileClose($file) _ClearButtonEvent() MsgBox($MB_SYSTEMMODAL, "提示", "导出成功") EndIf EndFunc Func _ClearButtonEvent() $chatIndex = -1 $lastIndex = -1 $nextIndex = -1 $listViewItemIndex = -1 GUICtrlSetData($meEdit,"") GUICtrlSetData($otherEdit,"") GUICtrlSetData($otherItemListLabel,"") _GUICtrlListView_DeleteAllItems($listView) EndFunc |
试用下载 https://download.csdn.net/download/vigiles/11259815
end
声明
本文由崔维友 威格灵 cuiweiyou vigiles cuiweiyou 原创,转载请注明出处:http://www.gaohaiyan.com/2326.html
承接App定制、企业web站点、办公系统软件 设计开发,外包项目,毕设