-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathxml2nt.js
56 lines (49 loc) · 1.88 KB
/
xml2nt.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
var xpath = require('xpath')
var dom = require('xmldom').DOMParser
var fs = require('fs')
var xml = fs.readFileSync('fachgebiete.xml', 'utf8')
var doc = new dom().parseFromString(xml)
var nodes = xpath.select('/valuespaces/valuespace[@property="ccm:taxonid"]/key', doc)
var topConcepts = []
var childConcepts = []
ID_PREFIX = 'n'
nodes.forEach(node => {
const id = `${ID_PREFIX}${node.textContent}`
const notation = node.textContent
const label = node.getAttribute('cap')
const parent = `${ID_PREFIX}${node.getAttribute('parent')}`
parent !== ID_PREFIX
? childConcepts.push({id, parent, label, notation })
: topConcepts.push({id, label, notation})
})
console.log(`
@base <http://w3id.org/class/hochschulfaechersystematik/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix dct: <http://purl.org/dc/terms/> .
<scheme> a skos:ConceptScheme ;
dct:title "Destatis-Systematik der Fächergruppen, Studienbereiche und Studienfächer"@de ;
skos:hasTopConcept ${topConcepts.map(concept => '<' + concept.id + '>').join(', ')} .
`)
topConcepts.forEach(concept => console.log(`
<${concept.id}> a skos:Concept ;
skos:prefLabel "${concept.label}"@de ;
${
childConcepts.some(child => child.parent === concept.id) &&
'skos:narrower ' + childConcepts.filter(child => child.parent === concept.id).map(child => '<' + child.id + '>').join(', ') + ';'
|| ''
}
skos:notation "${concept.notation}" ;
skos:topConceptOf <scheme> .
`))
childConcepts.forEach(concept => console.log(`
<${concept.id}> a skos:Concept ;
skos:prefLabel "${concept.label}"@de ;
${
childConcepts.some(child => child.parent === concept.id) &&
'skos:narrower ' + childConcepts.filter(child => child.parent === concept.id).map(child => '<' + child.id + '>').join(', ') + ';'
|| ''
}
skos:broader <${concept.parent}> ;
skos:notation "${concept.notation}" ;
skos:inScheme <scheme> .
`))