updated 添加表达式语法特性
This commit is contained in:
72
src/module/expression.js
Normal file
72
src/module/expression.js
Normal 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'
|
||||
})
|
||||
},
|
||||
];
|
||||
@@ -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 {};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user