FastWordQuery icon indicating copy to clipboard operation
FastWordQuery copied to clipboard

更新两处代码

Open andylee1890 opened this issue 4 years ago • 1 comments

1.有道词典释义过滤"人名"释义, 人名释义在背诵过程中是个不好的干扰因素,于是加上了过滤代码

            explan =[]
            for item in doc.findall(".//custom-translation/translation/content"):
                if not re.match('.*人名', item.text):
                    explan.append(item.text)
            explains = '<br>'.join([item
                                    for item in explan])
{'phonetic': 'UK [ˈkɒnstənt]   US [ˈkɑːnstənt]', 'us_phonetic': '/ˈkɑːnstənt/', 'uk_phonetic': '/ˈkɒnstənt/', 'explains': 'adj. 不变的;恒定的;经常的<br>n. [数] 常数;恒量'}

image

2.Dreye简化

       if elements:
            re_han_words = re.compile(u"[\uac00-\ud7ff]+")
            defstr = ''
            i = 0
            for e in elements :
                i = i+1
                # tstr = str(e)
                # tstr = re.sub('<img class="unexpand" name="tog"/><div class="exp">.*</p></div>', '', str(e))
                tstr = str(e).replace('<img class="unexpand" name="tog"/><div class="exp">','<div class="newexample">')
                #韩国字过滤
                m = re_han_words.search(tstr, 0)
                if m:
                    continue
                defstr = defstr+tstr
                if i>3:
                    break

            element = soup.find('div', attrs={'class': 'ref block'})
            if element:
                defstr2 = str(element)
                defstr2 = re.sub('<img class="unexpand" name="tog"/><div class="exp">.*</p></div>','',defstr2)
                defstr = defstr+defstr2

            #此处内部代理简繁转换,可直接引入简繁转换库
            res = requests.post('http://localhost:5000/convert', json={'word':self.quote_word,'str':defstr})
            res_json = json.loads(res.content)
            if res_json['rst']:
                defstr = res_json['rst']

            mask = '*' * len(self.quote_word)
            #defstr = defstr.replace(self.quote_word,mask)
            defstr = re.sub(r'\b'+self.quote_word,mask, defstr)

            result['def'] = u'{}'.format(defstr)

保留了核心解释,和英文解释 得到的效果如图: image

andylee1890 avatar Apr 30 '21 02:04 andylee1890

创建一个git分支,合并一下。

zhanaotian avatar May 11 '21 04:05 zhanaotian