update 对“我”的兼容
This commit is contained in:
parent
f7ba7d9c77
commit
81770c9720
6
dist/relationship.min.js
vendored
6
dist/relationship.min.js
vendored
File diff suppressed because one or more lines are too long
@ -2229,7 +2229,7 @@
|
|||||||
// 中文获取选择器
|
// 中文获取选择器
|
||||||
function getSelectors(str){
|
function getSelectors(str){
|
||||||
str = str.replace(/[二|三|四|五|六|七|八|九|十]{1,2}/g,'x');
|
str = str.replace(/[二|三|四|五|六|七|八|九|十]{1,2}/g,'x');
|
||||||
var lists = str.replace(/我的?/,'').replace(/家的?/,'的').split('的');
|
var lists = str.replace(/我的?(.+)/,'$1').replace(/家的?/,'的').split('的');
|
||||||
var result = [''];
|
var result = [''];
|
||||||
var isMatch = true;
|
var isMatch = true;
|
||||||
var replaceMap = {
|
var replaceMap = {
|
||||||
@ -2281,12 +2281,12 @@
|
|||||||
var res = [];
|
var res = [];
|
||||||
result.forEach(function(a){
|
result.forEach(function(a){
|
||||||
items.forEach(function(b){
|
items.forEach(function(b){
|
||||||
res.push(a+','+b);
|
res.push(a+(b?','+b:''));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
result = res;
|
result = res;
|
||||||
}
|
}
|
||||||
return isMatch?result:[];
|
return isMatch?result:[''];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 选择器转ID
|
// 选择器转ID
|
||||||
@ -2502,7 +2502,7 @@
|
|||||||
var from_selector = from_ids.length>1?'['+from_ids.join('|')+']':from_ids[0];
|
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];
|
var to_selector = r_ids.length>1?'['+r_ids.join('|')+']':r_ids[0];
|
||||||
return {
|
return {
|
||||||
'selector':(to?','+to_selector:'')+','+from_selector,
|
'selector':(to?','+to_selector:'')+(from?','+from_selector:''),
|
||||||
'sex':sex
|
'sex':sex
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -2525,7 +2525,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var from_selectors = getSelectors(options.text);
|
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);
|
// console.log('[selectors]',from_selectors,to_selectors);
|
||||||
var result = []; //匹配结果
|
var result = []; //匹配结果
|
||||||
from_selectors.forEach(function(from){
|
from_selectors.forEach(function(from){
|
||||||
|
@ -24,6 +24,7 @@ test('relationship.js show to be tested', function (t) {
|
|||||||
t.deepEqual(relationship({text:'老公的父母',target:'孩子'}),['爷爷','奶奶']);
|
t.deepEqual(relationship({text:'老公的父母',target:'孩子'}),['爷爷','奶奶']);
|
||||||
t.deepEqual(relationship({text:'爸爸的哥哥的弟弟的儿子'}),['堂哥','堂弟','兄弟','自己']);
|
t.deepEqual(relationship({text:'爸爸的哥哥的弟弟的儿子'}),['堂哥','堂弟','兄弟','自己']);
|
||||||
t.deepEqual(relationship({text:'外婆',target:'女婿',reverse:true}),['外曾孙女婿','外曾外孙女婿']);
|
t.deepEqual(relationship({text:'外婆',target:'女婿',reverse:true}),['外曾孙女婿','外曾外孙女婿']);
|
||||||
|
t.deepEqual(relationship({text:'我',target:'爸爸'}),['儿子','女儿']);
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user