Skip to content

Commit

Permalink
Updated distribution and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
iherman committed Feb 13, 2025
1 parent 1650750 commit ad8ffcf
Show file tree
Hide file tree
Showing 44 changed files with 171 additions and 505 deletions.
24 changes: 17 additions & 7 deletions dist/lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function toContext(vocab) {
// to set these in the context as well
if (property.range) {
for (const range of property.range) {
const [range_prefix, range_reference] = range.split(":");
if (range.startsWith("xsd:")) {
output["@type"] = range.replace("xsd:", "http://www.w3.org/2001/XMLSchema#");
break;
Expand All @@ -68,11 +69,17 @@ function toContext(vocab) {
}
else if (property.type.includes("owl:DatatypeProperty")) {
// This is the case when the property refers to an explicitly defined, non-standard datatype
const [range_prefix, range_reference] = range.split(":");
const range_url = prefix_url(range_prefix, vocab);
output["@type"] = range_url + range_reference;
break;
}
else {
// if range is a class, then it is a reference
if (vocab.classes.find(cl => cl.id === range_reference)) {
output["@type"] = "@id";
break;
}
}
}
}
if (property.dataset) {
Expand All @@ -95,21 +102,24 @@ function toContext(vocab) {
// Add the classes; note that this will also cover the mapping of
// all properties whose domain include a top level class
for (const cl of vocab.classes) {
const url = `${common_1.global.vocab_url}${cl.id}`;
const base_url = cl.prefix ? prefix_url(cl.prefix, vocab) : common_1.global.vocab_url;
const url = `${base_url}${cl.id}`;
// Create an embedded context for the class
// starting with the preamble and the final URL for the class
const embedded = {
...preamble
};
// The domain field in the property structure contains
// the prefixed version of the class ID...
const prefixed_id = `${common_1.global.vocab_prefix}:${cl.id}`;
const prefixed_id = `${cl.prefix}:${cl.id}`;
// Get all the properties that have this class in its domain
for (const prop of vocab.properties) {
if (prop.domain && prop.domain.includes(prefixed_id)) {
// bingo, this property can be added here
embedded[prop.id] = propertyContext(prop);
class_properties.add(prop.id);
if (prop.domain) {
if (prop.domain.includes(prefixed_id) || prop.domain.includes(cl.id)) {
// bingo, this property can be added here
embedded[prop.id] = propertyContext(prop);
class_properties.add(prop.id);
}
}
}
// If no properties are added, then the embedded context is unnecessary
Expand Down
33 changes: 16 additions & 17 deletions dist/lib/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@ function toHTML(vocab, template_text) {
}
};
// Factor out all common fields for the terms
// return the value that can be used as the id value of the section in HTML
// return the value that must be used as the id value of the containing section in HTML
const commonFields = (section, item) => {
// by default, the id of the term should be used for the enclosing section
// In the case of external terms, this is not the case...
let output = item.id;
let external_warning_text = "";
// External terms have a different behavior: ranges/domains should be ignored, and no RDFa should be
Expand All @@ -200,29 +201,28 @@ function toHTML(vocab, template_text) {
}
for (const prefix of vocab.prefixes) {
if (prefix.prefix === pr) {
return prefix;
return prefix.url;
}
}
throw new Error(`Unknown prefix for the external term "${id}": "${pr}"`);
})(item.prefix, item.id);
const curie = ns.prefix + ':' + item.id;
const curie = item.prefix + ':' + item.id;
// For external terms, the id of the enclosing section should not be the
// id of the term; it could be misleading. Instead, it is set to the full
// curie
output = computeHash(curie) /* curie */;
output = computeHash(curie);
external_warning_text = `
<b>This term is formally defined in another vocabulary</b>
(as <a href="${ns + item.id}">${curie}</a>), but is frequently used with this vocabulary and has been
included to aid readability of this document.
`;
document.addChild(section, 'h4', `<code>${item.id}</code>`);
const term = document.addChild(section, 'p', `<em>${item.label}</code>`);
if (item.status !== common_1.Status.stable) {
const span = document.addChild(term, 'span');
span.className = 'bold';
document.addChild(span, 'em', ` (${item.status})`);
}
const url = ns.url + item.id;
external_warning_text = `
<b>This term is formally defined in another vocabulary</b>
(as <a href="${url}">${curie}</a>), but is frequently used with this vocabulary and has been
included to aid readability of this document.
`;
if (item.defined_by) {
// By the logic of the program, at this point defined_by is always defined
// but picky compilers, like deno, push me to put this extra condition
Expand Down Expand Up @@ -277,14 +277,15 @@ function toHTML(vocab, template_text) {
div.setAttribute('property', 'rdfs:comment');
div.setAttribute('datatype', 'rdf:HTML');
}
else {
const warning = document.addChild(section, 'p', external_warning_text);
warning.setAttribute('class', 'note');
}
}
else if (item.type.includes("owl:ObjectProperty")) {
document.addChild(section, 'p', "The property's value should be a URL, i.e., not a literal.");
}
// Add the external warning, if applicable
if (item.external) {
const warning = document.addChild(section, 'p', external_warning_text);
warning.setAttribute('class', 'note');
}
if (item.see_also && item.see_also.length > 0) {
const dl = document.addChild(section, 'dl');
dl.className = 'terms';
Expand All @@ -309,17 +310,15 @@ function toHTML(vocab, template_text) {
}
}
if (!item.external) {
// This does not display, it is only here for RDFa's sake!
// These do not display, they are only here for RDFa's sake!
const span = document.addChild(section, 'span');
span.setAttribute('property', 'rdfs:isDefinedBy');
span.setAttribute('resource', `${vocab_prefix}:`);
// This does not display, it is only here for RDFa's sake!
const status_span = document.addChild(section, 'span');
status_span.setAttribute('style', 'display: none');
status_span.setAttribute('property', 'vs:term_status');
document.addText(`${item.status}`, status_span);
if (item.deprecated) {
// This does not display, it is only here for RDFa's sake!
const span = document.addChild(section, 'span');
span.setAttribute('property', 'owl:deprecated');
span.setAttribute('datatype', 'xsd:boolean');
Expand Down
Loading

0 comments on commit ad8ffcf

Please sign in to comment.