updated 添加表达式语法特性

This commit is contained in:
PASSER-BY
2022-11-11 00:53:09 +08:00
parent 6c1e03ff66
commit 7c4ada9667
12 changed files with 124 additions and 21 deletions

View File

@@ -1,14 +1,14 @@
export default {
'name':'广东',
'data':{
'f':['阿爸'],
'f':['老窦'],
'f,f':['阿爷'],
'f,f,f':['太公'],
'f,f,m':['太婆'],
'f,m':['阿嫲'],
'f,m,f':['太外公'],
'f,m,m':['太外婆'],
'f,ob':['伯'],
'f,ob':['伯'],
'f,ob,w':['伯娘'],
'f,lb':['阿叔'],
'f,lb,w':['阿婶'],
@@ -23,7 +23,7 @@ export default {
'1,f,xs,d,s':['姑表外甥'],
'0,f,xs,d,d':['姑表姨甥女'],
'1,f,xs,d,d':['姑表外甥女'],
'm':['阿妈','老母'],
'm':['老母'],
'm,f':['阿公'],
'm,f,f':['外太公'],
'm,f,m':['外太婆'],
@@ -44,13 +44,13 @@ export default {
'1,m,xb,d,s':['姨外甥'],
'0,m,xb,d,d':['姨姨甥女'],
'1,m,xb,d,d':['姨外甥女'],
'ob':['阿哥'],
'ob':['大佬'],
'ob,w':['阿嫂'],
'lb':['阿弟','细佬'],
'lb':['细佬'],
'lb,w':['弟妇'],
'xb,s':['侄'],
'xb,d':['侄女'],
'os':['姐'],
'os':['姐'],
'os,h':['姐夫'],
'ls':['阿妹'],
'ls,h':['妹夫'],

72
src/module/expression.js Normal file
View File

@@ -0,0 +1,72 @@
// 自然语言表达
export default [
{
exp:/^(\S+?)(应该|得)?(称呼|叫|喊)(什么|啥)?$/,
opt:match=>({
text:match[1]
})
},
{
exp:/^(\S+?)(应该|得)?(如何|怎么)(称呼|叫|喊)?$/,
opt:match=>({
text:match[1]
})
},
{
exp:/^(\S+?)是(谁|什么亲戚|啥亲戚)?$/,
opt:match=>({
text:match[1]
})
},
{
exp:/^(\S+?)(应该|得)?(称呼|叫|喊)(\S+?)(什么|啥)?$/,
opt:match=>({
text:match[4],
target:match[1]
})
},
{
exp:/^(\S+?)(应该|得)?(如何|怎么)(称呼|叫|喊)(\S+?)?$/,
opt:match=>({
text:match[5],
target:match[1]
})
},
{
exp:/^(\S+?)是(\S+?)的(谁|什么|什么亲戚|啥亲戚|什么人)?$/,
opt:match=>({
text:match[1],
target:match[2]
})
},
{
exp:/^(\S+?)(应该|得)?管(\S+?)叫(什么|啥)?$/,
opt:match=>({
text:match[2],
target:match[1]
})
},
{
exp:/^(\S+?)(和|与)(\S+?)(之间)?是(什么|啥)关系??$/,
opt:match=>({
text:match[1],
target:match[3],
type:'pair'
})
},
{
exp:/^(\S+?)是(什么|啥)(关系|人)?$/,
opt:match=>({
text:match[1],
type:'chain'
})
},
{
exp:/^(\S+?)对于(\S+?)是(什么|啥)关系??$/,
opt:match=>({
text:match[1],
target:match[2],
type:'chain'
})
},
];

View File

@@ -2,6 +2,7 @@
import _filter from './filter';
import _map from './map';
import _pair from './pair';
import _expression from './expression';
var _mode = {}; // 模式数据
var _data = Object.assign({},_map); // 最终数据
@@ -379,8 +380,7 @@ export function selector2id(selector,sex){
hash[selector] = true;
do{
s = selector;
for(var i in _filter){
var item = _filter[i];
for(var item of _filter){
// console.log('[filter]',item['exp'],selector);
selector = selector.replace(item['exp'],item['str']);
if(selector.includes('#')){
@@ -597,3 +597,14 @@ export function getDataByMode(sign){
}
return _data;
};
// 获取配置
export function getOptions(text){
for(var item of _expression){
var match = text.match(item['exp']);
if(match){
return item['opt'](match);
}
}
return {};
};

View File

@@ -1,5 +1,6 @@
import {
unique,
getOptions,
getSelectors,
mergeSelector,
selector2id,
@@ -14,6 +15,9 @@ var _data = getDataByMode(); // 最终数据
// 对外方法
var relationship = function (parameter){
if(typeof parameter =='string'){
parameter = getOptions(parameter);
}
var options = Object.assign({
text:'', // 目标对象:目标对象的称谓汉字表达,称谓间用‘的’字分隔
target:'', // 相对对象:相对对象的称谓汉字表达,称谓间用‘的’字分隔,空表示自己