update 对“我”的兼容

This commit is contained in:
PASSER-BY 2021-11-28 22:28:22 +08:00
parent f7ba7d9c77
commit 81770c9720
3 changed files with 9 additions and 8 deletions

File diff suppressed because one or more lines are too long

View File

@ -2229,7 +2229,7 @@
// 中文获取选择器
function getSelectors(str){
str = str.replace(/[二|三|四|五|六|七|八|九|十]{1,2}/g,'x');
var lists = str.replace(/我的?/,'').replace(/家的?/,'的').split('的');
var lists = str.replace(/我的?(.+)/,'$1').replace(/家的?/,'的').split('的');
var result = [''];
var isMatch = true;
var replaceMap = {
@ -2281,12 +2281,12 @@
var res = [];
result.forEach(function(a){
items.forEach(function(b){
res.push(a+','+b);
res.push(a+(b?','+b:''));
});
});
result = res;
}
return isMatch?result:[];
return isMatch?result:[''];
}
// 选择器转ID
@ -2502,7 +2502,7 @@
var from_selector = from_ids.length>1?'['+from_ids.join('|')+']':from_ids[0];
var to_selector = r_ids.length>1?'['+r_ids.join('|')+']':r_ids[0];
return {
'selector':(to?','+to_selector:'')+','+from_selector,
'selector':(to?','+to_selector:'')+(from?','+from_selector:''),
'sex':sex
};
}
@ -2525,7 +2525,7 @@
}
}
var from_selectors = getSelectors(options.text);
var to_selectors = options.target?getSelectors(options.target):[''];
var to_selectors = getSelectors(options.target);
// console.log('[selectors]',from_selectors,to_selectors);
var result = []; //匹配结果
from_selectors.forEach(function(from){

View File

@ -24,6 +24,7 @@ test('relationship.js show to be tested', function (t) {
t.deepEqual(relationship({text:'老公的父母',target:'孩子'}),['爷爷','奶奶']);
t.deepEqual(relationship({text:'爸爸的哥哥的弟弟的儿子'}),['堂哥','堂弟','兄弟','自己']);
t.deepEqual(relationship({text:'外婆',target:'女婿',reverse:true}),['外曾孙女婿','外曾外孙女婿']);
t.deepEqual(relationship({text:'我',target:'爸爸'}),['儿子','女儿']);
t.end();
});