listAttrAccessor get implemented

master
Malar Kannan 2017-07-20 19:24:14 +05:30
parent 7903855fec
commit 9d39bab8ca
1 changed files with 55 additions and 14 deletions

View File

@ -46,6 +46,39 @@ function simpleAttrAccessor(attrPred: any) {
};
}
function listAttrAccessor(attrPred: any) {
let { attribKey, pred, lens } = attrPred;
// let def = (value: any) => ({ _: value, $: { [attribKey]: attribVal } });
return {
get: (li: any) => {
let def: any = [];
let morphProps = _.get<any>(li, lens, def);
let morphExps = _.filter<any>(morphProps, (m) => {
return pred(m);
});
let mEs = morphExps.map((me) => {
let value = _.get<any>(me, '_', '');
let key = _.get<any>(me, '$.' + attribKey, '');
return { value, key };
});
return mEs;
},
// set: (li: any, value: string) => {
// let lexItem = _.cloneDeep(li);
// let allProps = _.get<any>(lexItem, lens, []);
// if (allProps.length > 0) {
// let prop = _.filter<any>(allProps, (m) => {
// return pred(m);
// });
// _.set(prop, '[0]._', value);
// } else {
// _.set(lexItem, lens, def(value));
// }
// return lexItem;
// }
};
}
// function attribListAccessor(lens: string, attrib: string, pred: any) {
// let def = (value: any) => ({ _: value, $: { form: attrib } });
// return {
@ -90,6 +123,13 @@ const mcParams = attrPredGen(
_.isEqual
);
const meParams = attrPredGen(
'lexprops[0].morphology[0].morph',
'form',
'morphclass',
_.negate(_.isEqual)
);
const frParams = attrPredGen(
'syntacticprops[0].property',
'id',
@ -118,20 +158,21 @@ const fieldMetaMap = {
},
morphexceptions: {
type: 'list',
get: (li: any) => {
let lens = 'lexprops[0].morphology[0].morph';
let def: any = [];
let morphProps = _.get<any>(li, lens, def);
let morphExps = _.filter<any>(morphProps, (m) => {
return _.get<any>(m, '$.form', '') !== 'morphclass';
});
let mEs = morphExps.map((me) => {
let value = _.get<any>(me, '_', '');
let key = _.get<any>(me, '$.form', '');
return { value, key };
});
return mEs;
}
...listAttrAccessor(meParams)
// get: (li: any) => {
// let lens = 'lexprops[0].morphology[0].morph';
// let def: any = [];
// let morphProps = _.get<any>(li, lens, def);
// let morphExps = _.filter<any>(morphProps, (m) => {
// return _.get<any>(m, '$.form', '') !== 'morphclass';
// });
// let mEs = morphExps.map((me) => {
// let value = _.get<any>(me, '_', '');
// let key = _.get<any>(me, '$.form', '');
// return { value, key };
// });
// return mEs;
// }
},
stats: { type: 'text', ...simpleAccessor('stats[0].property[0]._'), },
lang: {