updated 修复最优解问题
This commit is contained in:
parent
e5f0f47afc
commit
89dca5084c
2
dist/relationship.min.js
vendored
2
dist/relationship.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/relationship.zh-HK.min.js
vendored
2
dist/relationship.zh-HK.min.js
vendored
File diff suppressed because one or more lines are too long
@ -104,6 +104,17 @@ var getOptimal = function(options){
|
|||||||
from = from_chain.slice(i).join(',');
|
from = from_chain.slice(i).join(',');
|
||||||
to = to_chain.slice(i+1).join(',');
|
to = to_chain.slice(i+1).join(',');
|
||||||
sex = to_chain[i].match(/^([fhs1](&[ol\d]+)?|[olx]b)(&[ol\d]+)?/)?1:0;
|
sex = to_chain[i].match(/^([fhs1](&[ol\d]+)?|[olx]b)(&[ol\d]+)?/)?1:0;
|
||||||
|
}else if(options['optimal']){
|
||||||
|
from_match = from_chain[i].match(/([xol])[bs]/);
|
||||||
|
to_match = to_chain[i].match(/([xol])[bs]/);
|
||||||
|
from_attr = from_match?from_match[1]:'';
|
||||||
|
to_attr = to_match?to_match[1]:'';
|
||||||
|
if(from_attr=='x'||to_attr=='x'){
|
||||||
|
from = from_chain.slice(i+1).join(',');
|
||||||
|
to = to_chain.slice(i+1).join(',');
|
||||||
|
sex = from_chain[i].match(/^([fhs1](&[ol\d]+)?|[olx]b)(&[ol\d]+)?/)?1:0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -310,7 +321,8 @@ export function mergeSelector(param){
|
|||||||
var ops = getOptimal({
|
var ops = getOptimal({
|
||||||
'from':from,
|
'from':from,
|
||||||
'to':to,
|
'to':to,
|
||||||
'sex':my_sex
|
'sex':my_sex,
|
||||||
|
'optimal':param.optimal
|
||||||
});
|
});
|
||||||
from = ops['from'];
|
from = ops['from'];
|
||||||
to = ops['to'];
|
to = ops['to'];
|
||||||
|
@ -4,6 +4,7 @@ var relationship = require('..');
|
|||||||
|
|
||||||
test('relationship.js show to be tested', function (t) {
|
test('relationship.js show to be tested', function (t) {
|
||||||
// console.log('[test]',relationship({text:'堂哥',target:'叔叔',type:'pair',optimal:true}));
|
// console.log('[test]',relationship({text:'堂哥',target:'叔叔',type:'pair',optimal:true}));
|
||||||
|
|
||||||
t.deepEqual(relationship({text:'儿子的爸爸的妈妈',sex:1}),['妈妈']);
|
t.deepEqual(relationship({text:'儿子的爸爸的妈妈',sex:1}),['妈妈']);
|
||||||
t.deepEqual(relationship({text:'爱人',sex:1}),['老婆']);
|
t.deepEqual(relationship({text:'爱人',sex:1}),['老婆']);
|
||||||
t.deepEqual(relationship({text:'爱人的爱人',sex:1}),['自己']);
|
t.deepEqual(relationship({text:'爱人的爱人',sex:1}),['自己']);
|
||||||
@ -37,5 +38,6 @@ test('relationship.js show to be tested', function (t) {
|
|||||||
t.deepEqual(relationship({text:'爸爸的二爸'}),['二爷爷']);
|
t.deepEqual(relationship({text:'爸爸的二爸'}),['二爷爷']);
|
||||||
t.deepEqual(relationship({text:'大舅',target:'二舅的儿子'}),['大伯']);
|
t.deepEqual(relationship({text:'大舅',target:'二舅的儿子'}),['大伯']);
|
||||||
t.deepEqual(relationship({text:'堂哥',target:'叔叔',type:'pair'}),['叔侄','父子']);
|
t.deepEqual(relationship({text:'堂哥',target:'叔叔',type:'pair'}),['叔侄','父子']);
|
||||||
|
t.deepEqual(relationship({text:'堂哥',target:'叔叔',type:'pair',optimal:true}),['父子']);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user