Skip to content

Commit

Permalink
Make W3C script use the W3C API as source
Browse files Browse the repository at this point in the history
This is a complete re-write of the W3C update script to switch from the
still-maintained-but-deprecated `tr.rdf` file to the more complete and current
W3C API instead.

What changes? Essentially nothing substantial in terms of data, but:
- When an entry is updated, the `source` property will target the API endpoint
from which the data was pulled, such as:
`https://api.w3.org/specifications/_shortname_`
- The W3C API has a few additional statuses that were not reported in `tr.rdf`
such as `DNOTE`, `FPWD`, `LCWD`, and the registry statuses.
- The script fills out properties more systematically for versions
- The order of the properties for each entry is not always exactly the same as
the order generated by the previous script.

The first time the script runs, it will:
- Fix a few entries of very old specs in Specref, for which the title is not
the title of the actual spec.
- Add entries for the draft registries published by a couple of groups.
- Complete a few entries with additional versions that did not exist in
`tr.rdf` for some reason.
- Create consistent `obsoletes` properties, as Specref contains a few
`obsoletes` properties that don't have a matching `obsoletedBy` property.

The script only updates recently published entries by default. That is, it does
not attempt to refresh the whole list. That's needed because the W3C API
follows the HAL convention:
https://en.wikipedia.org/wiki/Hypertext_Application_Language

One consequence is that each API request returns only a minimal amount of
information, and re-generating the entire `w3c.json` file requires sending
~30000 requests, which would be at best impractical to do on an hourly basis,
all the more so because the W3C API server has some rate limits rules in place
(6000 requests every 10 minutes). More importantly, that would be a waste of
resources as data essentially never changes once published.

Thus the script takes an incremental approach instead and only refreshes:
1. Specifications recently published... where recently published means
specifications published since the newest publication date known to Specref
minus 2 weeks by default. The "minus 2 weeks" is meant to catch data fixes that
are sometimes made shortly after publication.
2. Specifications for which the base info (title, URL) is not aligned with the
W3C API. That's meant to fix the data in Specref during the transition, and to
catch further updates that could be made to the W3C API once in a while.

All in all, a typical update should send ~500 requests to the W3C API. The
code throttles requests to 1 every 100ms. Running the script should take ~1-2
minutes.

A more thorough refresh may be forced by calling the script with a date as
parameter (format YYYY-MM-DD, with month and day optional). The date gets
interpreted as the synchronization point. For example, to refresh all specs
published since 2023, run:

```
node scripts/w3c.js 2023
```

To force a "full" refresh (any year prior to 1995 would work):

```
node scripts/w3c.js 1995
```

A full refresh sends ~30k requests to the W3C API and may take >2h. I suggest
to run a full refresh manually once, shortly after this script starts being
used, and then to run it again every few months to capture potential fixes that
might have been made to the data in the meantime.

Running that full refresh will also be useful to fix the few `obsoletedBy`
properties that are not fully correct, and to move a few `hasErrata` links
to the right spec version, as some entries have these links at the root level
of the entry in Specref, whereas the latest version is no longer the REC that
linked to the errata.

I worked with @deniak to fix and complete the data in the W3C API where Specref
had more correct info. I also updated entries that contained incorrect info in
Specref.

The script contains a number of comments to explain the different cases that
need to be handled to be able to fully map the data in the W3C API with the
data in Specref. There will remain a few entries where the mapping is somewhat
imperfect, notably when the shortname of a spec evolved from a level-less
shortname to shortname with level, and sometimes back to a level-less
shortname (examples include `user-timing`, `performance-timeline`). There are
also a few entries for old specs that are flagged as retired in Specref
(`isRetired: true`) but not in the W3C API. Mismatches are reported to the
console as warnings. These should be addressed over time. The script preserves
the information in Specref in any case.

The script also preserves the information in Specref in case of transient
network errors while fetching info from the W3C API.

