Skip to content

Commit cc8001f

Browse files
committed
Add script to make sh:PropertyShape's unique
1 parent 84d29f8 commit cc8001f

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

util.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import path from "path"
2+
import { fileURLToPath } from "url"
3+
import { promises } from "fs"
4+
5+
const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)))
6+
const shaclDirs = [
7+
`${ROOT}/shacl`,
8+
`${ROOT}/shacl/beta`,
9+
`${ROOT}/shacl/bielefeld`
10+
]
11+
let shaclFiles = []
12+
for (let shaclDir of shaclDirs) {
13+
shaclFiles = shaclFiles.concat((await promises.readdir(shaclDir)).map(file => `${shaclDir}/${file}`).filter(file => file.endsWith(".ttl")))
14+
}
15+
16+
for (let file of shaclFiles) {
17+
// let filename = path.basename(file)
18+
let content = await promises.readFile(file, "utf8")
19+
const cls = "sh:PropertyShape"
20+
const regex = new RegExp(`^([^\\s#;]+)\\s+a\\s+${cls}\\b`, "gm")
21+
const matches = [... content.matchAll(regex)].map(m => m[1].trim())
22+
for (let match of matches) {
23+
const hash = Math.random().toString(36).slice(2, 5)
24+
content = content.split(match).join(`${match}_${hash}`)
25+
}
26+
await promises.writeFile(file, content, "utf8")
27+
}

0 commit comments

Comments
 (0)