|
| 1 | +const util = require('util'); |
| 2 | +const fs = require('fs/promises'); |
| 3 | +const exec = util.promisify(require('child_process').exec); |
| 4 | + |
| 5 | +const $rdf = require('rdflib'); |
| 6 | +const Namespace = $rdf.Namespace; |
| 7 | + |
| 8 | +const DC = Namespace("http://purl.org/dc/elements/1.1/"); |
| 9 | +const OWL = Namespace("http://www.w3.org/2002/07/owl#"); |
| 10 | +const RDF = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#"); |
| 11 | +const VANN = Namespace("http://purl.org/vocab/vann/"); |
| 12 | +const VOAF = Namespace("http://purl.org/vocommons/voaf#"); |
| 13 | + |
| 14 | +const map = [ |
| 15 | + { |
| 16 | + ttlFile: "../fno.ttl", |
| 17 | + outputFolder: "./ontology", |
| 18 | + uri: "https://w3id.org/function/ontology#", |
| 19 | + }, { |
| 20 | + ttlFile: "../fnoi.ttl", |
| 21 | + outputFolder: "./vocabulary/implementation", |
| 22 | + uri: "https://w3id.org/function/vocabulary/implementation#", |
| 23 | + }, { |
| 24 | + ttlFile: "../fnom.ttl", |
| 25 | + outputFolder: "./vocabulary/mapping", |
| 26 | + uri: "https://w3id.org/function/vocabulary/mapping#", |
| 27 | + }, |
| 28 | +] |
| 29 | + |
| 30 | +processMap(map); |
| 31 | + |
| 32 | +async function processMap(map) { |
| 33 | + for (const elem of map) { |
| 34 | + const store = await getStore(elem.ttlFile); |
| 35 | + await runWidoco(elem.ttlFile, elem.outputFolder, store); |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +async function runWidoco(ontFile, outFolder, store) { |
| 40 | + const preStuff = 'java -jar ../widoco-1.4.14-jar-with-dependencies.jar'; |
| 41 | + const postStuff = '-getOntologyMetadata -oops -rewriteAll -htaccess -webVowl -analytics UA-87734787-2 -excludeIntroduction'; |
| 42 | + const voc = store.any(null, RDF('type'), VOAF('Vocabulary')); |
| 43 | + const version = store.any(voc, OWL('versionInfo')).value; |
| 44 | + const uri = store.any(voc, VANN('preferredNamespaceUri')).value; |
| 45 | + const prefix = store.any(voc, VANN('preferredNamespacePrefix')).value; |
| 46 | + const commandVersion = `${preStuff} -ontFile ${ontFile} -outFolder ${outFolder}/${version} ${postStuff}`; |
| 47 | + const {stdout, stderr} = await exec(commandVersion); |
| 48 | + console.log(stdout); |
| 49 | + console.warn(stderr); |
| 50 | + const command = `${preStuff} -ontFile ${ontFile} -outFolder ${outFolder} ${postStuff}`; |
| 51 | + await exec(command); |
| 52 | + const appendData = `<p>The namespace is <b>${uri}</b>, the preferred prefix is <b>${prefix}</b></p>`; |
| 53 | + await fs.appendFile(`${outFolder}/${version}/sections/abstract-en.html`, appendData); |
| 54 | + await fs.appendFile(`${outFolder}/sections/abstract-en.html`, appendData); |
| 55 | + const descriptionPlaceholder = `This is a placeholder text for the description of your ontology. The description should include an explanation and a diagram explaining how the classes are related, examples of usage, etc.`; |
| 56 | + let description = await fs.readFile(`${outFolder}/sections/description-en.html`, 'utf8'); |
| 57 | + description = description.replace(descriptionPlaceholder, "Further description and explanation of these classes and properties are given in the Function Ontology Specification at https://w3id.org/function/spec"); |
| 58 | + await fs.writeFile(`${outFolder}/${version}/sections/description-en.html`, description); |
| 59 | + await fs.writeFile(`${outFolder}/sections/description-en.html`, description); |
| 60 | +} |
| 61 | + |
| 62 | +async function getStore(ontFile) { |
| 63 | + const store = $rdf.graph(); |
| 64 | + const body = await fs.readFile(ontFile, 'utf8'); |
| 65 | + $rdf.parse(body, store, "http://example.com/#", 'text/turtle'); |
| 66 | + return store; |
| 67 | +} |
0 commit comments