-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze_mappings.js
79 lines (64 loc) · 1.77 KB
/
analyze_mappings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const tags = require('./specs/new/prop_mappings')
const mappings = require('./specs/new/prop_summary')
function add (d, a, b, c) {
if (!(a in d)) { d[a] = {} }
if (!(b in d[a])) { d[a][b] = [] }
d[a][b].push(c)
}
function pad (object) {
return Math.max(...Object
.keys(object)
.map(prop => prop.toString().length))
}
function log (duplicates) {
const pad1 = pad(duplicates)
const pad2 = pad(Object.assign({}, ...Object.values(duplicates)))
for (let prop1 of Object.keys(duplicates).sort()) {
const object1 = duplicates[prop1]
let i = 0
for (let prop2 in object1) {
const object2 = object1[prop2]
console.log([
(i++ ? '' : prop1).padEnd(pad1, ' '),
prop2.padEnd(pad2, ' '),
object2.sort().join(', ')
].join(' '))
}
console.log()
}
}
const risDuplicates = {}
const cslDuplicates = {}
for (let tag in tags) {
const props = tags[tag]
for (let prop in props) {
const mapping = props[prop]
add(risDuplicates, prop, mapping, tag)
mappings[tag][prop].forEach(type => add(cslDuplicates, mapping, type.split(' ').pop(), tag))
}
}
console.log(`
RIS DUPLICATES
==============`)
for (let prop in risDuplicates) {
if (Object.keys(risDuplicates[prop]).length === 1) {
delete risDuplicates[prop]
}
}
log(risDuplicates)
console.log(`
CSL DUPLICATES
==============`)
for (let mapping in cslDuplicates) {
for (let type in cslDuplicates[mapping]) {
cslDuplicates[mapping][type] = cslDuplicates[mapping][type].filter((v, i, a) => a.indexOf(v) === i)
if (cslDuplicates[mapping][type].length === 1) {
delete cslDuplicates[mapping][type]
}
}
if (Object.keys(cslDuplicates[mapping]).length === 0) {
delete cslDuplicates[mapping]
}
}
delete cslDuplicates.false
log(cslDuplicates)