Repository: thunlp/WantWords Branch: main Commit: 2d4a238c72b6 Files: 17 Total size: 265.4 KB Directory structure: gitextract__e9ilabv/ ├── README.md ├── README_ZH.md ├── manage.py ├── model.py ├── model_en.py ├── static/ │ ├── css/ │ │ └── zzsc.css │ └── js/ │ ├── home.js │ └── zzsc.js ├── templates/ │ ├── about.html │ ├── about_en.html │ └── home.html ├── uwsgi.ini └── website_RD/ ├── __init__.py ├── settings.py ├── urls.py ├── views.py └── wsgi.py ================================================ FILE CONTENTS ================================================ ================================================ FILE: README.md ================================================ ### [中](README_ZH.md)|En

WantWords Logo

An Open-source Online Reverse Dictionary [link]

## News The WantWords MiniProgram has been launched. Welcome to scan the following QR code to try it!
MiniProgram QR code
## What Is a Reverse Dictionary? Opposite to a regular (forward) dictionary that provides definitions for query words, a reverse dictionary returns words semantically matching the query descriptions.
rd_example
## What Can a Reverse Dictionary Do? * Solve the *tip-of-the-tongue problem*, the phenomenon of failing to retrieve a word from memory * Help new language learners * Help word selection (or word dictionary) anomia patients, people who can recognize and describe an object but fail to name it due to neurological disorder ## Our System ### Workflow
workflow
### Core Model The core model of WantWords is based on our proposed **Multi-channel Reverse Dictionary Model** [[paper](https://ojs.aaai.org/index.php/AAAI/article/view/5365/5221)] [[code](https://github.com/thunlp/MultiRD)], as illustrate in the following figure.
model
### Pre-trained Models and Data You can [download](https://cloud.tsinghua.edu.cn/d/811dcb428ed24480bc60/) and decompress the pre-trained models and data to `BASE_PATH/website_RD/` to reimplement the system. ### Key Requirements * Django==2.2.5 * django-cors-headers==3.5.0 * numpy==1.17.2 * pytorch-transformers==1.2.0 * requests==2.22.0 * scikit-learn==0.22.1 * scipy==1.4.1 * thulac==0.2.0 * torch==1.2.0 * urllib3==1.25.6 * uWSGI==2.0.18 * uwsgitop==0.11 ## Cite If the code or data help you, please cite the following two papers. ``` @inproceedings{qi2020wantwords, title={WantWords: An Open-source Online Reverse Dictionary System}, author={Qi, Fanchao and Zhang, Lei and Yang, Yanhui and Liu, Zhiyuan and Sun, Maosong}, booktitle={Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations}, pages={175--181}, year={2020} } @inproceedings{zhang2020multi, title={Multi-channel reverse dictionary model}, author={Zhang, Lei and Qi, Fanchao and Liu, Zhiyuan and Wang, Yasheng and Liu, Qun and Sun, Maosong}, booktitle={Proceedings of the AAAI Conference on Artificial Intelligence}, pages={312--319}, year={2020} } ``` ================================================ FILE: README_ZH.md ================================================ ### 中|[En](README.md)

WantWords Logo

首个支持中文及跨语言查询的开源在线反向词典 [点击访问]

