From 4d99207acc6a79340237751b48c865109e19f61e Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Wed, 16 Oct 2024 16:00:32 +0900 Subject: [PATCH] [Update] Add WordFilter. --- data.js | 58 +------------ src-python/webui_controller.py | 27 +----- src-python/webui_mainloop.py | 3 - src-ui/app/App.jsx | 3 + .../_components/word_filter/WordFilter.jsx | 86 +++++++++++-------- .../transcription/Transcription.jsx | 12 +++ src-ui/logics/configs/index.js | 1 + .../transcription/useMicWordFilterList.js | 24 ++++++ src-ui/logics/useReceiveRoutes.js | 31 +++++++ src-ui/store.js | 5 +- 10 files changed, 125 insertions(+), 125 deletions(-) create mode 100644 src-ui/logics/configs/transcription/useMicWordFilterList.js diff --git a/data.js b/data.js index 80017a05..e7492f47 100644 --- a/data.js +++ b/data.js @@ -81,60 +81,4 @@ export const generateTestData = (num) => { } return testDataArray; -}; - -export const word_filter_list = [ - { value: "りんご", is_redoable: false }, - { value: "forest", is_redoable: false }, - { value: "もり", is_redoable: false }, - { value: "elephant", is_redoable: false }, - { value: "penguin", is_redoable: false }, - { value: "やま", is_redoable: false }, - { value: "notebook", is_redoable: false }, - { value: "zebra", is_redoable: false }, - { value: "ちょう", is_redoable: false }, - { value: "dinosaur", is_redoable: false }, - { value: "たいこ", is_redoable: false }, - { value: "カンガルー", is_redoable: false }, - { value: "ふうせん", is_redoable: false }, - { value: "candle", is_redoable: false }, - { value: "tiger", is_redoable: false }, - { value: "umbrella", is_redoable: false }, - { value: "garden", is_redoable: false }, - { value: "ペンギン", is_redoable: false }, - { value: "ひまわり", is_redoable: false }, - { value: "kangaroo", is_redoable: false }, - { value: "とうだい", is_redoable: false }, - { value: "シロフォン", is_redoable: false }, - { value: "ひこうき", is_redoable: false }, - { value: "しろ", is_redoable: false }, - { value: "しあわせ", is_redoable: false }, - { value: "xylophone", is_redoable: false }, - { value: "volcano", is_redoable: false }, - { value: "drum", is_redoable: false }, - { value: "lighthouse", is_redoable: false }, - { value: "quicksand", is_redoable: false }, - { value: "airplane", is_redoable: false }, - { value: "しまうま", is_redoable: false }, - { value: "sunflower", is_redoable: false }, - { value: "ジャングル", is_redoable: false }, - { value: "くじら", is_redoable: false }, - { value: "apple", is_redoable: false }, - { value: "island", is_redoable: false }, - { value: "ocean", is_redoable: false }, - { value: "rainbow", is_redoable: false }, - { value: "castle", is_redoable: false }, - { value: "かさ", is_redoable: false }, - { value: "ぞう", is_redoable: false }, - { value: "balloon", is_redoable: false }, - { value: "happiness", is_redoable: false }, - { value: "whale", is_redoable: false }, - { value: "にじ", is_redoable: false }, - { value: "ヨット", is_redoable: false }, - { value: "しま", is_redoable: false }, - { value: "かざん", is_redoable: false }, - { value: "ノート", is_redoable: false }, - { value: "mountain", is_redoable: false }, - { value: "うみ", is_redoable: false }, - { value: "ジャングル", is_redoable: false }, -]; \ No newline at end of file +}; \ No newline at end of file diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index 7a1fdc46..e20c8873 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -780,36 +780,11 @@ class Controller: @staticmethod def setMicWordFilter(data, *args, **kwargs) -> dict: - data = str(data) - data = [w.strip() for w in data.split(",") if len(w.strip()) > 0] - # Copy the list - new_mic_word_filter_list = config.MIC_WORD_FILTER - new_added_value = [] - for value in data: - if value in new_mic_word_filter_list: - # If the value is already in the list, do nothing. - pass - else: - new_mic_word_filter_list.append(value) - new_added_value.append(value) - config.MIC_WORD_FILTER = new_mic_word_filter_list - + config.MIC_WORD_FILTER = sorted(set(data), key=data.index) model.resetKeywordProcessor() model.addKeywords() return {"status":200, "result":config.MIC_WORD_FILTER} - @staticmethod - def delMicWordFilter(data, *args, **kwargs) -> dict: - try: - new_mic_word_filter_list = config.MIC_WORD_FILTER - new_mic_word_filter_list.remove(str(data)) - config.MIC_WORD_FILTER = new_mic_word_filter_list - model.resetKeywordProcessor() - model.addKeywords() - except Exception: - printLog("Delete Mic Word Filter", "There was no the target word in config.MIC_WORD_FILTER") - return {"status":200, "result":config.MIC_WORD_FILTER} - @staticmethod def getMicAvgLogprob(*args, **kwargs) -> dict: return {"status":200, "result":config.MIC_AVG_LOGPROB} diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index 7af0cd89..6891181b 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -196,7 +196,6 @@ mapping = { "/get/data/mic_word_filter": {"status": True, "variable":controller.getMicWordFilter}, "/set/data/mic_word_filter": {"status": True, "variable":controller.setMicWordFilter}, - "/delete/data/mic_word_filter": {"status": True, "variable":controller.delMicWordFilter}, "/get/data/auto_speaker_select": {"status": True, "variable":controller.getAutoSpeakerSelect}, "/set/enable/auto_speaker_select": {"status": True, "variable":controller.setEnableAutoSpeakerSelect}, @@ -523,8 +522,6 @@ if __name__ == "__main__": data = 5 case "/set//data/mic_word_filter": data = "test0, test1, test2" - case "/delete/data/mic_word_filter": - data = "test1" case "/set/data/selected_speaker_device": data = "スピーカー (Realtek High Definition Audio)" case "/set/data/speaker_threshold": diff --git a/src-ui/app/App.jsx b/src-ui/app/App.jsx index d7ced329..95eab896 100644 --- a/src-ui/app/App.jsx +++ b/src-ui/app/App.jsx @@ -54,6 +54,7 @@ import { useMicRecordTimeout, useMicPhraseTimeout, useMicMaxWords, + useMicWordFilterList, useSpeakerRecordTimeout, useSpeakerPhraseTimeout, useSpeakerMaxWords, @@ -109,6 +110,7 @@ const StartPythonFacadeComponent = () => { const { getMicRecordTimeout } = useMicRecordTimeout(); const { getMicPhraseTimeout } = useMicPhraseTimeout(); const { getMicMaxWords } = useMicMaxWords(); + const { getMicWordFilterList } = useMicWordFilterList(); const { getSpeakerRecordTimeout } = useSpeakerRecordTimeout(); const { getSpeakerPhraseTimeout } = useSpeakerPhraseTimeout(); @@ -160,6 +162,7 @@ const StartPythonFacadeComponent = () => { getMicRecordTimeout(); getMicPhraseTimeout(); getMicMaxWords(); + getMicWordFilterList(); getSpeakerRecordTimeout(); getSpeakerPhraseTimeout(); diff --git a/src-ui/app/config_page/setting_section/setting_box/_components/word_filter/WordFilter.jsx b/src-ui/app/config_page/setting_section/setting_box/_components/word_filter/WordFilter.jsx index 12c64662..b9f8eaa7 100644 --- a/src-ui/app/config_page/setting_section/setting_box/_components/word_filter/WordFilter.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/_components/word_filter/WordFilter.jsx @@ -1,11 +1,19 @@ import styles from "./WordFilter.module.scss"; import { _Entry } from "../_atoms/_entry/_Entry"; import { useState } from "react"; -import { useStore_WordFilterList, useStore_IsOpenedWordFilterList } from "@store"; +import { useStore_IsOpenedMicWordFilterList } from "@store"; +import { useMicWordFilterList } from "@logics_configs"; + export const WordFilter = () => { - const [input_value, setInputValue] = useState(); - const { currentWordFilterList, updateWordFilterList } = useStore_WordFilterList(); - const { currentIsOpenedWordFilterList, updateIsOpenedWordFilterList } = useStore_IsOpenedWordFilterList(); + const [input_value, setInputValue] = useState(""); + const { currentMicWordFilterList, updateMicWordFilterList, setMicWordFilterList } = useMicWordFilterList(); + const { currentIsOpenedMicWordFilterList, updateIsOpenedMicWordFilterList } = useStore_IsOpenedMicWordFilterList(); + + const extractRedoableFalseItem = (updated_list) => { + return updated_list.filter(item => { + if (item.is_redoable === false) return true; + }); + }; const onChangeEntry = (e) => { setInputValue(e.target.value); @@ -13,37 +21,43 @@ export const WordFilter = () => { const addWords = () => { if (input_value === undefined) return; - const input_value_array = input_value.split(","); - - let updated_list = [...currentWordFilterList.data]; - - for (let each_input_value of input_value_array) { - each_input_value = each_input_value.trim(); - if (each_input_value) { - const target_item = updated_list.find((item) => item.value === each_input_value); - if (target_item === undefined) { - // Add - updated_list = [...updated_list, { value: each_input_value, is_redoable: false }]; - } else { - // Update - updated_list = updated_list.map(item => - item.value === each_input_value ? { ...item, is_redoable: false } : item - ); + updateMicWordFilterList((prev_list) => { + const input_value_array = input_value.split(","); + let updated_list = [...prev_list.data]; + for (let each_input_value of input_value_array) { + each_input_value = each_input_value.trim(); + if (each_input_value) { + const target_item = updated_list.find((item) => item.value === each_input_value); + if (target_item === undefined) { + // Add + updated_list = [...updated_list, { value: each_input_value, is_redoable: false }]; + } else { + // Update + updated_list = updated_list.map(item => + item.value === each_input_value ? { ...item, is_redoable: false } : item + ); + } } } - } + const updated_list_for_restoring = extractRedoableFalseItem(updated_list).map((d) => d.value); + setMicWordFilterList(updated_list_for_restoring); + return updated_list; + }); - updateWordFilterList(updated_list); - updateIsOpenedWordFilterList(true); + updateIsOpenedMicWordFilterList(true); + setInputValue(""); }; const updateRedoable = (target_item_value, is_redoable) => { - updateWordFilterList((prev_list) => - prev_list.map(item => + updateMicWordFilterList((prev_list) => { + const updated_list = prev_list.data.map(item => item.value === target_item_value ? { ...item, is_redoable: is_redoable } : item - ) - ); + ); + const updated_list_for_restoring = extractRedoableFalseItem(updated_list).map((d) => d.value); + setMicWordFilterList(updated_list_for_restoring); + return updated_list; + }); }; const deleteAction = (target_item_value) => { @@ -57,17 +71,17 @@ export const WordFilter = () => { return (