updated 序数分析优化

This commit is contained in:
PASSER-BY
2023-01-30 23:29:12 +08:00
parent 99ca69948b
commit 24c2601633
3 changed files with 19 additions and 35 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+12 -28
View File
@@ -93,9 +93,6 @@ export function getSelectors(str){
while(lists.length){ while(lists.length){
let name = lists.shift(); //当前匹配词 let name = lists.shift(); //当前匹配词
let items = []; //当前匹配词可能性 let items = []; //当前匹配词可能性
let x_items = [];
let r_items = [];
let i_items = [];
let keywords = [name]; let keywords = [name];
let getList = function(name){ let getList = function(name){
// 词义扩展 // 词义扩展
@@ -122,47 +119,34 @@ export function getSelectors(str){
}; };
getList(name); getList(name);
// 通过关键词找关系 // 通过关键词找关系
let items_map = [[],[],[]];
keywords.forEach(function(name){ keywords.forEach(function(name){
let match = name.replace(/^[尕幺细满碎晚末尾幼]/,'小').match(/^[大|小]|^[一|二|三|四|五|六|七|八|九|十]+/); let match = name.replace(/^[尕幺细满碎晚末尾幼]/,'小').match(/^[大|小]|^[一|二|三|四|五|六|七|八|九|十]+/);
if(match){ // 匹配排序 if(match){ // 匹配排序
let x_name = name.replace(match[0],'几'); let x_name = name.replace(match[0],'几');
let r_name = name.replace(match[0],''); let r_name = name.replace(match[0],'');
let num = zh2number(match[0]); let num = zh2number(match[0]);
let x_ids = _cache[x_name]||[]; [x_name,r_name,name].forEach(function(name,index){
let r_ids = _cache[r_name]||[]; let ids = _cache[name];
let i_ids = _cache[name]||[]; if(ids&&ids.length){
if(x_ids.length){ ids.forEach(function(i){
x_ids.forEach(function(i){ let id = i.replace(/(,[hw])$/,'&'+num+'$1').replace(/([^hw]+)$/,'$1&'+num);
let r_i = i.replace(/(,[hw])$/,'&'+num+'$1').replace(/([^hw]+)$/,'$1&'+num); if(!i.match(/^[mf,]+$/)&&!name.match(/^[从世]/)){ // 直系祖辈不参与排序
x_items.push(r_i); items_map[index].push(id);
});
}else if(r_ids.length){
r_ids.forEach(function(i){
let r_i = i.replace(/(,[hw])$/,'&'+num+'$1').replace(/([^hw]+)$/,'$1&'+num);
if(!i.match(/^[mf,]+$/)&&!r_name.match(/^[从世]/)){ // 直系祖辈不参与排序
r_items.push(r_i);
} }
}); });
}else{
i_ids.forEach(function(i){
let r_i = i.replace(/(,[hw])$/,'&'+num+'$1').replace(/([^hw]+)$/,'$1&'+num);
i_items.push(r_i);
});
} }
});
} }
items = items.concat(_cache[name]||[]); items = items.concat(_cache[name]||[]);
}); });
// console.log('[keywords]',keywords); // console.log('[keywords]',keywords);
// 如找不到结果,再是否存在称呼的排行问题(不直接判断,因存在"大舅""三从父兄""三世祖"这样特俗含义的情况) // 如找不到结果,再是否存在称呼的排行问题(不直接判断,因存在"大舅""三从父兄""三世祖"这样特俗含义的情况)
items_map.forEach(function(items_x){
if(!items.length){ if(!items.length){
items = x_items; items = items_x;
}
if(!items.length){
items = r_items;
}
if(!items.length){
items = i_items;
} }
});
// 完全匹配不到结果 // 完全匹配不到结果
if(!items.length){ if(!items.length){
isMatch = false; isMatch = false;