Skip to content
Snippets Groups Projects
Commit 96144fb1 authored by Sebastian Bittrich's avatar Sebastian Bittrich
Browse files

drops json filter definition in favor of text

parent 3afe21a4
No related branches found
No related tags found
No related merge requests found
......@@ -78,38 +78,22 @@ const filter_aware_encoder1 = CifWriter.createEncoder({
binary: true,
binaryAutoClassifyEncoding: true
});
filter_aware_encoder1.setFilter(C.Category.filterOf([
{ // allow only category atom_site
categoryName: 'atom_site',
behavior: 'whitelist'
}, { // for atom_site: allow only Cartn_x and Cartn_y
categoryName: 'atom_site',
columnName: 'Cartn_x',
behavior: 'whitelist'
}, {
categoryName: 'atom_site',
columnName: 'Cartn_y',
behavior: 'whitelist'
}
]));
filter_aware_encoder1.setFilter(C.Category.filterOf('atom_site\n' +
'\n' +
'atom_site.Cartn_x\n' +
'atom_site.Cartn_y\n'));
const filter_aware_encoder2 = CifWriter.createEncoder({
binary: true
});
filter_aware_encoder2.setFilter(C.Category.filterOf([
{ // ignore atom_site category
categoryName: 'atom_site',
behavior: 'blacklist'
}, { // exclude field2
categoryName: 'other_fields',
columnName: 'field2',
behavior: 'blacklist'
}
]));
filter_aware_encoder2.setFilter(C.Category.filterOf('!atom_site\n' +
'\n' +
'!other_fields.field2\n'));
describe('filtering-config', () => {
const decoded1 = process(filter_aware_encoder1);
console.log(decoded1.blocks[0]);
const atom_site1 = decoded1.blocks[0].categories['atom_site'];
const cartn_x1 = atom_site1.getField('Cartn_x');
const cartn_y1 = atom_site1.getField('Cartn_y');
......
......@@ -140,22 +140,27 @@ export namespace Category {
export type FilteringBehavior = 'whitelist' | 'blacklist';
export function filterOf(directives: FilteringDirective[]): Filter {
export function filterOf(directives: string): Filter {
const cat_whitelist: string[] = [];
const cat_blacklist: string[] = [];
const field_whitelist: string[] = [];
const field_blacklist: string[] = [];
for (const d of directives) {
const field = d.columnName;
const name = field ? d.categoryName + '.' + d.columnName : d.categoryName;
const list = d.behavior === 'whitelist' ? (field ? field_whitelist : cat_whitelist) : (field ? field_blacklist : cat_blacklist);
for (let d of directives.split(/[\r\n]+/)) {
// allow for empty lines in config
if (d.length === 0) continue;
// let ! denote blacklisted entries
const blacklist = /^!/.test(d);
if (blacklist) d = d.substr(1);
const split = d.split(/\./);
const field = split[1];
const list = blacklist ? (field ? field_blacklist : cat_blacklist) : (field ? field_whitelist : cat_whitelist);
list[list.length] = name;
list[list.length] = d;
// ensure categories are aware about whitelisted columns
if (field && !cat_whitelist.includes(d.categoryName)) {
cat_whitelist[cat_whitelist.length] = d.categoryName;
if (field && !cat_whitelist.includes(split[0])) {
cat_whitelist[cat_whitelist.length] = split[0];
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment