Skip to content

Code to make RDF ontology from CSS properties JSON #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tools/css-json-to-ttl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

// Convert JSON on CVSS to Turtle for Css property namespace
const cssData = require( '../ed/css/CSS.json')

// console.log(JSON.stringify(cssData).slice(0,100))

function camelCasify (str) {
var result = str[0]
for (let i=1; i < str.length; i++) {
result += str[i-1] === '-' ? str[i].toUpperCase() : str[i]
}
return result.replace('-','')
}

console.log(`@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix css: <http://www.w3.org/ns/css#> .

<> rdfs:comment """This ontology allows CSS properties to be expressed in RDF.
The same camelcase convention is usede as is used by the subproperties of the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The same camelcase convention is usede as is used by the subproperties of the
The same camelcase convention is used as is used by the subproperties of the

style property in browser JS implementations.

""" .
`)
for (const prop in cssData.properties) {
const camel = camelCasify(prop)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I note that the JSON file exposes the camelcase name in the styleDeclaration property (last item in that array), so the camelCase function could be dropped and this line replaced by something like:

Suggested change
const camel = camelCasify(prop)
const camel = cssData.properties[prop].styleDeclaration.pop()

// console.log(` Property ${prop} - ${camel}`)
console.log(`css:${camel} a rdf:Property; rdfs:label "${prop}"; spec:values`)
}