## 新闻 WantWords小程序已上线,欢迎扫码体验!
MiniProgram QR code
## 什么是反向词典? 普通的词典告诉你某个词语的定义,而反向词典恰好相反,可以告诉你哪些词语符合你输入描述的意思。下图为WantWords在线反向词典的页面截图,其中演示了反向查词的一个示例,输入“山非常高”,系统将返回一系列模型认为表达“山非常高”意思的词语,例如“高峻”、“巍峨”等。
rd_example
## 反向词典可以用来做什么? * 解决“舌尖现象”(*tip-of-the-tongue*,又称话到嘴边说不出来),即暂时性忘词的问题 * 帮助语言学习者学习、巩固词汇 * 改善选词性失语者患者的生活质量,该病的症状是可以识别并描述一个物体,但是无法记起该物体的名字 ## 系统架构 ### 工作流
workflow
### 核心模型 WantWords的核心模型为我们此前发表在AAAI-20上的一篇论文提出的多通道反向词典模型:**Multi-channel Reverse Dictionary Model** [[论文](https://ojs.aaai.org/index.php/AAAI/article/view/5365/5221)] [[代码](https://github.com/thunlp/MultiRD)],其模型架构如下所示。
model
### 模型和数据 可从[此处](https://cloud.tsinghua.edu.cn/d/811dcb428ed24480bc60/)下载并解压模型和数据到 `BASE_PATH/website_RD/` 以构建此系统。 ### 关键依赖 * Django==2.2.5 * django-cors-headers==3.5.0 * numpy==1.17.2 * pytorch-transformers==1.2.0 * requests==2.22.0 * scikit-learn==0.22.1 * scipy==1.4.1 * thulac==0.2.0 * torch==1.2.0 * urllib3==1.25.6 * uWSGI==2.0.18 * uwsgitop==0.11 ## 引用 如果本项目的代码或者数据帮到你,请引用以下两篇论文: ``` @inproceedings{qi2020wantwords, title={WantWords: An Open-source Online Reverse Dictionary System}, author={Qi, Fanchao and Zhang, Lei and Yang, Yanhui and Liu, Zhiyuan and Sun, Maosong}, booktitle={Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations}, pages={175--181}, year={2020} } @inproceedings{zhang2020multi, title={Multi-channel reverse dictionary model}, author={Zhang, Lei and Qi, Fanchao and Liu, Zhiyuan and Wang, Yasheng and Liu, Qun and Sun, Maosong}, booktitle={Proceedings of the AAAI Conference on Artificial Intelligence}, pages={312--319}, year={2020} } ``` ================================================ FILE: manage.py ================================================ #!/usr/bin/env python """Django's command-line utility for administrative tasks.""" import os import sys def main(): os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website_RD.settings') try: from django.core.management import execute_from_command_line except ImportError as exc: raise ImportError( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" ) from exc execute_from_command_line(sys.argv) if __name__ == '__main__': main() ================================================ FILE: model.py ================================================ import torch class Encoder(torch.nn.Module): def __init__(self, vocab_size, embed_dim, hidden_dim, layers, class_num, encoder, sememe_num, chara_num, mode): super().__init__() self.vocab_size = vocab_size self.embed_dim = 200 self.hidden_dim = 768 self.layers = layers self.class_num = class_num self.sememe_num = sememe_num self.chara_num = chara_num self.embedding = torch.nn.Embedding(self.vocab_size, self.embed_dim, padding_idx=0, max_norm=5, sparse=True) self.embedding.weight.requires_grad = False self.embedding_dropout = torch.nn.Dropout(0.2) self.encoder = encoder self.fc = torch.nn.Linear(self.hidden_dim, self.embed_dim) self.loss = torch.nn.CrossEntropyLoss() self.relu = torch.nn.ReLU() if 'P' in mode: self.fc2 = torch.nn.Linear(self.hidden_dim, 13) if 's' in mode: self.fc1 = torch.nn.Linear(self.hidden_dim, self.sememe_num) if 'c' in mode: self.fc3 = torch.nn.Linear(self.hidden_dim, self.chara_num) if 'C' in mode: self.fc_C1 = torch.nn.Linear(self.hidden_dim, 12) self.fc_C2 = torch.nn.Linear(self.hidden_dim, 95) self.fc_C3 = torch.nn.Linear(self.hidden_dim, 1425) def forward(self, operation, x=None, w=None, ws=None, wP=None, wc=None, wC=None, msk_s=None, msk_c=None, mode=None): # x: T(bat, max_word_num) # w: T(bat) # x_embedding: T(bat, max_word_num, embed_dim) x = x.long() attention_mask = torch.gt(x, 0).to(torch.int64) h = self.encoder(x, attention_mask=attention_mask)[0] h_1 = self.embedding_dropout(h[:,0,:]) vd = self.fc(h_1) # score0: T(bat, 30000) = [bat, emb] .mm [class_num, emb].t() score0 = vd.mm(self.embedding.weight.data[[range(self.class_num)]].t()) score = score0 if 'C' in mode: # scC[i]: T(bat, Ci_size) # 词林的层次分类训练的慢,其实这样不公平,不平衡,因为词预测先收敛了,而cilin的分类还没效果,其他信息的利用也有同样的问题,不一定同时收敛!!! scC = [self.fc_C1(h_1), self.fc_C2(h_1), self.fc_C3(h_1)] score2 = torch.zeros((score0.shape[0], score0.shape[1]), dtype=torch.float32) rank = 0.6 for i in range(3): # wC[i]: T(class_num, Ci_size) # C_sc: T(bat, class_num) score2 += self.relu(scC[i].mm(wC[i].t())*(rank**i)) #----------add mean cilin-class score to those who have no cilin-class mean_cilin_sc = torch.mean(score2, 1) score2 = score2*(1-msk_c) + mean_cilin_sc.unsqueeze(1).mm(msk_c.unsqueeze(0)) #---------- score = score + score2/2 if 'P' in mode: ## POS prediction # score_POS: T(bat, 13) pos_num=12+1 score_POS = self.fc2(h_1) # s: (class_num, 13) multi-hot # weight_sc: T(bat, class_num) = [bat, 13] .mm [class_num, 13].t() weight_sc = self.relu(score_POS.mm(wP.t())) #print(torch.max(weight_sc), torch.min(weight_sc)) score = score + weight_sc if 's' in mode: ## sememe prediction # pos_score: T(bat, max_word_num, sememe_num) pos_score = self.fc1(h) # sem_score: T(bat, sememe_num) sem_score, _ = torch.max(pos_score, dim=1) # score: T(bat, class_num) = [bat, sememe_num] .mm [class_num, sememe_num].t() score1 = self.relu(sem_score.mm(ws.t())) #----------add mean sememe score to those who have no sememes # mean_sem_sc: T(bat) mean_sem_sc = torch.mean(score1, 1) # msk: T(class_num) score1 = score1 + mean_sem_sc.unsqueeze(1).mm(msk_s.unsqueeze(0)) #---------- score = score + score1 if 'c' in mode: ## character prediction # pos_score: T(bat, max_word_num, sememe_num) pos_score = self.fc3(h) # chara_score: T(bat, chara_num) chara_score, _ = torch.max(pos_score, dim=1) #chara_score = torch.sum(pos_score * alpha, 1) # score: T(bat, class_num) = [bat, sememe_num] .mm [class_num, sememe_num].t() score3 = self.relu(chara_score.mm(wc.t())) score = score + score3 ''' if RD_mode == 'CC': # fine-tune depended on the target word shouldn't exist in the definition. #score_res = score.clone().detach() mask1 = torch.lt(x, self.class_num).to(torch.int64) mask2 = torch.ones((score.shape[0], score.shape[1]), dtype=torch.float32) for i in range(x.shape[0]): mask2[i][x[i]*mask1[i]] = 0. score = score * mask2 + (-1e6)*(1-mask2) ''' #_, indices = torch.sort(score, descending=True) if operation == 'train': loss = self.loss(score, w.long()) return loss, score, indices elif operation == 'test': return score #, indices ================================================ FILE: model_en.py ================================================ import torch class Encoder(torch.nn.Module): def __init__(self, vocab_size, embed_dim, hidden_dim, layers, class_num, sememe_num, lexname_num, rootaffix_num, encoder): super().__init__() self.vocab_size = vocab_size self.embed_dim = 300 self.hidden_dim = 768 self.layers = layers self.class_num = class_num self.sememe_num = sememe_num self.lexname_num = lexname_num self.rootaffix_num = rootaffix_num self.embedding = torch.nn.Embedding(self.vocab_size, self.embed_dim, padding_idx=0, max_norm=5, sparse=True) self.embedding.weight.requires_grad = False self.embedding_dropout = torch.nn.Dropout(0.2) self.encoder = encoder self.fc = torch.nn.Linear(self.hidden_dim, self.embed_dim) self.fc_s = torch.nn.Linear(self.hidden_dim, self.sememe_num) self.fc_l = torch.nn.Linear(self.hidden_dim, self.lexname_num) self.fc_r = torch.nn.Linear(self.hidden_dim, self.rootaffix_num) self.loss = torch.nn.CrossEntropyLoss() self.relu = torch.nn.ReLU() def forward(self, operation, x=None, w=None, ws=None, wl=None, wr=None, msk_s=None, msk_l=None, msk_r=None, mode=None): # x: T(bat, max_word_num) # w: T(bat) # h: T(bat, max_word_num, 768) attention_mask = torch.gt(x, 0).to(torch.int64) h = self.encoder(x, attention_mask=attention_mask)[0] #h = self.encoder(x)[0] #h = self.embedding_dropout(h) ## word prediction # vd: T(bat, embed_dim) #h_1 = torch.max(h, dim=1)[0] #h_1 = h[:,0,:] # The first token of every sequence is always a special classification token ([CLS]). The final hidden state corresponding to this token is used as the aggregate sequence representation for classification tasks. h_1 = self.embedding_dropout(h[:,0,:]) vd = self.fc(h_1) # score0: T(bat, 30000) = [bat, emb] .mm [class_num, emb].t() score0 = vd.mm(self.embedding.weight.data[[range(self.class_num)]].t()) # BertVec: 30000, class_num: 50477+2 score = score0 if 's' in mode: ## sememe prediction # pos_score: T(bat, max_word_num, sememe_num) pos_score = self.fc_s(h) # sem_score: T(bat, sememe_num) sem_score, _ = torch.max(pos_score, dim=1) #sem_score = torch.sum(pos_score * alpha, 1) # score: T(bat, class_num) = [bat, sememe_num] .mm [class_num, sememe_num].t() score_s = self.relu(sem_score.mm(ws.t())) #----------add mean sememe score to those who have no sememes # mean_sem_sc: T(bat) mean_sem_sc = torch.mean(score_s, 1) # msk: T(class_num) score_s = score_s + mean_sem_sc.unsqueeze(1).mm(msk_s.unsqueeze(0)) #---------- score = score + score_s if 'r' in mode: ## root-affix prediction pos_score_ = self.fc_r(h) ra_score, _ = torch.max(pos_score_, dim=1) score_r = self.relu(ra_score.mm(wr.t())) mean_ra_sc = torch.mean(score_r, 1) score_r = score_r + mean_ra_sc.unsqueeze(1).mm(msk_r.unsqueeze(0)) score = score + score_r if 'l' in mode: ## lexname prediction lex_score = self.fc_l(h_1) score_l = self.relu(lex_score.mm(wl.t())) mean_lex_sc = torch.mean(score_l, 1) score_l = score_l + mean_lex_sc.unsqueeze(1).mm(msk_l.unsqueeze(0)) score = score + score_l #_, indices = torch.sort(score, descending=True) if operation == 'train': loss = self.loss(score, w) return loss, score, indices elif operation == 'test': return score#, indices ================================================ FILE: static/css/zzsc.css ================================================ @charset "utf-8"; /*容器*/ #xzw_starSys {}/*{width:400px;border:1px solid #ccc;padding:50px;margin:100px auto}*/ #xzw_starBox{position:relative;width:75px;float:left} /**/ #xzw_starSys .description{clear:both;padding:10px 0px} #xzw_starSys .star{height:20px;width:70px;position:relative;background:url(../images/123.png) repeat-x;cursor:pointer} #xzw_starSys .star li{list-style:none;float:left;padding:0px;margin:0px} #xzw_starSys .star li a{color:#09f;display:block;width:24px;height:20px;overflow:hidden;text-indent:-9999px;position:absolute;z-index:3} #xzw_starSys .star li a:hover{background:url(../images/123.png) 0 -25px repeat-x;z-index:2;left:0} #xzw_starSys .star a.one-star{left:0} #xzw_starSys .star a.one-star:hover{width:24px} #xzw_starSys .star a.two-stars{left:24px} #xzw_starSys .star a.two-stars:hover{width:48px} #xzw_starSys .star a.three-stars{left:48px} #xzw_starSys .star a.three-stars:hover{width:72px} #xzw_starSys .current-rating{background:url(../images/123.png) 0 -25px repeat-x;position:absolute;height:20px;z-index:1;top:0;left:0} ================================================ FILE: static/js/home.js ================================================ $(function() { $( "#tabs" ).tabs(); }); $(function() { $( "#tabs_inter" ).tabs({ collapsible: true }); }); $(function() { $( document ).tooltip({ track: true, hide: {duration: 0} ,position: { my: "left-20 top+25", at: "right bottom" } }); }); $(document).ready(function(){ // 必须有这一行,在页面加载之后执行,否则无效(不加的时候真的无效,已尝试)。 $('a.pop0').unbind("click").click(function(){ //.unbind("click") 部分解决(点词条重复触发的问题解决,但重新查询后重新触发还存在)重复绑定click从而重复触发click事件的问题【解决不易,这个很重要】 $('a.pop0').popover({ trigger: "manual" , html: true, animation:false}) .on("mouseover", function () { var _this = this; $(this).unbind("click").click(function () { //.unbind("click") 部分解决(同上)重复绑定click从而重复触发click事件的问题【解决不易,这个很重要】 $(this).popover("show"); // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 记录点击结果。 var description = $("#description").val(); //console.log($(_this).text()+"||"+description); $.get("/feedback/", { 'content': $(_this).text()+"||"+description, 'mode': 'FBW' }); $(".popover").on("mouseleave", function () { //【解决不易,这个很重要】 $(_this).popover('hide'); }); }); }).on("mouseout", function () { //mouseleave也有问题,在弹框里出现tip时,指针移到tip上就相当于离开目标了,此时弹框会消失(按需求是不应该消失的) var _this = this; setTimeout(function () { if (!$(".popover:hover").length) { $(_this).popover("hide"); if ($(window).width()>768) { //手机端不能加这一条,会发生框只闪一下而不显示的问题。【解决不易,这个很重要】 $("div.popover").hide(); //清理卡死的popover弹框 } } }, 200); }); }); $('a.pop1').unbind("click").click(function(){ //.unbind("click") 部分解决(点词条重复触发的问题解决,但重新查询后重新触发还存在)重复绑定click从而重复触发click事件的问题【解决不易,这个很重要】 $('a.pop1').popover({ trigger: "manual" , html: true, animation:false}) .on("mouseover", function () { var _this = this; $(this).unbind("click").click(function () { //.unbind("click") 部分解决(同上)重复绑定click从而重复触发click事件的问题【解决不易,这个很重要】 $(this).popover("show"); // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 记录点击结果。 var description = $("#description_EE").val(); //console.log($(_this).text()+"||"+description); $.get("/feedback/", { 'content': $(_this).text()+"||"+description, 'mode': 'FBW' }); $(".popover").on("mouseleave", function () { //【解决不易,这个很重要】 $(_this).popover('hide'); }); }); }).on("mouseout", function () { //mouseleave也有问题,在弹框里出现tip时,指针移到tip上就相当于离开目标了,此时弹框会消失(按需求是不应该消失的) var _this = this; setTimeout(function () { if (!$(".popover:hover").length) { $(_this).popover("hide"); if ($(window).width()>768) { //手机端不能加这一条,会发生框只闪一下而不显示的问题。【解决不易,这个很重要】 $("div.popover").hide(); //清理卡死的popover弹框 } } }, 200); }); }); $('a.pop2').unbind("click").click(function(){ //.unbind("click") 部分解决(点词条重复触发的问题解决,但重新查询后重新触发还存在)重复绑定click从而重复触发click事件的问题【解决不易,这个很重要】 $('a.pop2').popover({ trigger: "manual" , html: true, animation:false}) .on("mouseover", function () { var _this = this; $(this).unbind("click").click(function () { //.unbind("click") 部分解决(同上)重复绑定click从而重复触发click事件的问题【解决不易,这个很重要】 $(this).popover("show"); // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 记录点击结果。 var description = $("#description_CE").val(); //console.log($(_this).text()+"||"+description); $.get("/feedback/", { 'content': $(_this).text()+"||"+description, 'mode': 'FBW' }); $(".popover").on("mouseleave", function () { //【解决不易,这个很重要】 $(_this).popover('hide'); }); }); }).on("mouseout", function () { //mouseleave也有问题,在弹框里出现tip时,指针移到tip上就相当于离开目标了,此时弹框会消失(按需求是不应该消失的) var _this = this; setTimeout(function () { if (!$(".popover:hover").length) { $(_this).popover("hide"); if ($(window).width()>768) { //手机端不能加这一条,会发生框只闪一下而不显示的问题。【解决不易,这个很重要】 $("div.popover").hide(); //清理卡死的popover弹框 } } }, 200); }); }); $('a.pop3').unbind("click").click(function(){ //.unbind("click") 部分解决(点词条重复触发的问题解决,但重新查询后重新触发还存在)重复绑定click从而重复触发click事件的问题【解决不易,这个很重要】 $('a.pop3').popover({ trigger: "manual" , html: true, animation:false}) .on("mouseover", function () { var _this = this; $(this).unbind("click").click(function () { //.unbind("click") 部分解决(同上)重复绑定click从而重复触发click事件的问题【解决不易,这个很重要】 $(this).popover("show"); // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 记录点击结果。 var description = $("#description_EC").val(); //console.log($(_this).text()+"||"+description); $.get("/feedback/", { 'content': $(_this).text()+"||"+description, 'mode': 'FBW' }); $(".popover").on("mouseleave", function () { //【解决不易,这个很重要】 $(_this).popover('hide'); }); }); }).on("mouseout", function () { //mouseleave也有问题,在弹框里出现tip时,指针移到tip上就相当于离开目标了,此时弹框会消失(按需求是不应该消失的) var _this = this; setTimeout(function () { if (!$(".popover:hover").length) { $(_this).popover("hide"); if ($(window).width()>768) { //手机端不能加这一条,会发生框只闪一下而不显示的问题。【解决不易,这个很重要】 $("div.popover").hide(); //清理卡死的popover弹框 } } }, 200); }); }); }); // var getSelectedTabId = 0; $(function () { $('#tabs').tabs({ activate: function (event, ui) { var activeTab = $('#tabs').tabs('option', 'active'); getSelectedTabId = activeTab; // 适配英文界面 if (getSelectedTabId%2==1) { $("#id_clk1").attr("value","Propose Appropriate Words"); $("#id_clk2").attr("value","Make Suggestions"); $("#id_home").text("Home Page"); $("#id_about").attr("href","../about_en/").text("About Us"); $("#id_link").text("GitHub Link"); $("#idm_home").html(' Home'); $("#idm_about").attr("href","../about_en/").text("About Us"); $("#idm_link").text("GitHub Link"); } else { $("#id_clk1").attr("value","点此反馈推荐词"); $("#id_clk2").attr("value","点此反馈意见建议"); $("#id_home").text("反向词典主页"); $("#id_about").attr("href","../about/").text("关于我们"); $("#id_link").text("GitHub链接"); $("#idm_home").html(' 主页'); $("#idm_about").attr("href","../about/").text("关于我们"); $("#idm_link").text("GitHub链接"); }; } }); }) function diagWord() { if (getSelectedTabId%2==0) { var str=prompt("未能帮您找到想要的词?\n您认为与您描述相近的词:(多词可用标点分隔)",""); } else { var str=prompt("Any appropriate words in your opinion:",""); }; if (str!="" && str!=null) { if (getSelectedTabId%2==0) { alert("谢谢您的指导,本站希望与您一起学习,共同提升自然语言理解和应用能力!"); } else { alert("Thank you for your advice!"); }; if (getSelectedTabId==0) { var description = $("#description").val(); } else if (getSelectedTabId==1) { var description = $("#description_EE").val(); } else if (getSelectedTabId==2) { var description = $("#description_CE").val(); } else if (getSelectedTabId==3) { var description = $("#description_EC").val(); } else { var description = "unkown tabs"; }; $.get("/feedback/", { 'content': str+"|||"+description, 'mode': 'FBW' }); } } function diagSuggest() { if (getSelectedTabId%2==0) { var str=prompt("您对网站有何意见或建议?",""); if(str!="" && str!=null) { alert("感谢您的反馈!"); $.get("/feedback/", { 'content': str, 'mode': 'FBS' }); } } else { var str=prompt("Any suggestions about this website?",""); if(str!="" && str!=null) { alert("Thanks for your feedback!"); $.get("/feedback/", { 'content': str, 'mode': 'FBS' }); } }; } function diagError(i) { if (getSelectedTabId==0) { var word = $("#tabs-1 #li"+i).text(); } else if (getSelectedTabId==1) { var word = $("#tabs-2 #li"+i).text(); } else if (getSelectedTabId==2) { var word = $("#tabs-3 #li"+i).text(); } else if (getSelectedTabId==3) { var word = $("#tabs-4 #li"+i).text(); } else { var word = "unkown word"; }; if (getSelectedTabId%2==0) { var str=prompt("关于词“"+word+"”的相关错误描述:",""); } else { var str=prompt('Please describe mistakes about the word "'+word+'":',""); }; if (str!="" && str!=null) { if (getSelectedTabId%2==0) { alert("感谢您的反馈!"); } else { alert("Thanks for your feedback!"); }; str = "ERROR: " + word + ": " + str; $.get("/feedback/", { 'content': str, 'mode': 'FBS' }); } } function addTag(i, m) { if (getSelectedTabId==0) { var word = $("#tabs-1 #li"+i).text(); var description = $("#description").val(); var elemA = $("#tabs-1 #li"+i); var elemD = $("#tabs-1 #li"+i+" span"); } else if (getSelectedTabId==1) { var word = $("#tabs-2 #li"+i).text(); var description = $("#description_EE").val(); var elemA = $("#tabs-2 #li"+i); var elemD = $("#tabs-2 #li"+i+" span"); } else if (getSelectedTabId==2) { var word = $("#tabs-3 #li"+i).text(); var description = $("#description_CE").val(); var elemA = $("#tabs-3 #li"+i); var elemD = $("#tabs-3 #li"+i+" span"); } else if (getSelectedTabId==3) { var word = $("#tabs-4 #li"+i).text(); var description = $("#description_EC").val(); var elemA = $("#tabs-4 #li"+i); var elemD = $("#tabs-4 #li"+i+" span"); } else { return null; }; if (m==2) {elemA.append("")} else if (m==1) {elemD.remove()} else if (m==0) {elemA.append("")}; str = word + "|" + m; $.get("/feedback/", { 'content': str+"|||"+description, 'mode': 'FBW' }); } function clearAlert() { var selID = getSelectedTabId + 1; var elem = $("#tabs-" + selID +" .alert"); elem.remove(); //elem.slideUp("fast"); $("div.popover").hide(); //清理卡死的popover弹框 } function clearFilter() { var selID = getSelectedTabId + 1; clearAlert(); if (selID==1) { try { $("#filter_CN div").find("*").removeAttr("disabled"); if ($("#description").val()=="") { $('#result').html(""); } else { if ($("#description").val()==description_backup) { showTable(retData_backup, $('#result')); } else { modelProcecss(); }; }; } catch(err) { $('#result').html(""); }; $("#filter_CN div").find("*").val(this.defaultValue).css("background-color", ""); $("#filter_CN div.visible-xs").find("#POS_select_CC")[0].selectedIndex = 0; $("#filter_CN div.visible-lg").find("#POS_select_CC")[0].selectedIndex = 0; $("#filter_CN div.visible-xs").find("#main_select")[0].selectedIndex = 0; $("#filter_CN div.visible-lg").find("#main_select")[0].selectedIndex = 0; $("#filter_CN div.visible-xs").find("#rhyme_select_CC")[0].selectedIndex = 0; $("#filter_CN div.visible-lg").find("#rhyme_select_CC")[0].selectedIndex = 0; } else if (selID==2) { try { $("#filter_EE div").find("*").removeAttr("disabled"); if ($("#description_EE").val()=="") { $('#result_EE').html(""); } else { if ($("#description_EE").val()==description_backup_EE) { showTable(retData_backup_EE, $('#result_EE')); } else { modelProcecss_EE(); }; }; } catch(err) { $('#result_EE').html(""); }; $("#filter_EE div").find("*").val(this.defaultValue).css("background-color", ""); $("#filter_EE div.visible-xs").find("#POS_select_EE")[0].selectedIndex = 0; $("#filter_EE div.visible-lg").find("#POS_select_EE")[0].selectedIndex = 0; $("#filter_EE div.visible-xs").find("#main_select_EE")[0].selectedIndex = 0; $("#filter_EE div.visible-lg").find("#main_select_EE")[0].selectedIndex = 0; } else if (selID==3) { try { $("#filter_CE div").find("*").removeAttr("disabled"); if ($("#description_CE").val()=="") { $('#result_CE').html(""); } else { if ($("#description_CE").val()==description_backup_CE) { showTable(retData_backup_CE, $('#result_CE')); } else { modelProcecss_CE(); }; }; } catch(err) { $('#result_CE').html(""); }; $("#filter_CE div").find("*").val(this.defaultValue).css("background-color", ""); $("#filter_CE div.visible-xs").find("#POS_select_CE")[0].selectedIndex = 0; $("#filter_CE div.visible-lg").find("#POS_select_CE")[0].selectedIndex = 0; $("#filter_CE div.visible-xs").find("#main_select_CE")[0].selectedIndex = 0; $("#filter_CE div.visible-lg").find("#main_select_CE")[0].selectedIndex = 0; } else if (selID==4) { try { $("#filter_EC div").find("*").removeAttr("disabled"); if ($("#description_EC").val()=="") { $('#result_EC').html(""); } else { if ($("#description_EC").val()==description_backup_EC) { showTable(retData_backup_EC, $('#result_EC')); } else { modelProcecss_EC(); }; }; } catch(err) { $('#result_EC').html(""); }; $("#filter_EC div").find("*").val(this.defaultValue).css("background-color", ""); $("#filter_EC div.visible-xs").find("#POS_select_EC")[0].selectedIndex = 0; $("#filter_EC div.visible-lg").find("#POS_select_EC")[0].selectedIndex = 0; $("#filter_EC div.visible-xs").find("#main_select_EC")[0].selectedIndex = 0; $("#filter_EC div.visible-lg").find("#main_select_EC")[0].selectedIndex = 0; $("#filter_EC div.visible-xs").find("#rhyme_select_EC")[0].selectedIndex = 0; $("#filter_EC div.visible-lg").find("#rhyme_select_EC")[0].selectedIndex = 0; }; }; var itemsPerCol = 20; function htmlSuccess(str) { return '
' + str + '
'; }; function htmlInfo(str) { return '
信息:' + str + '
'; }; function htmlWarning(str) { return '
警告!' + str + '
'; }; function htmlDanger(str) { return '
错误!' + str + '
'; }; function htmlInfo_E(str) { return '
Info: ' + str + '
'; }; function htmlWarning_E(str) { return '
Caution! ' + str + '
'; }; function htmlDanger_E(str) { return '
Error! ' + str + '
'; }; function getContent(wdData, defi, i) { var reg = /[āáǎàōóǒòêēéěèīíǐìūúǔùǖǘǚǜü]/g; //[āáǎàōóǒòêēéěèīíǐìūúǔùǖǘǚǜüńňǹĀÅÀö∥ɡa-zA-Z•ɑ’] if (defi.replace(/br/g,'').replace(/strong/g,'').search(reg)>-1) { var htmlCont = '

