updated js优化
This commit is contained in:
parent
5de00bca62
commit
a706d387cc
4
dist/lang/relationship.zh-HK.min.js
vendored
4
dist/lang/relationship.zh-HK.min.js
vendored
File diff suppressed because one or more lines are too long
4
dist/lang/relationship.zh-HK.min.mjs
vendored
4
dist/lang/relationship.zh-HK.min.mjs
vendored
File diff suppressed because one or more lines are too long
4
dist/relationship.min.js
vendored
4
dist/relationship.min.js
vendored
File diff suppressed because one or more lines are too long
4
dist/relationship.min.mjs
vendored
4
dist/relationship.min.mjs
vendored
File diff suppressed because one or more lines are too long
@ -5,22 +5,23 @@ import _input from './data/input.js';
|
|||||||
import _sort from './data/sort.js';
|
import _sort from './data/sort.js';
|
||||||
import {modeData} from './mode.js';
|
import {modeData} from './mode.js';
|
||||||
|
|
||||||
let _hash = Object.assign({},modeData);
|
function mergeValues(target, source) {
|
||||||
for(let key in _input){
|
Object.entries(source).forEach(([key, value]) => {
|
||||||
_hash[key] = (_hash[key]||[]).concat(_input[key]);
|
target[key] = (target[key] || []).concat(value);
|
||||||
}
|
});
|
||||||
for(let key in _sort){
|
return target;
|
||||||
_hash[key] = (_hash[key]||[]).concat(_sort[key]);
|
|
||||||
}
|
}
|
||||||
|
let _hash = mergeValues({...modeData }, _input);
|
||||||
|
_hash = mergeValues(_hash, _sort);
|
||||||
|
|
||||||
let cacheData = {};
|
let cacheData = {};
|
||||||
for(let key in _hash){
|
Object.entries(_hash).forEach(([key, names]) => {
|
||||||
_hash[key].forEach(function(name){
|
names.forEach((name) => {
|
||||||
if(typeof cacheData[name]=='undefined'){
|
if (!cacheData[name]) {
|
||||||
cacheData[name] = [];
|
cacheData[name] = [];
|
||||||
}
|
}
|
||||||
cacheData[name].push(key);
|
cacheData[name].push(key);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
export {cacheData};
|
export {cacheData};
|
@ -44,12 +44,11 @@ export function reverseId(id,sex){
|
|||||||
sex = 0;
|
sex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let doing = function(sex){
|
const doing = function(sex){
|
||||||
let sid = (','+sex+','+id).replace(/,[fhs]|,[olx]b/g,',1').replace(/,[mwd]|,[olx]s/g,',0');
|
const sid = (','+sex+','+id).replace(/,[fhs]|,[olx]b/g,',1').replace(/,[mwd]|,[olx]s/g,',0');
|
||||||
sid = sid.substring(0,sid.length-2);
|
const sid_arr = sid.substring(0,sid.length-2).split(',').reverse();
|
||||||
let sid_arr = sid.split(',').reverse();
|
const r_id = id.split(',').reverse().map((id,i)=>hash[id][sid_arr[i]]).join(',');
|
||||||
let r_id = id.split(',').reverse().map((id,i)=>hash[id][sid_arr[i]]).join(',');
|
const gen = getGenById(r_id);
|
||||||
let gen = getGenById(r_id);
|
|
||||||
return r_id + (gen?'':age);
|
return r_id + (gen?'':age);
|
||||||
};
|
};
|
||||||
if(sex<0){
|
if(sex<0){
|
||||||
@ -61,19 +60,19 @@ export function reverseId(id,sex){
|
|||||||
|
|
||||||
// ID列表去重
|
// ID列表去重
|
||||||
export function filterId(arr){
|
export function filterId(arr){
|
||||||
let sameList = arr.filter(item=>item==item.replace(/[ol](?=[s|b])/g,'x').replace(/&[ol]/,''));
|
const sameList = arr.filter(item => item === item.replace(/[ol](?=[s|b])/g,'x').replace(/&[ol]/,''));
|
||||||
return arr.filter(item => {
|
return arr.filter(item => {
|
||||||
let temp = item.replace(/[ol](?=[s|b])/g,'x').replace(/&[ol]/,'');
|
const temp = item.replace(/[ol](?=[s|b])/g,'x').replace(/&[ol]/,'');
|
||||||
return sameList.includes(item)||item!=temp&&!sameList.includes(temp);
|
return sameList.includes(item)||item!=temp&&!sameList.includes(temp);
|
||||||
}).filter((item,idx,arr) => arr.indexOf(item) === idx);
|
}).filter((item,idx,arr) => arr.indexOf(item) === idx);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 通过ID获取世代数
|
// 通过ID获取世代数
|
||||||
export function getGenById(id){
|
export function getGenById(id){
|
||||||
let gMap = {'f':1,'m':1,'s':-1,'d':-1};
|
const gMap = {'f':1,'m':1,'s':-1,'d':-1};
|
||||||
let gen = 0;
|
let gen = 0;
|
||||||
id.split(',').forEach(function(sub){
|
id.split(',').forEach(sub => {
|
||||||
let s = sub.replace(/&[ol\d]+/,'');
|
const s = sub.replace(/&[ol\d]+/,'');
|
||||||
gen += gMap[s]||0;
|
gen += gMap[s]||0;
|
||||||
});
|
});
|
||||||
return gen;
|
return gen;
|
||||||
@ -82,29 +81,26 @@ export function getGenById(id){
|
|||||||
// 通过ID获取关系称呼
|
// 通过ID获取关系称呼
|
||||||
export function getItemsById(id){
|
export function getItemsById(id){
|
||||||
let items = [];
|
let items = [];
|
||||||
let getData = function(key){
|
const getData = function(key){
|
||||||
let ids = [];
|
let ids = [];
|
||||||
let k1 = key.replace(/(,[sd])(,[wh])?$/,'$1&o$2');
|
const k1 = key.replace(/(,[sd])(,[wh])?$/,'$1&o$2');
|
||||||
let k2 = key.replace(/(,[sd])(,[wh])?$/,'$1&l$2');
|
const k2 = key.replace(/(,[sd])(,[wh])?$/,'$1&l$2');
|
||||||
if(modeData[k1]&&modeData[k2]){
|
if(modeData[k1]&&modeData[k2]){
|
||||||
ids = [k1,k2];
|
ids = [k1,k2];
|
||||||
}else if(modeData[key]){
|
}else if(modeData[key]){
|
||||||
ids = [key];
|
ids = [key];
|
||||||
}
|
}
|
||||||
return filterId(ids).map(function(id){
|
return filterId(ids).map(id => modeData[id][0]);
|
||||||
return modeData[id][0];
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
// 对排序进行处理
|
// 对排序进行处理
|
||||||
if(id.match(/&([\d]+)(,[hw])?$/)){
|
if(id.match(/&([\d]+)(,[hw])?$/)){
|
||||||
let num = id.match(/&([\d]+)(,[hw])?$/)[1];
|
const num = id.match(/&([\d]+)(,[hw])?$/)[1];
|
||||||
let zh = number2zh(num);
|
const zh = number2zh(num);
|
||||||
id = id.replace(/&\d+/g,'');
|
id = id.replace(/&\d+/g,'');
|
||||||
if(_sort[id]){
|
if(_sort[id]){
|
||||||
let item = _sort[id][0].replace('几',zh);
|
items.push(_sort[id][0].replace('几',zh));
|
||||||
items.push(item);
|
|
||||||
}else if(modeData[id]){
|
}else if(modeData[id]){
|
||||||
let gen = getGenById(id);
|
const gen = getGenById(id);
|
||||||
let item = '';
|
let item = '';
|
||||||
if(gen<3&&!id.match(/[hw],/)){
|
if(gen<3&&!id.match(/[hw],/)){
|
||||||
modeData[id].forEach(function(name){
|
modeData[id].forEach(function(name){
|
||||||
@ -145,13 +141,14 @@ export function getItemsById(id){
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 通过ID获取关系链
|
// 通过ID获取关系链
|
||||||
let data = Object.assign({},modeData,{
|
let data = {
|
||||||
|
...modeData,
|
||||||
'xb': ['兄弟'],
|
'xb': ['兄弟'],
|
||||||
'xs': ['姐妹']
|
'xs': ['姐妹']
|
||||||
});
|
};
|
||||||
export function getChainById(id,sex=-1){
|
export function getChainById(id,sex=-1){
|
||||||
let item = id.split(',').map(function(sign){
|
let item = id.split(',').map(sign => {
|
||||||
let key = sign.replace(/&[ol\d]+/,'');
|
const key = sign.replace(/&[ol\d]+/,'');
|
||||||
return data[key][0];
|
return data[key][0];
|
||||||
}).join('的');
|
}).join('的');
|
||||||
if(sex>-1&&data[sex+','+id]){
|
if(sex>-1&&data[sex+','+id]){
|
||||||
@ -166,26 +163,23 @@ export function getChainById(id,sex=-1){
|
|||||||
|
|
||||||
// 通过ID获取关系合称
|
// 通过ID获取关系合称
|
||||||
export function getPairsById(id1,id2){
|
export function getPairsById(id1,id2){
|
||||||
|
id1 = id1.replace(/&\d+/g,'');
|
||||||
|
id2 = id2.replace(/&\d+/g,'');
|
||||||
|
const id1_x = id1.replace(/([ol])([bs])/g,'x$2');
|
||||||
|
const id2_x = id2.replace(/([ol])([bs])/g,'x$2');
|
||||||
|
const id1_r = id1.replace(/&[ol]/g,'');
|
||||||
|
const id2_r = id2.replace(/&[ol]/g,'');
|
||||||
|
|
||||||
let result = [];
|
let result = [];
|
||||||
let result_x = [];
|
let result_x = [];
|
||||||
let result_r = [];
|
let result_r = [];
|
||||||
id1 = id1.replace(/&\d+/g,'');
|
for(const key in _pair){
|
||||||
id2 = id2.replace(/&\d+/g,'');
|
const selectors = key.split('#');
|
||||||
let id1_x = id1.replace(/([ol])([bs])/g,'x$2');
|
|
||||||
let id2_x = id2.replace(/([ol])([bs])/g,'x$2');
|
|
||||||
let id1_r = id1.replace(/&[ol]/g,'');
|
|
||||||
let id2_r = id2.replace(/&[ol]/g,'');
|
|
||||||
for(let key in _pair){
|
|
||||||
let selectors = key.split('#');
|
|
||||||
if(selectors.length>1){
|
if(selectors.length>1){
|
||||||
let list1 = selector2id(selectors[0]);
|
const list1 = selector2id(selectors[0]);
|
||||||
let list2 = selector2id(selectors[1]);
|
const list2 = selector2id(selectors[1]);
|
||||||
let list1_r = list1.map(function(selector){
|
const list1_r = list1.map(selector => selector.replace(/&[ol\d]+/,'').replace(/([ol])([bs])/,'x$2'));
|
||||||
return selector.replace(/&[ol\d]+/,'').replace(/([ol])([bs])/,'x$2');
|
const list2_r = list2.map(selector => selector.replace(/&[ol\d]+/,'').replace(/([ol])([bs])/,'x$2'));
|
||||||
});
|
|
||||||
let list2_r = list2.map(function(selector){
|
|
||||||
return selector.replace(/&[ol\d]+/,'').replace(/([ol])([bs])/,'x$2');
|
|
||||||
});
|
|
||||||
if(list1.includes(id1)&&list2.includes(id2)||list1.includes(id2)&&list2.includes(id1)){
|
if(list1.includes(id1)&&list2.includes(id2)||list1.includes(id2)&&list2.includes(id1)){
|
||||||
result.push(_pair[key][0]);
|
result.push(_pair[key][0]);
|
||||||
}
|
}
|
||||||
|
@ -8,46 +8,39 @@ import _multipie from './data/multiple.js';
|
|||||||
|
|
||||||
import {expandSelector} from './selector.js';
|
import {expandSelector} from './selector.js';
|
||||||
|
|
||||||
let _map = Object.assign({},_multipie);
|
let _map = { ..._multipie };
|
||||||
|
|
||||||
// 分支 - 前缀处理
|
// 分支 - 前缀处理
|
||||||
let prefixMap = {};
|
const prefixMap = {};
|
||||||
for(let key in _prefix){
|
for(const key in _prefix){
|
||||||
prefixMap[key] = {};
|
prefixMap[key] = {};
|
||||||
for(let selector in _prefix[key]){
|
for(const selector in _prefix[key]){
|
||||||
expandSelector(selector).forEach(function(s){
|
expandSelector(selector).forEach(function(s){
|
||||||
prefixMap[key][s] = _prefix[key][selector];
|
prefixMap[key][s] = _prefix[key][selector];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 分支 - 节点处理
|
// 分支 - 节点处理
|
||||||
let branchMap = {};
|
const branchMap = {};
|
||||||
for(let selector in _branch){
|
for(const selector in _branch){
|
||||||
expandSelector(selector).forEach(function(s){
|
expandSelector(selector).forEach(function(s){
|
||||||
branchMap[s] = _branch[selector];
|
branchMap[s] = _branch[selector];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// 分支 - 合并
|
// 分支 - 合并
|
||||||
let getMap = function(prefixMap,branchMap){
|
const getMap = function(prefixMap,branchMap){
|
||||||
let map = {};
|
const map = {};
|
||||||
for(let key in branchMap){
|
for(const key in branchMap){
|
||||||
let tag = key.match(/\{.+?\}/)[0];
|
const tag = key.match(/\{.+?\}/)[0];
|
||||||
let nameList = branchMap[key];
|
const nameList = branchMap[key];
|
||||||
for(let k in prefixMap[tag]){
|
for(const k in prefixMap[tag]){
|
||||||
let prefixList = prefixMap[tag][k];
|
const prefixList = prefixMap[tag][k];
|
||||||
let newKey = key.replace(tag,k);
|
const newKey = key.replace(tag,k);
|
||||||
let isFilter = ['h,h','w,w','w,h','h,w'].some(pair=>(newKey.includes(pair)));
|
const isFilter = ['h,h','w,w','w,h','h,w'].some(pair=>(newKey.includes(pair)));
|
||||||
if(!isFilter){
|
if(!isFilter){
|
||||||
let newList = [];
|
const newList = prefixList.flatMap((prefix) =>
|
||||||
prefixList.forEach(function(prefix){
|
nameList.map((name) => (name.includes('?') ? name.replace('?', prefix) : prefix + name))
|
||||||
nameList.forEach(function(name){
|
);
|
||||||
if(name.includes('?')){
|
|
||||||
newList.push(name.replace('?',prefix));
|
|
||||||
}else{
|
|
||||||
newList.push(prefix+name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
if(!map[newKey]){
|
if(!map[newKey]){
|
||||||
map[newKey] = _map[newKey]||[];
|
map[newKey] = _map[newKey]||[];
|
||||||
}
|
}
|
||||||
@ -57,11 +50,11 @@ let getMap = function(prefixMap,branchMap){
|
|||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
};
|
};
|
||||||
_map = Object.assign({},_map,getMap(prefixMap,branchMap));
|
_map = {..._map,...getMap(prefixMap,branchMap)};
|
||||||
|
|
||||||
// 主要关系
|
// 主要关系
|
||||||
for(let key in _main){
|
for(let key in _main){
|
||||||
_map[key] = [].concat(_main[key],_map[key]||[]);
|
_map[key] = [..._main[key], ...(_map[key] || [])];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 版权彩蛋
|
// 版权彩蛋
|
||||||
@ -72,10 +65,10 @@ const mateMap = {
|
|||||||
'w':['妻','内','岳','岳家','丈人'],
|
'w':['妻','内','岳','岳家','丈人'],
|
||||||
'h':['夫','外','公','婆家','婆婆'],
|
'h':['夫','外','公','婆家','婆婆'],
|
||||||
};
|
};
|
||||||
let nameSet = new Set(Object.values(_map).flat());
|
const nameSet = new Set(Object.values(_map).flat());
|
||||||
for(let key in _map){
|
for(const key in _map){
|
||||||
if(key.match(/^[fm]/)||key.match(/^[olx][bs]$|^[olx][bs],[^mf]/)){ // 只对长辈或者兄弟辈匹配
|
if(key.match(/^[fm]/)||key.match(/^[olx][bs]$|^[olx][bs],[^mf]/)){ // 只对长辈或者兄弟辈匹配
|
||||||
for(let k in mateMap){
|
for(const k in mateMap){
|
||||||
let newKey = k+','+key;
|
let newKey = k+','+key;
|
||||||
if(key.match(/[fm]/)){
|
if(key.match(/[fm]/)){
|
||||||
let newKey_x = newKey.replace(/,[ol]([sb])(,[wh])?$/,',x$1$2').replace(/(,[sd])&[ol](,[wh])?$/,'$1$2');
|
let newKey_x = newKey.replace(/,[ol]([sb])(,[wh])?$/,',x$1$2').replace(/(,[sd])&[ol](,[wh])?$/,'$1$2');
|
||||||
@ -86,11 +79,11 @@ for(let key in _map){
|
|||||||
if(!_map[newKey]){
|
if(!_map[newKey]){
|
||||||
_map[newKey] = [];
|
_map[newKey] = [];
|
||||||
}
|
}
|
||||||
let prefixList = mateMap[k];
|
const prefixList = mateMap[k];
|
||||||
let nameList = _map[key];
|
const nameList = _map[key];
|
||||||
prefixList.forEach(function(prefix){
|
prefixList.forEach(function(prefix){
|
||||||
nameList.forEach(function(name){
|
nameList.forEach(function(name){
|
||||||
let newName = prefix+name;
|
const newName = prefix+name;
|
||||||
if(!nameSet.has(newName)){ // 配偶组合的称呼不得与原有称呼冲突(如:妻舅!=妻子的舅舅;外舅公!=老公的舅公)
|
if(!nameSet.has(newName)){ // 配偶组合的称呼不得与原有称呼冲突(如:妻舅!=妻子的舅舅;外舅公!=老公的舅公)
|
||||||
_map[newKey].push(newName);
|
_map[newKey].push(newName);
|
||||||
}
|
}
|
||||||
|
@ -4,18 +4,18 @@
|
|||||||
import _map from './map.js';
|
import _map from './map.js';
|
||||||
|
|
||||||
let _mode = {}; // 模式缓存
|
let _mode = {}; // 模式缓存
|
||||||
let modeData = Object.assign({},_map); // 最终数据
|
let modeData = { ..._map }; // 最终数据
|
||||||
|
|
||||||
// 设置模式数据
|
// 设置模式数据
|
||||||
export function setModeData(sign,data){
|
export function setModeData(sign,data){
|
||||||
_mode[sign] = Object.assign(_mode[sign]||{},data);
|
_mode[sign] = { ...(_mode[sign] || {}), ...data };
|
||||||
};
|
};
|
||||||
|
|
||||||
// 获取模式数据
|
// 获取模式数据
|
||||||
export function getModeData(sign){
|
export function getModeData(sign){
|
||||||
modeData = Object.assign({},_map);
|
modeData = { ..._map };
|
||||||
if(sign&&_mode[sign]){
|
if(sign&&_mode[sign]){
|
||||||
for(let key in _mode[sign]){
|
for(const key in _mode[sign]){
|
||||||
modeData[key] = [].concat(_mode[sign][key],_map[key]||[]);
|
modeData[key] = [].concat(_mode[sign][key],_map[key]||[]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
import _expression from './rule/expression.js';
|
import _expression from './rule/expression.js';
|
||||||
|
|
||||||
export function getOptions(text){
|
export function getOptions(text){
|
||||||
for(let item of _expression){
|
for(const item of _expression){
|
||||||
let match = text.match(item['exp']);
|
const match = text.match(item['exp']);
|
||||||
if(match){
|
if(match){
|
||||||
return item['opt'](match);
|
return item['opt'](match);
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import {reverseId,filterId,getGenById} from './id.js';
|
|||||||
import {cacheData} from './cache.js';
|
import {cacheData} from './cache.js';
|
||||||
|
|
||||||
// 获得最简
|
// 获得最简
|
||||||
let getOptimal = function(options){
|
const getOptimal = function(options){
|
||||||
let {
|
let {
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
@ -81,18 +81,18 @@ export function getSelectors(str){
|
|||||||
str = str.replace(/(伯|叔)+(父|母)?家的?(哥|姐|弟|妹)+/,'堂$3').replace(/(伯|叔)+(父|母)?家的?/,'堂');
|
str = str.replace(/(伯|叔)+(父|母)?家的?(哥|姐|弟|妹)+/,'堂$3').replace(/(伯|叔)+(父|母)?家的?/,'堂');
|
||||||
str = str.replace(/姨+(爸|父|丈|妈|母)?家的?(哥|姐|弟|妹)+/,'姨$2').replace(/姨+(爸|父|丈|妈|母)?家的?/,'姨');
|
str = str.replace(/姨+(爸|父|丈|妈|母)?家的?(哥|姐|弟|妹)+/,'姨$2').replace(/姨+(爸|父|丈|妈|母)?家的?/,'姨');
|
||||||
|
|
||||||
let lists = str.split('的');
|
const lists = str.split('的');
|
||||||
let result = [];
|
let result = [];
|
||||||
let isMatch = true;
|
let isMatch = true;
|
||||||
while(lists.length){
|
while(lists.length){
|
||||||
let name = lists.shift(); //当前匹配词
|
const name = lists.shift(); //当前匹配词
|
||||||
let items = []; //当前匹配词可能性
|
let items = []; //当前匹配词可能性
|
||||||
let keywords = [name];
|
const keywords = [name];
|
||||||
let getList = function(name){
|
let getList = function(name){
|
||||||
// 词义扩展
|
// 词义扩展
|
||||||
_replace.forEach(item => {
|
_replace.forEach(item => {
|
||||||
item['arr'].forEach(word =>{
|
item['arr'].forEach(word =>{
|
||||||
let name1 = name.replace(item['exp'],word);
|
const name1 = name.replace(item['exp'],word);
|
||||||
if(name1!=name){
|
if(name1!=name){
|
||||||
keywords.push(name1);
|
keywords.push(name1);
|
||||||
getList(name1);
|
getList(name1);
|
||||||
@ -100,9 +100,9 @@ export function getSelectors(str){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
// 同义词替换
|
// 同义词替换
|
||||||
for(let word in _similar){
|
for(const word in _similar){
|
||||||
let name1 = name.replace(word,_similar[word]);
|
const name1 = name.replace(word,_similar[word]);
|
||||||
let name2 = name.replace(_similar[word],word);
|
const name2 = name.replace(_similar[word],word);
|
||||||
if(name1!=name){
|
if(name1!=name){
|
||||||
keywords.push(name1);
|
keywords.push(name1);
|
||||||
}
|
}
|
||||||
@ -113,19 +113,19 @@ export function getSelectors(str){
|
|||||||
};
|
};
|
||||||
getList(name);
|
getList(name);
|
||||||
// 通过关键词找关系
|
// 通过关键词找关系
|
||||||
let items_map = [[],[],[]];
|
const items_map = [[],[],[]];
|
||||||
keywords.forEach(function(name){
|
keywords.forEach(function(name){
|
||||||
name = name.replace(/^[尕幺细满碎晚末尾幼]/,'小');
|
name = name.replace(/^[尕幺细满碎晚末尾幼]/,'小');
|
||||||
let match = name.match(/^[大|小]|^[一|二|三|四|五|六|七|八|九|十]+/);
|
const match = name.match(/^[大|小]|^[一|二|三|四|五|六|七|八|九|十]+/);
|
||||||
if(match){ // 匹配排序
|
if(match){ // 匹配排序
|
||||||
let x_name = name.replace(match[0],'几');
|
const x_name = name.replace(match[0],'几');
|
||||||
let r_name = name.replace(match[0],'');
|
const r_name = name.replace(match[0],'');
|
||||||
let num = zh2number(match[0]);
|
const num = zh2number(match[0]);
|
||||||
[x_name,r_name,name].forEach(function(name,index){
|
[x_name,r_name,name].forEach((name, index) => {
|
||||||
let ids = cacheData[name];
|
const ids = cacheData[name];
|
||||||
if(ids&&ids.length){
|
if(ids&&ids.length){
|
||||||
ids.forEach(function(i){
|
ids.forEach(i => {
|
||||||
let id = i.replace(/(,[hw])$/,'&'+num+'$1').replace(/([^hw]+)$/,'$1&'+num);
|
const id = i.replace(/(,[hw])$/,'&'+num+'$1').replace(/([^hw]+)$/,'$1&'+num);
|
||||||
if(!i.match(/^[mf,]+$/)&&!name.match(/^[从世]/)){ // 直系祖辈不参与排序
|
if(!i.match(/^[mf,]+$/)&&!name.match(/^[从世]/)){ // 直系祖辈不参与排序
|
||||||
items_map[index].push(id);
|
items_map[index].push(id);
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ export function getSelectors(str){
|
|||||||
if(!items.length){
|
if(!items.length){
|
||||||
isMatch = false;
|
isMatch = false;
|
||||||
}
|
}
|
||||||
let res = [];
|
const res = [];
|
||||||
if(!result.length){
|
if(!result.length){
|
||||||
result = [''];
|
result = [''];
|
||||||
}
|
}
|
||||||
@ -168,24 +168,14 @@ export function mergeSelector(param){
|
|||||||
sex:my_sex
|
sex:my_sex
|
||||||
} = param;
|
} = param;
|
||||||
if(my_sex<0){
|
if(my_sex<0){
|
||||||
let to_sex = -1;
|
const fromSex = from_selector.match(/^,[w1]/) ? 1 : from_selector.match(/^,[h0]/) ? 0 : -1;
|
||||||
let from_sex = -1;
|
const toSex = to_selector.match(/^,[w1]/) ? 1 : to_selector.match(/^,[h0]/) ? 0 : -1;
|
||||||
if(from_selector.match(/^,[w1]/)){
|
if (fromSex === -1 && toSex > -1) {
|
||||||
from_sex = 1;
|
my_sex = toSex;
|
||||||
}else if(from_selector.match(/^,[h0]/)){
|
} else if (fromSex > -1 && toSex === -1) {
|
||||||
from_sex = 0;
|
my_sex = fromSex;
|
||||||
}
|
} else if (fromSex === toSex) {
|
||||||
if(to_selector.match(/^,[w1]/)){
|
my_sex = fromSex;
|
||||||
to_sex = 1;
|
|
||||||
}else if(to_selector.match(/^,[h0]/)){
|
|
||||||
to_sex = 0;
|
|
||||||
}
|
|
||||||
if(from_sex==-1&&to_sex>-1){
|
|
||||||
my_sex = to_sex;
|
|
||||||
}else if(from_sex>-1&&to_sex==-1){
|
|
||||||
my_sex = from_sex;
|
|
||||||
}else if(from_sex==to_sex){
|
|
||||||
my_sex = from_sex;
|
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -195,9 +185,9 @@ export function mergeSelector(param){
|
|||||||
if(!from_ids.length||!to_ids.length){
|
if(!from_ids.length||!to_ids.length){
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
let result = [];
|
const result = [];
|
||||||
from_ids.forEach(function(from){
|
from_ids.forEach(from => {
|
||||||
to_ids.forEach(function(to){
|
to_ids.forEach(to => {
|
||||||
let sex = my_sex;
|
let sex = my_sex;
|
||||||
let selector = ','+to;
|
let selector = ','+to;
|
||||||
if(selector.match(/,([fhs1](&[ol\d]+)?|[olx]b)(&[ol\d]+)?$/)){
|
if(selector.match(/,([fhs1](&[ol\d]+)?|[olx]b)(&[ol\d]+)?$/)){
|
||||||
@ -239,15 +229,15 @@ export function mergeSelector(param){
|
|||||||
|
|
||||||
// 扩展选择器
|
// 扩展选择器
|
||||||
export function expandSelector(selector){
|
export function expandSelector(selector){
|
||||||
let result = [];
|
const result = [];
|
||||||
let hash = {};
|
const hash = {};
|
||||||
let getSelector = function(selector){
|
const getSelector = function(selector){
|
||||||
let s='';
|
|
||||||
if(!hash[selector]){
|
if(!hash[selector]){
|
||||||
hash[selector] = true;
|
hash[selector] = true;
|
||||||
|
let s='';
|
||||||
do{
|
do{
|
||||||
s = selector;
|
s = selector;
|
||||||
for(let item of _filter){
|
for(const item of _filter){
|
||||||
// console.log('[filter]',item['exp'],selector);
|
// console.log('[filter]',item['exp'],selector);
|
||||||
selector = selector.replace(item['exp'],item['str']);
|
selector = selector.replace(item['exp'],item['str']);
|
||||||
if(selector.includes('#')){
|
if(selector.includes('#')){
|
||||||
@ -289,8 +279,6 @@ export function selector2id(selector,sex){
|
|||||||
if(selector.match(/,[mwd0](&[ol\d]+)?,w|,[hfs1](&[ol\d]+)?,h/)){ //同志关系去除
|
if(selector.match(/,[mwd0](&[ol\d]+)?,w|,[hfs1](&[ol\d]+)?,h/)){ //同志关系去除
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
let result = expandSelector(selector).map(function(selector){
|
const result = expandSelector(selector).map(selector => selector.replace(/,[01]/, '').substr(1)); //去前面逗号和性别信息
|
||||||
return selector.replace(/,[01]/,'').substr(1); //去前面逗号和性别信息
|
|
||||||
});
|
|
||||||
return filterId(result);
|
return filterId(result);
|
||||||
};
|
};
|
@ -19,26 +19,21 @@ let relationship = function (parameter){
|
|||||||
}, parameter);
|
}, parameter);
|
||||||
// 切换模式
|
// 切换模式
|
||||||
getModeData(options.mode);
|
getModeData(options.mode);
|
||||||
|
let fromSelectors = getSelectors(options.text);
|
||||||
let from_selectors = getSelectors(options.text);
|
let toSelectors = getSelectors(options.target);
|
||||||
let to_selectors = getSelectors(options.target);
|
if (!toSelectors.length) {
|
||||||
if(!to_selectors.length){
|
toSelectors = [''];
|
||||||
to_selectors = [''];
|
|
||||||
}
|
}
|
||||||
let result = []; //匹配结果
|
const result = fromSelectors.flatMap(fromSelector => {
|
||||||
// console.log('[selectors]',from_selectors,to_selectors);
|
return toSelectors.flatMap(toSelector => {
|
||||||
from_selectors.forEach(function(from_selector){
|
return mergeSelector({
|
||||||
to_selectors.forEach(function(to_selector){
|
from: fromSelector,
|
||||||
mergeSelector({
|
to: toSelector,
|
||||||
from:from_selector,
|
|
||||||
to:to_selector,
|
|
||||||
sex: options.sex,
|
sex: options.sex,
|
||||||
optimal: options.optimal
|
optimal: options.optimal
|
||||||
}).forEach(function(data){
|
}).flatMap(data => {
|
||||||
// console.log('[data]',from_selector,to_selector,options.optimal,data);
|
const ids = data ? selector2id(data['selector'], data['sex']) : [];
|
||||||
let ids = data?selector2id(data['selector'],data['sex']):[];
|
return ids.flatMap(id => {
|
||||||
// console.log('[ids]',data['selector'],data['sex'],ids);
|
|
||||||
ids.forEach(function(id){
|
|
||||||
let temps = [id];
|
let temps = [id];
|
||||||
let sex = data['sex'];
|
let sex = data['sex'];
|
||||||
if (options.reverse) {
|
if (options.reverse) {
|
||||||
@ -49,33 +44,25 @@ let relationship = function (parameter){
|
|||||||
sex = 0;
|
sex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(options.type=='chain'){
|
if (options.type === 'chain') {
|
||||||
temps.forEach(function(id){
|
return temps.map(id => getChainById(id, sex)).filter(item => item);
|
||||||
let item = getChainById(id,data['sex']);
|
} else if (options.type === 'pair') {
|
||||||
if(item){
|
const reversedTemps = reverseId(id, data['sex']);
|
||||||
result.push(item);
|
return reversedTemps.flatMap(rId => getPairsById(id, rId));
|
||||||
}
|
|
||||||
});
|
|
||||||
}else if(options.type=='pair'){
|
|
||||||
temps = reverseId(id,data['sex']);
|
|
||||||
temps.forEach(function(r_id){
|
|
||||||
let pairs = getPairsById(id,r_id);
|
|
||||||
result = result.concat(pairs);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
temps.forEach(function(id){
|
return temps.flatMap(id => {
|
||||||
let items = getItemsById(id);
|
let items = getItemsById(id);
|
||||||
if (!items.length) {
|
if (!items.length) {
|
||||||
items = getItemsById(sex + ',' + id);
|
items = getItemsById(sex + ',' + id);
|
||||||
}
|
}
|
||||||
result = result.concat(items);
|
return items;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// console.log('[result]',result);
|
|
||||||
return [...new Set(result)];
|
return [...new Set(result)];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user