The new overwrites rules are needed during the transition (the changes need to
be made as the same time as the data gets updated), but can be dropped
afterwards. They affect specifications that switched from a shortname without
a level to a shortname with a level. Longer term, these should be handled
through the notion of specification series (see tobie#811).
  • Loading branch information
tidoust committed Oct 20, 2024
1 parent 6c13eab commit 289bd5d
Show file tree
Hide file tree
Showing 4 changed files with 617 additions and 409 deletions.
24 changes: 7 additions & 17 deletions overwrites/w3c.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
[
{ "id": "WebIDL", "action": "delete" },
{ "id": "WebIDL-1", "action": "delete" },
{ "id": "WebIDL-1", "action": "createAlias", "aliasOf": "WEBIDL"},
{ "id": "websockets", "action": "delete" },
{ "id": "url", "action": "delete" },
{ "id": "fullscreen", "action": "delete" },
{ "id": "notifications", "action": "delete" },
{ "id": "dom", "action": "delete" },
{ "id": "encoding", "action": "delete" },
{ "id": "hr-time", "action": "createAlias", "aliasOf": "hr-time-3"},
{ "id": "resource-timing", "action": "deleteProp", "prop": "obsoletes"},
{ "id": "resource-timing-1", "action": "createAlias", "aliasOf": "resource-timing"},
{ "id": "PNG", "action": "renameTo", "newId": "PNG-1"},
{ "id": "PNG", "action": "createAlias", "aliasOf": "png-3"},
{ "id": "media-source", "action": "createAlias", "aliasOf": "media-source-2" },
{ "id": "encrypted-media", "action": "createAlias", "aliasOf": "encrypted-media-2" }
]
{ "id": "vocab-dcat", "action": "delete" },
{ "id": "vocab-dcat", "action": "createAlias", "aliasOf": "vocab-dcat-1" },
{ "id": "wot-architecture", "action": "delete" },
{ "id": "wot-architecture", "action": "createAlias", "aliasOf": "wot-architecture10" },
{ "id": "wot-thing-description", "action": "delete" },
{ "id": "wot-thing-description", "action": "createAlias", "aliasOf": "wot-thing-description10" }
]
82 changes: 3 additions & 79 deletions scripts/get-shortname.js
Original file line number Diff line number Diff line change
@@ -1,104 +1,29 @@
var TR_URL = /https?:\/\/www\.w3\.org\/TR\//;

var SPECIAL_CASES = {
'https://www.w3.org/Search/9605-Indexing-Workshop/ReportOutcomes/S6Group2': "S6Group2",
'https://www.w3.org/TR/1998/NOTE-P3P10-Protocols': "P3P10-Protocols",
'https://www.w3.org/1999/05/WCA-terms/': "WCA-terms",
'https://www.w3.org/TR/1998/WD-HTTP-NG-goals': "HTTP-NG-goals",
'https://www.w3.org/TR/REC-html32': "HTML32",
'https://www.w3.org/TR/2001/WD-xhtml1-20011004/': 'xhtml1'
};