' + wdData['w'] + '

' + defi + '
' + ' ' + ' '; } else { var htmlCont = '

' + wdData['w'] + '

' + wdData['p'] + '
' + defi + '
' + ' ' + ' '; }; return htmlCont; }; function getTitle(i) { //var htmlTitle = '
'; var htmlTitle = '
'; return htmlTitle; }; function getContent_E(wdData, defi, i) { var htmlCont = '

' + wdData['w'] + '

' + defi + '
' + ' ' + ' '; //var htmlCont = '

' + wdData['word'] + '

' + '1. adj. ' + wdData['definition'] + '

' + ' ' + ' '; return htmlCont; }; function getTitle_E(i) { //var htmlTitle = '
'; var htmlTitle = '
'; return htmlTitle; }; function getContent_CE(wdData, defi, i) { var htmlCont = '

' + wdData['w'] + '

' + defi + '
' + ' ' + ' '; return htmlCont; }; function getContent_EC(wdData, defi, i) { var reg = /[āáǎàōóǒòêēéěèīíǐìūúǔùǖǘǚǜüńňǹĀÅÀö∥ɡa-zA-Z•ɑ’]/g; if (defi.replace(/br/g,'').replace(/strong/g,'').search(reg)>-1) { var htmlCont = '

' + wdData['w'] + '

' + defi + '
' + ' ' + ' '; } else { var htmlCont = '

' + wdData['w'] + '

