|
|
|
@ -65,22 +65,29 @@ const predicateIriByProp = new WeakMap<dom.PropertyDeclaration, string>(); |
|
|
|
|
function resolveCollisions(props: dom.PropertyDeclaration[]): void { |
|
|
|
|
const groups = new Map<string, dom.PropertyDeclaration[]>(); |
|
|
|
|
props.forEach((p) => { |
|
|
|
|
const base = p.name.replace(/\d+$/, ""); |
|
|
|
|
if (!groups.has(base)) groups.set(base, []); |
|
|
|
|
groups.get(base)!.push(p); |
|
|
|
|
const name = p.name; |
|
|
|
|
if (!groups.has(name)) groups.set(name, []); |
|
|
|
|
groups.get(name)!.push(p); |
|
|
|
|
}); |
|
|
|
|
groups.forEach((list) => { |
|
|
|
|
if (list.length < 2) return; |
|
|
|
|
|
|
|
|
|
const predicateIris = new Set( |
|
|
|
|
list.map((p) => predicateIriByProp.get(p)).filter(Boolean) |
|
|
|
|
); |
|
|
|
|
if (predicateIris.size < 2) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// First pass rename using second last segment
|
|
|
|
|
list.forEach((prop) => { |
|
|
|
|
const iri = predicateIriByProp.get(prop) || prop.name; |
|
|
|
|
const iri = predicateIriByProp.get(prop); |
|
|
|
|
if (!iri) return; |
|
|
|
|
const segs = iri.split(/[#:\/]/).filter(Boolean); |
|
|
|
|
if (!segs.length) return; |
|
|
|
|
if (segs.length < 2) return; |
|
|
|
|
const local = segs.at(-1)!; |
|
|
|
|
const secondLast = segs.length > 1 ? segs.at(-2)! : undefined; |
|
|
|
|
if (secondLast) { |
|
|
|
|
prop.name = `${secondLast}_${local}`; |
|
|
|
|
} |
|
|
|
|
const secondLast = segs.at(-2)!; |
|
|
|
|
prop.name = `${secondLast}_${local}`; |
|
|
|
|
}); |
|
|
|
|
// Detect any remaining duplicates after first pass
|
|
|
|
|
const nameCounts = new Map<string, number>(); |
|
|
|
@ -89,7 +96,8 @@ function resolveCollisions(props: dom.PropertyDeclaration[]): void { |
|
|
|
|
); |
|
|
|
|
list.forEach((p) => { |
|
|
|
|
if (nameCounts.get(p.name)! > 1) { |
|
|
|
|
p.name = predicateIriByProp.get(p) || p.name; |
|
|
|
|
const iri = predicateIriByProp.get(p); |
|
|
|
|
if (iri) p.name = iri; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|