Skip to content

Commit

Permalink
Merge pull request #26 from w3c/allow-multiple-definitions
Browse files Browse the repository at this point in the history
Allow multiple definitions, i.e., `defined_by` statements
  • Loading branch information
iherman authored Sep 12, 2024
2 parents 38ae1f4 + 54b685d commit ba6dd05
Show file tree
Hide file tree
Showing 53 changed files with 219 additions and 152 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Each block sequence consists of blocks with the following keys:`id`, `property`,
- `label` refers to a short header label to the term. If missing, the capitalized value of `id` is used.
- `comment` refers to a longer description of the term, and can be used for blocks in the `class`, `property` and `individual` top-level blocks. It may include [HTML Flow content elements](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories). The comment will be encapsulated into an HTML `<div>` element and will then be displayed verbatim in the HTML version of the vocabulary, and as a literal of type `rdf:HTML` in the JSON-LD and Turtle versions. Note that the Markdown syntax for simple formatting, like the use of backtick for `<code.../>`, may also be used.
- `type` refers to RDF types. Note that the tool automatically adds types like `rdf:Property`, `rdfs:Class`, etc.; this key is to be used for the vocabulary specific types only.
- `defined_by` should be a URL, referring to the formal definition of the term.
- `defined_by` should be a URL, or a list thereof, referring to the formal definition(s) of the term.
- `see_also` refers to one or more blocks with `label` and `url` keys, providing a human readable title and a URL, respectively, to an external document that can be referred to by the description of the term. (These are translated into an `rdfs:seeAlso` term in the vocabulary.)
- The `status` key refers to a string that can be `stable`, `reserved`, or `deprecated`. The terms are divided, in the HTML output, into these three sections. `stable` is the default.
- The `deprecated` key refers to a boolean, signaling whether term is deprecated or not. Default is `false`. This property is a leftover from earlier version and is overwritten, if applicable, by the value of `status`.
Expand Down
2 changes: 1 addition & 1 deletion dist/lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function finalizeRawEntry(raw) {
domain: toArray(raw.domain),
range: toArray(raw.range),
deprecated: deprecated,
defined_by: (raw.defined_by) ? raw.defined_by : "",
defined_by: toArray(raw.defined_by) ?? [],
status: status,
comment: (raw.comment) ? cleanComment(raw.comment) : "",
see_also: toSeeAlso(raw.see_also),
Expand Down
14 changes: 12 additions & 2 deletions dist/lib/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ exports.toHTML = void 0;
*/
const common_1 = require("./common");
const jsdom_1 = require("jsdom");
// This object is need for a proper formatting of some text
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });
/**
* A thin layer on top of the regular DOM Document. Necessary to "hide" the differences between
* the JSDOM and Deno's DOM WASM implementations; higher layers should not depend on these.
Expand Down Expand Up @@ -168,8 +170,16 @@ function toHTML(vocab, template_text) {
span.className = 'bold';
document.addChild(span, 'em', ` (${item.status})`);
}
if (item.defined_by !== "") {
document.addChild(section, 'p', `See the <a rel="rdfs:isDefinedBy" href="${item.defined_by}">formal definition of the term</a>.`);
switch (item.defined_by.length) {
case 0: break;
case 1: {
document.addChild(section, 'p', `See the <a rel="rdfs:isDefinedBy" href="${item.defined_by}">formal definition of the term</a>.`);
break;
}
default: {
const refs = item.defined_by.map((def) => `<a rel="rdfs:isDefinedBy" href="${def}">here</a>`);
document.addChild(section, 'p', `See the formal definitions ${formatter.format(refs)}.`);
}
}
if (item.comment !== "") {
let description = item.comment;
Expand Down
9 changes: 7 additions & 2 deletions dist/lib/jsonld.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ function toJSONLD(vocab) {
"@type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML"
};
}
if (entry.defined_by !== '') {
target["rdfs:isDefinedBy"] = `${entry.defined_by}`;
if (entry.defined_by.length !== 0) {
if (entry.defined_by.length === 1) {
target["rdfs:isDefinedBy"] = entry.defined_by[0];
}
else {
target["rdfs:isDefinedBy"] = entry.defined_by;
}
}
target["vs:term_status"] = `${entry.status}`;
if (entry.see_also && entry.see_also.length > 0) {
Expand Down
5 changes: 3 additions & 2 deletions dist/lib/turtle.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ function toTurtle(vocab) {
if (entry.comment !== '') {
turtle += ` rdfs:comment """<div>${entry.comment}</div>"""^^rdf:HTML ;\n`;
}
if (entry.defined_by !== '') {
turtle += ` rdfs:isDefinedBy <${entry.defined_by}>, <${common_1.global.vocab_url}> ;\n`;
if (entry.defined_by.length !== 0) {
const defs = entry.defined_by.map((def) => `<${def}>`).join(", ");
turtle += ` rdfs:isDefinedBy ${defs}, <${common_1.global.vocab_url}> ;\n`;
}
else {
turtle += ` rdfs:isDefinedBy <${common_1.global.vocab_url}> ;\n`;
Expand Down
20 changes: 18 additions & 2 deletions dist/lib/vocab.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@
"type": "string"
},
"defined_by": {
"type": "string",
"format": "uri"
"$ref": "#/$defs/URIOrArrayOfURIs"
},
"see_also": {
"$ref": "#/$defs/SeeAlso"
Expand Down Expand Up @@ -190,6 +189,23 @@
]
},

"URIOrArrayOfURIs": {
"description": "Some of the URI values may be arrays or single URIs, hence this utility schema",
"oneOf": [
{
"type": "string",
"format": "uri"
},
{
"type": "array",
"items": {
"type": "string",
"format": "uri"
}
}
]
},

"ExampleElement": {
"title" : "A single example block, with an optional label",
"type": "object",
Expand Down
Loading

0 comments on commit ba6dd05

Please sign in to comment.