huangrunheng hace 2 años
padre
commit
7a043e70dc

+ 46 - 14
tasks/DemonEncounter/data/answer.py

@@ -3,6 +3,7 @@
 # github https://github.com/runhey
 # github https://github.com/runhey
 import csv
 import csv
 import re
 import re
+import difflib
 
 
 from datetime import datetime
 from datetime import datetime
 from pathlib import Path
 from pathlib import Path
@@ -44,23 +45,39 @@ class Answer:
         :param options:
         :param options:
         :return:
         :return:
         """
         """
+        def decide_by_question_foreach(ques: str, ops: list[str]):
+            # 这个是最耗时的操作,遍历数据库中的所有题目,找到最相识的题目和选项
+            for key, values in self.data.items():
+                question_match_ratio = difflib.SequenceMatcher(None, ques, key).ratio()
+                if question_match_ratio < 0.7:
+                    continue
+                for value in values:
+                    for index, option in enumerate(ops):
+                        option_match_ratio = difflib.SequenceMatcher(None, option, value).ratio()
+                        if option_match_ratio >= 0.5:
+                            logger.warning('The worst case: no match found for question and option')
+                            logger.warning('Now traversing the entire database to find the most similar question and option')
+                            logger.warning(f'Most similar question: {key} and most similar option: {value}')
+                            return index + 1
+            return None
+
         def decide_by_options(question: str, ops: list[str]):
         def decide_by_options(question: str, ops: list[str]):
             # 瞎猫当死耗子
             # 瞎猫当死耗子
-            opts = {}
+            matches = {}
             for index, option in enumerate(ops):
             for index, option in enumerate(ops):
-                for char in option:
-                    pass
-                if option in self.data_options.keys():
-                    cnts = [count_intersection(question, ques) for ques in self.data_options[option] ]
-                    cnts.sort(reverse=True)
-                    opts[index + 1] = cnts[0]
-            #
-            if opts:
-                opts = sorted(opts.items(), key=lambda x: x[1], reverse=True)
-            if opts:
+                if option not in self.data_options.keys():
+                    continue
+                for ques in self.data_options[option]:
+                    ques_match_ratio = difflib.SequenceMatcher(None, ques, question).ratio()
+                    if ques_match_ratio > 0.8:
+                        matches[index + 1] = ques_match_ratio
+            if matches:
+                opts = sorted(matches.items(), key=lambda x: x[1], reverse=True)
+                logger.warning('No match found for question,\n Now traversing the entire database to find the most similar question')
+                logger.warning(f'Most similar answer: {opts[0][0]}, and similarity char number is {opts[0][1]}')
                 return opts[0][0]
                 return opts[0][0]
-            else:
-                return None
+            index = decide_by_question_foreach(question, ops)
+            return index if index else None
 
 
 
 
         question = question.replace('「', '').replace('」', '').replace('?', '')
         question = question.replace('「', '').replace('」', '').replace('?', '')
@@ -92,7 +109,22 @@ class Answer:
                     if len(match) - count_intersection(match, option) <= 1 :
                     if len(match) - count_intersection(match, option) <= 1 :
                         logger.warning('Option is not match: %s, %s', match, option)
                         logger.warning('Option is not match: %s, %s', match, option)
                         return index + 1
                         return index + 1
-        # 选项一个都对不上可能是,识别的选项异常
+        # 最保守策略,答案匹配度最高
+        opts = {}
+        for index, option in enumerate(options):
+            item_match_ratio = 0
+            for match in question_matches:
+                match_ratio = difflib.SequenceMatcher(None, match, option).ratio()
+                if match_ratio >= 0.33 and match_ratio > item_match_ratio:
+                    item_match_ratio = match_ratio
+            if item_match_ratio > 0:
+                opts[index + 1] = item_match_ratio
+        if opts:
+            opts = sorted(opts.items(), key=lambda x: x[1], reverse=True)
+            logger.warning(f'Use SequenceMatcher and get answers: {opts[0][0]}, score: {opts[0][1]}')
+            return opts[0][0]
+
+        # 选项一个都对不上可能是,正确答案检测为空
         for index, option in enumerate(options):
         for index, option in enumerate(options):
             if option == '':
             if option == '':
                 logger.error('Option is empty: %s', options)
                 logger.error('Option is empty: %s', options)

+ 1 - 0
tasks/DemonEncounter/data/data.csv

@@ -1576,3 +1576,4 @@ SSR式神可以通过多少个对应的式神碎片召唤获得,50
 头像框一百鬼之主的获得方式是,为崽而战捌段前十
 头像框一百鬼之主的获得方式是,为崽而战捌段前十
 以下式神中哪一位是可爱的女孩子,纸舞
 以下式神中哪一位是可爱的女孩子,纸舞
 想要回顾已经解锁的绘卷剧情入口是,点击庭院大树一追忆绘卷
 想要回顾已经解锁的绘卷剧情入口是,点击庭院大树一追忆绘卷
+御魂珍珠的四件套可能触发的效果是,使被治疗目标获得护

+ 1 - 1
tasks/Quiz/script_task.py

@@ -89,7 +89,7 @@ class ScriptTask(GameUi, QuizAssets, ActivityShikigamiAssets, Debugger):
                 continue
                 continue
         self.last_select_1, self.last_select_2, self.last_select_3, self.last_select_4 = '', '', '', ''
         self.last_select_1, self.last_select_2, self.last_select_3, self.last_select_4 = '', '', '', ''
 
 
-        quiz_timer = Timer(1)
+        quiz_timer = Timer(1.4)
         quiz_timer.start()
         quiz_timer.start()
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()