var SHORT_NAME_SPECIAL_CASES = {
"html": "w3c-html",
"NOTE-CSS-potential": "CSS-potential",
"NOTE-P3P10-principles": "P3P10-principles",
"NOTE-SYMM-modules": "SYMM-modules",
"NOTE-XML-FRAG-REQ": "XML-FRAG-REQ",
"NOTE-html-lan": "html-lan",
"NOTE-voice": "voice",
"NOTE-xh": "xh",
"NOTE-xlink-principles": "xlink-principles",
"NOTE-xml-canonical-req": "xml-canonical-req",
"NOTE-xml-infoset-req": "xml-infoset-req",
"NOTE-xml-schema-req": "xml-schema-req",
"NOTE-xptr-infoset-liaison": "xptr-infoset-liaison",
"NOTE-xptr-req": "xptr-req",
"NOTE-HTTP-NG-testbed": "HTTP-NG-testbed",
"NOTE-WCA": "WCA",
"NOTE-html40-mobile": "html40-mobile",
"NOTE-rdf-uml": "rdf-uml",
"NOTE-xlink-req": "xlink-req",
"WD-DSIG-label-arch": "DSIG-label-arch",
"WD-HTTP-NG-architecture": "HTTP-NG-architecture",
"WD-HTTP-NG-goals": "HTTP-NG-goals",
"WD-HTTP-NG-interfaces": "HTTP-NG-interfaces",
"WD-HTTP-NG-wire": "HTTP-NG-wire",
"WD-P3P-arch": "P3P-arch",
"WD-P3P-grammar": "P3P-grammar",
"WD-SVGReq": "SVGReq",
"WD-XSLReq": "XSLReq",
"WD-acss": "acss",
"WD-font": "font",
"WD-http-pep": "http-pep",
"WD-ilu-requestor": "ilu-requestor",
"WD-jepi-uppflow": "jepi-uppflow",
"WD-mux": "mux",
"WD-positioning": "positioning",
"WD-print": "print",
"NOTE-agent-attributes": "agent-attributes",
"NOTE-amaya": "amaya",
"NOTE-AS": "AS",
"NOTE-authentform": "authentform",
"NOTE-CCPPexchange": "CCPPexchange",
"NOTE-CSS-smil": "CSS-smil",
"NOTE-datetime": "datetime",
"NOTE-dcd": "dcd",
"NOTE-ddml": "ddml",
"NOTE-drawml": "drawml",
"NOTE-drp": "drp",
"NOTE-eu-conf": "eu-conf",
"NOTE-expamaya": "expamaya",
"NOTE-framework-970706": "framework-970706",
"NOTE-gdiff": "gdiff",
"NOTE-HGML": "HGML",
"NOTE-html": "html",
"NOTE-HTMLComponents": "HTMLComponents",
"NOTE-HTMLplusTIME": "HTMLplusTIME",
"NOTE-http-edit-dist-scenarios": "http-edit-dist-scenarios",
"NOTE-ice": "ice",
"NOTE-IPWG-Practices": "IPWG-Practices",
"NOTE-jepi": "jepi",
"NOTE-link": "link",
"NOTE-MCF-XML": "MCF-XML",
"NOTE-P3P-CACM": "P3P-CACM",
"NOTE-PICS-Cookie-extension": "PICS-Cookie-extension",
"NOTE-pics-ng-metadata": "pics-ng-metadata",
"NOTE-PICS-Statement": "PICS-Statement",
"NOTE-PIDL": "PIDL",
"NOTE-rdf-simple-intro": "rdf-simple-intro",
"NOTE-rdfarch": "rdfarch",
"NOTE-SDML": "SDML",
"NOTE-SOX": "SOX",
"NOTE-stts2": "stts2",
"NOTE-STTS3": "STTS3",
"NOTE-TPRC-970930": "TPRC-970930",
"NOTE-uclp": "uclp",
"NOTE-VML": "VML",
"NOTE-WAP": "WAP",
"NOTE-webarch-extlang": "webarch-extlang",
"NOTE-widl": "widl",
"NOTE-XFDL": "XFDL",
"NOTE-xml-ql": "xml-ql",
"NOTE-XSL": "XSL",
"NOTE-XSL-and-CSS": "XSL-and-CSS",
"REC-CSS1": "CSS1",
"REC-DOM-Level-1": "DOM-Level-1",
"REC-DSig-label": "DSig-label",
"REC-html32": "HTML32",
"REC-MathML": "MathML",
"REC-PICS-labels": "PICS-labels",
"REC-PICS-services": "PICS-services",
"REC-PICSRules": "PICSRules",
"REC-rdf-syntax": "rdf-syntax-grammar",
"REC-smil": "smil",
"REC-WebCGM": "WebCGM",
"WD-logfile": "logfile",
Expand All @@ -111,10 +36,9 @@ var SHORT_NAME_SPECIAL_CASES = {
}

function getShortName(url) {
if (SPECIAL_CASES[url]) return SPECIAL_CASES[url];
var parts = url.replace(TR_URL, "").split("/").filter(function(p) { return p != "/" && p != ''; });
if (parts.length > 1) throw new Error("Can't identify shortName from url " + url);
var part = parts[0]
var part = parts[0];
return SHORT_NAME_SPECIAL_CASES[part] || part;
}

Expand Down
1 change: 1 addition & 0 deletions scripts/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,6 @@ function tryOverwrite(f) {
delete ref[action.prop];
}
});
references = sortRefs(references);
writeBiblio(f, references);
}
Loading

0 comments on commit 289bd5d

Please sign in to comment.