-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a815bb0
commit 281d6ce
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const fs = require("fs"); | ||
const vocabFolder = "./vocabularies/"; | ||
const type = process.argv[2]; | ||
|
||
const namespaces = {}; | ||
const vocabularies = {}; | ||
const output = []; | ||
|
||
function search(node, kind, prefix) { | ||
for (const elem in node) | ||
if (node[elem].$Kind === kind) { | ||
if (node[elem].$Type === type) | ||
output.push(prefix + elem); | ||
else if (node[elem].$Type) { | ||
const i = node[elem].$Type.lastIndexOf("."); | ||
const voc = vocabularies[node[elem].$Type.substring(0, i)]; | ||
if (voc) | ||
search(voc[node[elem].$Type.substring(i + 1)], undefined, prefix + elem + "/"); | ||
} | ||
} | ||
} | ||
|
||
fs.readdirSync(vocabFolder) | ||
.filter((fn) => fn.endsWith(".json")) | ||
.forEach(function(fn) { | ||
const voc = JSON.parse(fs.readFileSync(vocabFolder + fn)) | ||
for (const ns in voc) if (ns[0] !== "$") { | ||
namespaces[voc[ns].$Alias] = ns; | ||
vocabularies[voc[ns].$Alias] = voc[ns]; | ||
} | ||
}); | ||
for (const ns in vocabularies) | ||
search(vocabularies[ns], "Term", namespaces[ns] + "."); | ||
process.stdout.write(JSON.stringify(output)); |