' + wdData['p'] + '
' + defi + '
' + ' ' + ' '; }; return htmlCont; }; function showTable(dictList, res_elem) { //$('div.popover').children().hide(); var words = ''; for (var d in dictList) { words = words + ' ' + dictList[d].w; }; var desti = "/GetEnDefis/"; if ('p' in dictList[0]) { desti = "/GetChDefis/"; }; $.post(desti, {'w': words}, function (ret) { var defis = ret.slice(0); var block_start = '
'; var block_end = '
'; var html = '
'; var i = 0; var num = dictList.length>100 ? 100 : dictList.length; for (; i'; } if (getSelectedTabId==0) { if ($(window).width()<751 || window.innerWidth<768) { html = html + '
  • ' + wd_data['w'] + '
  • '; } else { html = html + '
  • ' + wd_data['w'] + '
  • '; }; } else if (getSelectedTabId==1) { if ($(window).width()<751 || window.innerWidth<768) { html = html + '
  • ' + wd_data['w'] + '
  • '; } else { html = html + '
  • ' + wd_data['w'] + '
  • '; }; } else if (getSelectedTabId==2) { if ($(window).width()<751 || window.innerWidth<768) { html = html + '
  • ' + wd_data['w'] + '
  • '; } else { html = html + '
  • ' + wd_data['w'] + '
  • '; }; } else { if ($(window).width()<751 || window.innerWidth<768) { html = html + '
  • ' + wd_data['w'] + '
  • '; } else { html = html + '
  • ' + wd_data['w'] + '
  • '; }; }; i += 1; if (i%itemsPerCol==0) { html += block_end; } }; clearAlert(); res_elem.html(html); if (getSelectedTabId==0) { $('a.pop0').click(); } else if (getSelectedTabId==1) { $('a.pop1').click(); } else if (getSelectedTabId==2) { $('a.pop2').click(); } else { $('a.pop3').click(); } //$('a.pop').click(); // 这里是用于对新生成的html进行绑定,因为HTML是静态代码,页面生成时绑定了js和html的关系(执行了js代码一次),但是这个新生成的html不被当时的js代码绑定,所以这里再执行一次js代码。 //$('div.popover').children().hide(); $('div.popover').hide(); if (getSelectedTabId%2==0) { res_elem.before('
    使用建议:
    1、配合筛选器使用,效果更佳。
    2、按相关性排序或聚类排列可以把更相关的词排在前面。
    3、点击词语显示详情,在详情框顶部可对该词点“赞”或“踩”。
    欢迎多点评,将有助于为大家做出更精准的推荐服务 : )
    '); $(".alert").on("click", function(){$(this).slideUp("fast");}); } else { res_elem.before('
    Suggestions:
    1. Better results with filtering.
    2. More relevant words can be ranked in the first place by ranking by relevance or clustering.
    3. Click on a word to see details. You can mark a word good or bad at the top of the details box.
    Welcome to mark more words, which is helpful for more accurate recommendation : )
    '); $(".alert").on("click", function(){$(this).slideUp("fast");}); }; }); }; function showTable_Cluster(dictList, res_elem) { var block_start = '
    '; var block_end = '
    '; var html = '
    '; var i = 0; var num = dictList.length; var itemsPerCol_ = 10; var count = 0; var Class = 0; var addFlag = true; for (; i0) { html += block_end; count = 0; }; Class += 1; html += block_start; html = html + '
      '; } //if ('p' in wd_data) { // 中文里有 wd_data['pinyin']。 if (getSelectedTabId==0) { $("#filter_CN div").find("input").attr("disabled", "disabled"); $("#filter_CN div.visible-xs").find("#POS_select_CC").attr("disabled", "disabled"); $("#filter_CN div.visible-lg").find("#POS_select_CC").attr("disabled", "disabled"); $("#filter_CN div.visible-xs").find("#rhyme_select_CC").attr("disabled", "disabled"); $("#filter_CN div.visible-lg").find("#rhyme_select_CC").attr("disabled", "disabled"); if ($(window).width()<751 || window.innerWidth<768) { html = html + '
    • ' + wd_data['w'] + '
    • '; } else { html = html + '
    • ' + wd_data['w'] + '
    • '; } } else if (getSelectedTabId==1) { $("#filter_EE div").find("input").attr("disabled", "disabled"); $("#filter_EE div.visible-xs").find("#POS_select_EE").attr("disabled", "disabled"); $("#filter_EE div.visible-lg").find("#POS_select_EE").attr("disabled", "disabled"); if ($(window).width()<751 || window.innerWidth<768) { html = html + '
    • ' + wd_data['w'] + '
    • '; } else { html = html + '
    • ' + wd_data['w'] + '
    • '; }; } else if (getSelectedTabId==2) { $("#filter_CE div").find("input").attr("disabled", "disabled"); $("#filter_CE div.visible-xs").find("#POS_select_CE").attr("disabled", "disabled"); $("#filter_CE div.visible-lg").find("#POS_select_CE").attr("disabled", "disabled"); if ($(window).width()<751 || window.innerWidth<768) { html = html + '
    • ' + wd_data['w'] + '
    • '; } else { html = html + '
    • ' + wd_data['w'] + '
    • '; }; } else { $("#filter_EC div").find("input").attr("disabled", "disabled"); $("#filter_EC div.visible-xs").find("#POS_select_EC").attr("disabled", "disabled"); $("#filter_EC div.visible-lg").find("#POS_select_EC").attr("disabled", "disabled"); $("#filter_EC div.visible-xs").find("#rhyme_select_EC").attr("disabled", "disabled"); $("#filter_EC div.visible-lg").find("#rhyme_select_EC").attr("disabled", "disabled"); if ($(window).width()<751 || window.innerWidth<768) { html = html + '
    • ' + wd_data['w'] + '
    • '; } else { html = html + '
    • ' + wd_data['w'] + '
    • '; }; }; i += 1; count += 1; }; clearAlert(); res_elem.html(html); if (getSelectedTabId==0) { $('a.pop0').click(); } else if (getSelectedTabId==2) { $('a.pop1').click(); } else if (getSelectedTabId==2) { $('a.pop2').click(); } else { $('a.pop3').click(); } //$('a.pop').click(); // 这里是用于对新生成的html进行绑定,因为HTML是静态代码,页面生成时绑定了js和html的关系(执行了js代码一次),但是这个新生成的html不被当时的js代码绑定,所以这里再执行一次js代码。 $('div.popover').hide(); }; var retData_backup; //全局变量保存返回值原始数据。 var description_backup; //filterRes(); function filterRes(dictList) { //console.log("filterRes"); //var filter_POS = $("#filter1").val(); //document.getElementById("filter1").value if ($(window).width()<751 || window.innerWidth<768) { var POS_select_CC=$("#filter_CN div.visible-xs").find("#POS_select_CC"); var filter2=$("#filter_CN div.visible-xs").find("#filter2"); var filter3=$("#filter_CN div.visible-xs").find("#filter3"); var filter4=$("#filter_CN div.visible-xs").find("#filter4"); var filter5=$("#filter_CN div.visible-xs").find("#filter5"); var main_select=$("#filter_CN div.visible-xs").find("#main_select"); var rhyme_select_CC=$("#filter_CN div.visible-xs").find("#rhyme_select_CC"); } else { var POS_select_CC=$("#filter_CN div.visible-lg").find("#POS_select_CC"); var filter2=$("#filter_CN div.visible-lg").find("#filter2"); var filter3=$("#filter_CN div.visible-lg").find("#filter3"); var filter4=$("#filter_CN div.visible-lg").find("#filter4"); var filter5=$("#filter_CN div.visible-lg").find("#filter5"); var main_select=$("#filter_CN div.visible-lg").find("#main_select"); var rhyme_select_CC=$("#filter_CN div.visible-lg").find("#rhyme_select_CC"); }; //var filter_POS = document.getElementById("POS_select_CC").options.selectedIndex; var filter_POS = POS_select_CC[0].selectedIndex; var filter_len = filter2.val(); var filter_1stPY = filter3.val(); var filter_strok = filter4.val(); var filter_shape = filter5.val(); var sort_rule = main_select[0].selectedIndex; var filter_rhyme = rhyme_select_CC[0].selectedIndex; if (filter_POS>0) { POS_select_CC.css("background-color", "#fffdef"); } else { POS_select_CC.css("background-color", ""); }; if (filter_len!="") { filter2.css("background-color", "#fffdef"); } else { filter2.css("background-color", ""); }; if (filter_1stPY!="") { filter3.css("background-color", "#fffdef"); } else { filter3.css("background-color", ""); }; if (filter_strok!="") { filter4.css("background-color", "#fffdef"); } else { filter4.css("background-color", ""); }; if (filter_shape!="") { filter5.css("background-color", "#fffdef"); } else { filter5.css("background-color", ""); }; if (sort_rule>0) { main_select.css("background-color", "#fffdef"); } else { main_select.css("background-color", ""); }; if (filter_rhyme>0) { rhyme_select_CC.css("background-color", "#fffdef"); } else { rhyme_select_CC.css("background-color", ""); }; switch (filter_POS) { case 0: var dictList_filtered = dictList.slice(0); break; case 1: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("名")>-1}); break; case 2: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("动")>-1}); break; case 3: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("形")>-1}); break; case 4: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("副")>-1}); break; case 5: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("介")>-1}); break; case 6: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("数")>-1}); break; case 7: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("连")>-1}); break; case 8: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("助")>-1}); break; case 9: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("量")>-1}); break; case 10: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("叹")>-1}); break; case 11: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("代")>-1}); break; case 12: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("拟声")>-1}); break; case 13: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("无")>-1}); break; }; if (dictList_filtered.length == 0) { //信息框 $("#filter_CN").after(htmlInfo("无筛选结果,请修改筛选条件。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; if (filter_rhyme>0) { var dictList_filtered = dictList_filtered.filter(function (value) {return value.r.indexOf(filter_rhyme)>-1}); }; if (dictList_filtered.length == 0) { //信息框 $("#filter_CN").after(htmlInfo("无筛选结果,请修改筛选条件。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; if (filter_len != "") { if (filter_len>0 && filter_len<=8) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.l == filter_len; }; } else if (filter_len.indexOf('>')>-1 && filter_len.slice(filter_len.indexOf('>')+1)>0) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.l > filter_len.slice(filter_len.indexOf('>')+1); }; filter2.val(">" + filter_len.slice(filter_len.indexOf('>')+1)); } else if (filter_len.indexOf('<')>-1 && filter_len.slice(filter_len.indexOf('<')+1)>0) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.l < filter_len.slice(filter_len.indexOf('<')+1); }; filter2.val("<" + filter_len.slice(filter_len.indexOf('<')+1)); } else { //警告框 $("#filter_CN").after(htmlWarning("字数筛选条件 “"+filter_len+"” 超出范围或无法识别。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); filter2.val(this.defaultValue); return false; }; }; if (dictList_filtered.length == 0) { //信息框 $("#filter_CN").after(htmlInfo("无筛选结果,请修改筛选条件。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; if (filter_1stPY != "") { /*if (filter_1stPY>='A' && filter_1stPY<='z') { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.w[0] == filter_1stPY[0]; }; document.getElementById("filter3").value = filter_1stPY[0].toLowerCase(); }*/ filter_1stPY = filter_1stPY.toLowerCase(); var reg = /[a-z]/g; if (filter_1stPY.replace(reg, "")=="") { //证明只有英文字母 var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { var pyszm = value.s.split(" "); for (var i=0;i0) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.b == filter_strok; }; } else if (filter_strok.indexOf('>')>-1 && filter_strok.slice(filter_strok.indexOf('>')+1)>0) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.b > filter_strok.slice(filter_strok.indexOf('>')+1); }; filter4.val(">" + filter_strok.slice(filter_strok.indexOf('>')+1)); } else if (filter_strok.indexOf('<')>-1 && filter_strok.slice(filter_strok.indexOf('<')+1)>0) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.b < filter_strok.slice(filter_strok.indexOf('<')+1); }; filter4.val("<" + filter_strok.slice(filter_strok.indexOf('<')+1)); } else { //警告框 $("#filter_CN").after(htmlWarning("笔画筛选条件 “"+filter_strok+"” 无法识别。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); filter4.val(this.defaultValue); return false; }; }; if (dictList_filtered.length == 0) { //信息框 $("#filter_CN").after(htmlInfo("无筛选结果,请修改筛选条件。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; //*为匹配0到多字;?匹配1字;+为且;[...]匹配集合内任一字;[^...]不匹配集合内任何字 if (filter_shape != "") { var reg = /[\u4e00-\u9fa5]/g; var ruleStr = "或********或????????或????????或++++++++或[^]或[]"; //多次匹配模式(第一个“或”字占位符必须加,因为如果搜索目标是空的则搜索结果是位置0) //var ruleStr = "或*或?或?或+或[^]或[]"; //单次匹配模式 var ruleInd = ruleStr.indexOf(filter_shape.replace(reg, "")); var tmp = filter_shape.match(reg); try { var hanziStr = tmp.join(""); } catch(err) { var hanziStr = ""; }; if (ruleInd>-1) { if (ruleStr[ruleInd]=='*') { var hanziArr = filter_shape.split('*'); var dictList_filtered = dictList_filtered.filter(function (value) { var tmp = []; for (var i=0;i ["山","水",""],有一个空,因为*在边上的原因。 if (this[i].length>0) { tmp.push(this[i]); }; }; if (tmp.length==0) { return true;}; //没有汉字,则都算符合。 if (this[0]!="") { // 开头不是*而是字时,必须匹配第一个字/词 if (value.w[0]!=this[0]) {return false;}; }; if (this[this.length-1]!="") { // 结尾不是*而是字时,必须匹配最后一个字/词 if (value.w[value.w.length-1]!=this[this.length-1]) {return false;}; }; if (tmp.length==1) { //一个字或词,找到就符合。 if (value.w.indexOf(tmp[0])>-1) { return true; } else { return false; }; } else { var ind = value.w.indexOf(tmp[0]); if (ind<0) {return false;}; for (var i=1;i-1) {return false;}; }; return true; }, hanziStr); } else if (ruleStr[ruleInd]=='[') { var dictList_filtered = dictList_filtered.filter(function (value) { for (var i=0;i-1) {return true;}; }; return false; }, hanziStr); } else { //警告框 $("#filter_CN").after(htmlWarning("词形筛选条件 “"+filter_shape+"” 无法识别。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); filter5.val(this.defaultValue); return false; }; } else { //警告框 $("#filter_CN").after(htmlWarning("词形筛选条件 “"+filter_shape+"” 无法识别。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); filter5.val(this.defaultValue); return false; }; }; if (dictList_filtered.length == 0) { //信息框 $("#filter_CN").after(htmlInfo("无筛选结果,请修改筛选条件。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; dictList_filtered = dictList_filtered.slice(0,100); switch (sort_rule) { case 1: dictList_filtered.sort(function(a, b){ if (a.s[0] > b.s[0]) { return 1; } else if (a.s[0] < b.s[0]) { return -1; } else { return 0; } }); break; case 2: dictList_filtered.sort(function(a, b){ if (a.s[0] > b.s[0]) { return -1; } else if (a.s[0] < b.s[0]) { return 1; } else { return 0; } }); break; case 3: dictList_filtered.sort(function(a, b){return a.b - b.b}); break; case 4: dictList_filtered.sort(function(a, b){return b.b - a.b}); break; case 5: dictList_filtered.sort(function(a, b){return a.B - b.B}); break; case 6: dictList_filtered.sort(function(a, b){return b.B - a.B}); break; }; showTable(dictList_filtered, $('#result')); }; function modelProcecss() { clearAlert(); var description = $("#description").val(); if (description.length==0) { $("#filter_CN").after(htmlDanger("输入描述不能为空。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return true; }; var reg = /[\u4e00-\u9fa5]/g; if (description.search(reg)<0) { $("#filter_CN").after(htmlDanger("输入字符无法识别。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return true; }; //聚类功能 if ($(window).width()<751 || window.innerWidth<768) { var main_select=$("#filter_CN div.visible-xs").find("#main_select"); } else { var main_select=$("#filter_CN div.visible-lg").find("#main_select"); }; var sort_rule = main_select[0].selectedIndex; if (sort_rule==7) { $.get("/ChineseRDCluster/", { 'description': description, 'mode': 'CC' }, function (ret) { showTable_Cluster(ret, $('#result')); }); return true; } $("#filter_CN div").find("*").removeAttr("disabled"); //console.log('modelProcecss'); if ($("#description").val()==description_backup) { filterRes(retData_backup); } else { $.get("/ChineseRD/", { 'description': description, 'mode': 'CC' }, function (ret) { try { retData_backup = ret.slice(0); description_backup = description.slice(0); filterRes(retData_backup); $("#filter_CN").show(); } catch(err) { $('#result').html(""); switch (ret['error']){ case 0: //错误框 $("#filter_CN").after(htmlDanger("输入描述不能为空。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); break; case 1: //错误框 $("#filter_CN").after(htmlDanger("输入字符无法识别。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); break; default: //报出明确的错误类型。 $("#filter_CN").after(htmlDanger(err.name)); $(".alert").on("click", function(){$(this).slideUp("fast");}); } } }); } }; function onkeySearch() { $('#result').html(""); clearAlert(); modelProcecss(); }; $(document).ready(function () { $("#description").keypress(function(e) { if(e.keyCode == 13) { $('#result').html(""); clearAlert(); modelProcecss(); } }); }); var retData_backup_EE; //全局变量保存返回值原始数据。 var description_backup_EE; function filterRes_EE(dictList) { if ($(window).width()<751 || window.innerWidth<768) { var POS_select_EE=$("#filter_EE div.visible-xs").find("#POS_select_EE"); var filter1=$("#filter_EE div.visible-xs").find("#filter1_EE"); var filter2=$("#filter_EE div.visible-xs").find("#filter2_EE"); var filter3=$("#filter_EE div.visible-xs").find("#filter3_EE"); var main_select=$("#filter_EE div.visible-xs").find("#main_select_EE"); } else { var POS_select_EE=$("#filter_EE div.visible-lg").find("#POS_select_EE"); var filter1=$("#filter_EE div.visible-lg").find("#filter1_EE"); var filter2=$("#filter_EE div.visible-lg").find("#filter2_EE"); var filter3=$("#filter_EE div.visible-lg").find("#filter3_EE"); var main_select=$("#filter_EE div.visible-lg").find("#main_select_EE"); }; var filter_POS = POS_select_EE[0].selectedIndex; var filter_len = filter1.val(); var filter_initial = filter2.val(); var filter_shape = filter3.val(); var sort_rule = main_select[0].selectedIndex; if (filter_POS>0) { POS_select_EE.css("background-color", "#fffdef"); } else { POS_select_EE.css("background-color", ""); }; if (filter_len!="") { filter1.css("background-color", "#fffdef"); } else { filter1.css("background-color", ""); }; if (filter_initial!="") { filter2.css("background-color", "#fffdef"); } else { filter2.css("background-color", ""); }; if (filter_shape!="") { filter3.css("background-color", "#fffdef"); } else { filter3.css("background-color", ""); }; if (sort_rule>0) { main_select.css("background-color", "#fffdef"); } else { main_select.css("background-color", ""); }; switch (filter_POS) { case 1: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("n")>-1}); break; case 2: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("v")>-1}); break; case 3: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("adj")>-1}); break; case 4: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("adv")>-1}); break; case 5: var dictList_filtered = dictList.filter(function (value) {return value.P.length==0}); break; case 0: var dictList_filtered = dictList.slice(0); break; }; if (dictList_filtered.length == 0) { //信息框 $("#filter_EE").after(htmlInfo_E("No screening results, please modify the POS screening condition.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; if (filter_len != "") { if (filter_len>0) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.w.length == filter_len; }; } else if (filter_len.indexOf('>')>-1 && filter_len.slice(filter_len.indexOf('>')+1)>0) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.w.length > filter_len.slice(filter_len.indexOf('>')+1); }; filter1.val(">" + filter_len.slice(filter_len.indexOf('>')+1)); } else if (filter_len.indexOf('<')>-1 && filter_len.slice(filter_len.indexOf('<')+1)>0) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.w.length < filter_len.slice(filter_len.indexOf('<')+1); }; filter1.val("<" + filter_len.slice(filter_len.indexOf('<')+1)); } else { //警告框 $("#filter_EE").after(htmlWarning_E("Word length screening condition '"+filter_len+"' is out of range or unrecognizable.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); filter1.val(this.defaultValue); return false; }; }; if (dictList_filtered.length == 0) { //信息框 $("#filter_EE").after(htmlInfo_E("No screening results, please modify the word length screening condition.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; if (filter_initial != "") { var reg = /[a-zA-Z]/g; if (filter_initial.replace(reg, "")=="") { //证明只有英文字母 var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.w[0] == filter_initial[0].toLowerCase(); }; filter2.val(filter_initial[0]); } else { //警告框 $("#filter_EE").after(htmlWarning_E("Word initial screening condition '"+filter_initial+"' is not recognizable.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); filter2.val(this.defaultValue); return false; }; }; if (dictList_filtered.length == 0) { //信息框 $("#filter_EE").after(htmlInfo_E("No screening results, please modify the initial screening condition.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; //*为匹配0到多字;?匹配1字 if (filter_shape != "") { var reg = /[a-zA-Z]/g; var ruleStr = "或****************或????????????????或????????????????"; //多次匹配模式(第一个“或”字占位符必须加,因为如果搜索目标是空的则搜索结果是位置0) var ruleInd = ruleStr.indexOf(filter_shape.replace(reg, "")); if (ruleInd>-1) { if (ruleStr[ruleInd]=='*') { var charArr = filter_shape.split('*'); var dictList_filtered = dictList_filtered.filter(function (value) { var tmp = []; for (var i=0;i ["dic","on",""],有一个空,因为*在边上的原因。 if (this[i].length>0) { tmp.push(this[i]); }; }; if (tmp.length==0) { return true;}; //没有字母,则都算符合。 if (this[0]!="") { // 开头不是*而是字时,必须匹配第一个字母片段。########0814修改BUG:value.w[0]!=this[0]错在字母和字母片段进行对比。而是匹配第一个字母片段的首字母。 if (value.w[0]!=this[0][0]) {return false;}; }; if (this[this.length-1]!="") { // 结尾不是*而是字时,必须匹配最后一个字母片段。########0814修改BUG:value.w[0]!=this[0]错在字母和字母片段进行对比。而是匹配末字母片段的末字母。 if (value.w[value.w.length-1]!=this[this.length-1][this[this.length-1].length-1]) {return false;}; }; if (tmp.length==1) { //一个字母片段,找到就符合。 if (value.w.indexOf(tmp[0])>-1) { return true; } else { return false; }; } else { var ind = value.w.indexOf(tmp[0]); if (ind<0) {return false;}; for (var i=1;i b.w[0]) { return 1; } else if (a.w[0] < b.w[0]) { return -1; } else { if (a.w[1] > b.w[1]) { return 1; } else if (a.w[1] < b.w[1]) { return -1; } else { return 0; } } }); break; case 2: dictList_filtered.sort(function(a, b){ if (a.w[0] > b.w[0]) { return -1; } else if (a.w[0] < b.w[0]) { return 1; } else { if (a.w[1] > b.w[1]) { return -1; } else if (a.w[1] < b.w[1]) { return 1; } else { return 0; } } }); break; case 3: dictList_filtered.sort(function(a, b){return a.w.length - b.w.length}); break; case 4: dictList_filtered.sort(function(a, b){return b.w.length - a.w.length}); break; }; showTable(dictList_filtered, $('#result_EE')); }; function modelProcecss_EE() { clearAlert(); var description = $("#description_EE").val(); if (description.length==0) { $("#filter_EE").after(htmlDanger_E("The input description cannot be empty.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return true; }; var reg = /[a-zA-Z]/; if (description.search(reg)<0) { $("#filter_EE").after(htmlDanger_E("The input characters are unrecognizable.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return true; }; // 聚类功能 if ($(window).width()<751 || window.innerWidth<768) { var main_select=$("#filter_EE div.visible-xs").find("#main_select_EE"); } else { var main_select=$("#filter_EE div.visible-lg").find("#main_select_EE"); }; var sort_rule = main_select[0].selectedIndex; if (sort_rule==5) { $.get("/EnglishRDCluster/", { 'description': description, 'mode': 'EE' }, function (ret) { showTable_Cluster(ret, $('#result_EE')); }); return true; } $("#filter_EE div").find("*").removeAttr("disabled"); if ($("#description_EE").val()==description_backup_EE) { filterRes_EE(retData_backup_EE); } else { $.get("/EnglishRD/", { 'description': description, 'mode': 'EE' }, function (ret) { try { retData_backup_EE = ret.slice(0); description_backup_EE = description.slice(0); //console.log(ret); filterRes_EE(retData_backup_EE); $("#filter_EE").show(); } catch(err) { $('#result_EE').html(""); switch (ret['error']){ case 0: //错误框 $("#filter_EE").after(htmlDanger_E("The input description cannot be empty.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); break; case 1: //错误框 $("#filter_EE").after(htmlDanger_E("The input characters are unrecognizable.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); break; default: //报出明确的错误类型。 $("#filter_EE").after(htmlDanger_E(err.name)); $(".alert").on("click", function(){$(this).slideUp("fast");}); } } }); } }; function onkeySearch_EE() { $('#result_EE').html(""); clearAlert(); modelProcecss_EE(); }; $(document).ready(function () { $("#description_EE").keypress(function(e) { if(e.keyCode == 13) { $('#result_EE').html(""); clearAlert(); modelProcecss_EE(); } }); }); var retData_backup_CE; //全局变量保存返回值原始数据。 var description_backup_CE; function filterRes_CE(dictList) { if ($(window).width()<751 || window.innerWidth<768) { var POS_select_CE=$("#filter_CE div.visible-xs").find("#POS_select_CE"); var filter1=$("#filter_CE div.visible-xs").find("#filter1_CE"); var filter2=$("#filter_CE div.visible-xs").find("#filter2_CE"); var filter3=$("#filter_CE div.visible-xs").find("#filter3_CE"); var main_select=$("#filter_CE div.visible-xs").find("#main_select_CE"); } else { var POS_select_CE=$("#filter_CE div.visible-lg").find("#POS_select_CE"); var filter1=$("#filter_CE div.visible-lg").find("#filter1_CE"); var filter2=$("#filter_CE div.visible-lg").find("#filter2_CE"); var filter3=$("#filter_CE div.visible-lg").find("#filter3_CE"); var main_select=$("#filter_CE div.visible-lg").find("#main_select_CE"); }; var filter_POS = POS_select_CE[0].selectedIndex; var filter_len = filter1.val(); var filter_initial = filter2.val(); var filter_shape = filter3.val(); var sort_rule = main_select[0].selectedIndex; if (filter_POS>0) { POS_select_CE.css("background-color", "#fffdef"); } else { POS_select_CE.css("background-color", ""); }; if (filter_len!="") { filter1.css("background-color", "#fffdef"); } else { filter1.css("background-color", ""); }; if (filter_initial!="") { filter2.css("background-color", "#fffdef"); } else { filter2.css("background-color", ""); }; if (filter_shape!="") { filter3.css("background-color", "#fffdef"); } else { filter3.css("background-color", ""); }; if (sort_rule>0) { main_select.css("background-color", "#fffdef"); } else { main_select.css("background-color", ""); }; switch (filter_POS) { case 1: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("n")>-1}); break; case 2: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("v")>-1}); break; case 3: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("adj")>-1}); break; case 4: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("adv")>-1}); break; case 5: var dictList_filtered = dictList.filter(function (value) {return value.P.length==0}); break; case 0: var dictList_filtered = dictList.slice(0); break; }; if (dictList_filtered.length == 0) { //信息框 $("#filter_CE").after(htmlInfo("无筛选结果,请修改筛选条件。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; if (filter_len != "") { if (filter_len>0 && filter_len<=30) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.w.length == filter_len; }; } else if (filter_len.indexOf('>')>-1 && filter_len.slice(filter_len.indexOf('>')+1)>0) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.w.length > filter_len.slice(filter_len.indexOf('>')+1); }; filter1.val(">" + filter_len.slice(filter_len.indexOf('>')+1)); } else if (filter_len.indexOf('<')>-1 && filter_len.slice(filter_len.indexOf('<')+1)>0) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.w.length < filter_len.slice(filter_len.indexOf('<')+1); }; filter1.val("<" + filter_len.slice(filter_len.indexOf('<')+1)); } else { //警告框 $("#filter_CE").after(htmlWarning("单词长度筛选条件 '"+filter_len+"' 超出范围或无法识别。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); filter1.val(this.defaultValue); return false; }; }; if (dictList_filtered.length == 0) { //信息框 $("#filter_CE").after(htmlInfo("无筛选结果,请修改筛选条件。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; if (filter_initial != "") { var reg = /[a-zA-Z]/g; if (filter_initial.replace(reg, "")=="") { //证明只有英文字母 var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.w[0] == filter_initial[0].toLowerCase(); }; filter2.val(filter_initial[0]); } else { //警告框 $("#filter_CE").after(htmlWarning("单词首字母筛选条件 '"+filter_initial+"' 无法识别。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); filter2.val(this.defaultValue); return false; }; }; if (dictList_filtered.length == 0) { //信息框 $("#filter_CE").after(htmlInfo("无筛选结果,请修改筛选条件。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; //*为匹配0到多字;?匹配1字 if (filter_shape != "") { var reg = /[a-zA-Z]/g; var ruleStr = "或****************或????????????????或????????????????"; //多次匹配模式(第一个“或”字占位符必须加,因为如果搜索目标是空的则搜索结果是位置0) var ruleInd = ruleStr.indexOf(filter_shape.replace(reg, "")); if (ruleInd>-1) { if (ruleStr[ruleInd]=='*') { var charArr = filter_shape.split('*'); var dictList_filtered = dictList_filtered.filter(function (value) { var tmp = []; for (var i=0;i ["dic","on",""],有一个空,因为*在边上的原因。 if (this[i].length>0) { tmp.push(this[i]); }; }; if (tmp.length==0) { return true;}; //没有字母,则都算符合。 if (this[0]!="") { // 开头不是*而是字时,必须匹配第一个字母片段。########0814修改BUG:value.w[0]!=this[0]错在字母和字母片段进行对比。而是匹配第一个字母片段的首字母。 if (value.w[0]!=this[0][0]) {return false;}; }; if (this[this.length-1]!="") { // 结尾不是*而是字时,必须匹配最后一个字母片段。########0814修改BUG:value.w[0]!=this[0]错在字母和字母片段进行对比。而是匹配末字母片段的末字母。 if (value.w[value.w.length-1]!=this[this.length-1][this[this.length-1].length-1]) {return false;}; }; if (tmp.length==1) { //一个字母片段,找到就符合。 if (value.w.indexOf(tmp[0])>-1) { return true; } else { return false; }; } else { var ind = value.w.indexOf(tmp[0]); if (ind<0) {return false;}; for (var i=1;i b.w[0]) { return 1; } else if (a.w[0] < b.w[0]) { return -1; } else { if (a.w[1] > b.w[1]) { return 1; } else if (a.w[1] < b.w[1]) { return -1; } else { return 0; } } }); break; case 2: dictList_filtered.sort(function(a, b){ if (a.w[0] > b.w[0]) { return -1; } else if (a.w[0] < b.w[0]) { return 1; } else { if (a.w[1] > b.w[1]) { return -1; } else if (a.w[1] < b.w[1]) { return 1; } else { return 0; } } }); break; case 3: dictList_filtered.sort(function(a, b){return a.w.length - b.w.length}); break; case 4: dictList_filtered.sort(function(a, b){return b.w.length - a.w.length}); break; }; showTable(dictList_filtered, $('#result_CE')); }; function modelProcecss_CE() { clearAlert(); var description = $("#description_CE").val(); if (description.length==0) { $("#filter_CE").after(htmlDanger("输入描述不能为空。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return true; }; var reg = /[\u4e00-\u9fa5]/g; if (description.search(reg)<0) { $("#filter_CE").after(htmlDanger("输入字符无法识别。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return true; }; // 聚类功能 if ($(window).width()<751 || window.innerWidth<768) { var main_select=$("#filter_CE div.visible-xs").find("#main_select_CE"); } else { var main_select=$("#filter_CE div.visible-lg").find("#main_select_CE"); }; var sort_rule = main_select[0].selectedIndex; if (sort_rule==5) { $.get("/EnglishRDCluster/", { 'description': description, 'mode': 'CE' }, function (ret) { showTable_Cluster(ret, $('#result_CE')); }); return true; } $("#filter_CE div").find("*").removeAttr("disabled"); if ($("#description_CE").val()==description_backup_CE) { filterRes_CE(retData_backup_CE); } else { $.get("/EnglishRD/", { 'description': description, 'mode': 'CE' }, function (ret) { try { retData_backup_CE = ret.slice(0); description_backup_CE = description.slice(0); //console.log(ret); filterRes_CE(retData_backup_CE); $("#filter_CE").show(); } catch(err) { $('#result_CE').html(""); switch (ret['error']){ case 0: //错误框 $("#filter_CE").after(htmlDanger("输入描述不能为空。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); break; case 1: //错误框 $("#filter_CE").after(htmlDanger("输入字符无法识别。")); $(".alert").on("click", function(){$(this).slideUp("fast");}); break; default: //报出明确的错误类型。 $("#filter_CE").after(htmlDanger(err.name)); $(".alert").on("click", function(){$(this).slideUp("fast");}); } } }); } }; function onkeySearch_CE() { $('#result_CE').html(""); clearAlert(); modelProcecss_CE(); }; $(document).ready(function () { $("#description_CE").keypress(function(e) { if(e.keyCode == 13) { $('#result_CE').html(""); clearAlert(); modelProcecss_CE(); } }); }); var retData_backup_EC; //全局变量保存返回值原始数据。 var description_backup_EC; //filterRes_EC(); function filterRes_EC(dictList) { //console.log("filterRes_EC"); //var filter_POS = $("#filter1_EC").val(); //document.getElementById("filter1").value if ($(window).width()<751 || window.innerWidth<768) { var POS_select_EC=$("#filter_EC div.visible-xs").find("#POS_select_EC"); var filter2=$("#filter_EC div.visible-xs").find("#filter2_EC"); var filter3=$("#filter_EC div.visible-xs").find("#filter3_EC"); var filter4=$("#filter_EC div.visible-xs").find("#filter4_EC"); var filter5=$("#filter_EC div.visible-xs").find("#filter5_EC"); var main_select=$("#filter_EC div.visible-xs").find("#main_select_EC"); var rhyme_select_EC=$("#filter_EC div.visible-xs").find("#rhyme_select_EC"); } else { var POS_select_EC=$("#filter_EC div.visible-lg").find("#POS_select_EC"); var filter2=$("#filter_EC div.visible-lg").find("#filter2_EC"); var filter3=$("#filter_EC div.visible-lg").find("#filter3_EC"); var filter4=$("#filter_EC div.visible-lg").find("#filter4_EC"); var filter5=$("#filter_EC div.visible-lg").find("#filter5_EC"); var main_select=$("#filter_EC div.visible-lg").find("#main_select_EC"); var rhyme_select_EC=$("#filter_EC div.visible-lg").find("#rhyme_select_EC"); }; //var filter_POS = document.getElementById("POS_select_CC").options.selectedIndex; var filter_POS = POS_select_EC[0].selectedIndex; var filter_len = filter2.val(); var filter_1stPY = filter3.val(); var filter_strok = filter4.val(); var filter_shape = filter5.val(); var sort_rule = main_select[0].selectedIndex; var filter_rhyme = rhyme_select_EC[0].selectedIndex; if (filter_POS>0) { POS_select_EC.css("background-color", "#fffdef"); } else { POS_select_EC.css("background-color", ""); }; if (filter_len!="") { filter2.css("background-color", "#fffdef"); } else { filter2.css("background-color", ""); }; if (filter_1stPY!="") { filter3.css("background-color", "#fffdef"); } else { filter3.css("background-color", ""); }; if (filter_strok!="") { filter4.css("background-color", "#fffdef"); } else { filter4.css("background-color", ""); }; if (filter_shape!="") { filter5.css("background-color", "#fffdef"); } else { filter5.css("background-color", ""); }; if (sort_rule>0) { main_select.css("background-color", "#fffdef"); } else { main_select.css("background-color", ""); }; if (filter_rhyme>0) { rhyme_select_EC.css("background-color", "#fffdef"); } else { rhyme_select_EC.css("background-color", ""); }; switch (filter_POS) { case 0: var dictList_filtered = dictList.slice(0); break; case 1: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("名")>-1}); break; case 2: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("动")>-1}); break; case 3: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("形")>-1}); break; case 4: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("副")>-1}); break; case 5: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("介")>-1}); break; case 6: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("数")>-1}); break; case 7: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("连")>-1}); break; case 8: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("助")>-1}); break; case 9: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("量")>-1}); break; case 10: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("叹")>-1}); break; case 11: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("代")>-1}); break; case 12: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("拟声")>-1}); break; case 13: var dictList_filtered = dictList.filter(function (value) {return value.P.indexOf("无")>-1}); break; }; if (dictList_filtered.length == 0) { //信息框 $("#filter_EC").after(htmlInfo_E("No screening results, please modify the POS screening condition.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; if (filter_rhyme>0) { var dictList_filtered = dictList_filtered.filter(function (value) {return value.r.indexOf(filter_rhyme)>-1}); }; if (dictList_filtered.length == 0) { //信息框 $("#filter_EC").after(htmlInfo_E("No screening results, please modify the rhyme screening condition.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; if (filter_len != "") { if (filter_len>0 && filter_len<=8) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.l == filter_len; }; } else if (filter_len.indexOf('>')>-1 && filter_len.slice(filter_len.indexOf('>')+1)>0) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.l > filter_len.slice(filter_len.indexOf('>')+1); }; filter2.val(">" + filter_len.slice(filter_len.indexOf('>')+1)); } else if (filter_len.indexOf('<')>-1 && filter_len.slice(filter_len.indexOf('<')+1)>0) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.l < filter_len.slice(filter_len.indexOf('<')+1); }; filter2.val("<" + filter_len.slice(filter_len.indexOf('<')+1)); } else { //警告框 $("#filter_EC").after(htmlWarning_E("Word length screening condition '"+filter_len+"' is out of range or unrecognizable.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); filter2.val(this.defaultValue); return false; }; }; if (dictList_filtered.l == 0) { //信息框 $("#filter_EC").after(htmlInfo_E("No screening results, please modify the word length screening condition.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; if (filter_1stPY != "") { filter_1stPY = filter_1stPY.toLowerCase() var reg = /[a-z]/g; if (filter_1stPY.replace(reg, "")=="") { //证明只有英文字母 var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { var pyszm = value.s.split(" "); for (var i=0;i0) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.b == filter_strok; }; } else if (filter_strok.indexOf('>')>-1 && filter_strok.slice(filter_strok.indexOf('>')+1)>0) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.b > filter_strok.slice(filter_strok.indexOf('>')+1); }; document.getElementById("filter4_EC").value = ">" + filter_strok.slice(filter_strok.indexOf('>')+1); } else if (filter_strok.indexOf('<')>-1 && filter_strok.slice(filter_strok.indexOf('<')+1)>0) { var dictList_filtered = dictList_filtered.filter(localFunc); function localFunc(value) { return value.b < filter_strok.slice(filter_strok.indexOf('<')+1); }; document.getElementById("filter4_EC").value = "<" + filter_strok.slice(filter_strok.indexOf('<')+1); } else { //警告框 $("#filter_EC").after(htmlWarning_E("Number of strokes screening condition '"+filter_strok+"' is not recognizable.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); document.getElementById("filter4_EC").value = ""; return false; }; }; if (dictList_filtered.length == 0) { //信息框 $("#filter_EC").after(htmlInfo_E("No screening results, please modify the number of strokes screening condition.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; //*为匹配0到多字;?匹配1字;+为且;[...]匹配集合内任一字;[^...]不匹配集合内任何字 if (filter_shape != "") { var reg = /[\u4e00-\u9fa5]/g; var ruleStr = "或********或????????或????????或++++++++或[^]或[]"; //多次匹配模式(第一个“或”字占位符必须加,因为如果搜索目标是空的则搜索结果是位置0) //var ruleStr = "或*或?或?或+或[^]或[]"; //单次匹配模式 var ruleInd = ruleStr.indexOf(filter_shape.replace(reg, "")); var tmp = filter_shape.match(reg); try { var hanziStr = tmp.join(""); } catch(err) { var hanziStr = ""; }; if (ruleInd>-1) { if (ruleStr[ruleInd]=='*') { var hanziArr = filter_shape.split('*'); var dictList_filtered = dictList_filtered.filter(function (value) { var tmp = []; for (var i=0;i ["山","水",""],有一个空,因为*在边上的原因。 if (this[i].length>0) { tmp.push(this[i]); }; }; if (tmp.length==0) { return true;}; //没有汉字,则都算符合。 if (this[0]!="") { // 开头不是*而是字时,必须匹配第一个字/词 if (value.w[0]!=this[0]) {return false;}; }; if (this[this.length-1]!="") { // 结尾不是*而是字时,必须匹配最后一个字/词 if (value.w[value.w.length-1]!=this[this.length-1]) {return false;}; }; if (tmp.length==1) { //一个字或词,找到就符合。 if (value.w.indexOf(tmp[0])>-1) { return true; } else { return false; }; } else { var ind = value.w.indexOf(tmp[0]); if (ind<0) {return false;}; for (var i=1;i-1) {return false;}; }; return true; }, hanziStr); } else if (ruleStr[ruleInd]=='[') { var dictList_filtered = dictList_filtered.filter(function (value) { for (var i=0;i-1) {return true;}; }; return false; }, hanziStr); } else { //警告框 $("#filter_EC").after(htmlWarning_E("Wildcard patterns screening condition '"+filter_shape+"' is not recognizable.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); filter5.val(this.defaultValue); return false; }; } else { //警告框 $("#filter_EC").after(htmlWarning_E("Wildcard patterns screening condition '"+filter_shape+"' is not recognizable.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); filter5.val(this.defaultValue); return false; }; }; if (dictList_filtered.length == 0) { //信息框 $("#filter_EC").after(htmlInfo_E("No screening results, please modify the Wildcard patterns screening condition.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return false; }; dictList_filtered = dictList_filtered.slice(0,100); switch (sort_rule) { case 1: dictList_filtered.sort(function(a, b){ if (a.s[0] > b.s[0]) { return 1; } else if (a.s[0] < b.s[0]) { return -1; } else { return 0; } }); break; case 2: dictList_filtered.sort(function(a, b){ if (a.s[0] > b.s[0]) { return -1; } else if (a.s[0] < b.s[0]) { return 1; } else { return 0; } }); break; case 3: dictList_filtered.sort(function(a, b){return a.b - b.b}); break; case 4: dictList_filtered.sort(function(a, b){return b.b - a.b}); break; case 5: dictList_filtered.sort(function(a, b){return a.B - b.B}); break; case 6: dictList_filtered.sort(function(a, b){return b.B - a.B}); break; }; showTable(dictList_filtered, $('#result_EC')); }; function modelProcecss_EC() { clearAlert(); var description = $("#description_EC").val(); if (description.length==0) { $("#filter_EC").after(htmlDanger_E("The input description cannot be empty.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return true; }; var reg = /[a-zA-Z]/; if (description.search(reg)<0) { $("#filter_EC").after(htmlDanger_E("The input characters are unrecognizable.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); return true; }; // 聚类功能 if ($(window).width()<751 || window.innerWidth<768) { var main_select=$("#filter_EC div.visible-xs").find("#main_select_EC"); } else { var main_select=$("#filter_EC div.visible-lg").find("#main_select_EC"); }; var sort_rule = main_select[0].selectedIndex; if (sort_rule==7) { $.get("/ChineseRDCluster/", { 'description': description, 'mode': 'EC' }, function (ret) { showTable_Cluster(ret, $('#result_EC')); }); return true; } $("#filter_EC div").find("*").removeAttr("disabled"); if ($("#description_EC").val()==description_backup_EC) { filterRes_EC(retData_backup_EC); } else { $.get("/ChineseRD/", { 'description': description, 'mode': 'EC' }, function (ret) { retData_backup_EC = ret.slice(0); description_backup_EC = description.slice(0); //console.log(ret); try { filterRes_EC(retData_backup_EC); $("#filter_EC").show(); } catch(err) { $('#result_EC').html(""); switch (ret['error']){ case 0: //错误框 $("#filter_EC").after(htmlDanger_E("The input description cannot be empty.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); break; case 1: //错误框 $("#filter_EC").after(htmlDanger_E("The input characters are unrecognizable.")); $(".alert").on("click", function(){$(this).slideUp("fast");}); break; default: //报出明确的错误类型。 $("#filter_EC").after(htmlDanger(err.name)); $(".alert").on("click", function(){$(this).slideUp("fast");}); } } }); } }; function onkeySearch_EC() { $('#result_EC').html(""); clearAlert(); modelProcecss_EC(); }; $(document).ready(function () { $("#description_EC").keypress(function(e) { if(e.keyCode == 13) { $('#result_EC').html(""); clearAlert(); modelProcecss_EC(); } }); }); $(document).ready(function () { $("#description_EO").keypress(function(e) { if(e.keyCode == 13) { var description = $("#description_EO").val(); $.get("/EnglishRD/", { 'description': description, 'mode': 'EO' }, function (ret) { $('#result_EO').html(ret) }) } }); }); $(document).ready(function(){ $("#flip_EE").click(function(){ $("#panel_EE").slideToggle("fast", function(){ if($(this).is(":visible")){ $("#flip_EE").html('Clear and Hide Filter ')} else{ clearAlert(); $("#filter_EE div").find("*").removeAttr("disabled"); try { if ($("#description_EE").val()=="") { $('#result_EE').html(""); } else { if ($("#description_EE").val()==description_backup_EE) { showTable(retData_backup_EE, $('#result_EE')); } else { modelProcecss_EE(); }; }; } catch(err) { $('#result_EE').html(""); }; $("#filter_EE.panel").find("*").val(this.defaultValue).css("background-color", ""); $("#flip_EE").html('Open Filter ')} document.getElementById("main_select_EE").options.selectedIndex = 0; document.getElementById("POS_select_EE").options.selectedIndex = 0; }); }); }); $(document).ready(function(){ $("#flip_CE").click(function(){ $("#panel_CE").slideToggle("fast", function(){ if($(this).is(":visible")){ $("#flip_CE").html('清除并收起 筛选器 ')} else{ clearAlert(); $("#filter_CE div").find("*").removeAttr("disabled"); try { if ($("#description_CE").val()=="") { $('#result_CE').html(""); } else { if ($("#description_CE").val()==description_backup_CE) { showTable(retData_backup_CE, $('#result_CE')); } else { modelProcecss_CE(); }; }; } catch(err) { $('#result_CE').html(""); }; $("#filter_CE.panel").find("*").val(this.defaultValue).css("background-color", ""); $("#flip_CE").html('开启 筛选器 ')} document.getElementById("main_select_CE").options.selectedIndex = 0; document.getElementById("POS_select_CE").options.selectedIndex = 0; }); }); }); $(document).ready(function(){ $("#flip_EC").click(function(){ $("#panel_EC").slideToggle("fast", function(){ if($(this).is(":visible")){ $("#flip_EC").html('Clear and Hide Filter ')} else{ clearAlert(); $("#filter_EC div").find("*").removeAttr("disabled"); try { if ($("#description_EC").val()=="") { $('#result_EC').html(""); } else { if ($("#description_EC").val()==description_backup_EC) { showTable(retData_backup_EC, $('#result_EC')); } else { modelProcecss_EC(); }; }; } catch(err) { $('#result_EC').html(""); }; $("#filter_EC div.panel").find("*").val(this.defaultValue).css("background-color", ""); $("#flip_EC").html('Open Filter ')} document.getElementById("main_select_EC").options.selectedIndex = 0; document.getElementById("POS_select_EC").options.selectedIndex = 0; document.getElementById("rhyme_select_EC").options.selectedIndex = 0; }); }); }); $(document).ready(function(){ $("#flip").click(function(){ $("#panel").slideToggle("fast", function(){ if($(this).is(":visible")){ $("#flip").html('清除并收起 筛选器 ')} else{ clearAlert(); $("#filter_CN div").find("*").removeAttr("disabled"); try { if ($("#description").val()=="") { //收起筛选器后,若输入为空(可能一开始就是空,或改为空但没按回车)则清空 输出区。 $('#result').html(""); } else { if ($("#description").val()==description_backup) { //输入框中没变化,则因为没有筛选条件而直接显示上一次的结果。 showTable(retData_backup, $('#result')); } else { modelProcecss(); //输入框里有变化,则重新计算结果(没有筛选条件,filterRes中的判断都会跳过的,不慢)。 }; }; } catch(err) { $('#result').html(""); }; $("#filter_CN div.panel").find("*").val(this.defaultValue); $("#flip").html('开启 筛选器 ')} document.getElementById("main_select").options.selectedIndex = 0; document.getElementById("POS_select_CC").options.selectedIndex = 0; document.getElementById("rhyme_select_CC").options.selectedIndex = 0; }); }); }); ================================================ FILE: static/js/zzsc.js ================================================ //star $(document).ready(function(){ var stepW = 24; var starRes = new Array("毫无关系","基本相关","非常匹配"); var stars = $("#star > li"); var starResTemp; $("#showb").css("width",0); stars.each(function(i){ $(stars[i]).click(function(e){ var n = i+1; $("#showb").css({"width":stepW*n}); starResTemp = starRes[i]; $(this).find('a').blur(); return stopDefault(e); return starResTemp; }); }); stars.each(function(i){ $(stars[i]).hover( function(){ $(".starRes").text(starRes[i]); }, function(){ if(starResTemp != null) $(".starRes").text(starResTemp); else $(".starRes").text(""); } ); }); }); function stopDefault(e){ if(e && e.preventDefault) e.preventDefault(); else window.event.returnValue = false; return false; }; ================================================ FILE: templates/about.html ================================================ 万词王 关于我们

      清华大学人工智能研究院

      清华大学人工智能研究院为校级跨学科交叉科研机构,成立于2018年6月28日。研究院以“一个核心、两个融合”作为发展战略,即以人工智能基础理论和基本方法研究为核心,积极推进大跨度的学科交叉融合,积极推进大范围的技术与产业、学校与企业融合,充分发挥清华大学在多学科综合、优秀人才汇聚、高水平国际合作等方面的独特优势,在人工智能的基础理论和基本方法上开展源头性和颠覆性创新,力争将人工智能研究院打造成为一个具有全球影响力的人工智能高端研究机构。院长为清华大学计算机系教授、中国科学院院士张钹,学术委员会主任为清华大学交叉信息研究院院长、图灵奖获得者姚期智。


      清华大学自然语言处理与社会人文计算实验室

      清华大学计算机系自然语言处理与社会人文计算实验室(THUNLP)成立于20世纪70年代末,最初在黄昌宁教授的带领下从事中文信息处理方面的研究工作,是国内开展自然语言处理研究最早、深具影响力的科研单位,同时也是中国中文信息学会(全国一级学会)计算语言学专业委员会的挂靠单位。实验室学术带头人为孙茂松教授,实验室教师队伍还包括刘洋教授和刘知远副教授。实验室面向以中文为核心的自然语言处理前沿基础课题开展系统深入的研究工作,研究领域涵盖计算语言学的核心问题以及社会计算和人文计算,近年来在973、863、国家自然科学基金等项目的支持下,实验室师生在IJCAI、AAAI、ACL、EMNLP等国际顶级会议和期刊上发表多篇高水平学术论文,与CMU、NUS、Google等国际名校和企业有长期良好的合作关系,培养的优秀毕业生大多到清华大学、谷歌、百度、阿里、微软等著名高校和企业工作。

      WantWords由THUNLP开发和维护,项目指导教师为孙茂松教授和刘知远副教授,开发团队成员包括岂凡超,张磊,杨延辉。


      THUNLP学术带头人孙茂松教授简介

      孙茂松,清华大学计算机系教授,清华大学人工智能研究院常务副院长,博士生导师。主要研究领域为自然语言处理、互联网智能、机器学习、社会计算和计算教育学。国家重点基础研究发展计划(973计划)项目首席科学家,国家社会科学基金重大项目首席专家。在国际和国内学术期刊及会议上共发表论文400余篇,近三年发表60余篇,是大陆研究机构中最早在自然语言处理国际顶级会议ACL(1998年)和顶级期刊CL(2009年)发表论文的学者,Google Scholar引用10000余次,主持完成文本信息处理领域ISO国际标准2项。2013年带领团队研发全球第一个中文慕课平台“学堂在线”,为我国和清华的在线教育事业作出了重要贡献。曾获2007年全国语言文字先进工作者,2016年全国优秀科技工作者,2016年首都市民学习之星等荣誉。


      联系方式


      • 电话:(+8610) 62777701

      • 地址:北京市海淀区清华大学FIT楼4-505

      • 邮编:100094


      清华大学人工智能研究院

      清华大学人工智能研究院为校级跨学科交叉科研机构,成立于2018年6月28日。研究院以“一个核心、两个融合”作为发展战略,即以人工智能基础理论和基本方法研究为核心,积极推进大跨度的学科交叉融合,积极推进大范围的技术与产业、学校与企业融合,充分发挥清华大学在多学科综合、优秀人才汇聚、高水平国际合作等方面的独特优势,在人工智能的基础理论和基本方法上开展源头性和颠覆性创新,力争将人工智能研究院打造成为一个具有全球影响力的人工智能高端研究机构。院长为清华大学计算机系教授、中国科学院院士张钹,学术委员会主任为清华大学交叉信息研究院院长、图灵奖获得者姚期智。


      清华大学自然语言处理与社会人文计算实验室

      清华大学计算机系自然语言处理与社会人文计算实验室(THUNLP)成立于20世纪70年代末,最初在黄昌宁教授的带领下从事中文信息处理方面的研究工作,是国内开展自然语言处理研究最早、深具影响力的科研单位,同时也是中国中文信息学会(全国一级学会)计算语言学专业委员会的挂靠单位。实验室学术带头人为孙茂松教授,实验室教师队伍还包括刘洋教授和刘知远副教授。实验室面向以中文为核心的自然语言处理前沿基础课题开展系统深入的研究工作,研究领域涵盖计算语言学的核心问题以及社会计算和人文计算,近年来在973、863、国家自然科学基金等项目的支持下,实验室师生在IJCAI、AAAI、ACL、EMNLP等国际顶级会议和期刊上发表多篇高水平学术论文,与CMU、NUS、Google等国际名校和企业有长期良好的合作关系,培养的优秀毕业生大多到清华大学、谷歌、百度、阿里、微软等著名高校和企业工作。

      WantWords由THUNLP开发和维护,项目指导教师为孙茂松教授和刘知远副教授,开发团队成员包括岂凡超,张磊,杨延辉。


      THUNLP学术带头人孙茂松教授简介

      孙茂松,清华大学计算机系教授,清华大学人工智能研究院常务副院长,博士生导师。主要研究领域为自然语言处理、互联网智能、机器学习、社会计算和计算教育学。国家重点基础研究发展计划(973计划)项目首席科学家,国家社会科学基金重大项目首席专家。在国际和国内学术期刊及会议上共发表论文400余篇,近三年发表60余篇,是大陆研究机构中最早在自然语言处理国际顶级会议ACL(1998年)和顶级期刊CL(2009年)发表论文的学者,Google Scholar引用10000余次,主持完成文本信息处理领域ISO国际标准2项。2013年带领团队研发全球第一个中文慕课平台“学堂在线”,为我国和清华的在线教育事业作出了重要贡献。曾获2007年全国语言文字先进工作者,2016年全国优秀科技工作者,2016年首都市民学习之星等荣誉。


      联系方式


      • 电话:(+8610) 62777701

      • 地址:北京市海淀区清华大学FIT楼4-505

      • 邮编:100094

      ================================================ FILE: templates/about_en.html ================================================ WantWords About Us

      Institute for Artificial Intelligence, Tsinghua University

      Institute for Artificial Intelligence, Tsinghua University, built in June 2018, is a university-level cross-disciplinary research institute. The institute has formed the development strategy of "one core, two fusions", namely taking basic theories and research methods of artificial intelligence as the core and facilitating the fusions of different disciplines and the fusions of technology and industry together with university and enterprise. The institute will make full use of Tsinghua University's unique advantages in multidisciplinary integration, outstanding talents gathering and high-level international cooperation and foster radical innovation in the basic theories and methods of artificial intelligence, aiming to become a high-end artificial intelligence research institute with global influence. Director of the institute is Dr. Bo Zhang, professor of Department of Computer Science and Technology at Tsinghua University and academician of Chinese Academy of Sciences. Chairman of the academic committee is Dr. Andrew Chi-Chih Yao, Dean of the Institute for Interdisciplinary Information Sciences at Tsinghua University and the Turing Award winner.


      The Natural Language Processing Group, Tsinghua University

      The Natural Language Processing Group, Tsinghua University, short for THUNLP, was established in the 1970s. It was first led by Professor Changning Huang, carrying out research on Chinese information processing. It conducted natural language processing (NLP) research earliest and is very influential in China. THUNLP is also the linked unit of the computational linguistics technical committee of Chinese Information Processing Society of China. The faculty members include Professor Maosong Sun, the principal investigator of THUNLP, Professor Yang Liu and Associate Professor Zhiyuan Liu. The group conducts systematic and in-depth research on the front-line basic topics of natural language processing, whose research areas cover the core issues of computational linguistics, social computing and human computing. With the support of programs including 973, 863 and NSFC, members of THUNLP have published many high-level academic papers on international top conferences and journals including AAAI, IJCAI, ACL and EMNLP. In addition, THUNLP has developed long-term cooperations with famous universities and enterprises in the world such as CMU, NUS and Google. The alumni work for well-known higher educational institutions and companies like Tsinghua University, Google, Baidu, Alibaba and Microsoft.

      WantWords is developed and maintained by THUNLP. Project instructors are Professor Maosong Sun and Zhiyuan Liu, and members comprise Fanchao Qi, Lei Zhang and Yanhui Yang.


      Professor Maosong Sun, the Principal Investigator of THUNLP

      Maosong Sun is a full professor of Department of Computer Science and Technology at Tsinghua University and executive deputy director of the Institute for Artificial Intelligence, Tsinghua University. His research interests mainly lie in NLP, web intelligence, machine learning, social computing and computational pedagogy. Professor Sun is the chief scientist of the National Basic Research Program (973 Program) and the chief expert of major projects of the National Social Science Fund. He has published more than 400 academic papers on international and domestic journals and conferences. He is the first among scholars of mainland China who published papers on ACL, the top conference of NLP, and CL, the top journal of NLP. His citations have exceeded 10,000 according to Google Scholar. In 2013, he led a team to develop the world's first Chinese MOOC platform xuetangX and made an important contribution to the development of China's online learning. He was awarded the National Advanced Worker in Language in 2007, the National Excellent Science and Technology Worker in 2016 and Learning Star of Beijing Citizens in 2016.


      Contact Us


      • Phone:(+8610) 62777701

      • Address:Room 4-505, FIT Building, Tsinghua University, Haidian District, Beijing City, China 100084


      Institute for Artificial Intelligence, Tsinghua University

      Institute for Artificial Intelligence, Tsinghua University, built in June 2018, is a university-level cross-disciplinary research institute. The institute has formed the development strategy of "one core, two fusions", namely taking basic theories and research methods of artificial intelligence as the core and facilitating the fusions of different disciplines and the fusions of technology and industry together with university and enterprise. The institute will make full use of Tsinghua University's unique advantages in multidisciplinary integration, outstanding talents gathering and high-level international cooperation and foster radical innovation in the basic theories and methods of artificial intelligence, aiming to become a high-end artificial intelligence research institute with global influence. Director of the institute is Dr. Bo Zhang, professor of Department of Computer Science and Technology at Tsinghua University and academician of Chinese Academy of Sciences. Chairman of the academic committee is Dr. Andrew Chi-Chih Yao, Dean of the Institute for Interdisciplinary Information Sciences at Tsinghua University and the Turing Award winner.


      The Natural Language Processing Group, Tsinghua University

      The Natural Language Processing Group, Tsinghua University, short for THUNLP, was established in the 1970s. It was first led by Professor Changning Huang, carrying out research on Chinese information processing. It conducted natural language processing (NLP) research earliest and is very influential in China. THUNLP is also the linked unit of the computational linguistics technical committee of Chinese Information Processing Society of China. The faculty members include Professor Maosong Sun, the principal investigator of THUNLP, Professor Yang Liu and Associate Professor Zhiyuan Liu. The group conducts systematic and in-depth research on the front-line basic topics of natural language processing, whose research areas cover the core issues of computational linguistics, social computing and human computing. With the support of programs including 973, 863 and NSFC, members of THUNLP have published many high-level academic papers on international top conferences and journals including AAAI, IJCAI, ACL and EMNLP. In addition, THUNLP has developed long-term cooperations with famous universities and enterprises in the world such as CMU, NUS and Google. The alumni work for well-known higher educational institutions and companies like Tsinghua University, Google, Baidu, Alibaba and Microsoft.

      WantWords is developed and maintained by THUNLP. Project instructors are Professor Maosong Sun and Zhiyuan Liu, and members comprise Fanchao Qi, Lei Zhang and Yanhui Yang.


      Professor Maosong Sun, the Principal Investigator of THUNLP

      Maosong Sun is a full professor of Department of Computer Science and Technology at Tsinghua University and executive deputy director of the Institute for Artificial Intelligence, Tsinghua University. His research interests mainly lie in NLP, web intelligence, machine learning, social computing and computational pedagogy. Professor Sun is the chief scientist of the National Basic Research Program (973 Program) and the chief expert of major projects of the National Social Science Fund. He has published more than 400 academic papers on international and domestic journals and conferences. He is the first among scholars of mainland China who published papers on ACL, the top conference of NLP, and CL, the top journal of NLP. His citations have exceeded 10,000 according to Google Scholar. In 2013, he led a team to develop the world's first Chinese MOOC platform xuetangX and made an important contribution to the development of China's online learning. He was awarded the National Advanced Worker in Language in 2007, the National Excellent Science and Technology Worker in 2016 and Learning Star of Beijing Citizens in 2016.


      Contact Us


      • Phone:(+8610) 62777701

      • Address:Room 4-505, FIT Building, Tsinghua University, Haidian District, Beijing City, China 100084

      ================================================ FILE: templates/home.html ================================================ 万词王 wantwords

      反向词典





      开启 筛选器
      筛选:


      Reverse Dictionary





      Open Filter
      Filter:


      汉英反向词典





      开启 筛选器
      筛选:


      English-Chinese
      Reverse Dictionary





      Open Filter
      Filter:



          
      ================================================ FILE: uwsgi.ini ================================================ # website_RD_uwsgi.ini file [uwsgi] # Django-related settings socket = 127.0.0.1:8000 # the base directory (full path) chdir = /home/zhanglei/website_RD/ # Django s wsgi file module = website_RD.wsgi # process-related settings # master master = true # maximum number of worker processes processes = 2 threads = 2 # ... with appropriate permissions - may be needed # chmod-socket = 664 # clear environment on exit vacuum = true ================================================ FILE: website_RD/__init__.py ================================================ # ================================================ FILE: website_RD/settings.py ================================================ """ Django settings for website_RD project. Generated by 'django-admin startproject' using Django 2.2.3. For more information on this file, see https://docs.djangoproject.com/en/2.2/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/2.2/ref/settings/ """ import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'teh-$sfknb+4vwa#dne!k58eg*dqbty_fv&zs-e!h=3wb77d#v' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = False #True #DEBUG = True ALLOWED_HOSTS = ['*'] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', #'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'website_RD.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR+"/templates",], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'website_RD.wsgi.application' # Database # https://docs.djangoproject.com/en/2.2/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] # Internationalization # https://docs.djangoproject.com/en/2.2/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ STATIC_FINDERS = [ 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', ] STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'staticfiles'), ) STATIC_ROOT = os.path.join(BASE_DIR, 'static') ================================================ FILE: website_RD/urls.py ================================================ """website_RD URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.2/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.urls import path from . import views urlpatterns = [ #path('admin/', admin.site.urls), #path('admin/', views.admin), path('datastatistics/', views.admin), #path(r'^$', views.home), path('', views.home), path('home/', views.home), path('ChineseRD/', views.ChineseRD), path('EnglishRD/', views.EnglishRD), path('feedback/', views.feedback), path('about/', views.about), path('about_en/', views.about_en), path('papers/', views.papers), path('help/', views.help), path('GetChDefis/', views.GetChDefis), path('GetEnDefis/', views.GetEnDefis), path('ChineseRDCluster/', views.ChineseRDCluster), path('EnglishRDCluster/', views.EnglishRDCluster), #path('/', views.), ] ================================================ FILE: website_RD/views.py ================================================ import torch, gc, json, os, thulac, string, re, requests, hashlib, urllib.parse import numpy as np from django.shortcuts import render, render_to_response from django.http import HttpResponse from datetime import datetime from pytorch_transformers import * from sklearn.cluster import KMeans kmeans = KMeans(n_clusters=6, n_jobs=1, random_state=0, init='k-means++', max_iter=10) def md5(str): m = hashlib.md5() m.update(str.encode("utf8")) return m.hexdigest() appid = '20***************79' secretKey = 'D2u0***********Yhz5' BASE_DIR = './website_RD/' device = torch.device('cpu') torch.backends.cudnn.benchmark = True words_t = torch.tensor(np.array([0])) itemsPerCol = 20 GET_NUM = 100 NUM_RESPONSE = 500 words_t = torch.tensor(np.array([0])) tokenizer_class = BertTokenizer tokenizer_Ch = tokenizer_class.from_pretrained('bert-base-chinese') tokenizer_En = tokenizer_class.from_pretrained('bert-base-uncased') #========================ChineseRD MODE = 'Psc' lac = thulac.thulac() def load_data(): (word2index, index2word, _, _, _, _, _) = np.load(BASE_DIR + 'data_inUse1.npy', allow_pickle=True) wd_charas = np.load(BASE_DIR + 'data_inUse2.npy', allow_pickle=True) ((_, _, _, wd_sems, wd_POSs),(_, mask_s)) = np.load(BASE_DIR + 'data_inUse3.npy', allow_pickle=True) mask_s = torch.from_numpy(mask_s).to(device) wd_POSs = torch.from_numpy(wd_POSs).float().to(device) wd_charas = torch.from_numpy(wd_charas).float().to(device) wd_sems = torch.from_numpy(wd_sems).float().to(device) wd_C = [] mask_c = [] mask_s = mask_s.float() return word2index, index2word, (wd_C, wd_sems, wd_POSs, wd_charas), (mask_c, mask_s) word2index, index2word, wd_features, mask_ = load_data() (wd_C, wd_sems, wd_POSs, wd_charas) = wd_features (mask_c, mask_s) = mask_ index2word = np.array(index2word) # 添加同义词词林用于描述为一个词时的同义词推荐 index2synset = [[] for i in range(len(word2index))] for line in open(BASE_DIR + 'word2synset_synset.txt').readlines(): wd = line.split()[0] synset = line.split()[1:] for syn in synset: index2synset[word2index[wd]].append(word2index[syn]) MODEL_FILE = BASE_DIR + 'Zh.model' model = torch.load(MODEL_FILE, map_location=lambda storage, loc: storage) model.eval() wd_data_ = json.load(open(BASE_DIR+'wd_def_for_website_zh.json')) #wd_data = dict() wd_data = wd_data_.copy() wd_defi = wd_data_.copy() for wd in wd_data_: #wd_data[wd] = {'w': wd_data_[wd]['word'], 'd': wd_data_[wd]['definition'], 'P': wd_data_[wd]['POS'], 'l': wd_data_[wd]['length'], 'b': wd_data_[wd]['bihuashu'], 'B': wd_data_[wd]['bihuashu1st'], 'p': wd_data_[wd]['pinyin'], 's': wd_data_[wd]['pinyinshouzimu'], 'r': wd_data_[wd]['rhyme']} wd_data[wd] = {'w': wd_data_[wd]['word'], 'P': wd_data_[wd]['POS'], 'l': wd_data_[wd]['length'], 'b': wd_data_[wd]['bihuashu'], 'B': wd_data_[wd]['bihuashu1st'], 'p': wd_data_[wd]['pinyin'], 's': wd_data_[wd]['pinyinshouzimu'], 'r': wd_data_[wd]['rhyme']} wd_defi[wd] = wd_data_[wd]['definition'] del wd_data_ #========================EnglishRD MODE_en = 'rsl' MODEL_FILE_en = BASE_DIR + 'En.model' wd_data_en_ = json.load(open(BASE_DIR+'wd_def_for_website_En.json')) wd_data_en = wd_data_en_.copy() wd_defi_en = wd_data_en_.copy() for wd in wd_data_en_: #wd_data_en[wd] = {'w': wd_data_en_[wd]['word'], 'd': wd_data_en_[wd]['definition'], 'P': wd_data_en_[wd]['POS']} wd_data_en[wd] = {'w': wd_data_en_[wd]['word'], 'P': wd_data_en_[wd]['POS']} wd_defi_en[wd] = wd_data_en_[wd]['definition'] del wd_data_en_ gc.collect() def label_multihot(labels, num): sm = np.zeros((len(labels), num), dtype=np.float32) for i in range(len(labels)): for s in labels[i]: if s >= num: break sm[i, s] = 1 return sm def word2feature(dataset, word_num, feature_num, feature_name): max_feature_num = max([len(instance[feature_name]) for instance in dataset]) ret = np.zeros((word_num, max_feature_num), dtype=np.int64) ret.fill(feature_num) for instance in dataset: if ret[instance['word'], 0] != feature_num: continue # this target_words has been given a feature mapping, because same word with different definition in dataset feature = instance[feature_name] ret[instance['word'], :len(feature)] = np.array(feature) return torch.tensor(ret, dtype=torch.int64, device=device) def mask_noFeature(label_size, wd2fea, feature_num): mask_nofea = torch.zeros(label_size, dtype=torch.float32, device=device) for i in range(label_size): feas = set(wd2fea[i].detach().cpu().numpy().tolist())-set([feature_num]) if len(feas)==0: mask_nofea[i] = 1 return mask_nofea (_, (_, label_size, _, _), (word2index_en, index2word_en, index2sememe, index2lexname, index2rootaffix)) = np.load(BASE_DIR + 'data_inUse1_en.npy', allow_pickle=True) (data_train_idx, data_dev_idx, data_test_500_seen_idx, data_test_500_unseen_idx, data_defi_c_idx, data_desc_c_idx) = np.load(BASE_DIR + 'data_inUse2_en.npy', allow_pickle=True) data_all_idx = data_train_idx + data_dev_idx + data_test_500_seen_idx + data_test_500_unseen_idx + data_defi_c_idx index2word_en = np.array(index2word_en) sememe_num = len(index2sememe) wd2sem = word2feature(data_all_idx, label_size, sememe_num, 'sememes') wd_sems_ = label_multihot(wd2sem, sememe_num) wd_sems_ = torch.from_numpy(np.array(wd_sems_)).to(device) lexname_num = len(index2lexname) wd2lex = word2feature(data_all_idx, label_size, lexname_num, 'lexnames') wd_lex = label_multihot(wd2lex, lexname_num) wd_lex = torch.from_numpy(np.array(wd_lex)).to(device) rootaffix_num = len(index2rootaffix) wd2ra = word2feature(data_all_idx, label_size, rootaffix_num, 'root_affix') wd_ra = label_multihot(wd2ra, rootaffix_num) wd_ra = torch.from_numpy(np.array(wd_ra)).to(device) mask_s_ = mask_noFeature(label_size, wd2sem, sememe_num) mask_l = mask_noFeature(label_size, wd2lex, lexname_num) mask_r = mask_noFeature(label_size, wd2ra, rootaffix_num) #del data_all_idx, data_train_idx, data_dev_idx, data_test_idx del data_all_idx, data_train_idx, data_dev_idx, data_test_500_seen_idx, data_test_500_unseen_idx, data_defi_c_idx gc.collect() print('-------------------------3') # 添加wordnet synset用于描述为一个词时的同义词推荐 index2synset_en = [[] for i in range(len(word2index_en))] for line in open(BASE_DIR + 'word_synsetWords.txt').readlines(): wd = line.split()[0] synset = line.split()[1:] for syn in synset: index2synset_en[word2index_en[wd]].append(word2index_en[syn]) model_en = torch.load(MODEL_FILE_en, map_location=lambda storage, loc: storage) model_en.eval() def home(request): return render(request, 'home.html') def admin(request): result = json.load(open('datastatistics.current', 'r')) [updatetime, pageview, totalqueries, uniquevisitor, effectiveflow, weeknum, weekvalue, month2019v, month2020v, visit2019v, visit2020v, feedbackinfo] = result pageview = format(pageview, ',') totalqueries = format(totalqueries, ',') uniquevisitor = format(uniquevisitor, ',') effectiveflow = format(effectiveflow, ',') def fixvalue2str(value): i = -1 while(True): # fix the value if 0 if value[i] == 0: value[i] = -1 i -= 1 else: break value = [i+1 for i in value] value = str(value).replace(', 0', ', ') # replace 0 to null for painting return value weekvalue = fixvalue2str(weekvalue) return render(request, 'admin.html', context=locals()) def about(request): return render(request, 'about.html') def about_en(request): return render(request, 'about_en.html') def papers(request): return render(request, 'papers.html') def help(request): return render(request, 'help.html') def Score2Hexstr(score, maxsc): thr = maxsc/1.5 l = len(score) ret = ['00']*l for i in range(l): res = int(200*(score[i] - thr)/thr) if res>15: ret[i] = hex(res)[2:] else: break return ret def ChineseRD(request): description = request.GET['description'] RD_mode = request.GET['mode'] if RD_mode=='EC': q = description fromLang = 'en' toLang = 'zh' salt = "35555" sign = appid+q+salt+secretKey sign = md5(sign) url = "http://api.fanyi.baidu.com/api/trans/vip/translate" url = url + '?appid='+appid+'&q='+urllib.parse.quote(q)+'&from='+fromLang+'&to='+toLang+'&salt='+str(salt)+'&sign='+sign response = requests.request("GET", url) description = eval(response.text)['trans_result'][0]['dst'] with torch.no_grad(): def_words = [w for w, p in lac.cut(description)] def_word_idx = [] if len(def_words) > 0: for def_word in def_words: if def_word in word2index: def_word_idx.append(word2index[def_word]) else: for dw in def_word: try: def_word_idx.append(word2index[dw]) except: def_word_idx.append(word2index['']) x_len = len(def_word_idx) if set(def_word_idx)=={word2index['']}: x_len = 1 if x_len==1: if def_word_idx[0]>1: score = ((model.embedding.weight.data).mm((model.embedding.weight.data[def_word_idx[0]]).unsqueeze(1))).squeeze(1) if RD_mode=='CC': score[def_word_idx[0]] = -10. score[np.array(index2synset[def_word_idx[0]])] *= 2 sc, indices = torch.sort(score, descending=True) predicted = indices[:NUM_RESPONSE].detach().cpu().numpy() score = sc[:NUM_RESPONSE].detach().numpy() maxsc = sc[0].detach().item() s2h = Score2Hexstr(score, maxsc) else: predicted= [] ret = {'error': 1} # 字符无法识别 else: defi = '[CLS] ' + description def_word_idx = tokenizer_Ch.encode(defi)[:80] def_word_idx.extend(tokenizer_Ch.encode('[SEP]')) definition_words_t = torch.tensor(np.array(def_word_idx), dtype=torch.int64, device=device) definition_words_t = definition_words_t.unsqueeze(0) # batch_size = 1 score = model('test', x=definition_words_t, w=words_t, ws=wd_sems, wP=wd_POSs, wc=wd_charas, wC=wd_C, msk_s=mask_s, msk_c=mask_c, mode=MODE) sc, indices = torch.sort(score, descending=True) predicted = indices[0, :NUM_RESPONSE].detach().cpu().numpy() score = sc[0, :NUM_RESPONSE].detach().numpy() maxsc = sc[0, 0].detach().item() s2h = Score2Hexstr(score, maxsc) else: predicted= [] ret = {'error': 0} # 输入为空 if len(predicted)>0: res = index2word[predicted] ret = [] cn = -1 if RD_mode=='CC': def_words = set(def_words) for wd in res: cn += 1 if wd not in def_words: try: ret.append(wd_data[wd]) ret[len(ret)-1]['c'] = s2h[cn] except: continue else: for wd in res: cn += 1 try: ret.append(wd_data[wd]) ret[len(ret)-1]['c'] = s2h[cn] except: continue return HttpResponse(json.dumps(ret,ensure_ascii=False),content_type="application/json,charset=utf-8") def getClass2Class(r, score): perCluster = [[],[],[],[],[],[]] for i in range(GET_NUM): perCluster[r[i]].append(score[i]) scorePC = [] for i in range(6): l = len(perCluster[i]) if len(perCluster[i])<5 else 5 scorePC.append(sum(perCluster[i][:l])/l) ind = [indsc[0] for indsc in sorted(enumerate(scorePC), key=lambda x:x[1], reverse=True)] class2class = [0,0,0,0,0,0] for i in range(6): class2class[ind[i]] = i return class2class def ChineseRDCluster(request): description = request.GET['description'] RD_mode = request.GET['mode'] if RD_mode=='EC': q = description fromLang = 'en' toLang = 'zh' salt = "35555" sign = appid+q+salt+secretKey sign = md5(sign) url = "http://api.fanyi.baidu.com/api/trans/vip/translate" url = url + '?appid='+appid+'&q='+urllib.parse.quote(q)+'&from='+fromLang+'&to='+toLang+'&salt='+str(salt)+'&sign='+sign response = requests.request("GET", url) description = eval(response.text)['trans_result'][0]['dst'] with torch.no_grad(): def_words = [w for w, p in lac.cut(description)] def_word_idx = [] if len(def_words) > 0: for def_word in def_words: if def_word in word2index: def_word_idx.append(word2index[def_word]) else: for dw in def_word: try: def_word_idx.append(word2index[dw]) except: def_word_idx.append(word2index['']) x_len = len(def_word_idx) if set(def_word_idx)=={word2index['']}: x_len = 1 if x_len==1: if def_word_idx[0]>1: score = ((model.embedding.weight.data).mm((model.embedding.weight.data[def_word_idx[0]]).unsqueeze(1))).squeeze(1) if RD_mode=='CC': score[def_word_idx[0]] = -10. score[np.array(index2synset[def_word_idx[0]])] *= 2 sc, indices = torch.sort(score, descending=True) predicted = indices[:GET_NUM].detach().cpu().numpy() score = sc[:GET_NUM].detach().numpy() maxsc = sc[0].detach().item() s2h = Score2Hexstr(score, maxsc) r = kmeans.fit_predict(model.embedding.weight.data[predicted[:GET_NUM]].cpu().numpy()) # GET_NUM class2class = getClass2Class(r, score[:GET_NUM]) else: predicted= [] ret = {'error': 1} # 字符无法识别 else: defi = '[CLS] ' + description def_word_idx = tokenizer_Ch.encode(defi)[:80] def_word_idx.extend(tokenizer_Ch.encode('[SEP]')) definition_words_t = torch.tensor(np.array(def_word_idx), dtype=torch.int64, device=device) definition_words_t = definition_words_t.unsqueeze(0) # batch_size = 1 score = model('test', x=definition_words_t, w=words_t, ws=wd_sems, wP=wd_POSs, wc=wd_charas, wC=wd_C, msk_s=mask_s, msk_c=mask_c, mode=MODE) sc, indices = torch.sort(score, descending=True) predicted = indices[0, :GET_NUM].detach().cpu().numpy() score = sc[0, :GET_NUM].detach().numpy() maxsc = sc[0, 0].detach().item() s2h = Score2Hexstr(score, maxsc) r = kmeans.fit_predict(model.embedding.weight.data[predicted[:GET_NUM]].cpu().numpy()) # GET_NUM class2class = getClass2Class(r, score[:GET_NUM]) else: predicted= [] ret = {'error': 0} # 输入为空 if len(predicted)>0: res = index2word[predicted] ret = [] cn = -1 if RD_mode=='CC': def_words = set(def_words) for wd in res: cn += 1 if wd not in def_words: try: ret.append(wd_data[wd]) ret[len(ret)-1]['c'] = s2h[cn] ret[len(ret)-1]['C'] = class2class[int(r[cn])] # 必须转为int,否则其实是int64类型,会报不能json序列化的错误 ret[len(ret)-1]['d'] = wd_defi[wd] ret.sort(key=lambda x: x['C']) except: continue else: for wd in res: cn += 1 try: ret.append(wd_data[wd]) ret[len(ret)-1]['c'] = s2h[cn] ret[len(ret)-1]['C'] = class2class[int(r[cn])] # 必须转为int,否则其实是int64类型,会报不能json序列化的错误 ret[len(ret)-1]['d'] = wd_defi[wd] ret.sort(key=lambda x: x['C']) except: continue return HttpResponse(json.dumps(ret,ensure_ascii=False),content_type="application/json,charset=utf-8") def EnglishRDCluster(request): description = request.GET['description'] RD_mode = request.GET['mode'] if RD_mode=='CE': filter = re.compile(r"[\u4e00-\u9fa5]+") desc = ''.join(filter.findall(description)) def_words = [w for w, p in lac.cut(desc)] q = description fromLang = 'zh' toLang = 'en' salt = "35555" sign = appid+q+salt+secretKey sign = md5(sign) url = "http://api.fanyi.baidu.com/api/trans/vip/translate" url = url + '?appid='+appid+'&q='+urllib.parse.quote(q)+'&from='+fromLang+'&to='+toLang+'&salt='+str(salt)+'&sign='+sign response = requests.request("GET", url) description = eval(response.text)['trans_result'][0]['dst'] with torch.no_grad(): def_words = re.sub('[%s]' % re.escape(string.punctuation), ' ', description) def_words = def_words.lower() def_words = def_words.strip().split() def_word_idx = [] if len(def_words) > 0: for def_word in def_words: if def_word in word2index_en: def_word_idx.append(word2index_en[def_word]) else: def_word_idx.append(word2index_en['']) x_len = len(def_word_idx) if set(def_word_idx)=={word2index_en['']}: x_len = 1 if x_len==1: if def_word_idx[0]>1: score = ((model_en.embedding.weight.data).mm((model_en.embedding.weight.data[def_word_idx[0]]).unsqueeze(1))).squeeze(1) if RD_mode=='EE': score[def_word_idx[0]] = -10. score[np.array(index2synset_en[def_word_idx[0]])] *= 2 sc, indices = torch.sort(score, descending=True) predicted = indices[:GET_NUM].detach().cpu().numpy() score = sc[:GET_NUM].detach().numpy() maxsc = sc[0].detach().item() s2h = Score2Hexstr(score, maxsc) r = kmeans.fit_predict(model.embedding.weight.data[predicted[:GET_NUM]].cpu().numpy()) # GET_NUM class2class = getClass2Class(r, score[:GET_NUM]) else: predicted= [] ret = {'error': 1} # 字符无法识别 else: defi = '[CLS] ' + description def_word_idx = tokenizer_En.encode(defi)[:60] def_word_idx.extend(tokenizer_En.encode('[SEP]')) definition_words_t = torch.tensor(np.array(def_word_idx), dtype=torch.int64, device=device) definition_words_t = definition_words_t.unsqueeze(0) # batch_size = 1 score = model_en('test', x=definition_words_t, w=words_t, ws=wd_sems_, wl=wd_lex, wr=wd_ra, msk_s=mask_s_, msk_l=mask_l, msk_r=mask_r, mode=MODE_en) sc, indices = torch.sort(score, descending=True) predicted = indices[0, :GET_NUM].detach().cpu().numpy() score = sc[0, :GET_NUM].detach().numpy() maxsc = sc[0, 0].detach().item() s2h = Score2Hexstr(score, maxsc) r = kmeans.fit_predict(model.embedding.weight.data[predicted[:GET_NUM]].cpu().numpy()) # GET_NUM class2class = getClass2Class(r, score[:GET_NUM]) else: predicted= [] ret = {'error': 0} # 输入为空 if len(predicted)>0: res = index2word_en[predicted] ret = [] cn = -1 if RD_mode == "EE": def_words = set(def_words) for wd in res: cn += 1 if len(wd)>1 and (wd not in def_words): try: ret.append(wd_data_en[wd]) # wd_data_en[wd] = {'word': word, 'definition':defis, 'POS':['n']}] ret[len(ret)-1]['c'] = s2h[cn] ret[len(ret)-1]['C'] = class2class[int(r[cn])] # 必须转为int,否则其实是int64类型,会报不能json序列化的错误 ret[len(ret)-1]['d'] = wd_defi_en[wd] ret.sort(key=lambda x: x['C']) except: continue else: for wd in res: cn += 1 if len(wd)>1: try: ret.append(wd_data_en[wd]) # wd_data_en[wd] = {'word': word, 'definition':defis, 'POS':['n']}] ret[len(ret)-1]['c'] = s2h[cn] ret[len(ret)-1]['C'] = class2class[int(r[cn])] # 必须转为int,否则其实是int64类型,会报不能json序列化的错误 ret[len(ret)-1]['d'] = wd_defi_en[wd] ret.sort(key=lambda x: x['C']) except: continue return HttpResponse(json.dumps(ret,ensure_ascii=False),content_type="application/json,charset=utf-8") def EnglishRD(request): description = request.GET['description'] RD_mode = request.GET['mode'] if RD_mode=='CE': q = description fromLang = 'zh' toLang = 'en' salt = "35555" sign = appid+q+salt+secretKey sign = md5(sign) url = "http://api.fanyi.baidu.com/api/trans/vip/translate" url = url + '?appid='+appid+'&q='+urllib.parse.quote(q)+'&from='+fromLang+'&to='+toLang+'&salt='+str(salt)+'&sign='+sign response = requests.request("GET", url) description = eval(response.text)['trans_result'][0]['dst'] #print(description) with torch.no_grad(): def_words = re.sub('[%s]' % re.escape(string.punctuation), ' ', description) def_words = def_words.lower() def_words = def_words.strip().split() def_word_idx = [] if len(def_words) > 0: for def_word in def_words: if def_word in word2index_en: def_word_idx.append(word2index_en[def_word]) else: def_word_idx.append(word2index_en['']) x_len = len(def_word_idx) if set(def_word_idx)=={word2index_en['']}: x_len = 1 if x_len==1: if def_word_idx[0]>1: score = ((model_en.embedding.weight.data).mm((model_en.embedding.weight.data[def_word_idx[0]]).unsqueeze(1))).squeeze(1) if RD_mode=='EE': score[def_word_idx[0]] = -10. score[np.array(index2synset_en[def_word_idx[0]])] *= 2 sc, indices = torch.sort(score, descending=True) predicted = indices[:NUM_RESPONSE].detach().cpu().numpy() score = sc[:NUM_RESPONSE].detach().numpy() maxsc = sc[0].detach().item() s2h = Score2Hexstr(score, maxsc) else: predicted= [] ret = {'error': 1} # 字符无法识别 else: defi = '[CLS] ' + description def_word_idx = tokenizer_En.encode(defi)[:60] def_word_idx.extend(tokenizer_En.encode('[SEP]')) definition_words_t = torch.tensor(np.array(def_word_idx), dtype=torch.int64, device=device) definition_words_t = definition_words_t.unsqueeze(0) # batch_size = 1 score = model_en('test', x=definition_words_t, w=words_t, ws=wd_sems_, wl=wd_lex, wr=wd_ra, msk_s=mask_s_, msk_l=mask_l, msk_r=mask_r, mode=MODE_en) sc, indices = torch.sort(score, descending=True) predicted = indices[0, :NUM_RESPONSE].detach().cpu().numpy() score = sc[0, :NUM_RESPONSE].detach().numpy() maxsc = sc[0, 0].detach().item() s2h = Score2Hexstr(score, maxsc) else: predicted= [] ret = {'error': 0} # 输入为空 if len(predicted)>0: res = index2word_en[predicted] ret = [] cn = -1 if RD_mode == "EE": def_words = set(def_words) for wd in res: cn += 1 if len(wd)>1 and (wd not in def_words): try: ret.append(wd_data_en[wd]) # wd_data_en[wd] = {'word': word, 'definition':defis, 'POS':['n']}] ret[len(ret)-1]['c'] = s2h[cn] except: continue else: for wd in res: cn += 1 if len(wd)>1: try: ret.append(wd_data_en[wd]) # wd_data_en[wd] = {'word': word, 'definition':defis, 'POS':['n']}] ret[len(ret)-1]['c'] = s2h[cn] except: continue return HttpResponse(json.dumps(ret,ensure_ascii=False),content_type="application/json,charset=utf-8") def feedback(request): content = request.GET['content'] FBmode = request.GET['mode'] if FBmode=='FBS': f = open('./feedBackLog/'+datetime.now().date().strftime('%Y%m')+'suggestion.log', 'a') f.write(datetime.now().strftime('[%Y%m%d%H%M%S] ')+content+'\n') elif FBmode=='FBW': f = open('./feedBackLog/'+datetime.now().date().strftime('%Y%m')+'wordsDesc.log', 'a') f.write(datetime.now().strftime('[%Y%m%d%H%M%S] ')+content+'\n') f.close() return HttpResponse("") def GetChDefis(request): if(request.method == 'POST'): words = request.POST['w'].split() else: # GET method words = request.GET['w'].split() ret = [] for w in words: ret.append(wd_defi[w]) return HttpResponse(json.dumps(ret,ensure_ascii=False),content_type="application/json,charset=utf-8") def GetEnDefis(request): if(request.method == 'POST'): words = request.POST['w'].split() else: # GET method words = request.GET['w'].split() ret = [] for w in words: ret.append(wd_defi_en[w]) return HttpResponse(json.dumps(ret,ensure_ascii=False),content_type="application/json,charset=utf-8") ================================================ FILE: website_RD/wsgi.py ================================================ """ WSGI config for website_RD project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ """ import os from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website_RD.settings') application = get_wsgi_application()