Skip to content

Commit

Permalink
Translator for the UK National Archives case law archive.
Browse files Browse the repository at this point in the history
Available at https://caselaw.nationalarchives.gov.uk/.

This follows the example of the existing [BAILII](https://www.bailii.org/) translator for formatting UK case law as zotero entries,
and relies on the LegalDocXML representation of each case made available on the national archives site as a canonical source of metadata.

It will import individual judgments, as well as allowing 'multiple' import on search result and collection pages.
  • Loading branch information
timcowlishaw committed Dec 11, 2023
1 parent 3ad35cf commit 01ad22c
Showing 1 changed file with 129 additions and 0 deletions.
129 changes: 129 additions & 0 deletions National Archives (UK) Find Case Law.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"translatorID": "5c0588e6-561f-4ab3-bb13-4f72bf049ca8",
"label": "National Archives (UK) Find Case Law",
"creator": "Tim Cowlishaw <[email protected]>",
"target": "https?:\\/\\/caselaw\\.nationalarchives\\.gov\\.uk\\/",
"minVersion": "5.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2023-12-11 14:59:32"
}

function detectWeb(doc, url) {

Check warning on line 15 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

Missing license block

Check failure on line 15 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

'url' is defined but never used. Allowed unused args must match /^_/u
if (isJudgment(doc)) {
return "case";
}
else if (isResultsList(doc)) {
return "multiple";
}
return false;
}

function doWeb(doc, url) {

Check failure on line 25 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

Expected to return a value at the end of function 'doWeb'
if(isJudgment(doc)) {

Check warning on line 26 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

Expected space(s) after "if"
return scrape(doc, url);
} else if(isResultsList(doc)) {

Check warning on line 28 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

Closing curly brace appears on the same line as the subsequent block

Check warning on line 28 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

Expected space(s) after "if"
items = ZU.getItemArray(doc, doc.querySelector("ul.judgment-listing__list"), /\/[a-zA-Z0-9]+/)

Check failure on line 29 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

'items' is not defined

Check failure on line 29 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

Missing semicolon
return Z.selectItems(items, function(items) {

Check failure on line 30 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

'items' is not defined

Check warning on line 30 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

Missing space before function parentheses
if (items) ZU.processDocuments(Object.keys(items), scrape);
});
}
}

function isJudgment(doc) {
return doc.querySelector("article.judgment") !== null;
}

function isResultsList(doc) {
return doc.querySelector("ul.judgment-listing__list") !== null;
}

function scrape(doc, url) {
const item = new Z.Item("case");
ZU.doGet(url + "/data.xml", function (text) {

Check failure on line 46 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

Trailing spaces not allowed
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(text, "text/xml");
function xpath(path) {
return ZU.xpathText(xmlDoc, path, {

Check failure on line 50 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

Unexpected line break after this opening brace
"akn": "http://docs.oasis-open.org/legaldocml/ns/akn/3.0",

Check failure on line 51 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

Unnecessarily quoted property 'akn' found

Check failure on line 51 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

Trailing spaces not allowed
"uk": "https://caselaw.nationalarchives.gov.uk/akn"}

Check failure on line 52 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

Unnecessarily quoted property 'uk' found
);
}
item.uri = xpath("//akn:FRBRExpression/akn:FRBRuri/@value")
item.title = xpath("//akn:FRBRWork/akn:FRBRname/@value");
item.dateDecided = xpath('//akn:FRBRWork/akn:FRBRdate[@name="judgment"]/@date');
item.court = xpath('//uk:court');
new Array(xpath('//akn:judge/@refersTo')).forEach(function(href) {

Check warning on line 59 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

Missing space before function parentheses
if(href !== null) {

Check warning on line 60 in National Archives (UK) Find Case Law.js

View workflow job for this annotation

GitHub Actions / Lint, Check, Test

Expected space(s) after "if"
const id = href.replace("#", "");
item.creators.pop({
lastName: xpath(`//akn:TLCPerson[@eId='${id}']/@showAs`),
creatorType: "author",
fieldMode: true
} )
}
});
const ncn = xpath("//uk:cite");
item.notes.push({ note: `Neutral Citation Number: ${ncn}`})
item.complete();
});
}/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://caselaw.nationalarchives.gov.uk/ewhc/qb/2020/3156",
"items": [
{
"itemType": "case",
"caseName": "Vardy v Rooney",
"creators": [
{
"lastName": "THE HON. MR JUSTICE WARBY",
"creatorType": "author",
"fieldMode": true
}
],
"dateDecided": "2020-11-20",
"court": "EWHC-QBD",
"attachments": [],
"tags": [],
"notes": [
{
"note": "Neutral Citation Number: [2020] EWHC 3156 (QB)"
}
],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://caselaw.nationalarchives.gov.uk/ewca/civ/2021/567",
"items": [
{
"itemType": "case",
"caseName": "Corbyn v Millett",
"creators": [],
"dateDecided": "2021-04-20",
"court": "EWCA-Civil",
"attachments": [],
"tags": [],
"notes": [
{
"note": "Neutral Citation Number: [2021] EWCA Civ 567"
}
],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://caselaw.nationalarchives.gov.uk/judgments/search?query=Corbyn",
"items": "multiple"
}
]
/** END TEST CASES **/

0 comments on commit 01ad22c

Please sign in to comment.