Skip to content

Commit

Permalink
Add script to convert CRM class hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtich committed Oct 28, 2024
1 parent d725e58 commit b0d3ecc
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions crmpg2rdf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fs from "fs"
import { pgformat, ParsingError } from "pgraphs"

const graph = pgformat.pg.parse(fs.readFileSync(`voc/crm-all-classes.pg`).toString())

console.log(
`@prefix crm: <http://www.cidoc-crm.org/cidoc-crm/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
`)

const classes = []

function emitClass(id) {
if (id in classes) return
console.log(`crm:${id} a owl:Class .`)
classes[id] = true
}

for (let { from, to, labels } of graph.edges) {
emitClass(from)
if (labels[0] === "replacedBy") {
console.log(`crm:${from} owl:deprecated true .`)
}
if (labels[0] == "superClass" || labels[0] == "replacedBy") {
console.log(`crm:${from} rdfs:subClassOf crm:${to} .`)
}
}

for (let { to } of graph.edges) { emitClass(to) }
for (let { id } of graph.nodes) { emitClass(id) }

0 comments on commit b0d3ecc

Please sign in to comment.