Skip to content

Commit

Permalink
feature: add UK National Archives Find Case Law as source
Browse files Browse the repository at this point in the history
  • Loading branch information
hueyy committed Apr 30, 2023
1 parent 5c5517a commit d4effe2
Show file tree
Hide file tree
Showing 8 changed files with 2,816 additions and 2,490 deletions.
5,129 changes: 2,679 additions & 2,450 deletions package-lock.json

Large diffs are not rendered by default.

72 changes: 36 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clerkent",
"version": "3.5.2",
"version": "3.6.0",
"private": true,
"description": "quick search legal search",
"repository": "https://github.com/lacuna-technologies/clerkent.git",
Expand Down Expand Up @@ -41,77 +41,77 @@
]
},
"dependencies": {
"@babel/runtime": "^7.20.13",
"@babel/runtime": "^7.21.5",
"async-mutex": "^0.4.0",
"axios": "^1.2.3",
"axios-cache-interceptor": "^1.0.0",
"axios": "^1.4.0",
"axios-cache-interceptor": "^1.0.1",
"cheerio": "^1.0.0-rc.12",
"fuse.js": "^6.6.2",
"leven": "^4.0.0",
"memoizee": "^0.4.15",
"preact": "^10.11.3",
"preact": "^10.13.2",
"preact-router": "^4.1.0",
"qs": "^6.11.0",
"react-select": "^5.7.0",
"rss-parser": "^3.12.0",
"qs": "^6.11.1",
"react-select": "^5.7.2",
"rss-parser": "^3.13.0",
"svg-country-flags": "^1.2.10"
},
"devDependencies": {
"@babel/cli": "^7.20.7",
"@babel/core": "^7.20.12",
"@babel/cli": "^7.21.5",
"@babel/core": "^7.21.5",
"@babel/node": "^7.20.7",
"@babel/plugin-transform-react-jsx": "^7.20.13",
"@babel/plugin-transform-runtime": "^7.19.6",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@babel/plugin-transform-react-jsx": "^7.21.5",
"@babel/plugin-transform-runtime": "^7.21.4",
"@babel/preset-env": "^7.21.5",
"@babel/preset-typescript": "^7.21.5",
"@testing-library/preact": "^3.2.3",
"@types/jest": "^29.2.6",
"@types/jest": "^29.5.1",
"@types/memoizee": "^0.4.8",
"@types/node": "^18.11.18",
"@types/node": "^18.16.3",
"@types/qs": "^6.9.7",
"@types/sharp": "^0.31.1",
"@types/webpack": "^5.28.0",
"@typescript-eslint/eslint-plugin": "^5.49.0",
"@typescript-eslint/parser": "^5.49.0",
"autoprefixer": "^10.4.13",
"@types/webpack": "^5.28.1",
"@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1",
"autoprefixer": "^10.4.14",
"babel-loader": "^9.1.2",
"clean-webpack-plugin": "^4.0.0",
"codecov": "^3.8.3",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.7.3",
"eslint": "^8.32.0",
"eslint": "^8.39.0",
"eslint-config-preact": "^1.3.0",
"eslint-plugin-disable": "^2.0.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-json-format": "^2.0.1",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-sonarjs": "^0.18.0",
"eslint-plugin-sonarjs": "^0.19.0",
"eslint-plugin-sort-keys-fix": "^1.1.2",
"eslint-plugin-unicorn": "^45.0.2",
"eslint-plugin-unicorn": "^46.0.0",
"file-loader": "^6.2.0",
"filemanager-webpack-plugin": "^7.0.0",
"fork-ts-checker-webpack-plugin": "^7.3.0",
"html-webpack-plugin": "^5.5.0",
"html-webpack-plugin": "^5.5.1",
"husky": "^8.0.3",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"lint-staged": "^13.1.0",
"mini-css-extract-plugin": "^2.7.2",
"postcss": "^8.4.21",
"postcss-loader": "^7.0.2",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"lint-staged": "^13.2.2",
"mini-css-extract-plugin": "^2.7.5",
"postcss": "^8.4.23",
"postcss-loader": "^7.3.0",
"resolve-url-loader": "^5.0.0",
"sharp": "^0.31.3",
"sharp": "^0.32.1",
"svg-inline-loader": "^0.8.2",
"tailwindcss": "^3.2.4",
"terser-webpack-plugin": "^5.3.6",
"ts-jest": "^29.0.5",
"tailwindcss": "^3.3.2",
"terser-webpack-plugin": "^5.3.7",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"tsc-files": "^1.1.3",
"typescript": "^4.9.4",
"typescript": "^5.0.4",
"webextension-polyfill-ts": "^0.26.0",
"webpack": "^5.75.0",
"webpack": "^5.81.0",
"webpack-cli": "^4.10.0",
"wext-manifest-loader": "^3.0.0",
"wext-manifest-webpack-plugin": "^1.2.1"
Expand Down
6 changes: 6 additions & 0 deletions src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ const UK_DATABASES: CountryDatabases = {
name: `BAILII`,
url: `https://www.bailii.org/`,
},
findcaselaw: {
icon: ``,
name: `Find Case Law`,
url: `https://caselaw.nationalarchives.gov.uk`,
},
ipo: {
icon: ``,
name: `IPO`,
Expand Down Expand Up @@ -378,6 +383,7 @@ const DEFAULT_DATABASES_STATUS= {
UK: {
bailii: true,
commonlii: true,
findcaselaw: true,
ipo: false,
},
UN: {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Finder/CaseCitationFinder/SG.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Constants from '../../Constants'
import { formatAbbrs, sortCasesByVolume, sortCitationsByVolume } from './utils'
import { formatAbbrs, sortCasesByVolume } from './utils'
import { SGSTBlongFormatRegex } from 'utils/scraper/SG/STB'

export const SGSCAbbrs = [
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Finder/CaseCitationFinder/UK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const sortUKCases = (
attribute,
)

const ukIPORegex = /(\[\d{4}] UKIntelP o\d{5}|(BL)?O\/?\d{3}\/?(?<year>\d{2}))/
const ukIPORegex = /(\[\d{4}] UKIntelP o\d{5}|(BL)?O\/?\d{3}\/?(?<ukipoyear>\d{2}))/

export const findUKCaseCitationMatches = (query: string) => {
const abbrs = formatAbbrs(UKAbbrs)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/scraper/SG/STB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const BASE_URL = `https://www.stratatb.gov.sg`
const CURRENT_DECISIONS = `${BASE_URL}/resources-judgments.html`
const HISTORICAL_DECISIONS = `${BASE_URL}/resources-judgments-archives.html`

export const SGSTBlongFormatRegex = /stb(\sno\.?)?\s?(?<number>\d{1,4}[a-z]?)((\s(and|&)\s\d{1,4}[a-z]?)|(\/\d{1,4}[a-z]?)+)?\sof\s(?<year>[12]\d{3})/gi
export const SGSTBlongFormatRegex = /stb(\sno\.?)?\s?(?<stbnumber>\d{1,4}[a-z]?)((\s(and|&)\s\d{1,4}[a-z]?)|(\/\d{1,4}[a-z]?)+)?\sof\s(?<stbyear>[12]\d{3})/gi
const SGSTBsquareBracketRegex = /\[(?<year>[12]\d{3})] sgstb (?<number>\d{1,4}[a-z]?)/gi
export const SGSTBIsSquareBracketFormat = (citation: string): boolean => (new RegExp(SGSTBsquareBracketRegex, `i`)).test(citation)
export const SGSTBIsLongFormat = (citation: string): boolean => (new RegExp(SGSTBlongFormatRegex, `i`)).test(citation)
export const SGSTBLongFormat = (squareBracketCitation: string) => {
const [match] = [...squareBracketCitation.matchAll(
SGSTBsquareBracketRegex,
)]
return `STB ${match.groups.number} of ${match.groups.year}`
return `STB ${match.groups.stbnumber} of ${match.groups.stbyear}`
}
export const SGSTBSquareBracketFormat = (longCitation: string): string => {
const [match] = [...longCitation.matchAll(
Expand Down
87 changes: 87 additions & 0 deletions src/utils/scraper/UK/FindCaseLaw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import * as cheerio from 'cheerio'
import Request from '../../Request'
import Constants from 'utils/Constants'
import Helpers from 'utils/Helpers'

const ASSETS_DOMAIN = `https://assets.caselaw.nationalarchives.gov.uk`
const DOMAIN = `https://caselaw.nationalarchives.gov.uk`

const generatePDFPath = (path: string): string => {
const segments = path.slice(1).split(`/`).join(`_`)
return `${path}/${segments}.pdf`
}

const parseCases = (html: string): Law.Case[] => {
const $ = cheerio.load(html)
if($(`.results__results-intro`).text().trim() === `We found 0 judgments`){
return []
}
return $(`.results__result-list-container > .judgment-listing__list > li`).map((_, element): Law.Case => {
const name = $(`span.judgment-listing__title`, element).text().trim()
const citation = $(`span.judgment-listing__neutralcitation`, element).text().trim()
const path = $(`span.judgment-listing__title> a`, element).attr(`href`)
const link = DOMAIN + path

return {
citation,
database: Constants.DATABASES.UK_findcaselaw,
jurisdiction: Constants.JURISDICTIONS.UK.id,
links: [
{
doctype: `Judgment`,
filetype: `HTML`,
url: link,
},
{
doctype: `Judgment`,
filetype: `PDF`,
url: ASSETS_DOMAIN + generatePDFPath(path),
},
],
name,
}
}).get().filter(({ citation }) => Helpers.isCitationValid(citation))
}

const getCaseByCitation = async (citation: string): Promise<Law.Case[]> => {
const response = await Request.get(
`${DOMAIN}/judgments/advanced_search`,
{
params: {
from: ``,
judge: ``,
order: `-relevance`,
party: ``,
per_page: 10,
query: `"${citation}"`,
to: ``,
},
},
)
return parseCases(response.data)
}

const getCaseByName = async (caseName: string): Promise<Law.Case[]> => {
const response = await Request.get(
`${DOMAIN}/judgments/advanced_search`,
{
params: {
from: ``,
judge: ``,
order: `-relevance`,
party: ``,
per_page: 10,
query: caseName,
to: ``,
},
},
)
return parseCases(response.data)
}

const FindCaseLaw = {
getCaseByCitation,
getCaseByName,
}

export default FindCaseLaw
4 changes: 4 additions & 0 deletions src/utils/scraper/UK/UK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import { sortUKCases } from '../../Finder/CaseCitationFinder/UK'
import Constants from '../../Constants'
import { databaseUseDatabase, databaseUseJurisdiction, makeEventTarget } from '../utils'
import UKIPO from './UKIPO'
import FindCaseLaw from './FindCaseLaw'

const databaseUseUK = databaseUseJurisdiction(`UK`)
const databaseUseBailii = databaseUseDatabase(`bailii`, databaseUseUK)
const databaseUseCommonLII = databaseUseDatabase(`commonlii`, databaseUseUK)
const databaseUseIPO = databaseUseDatabase(`ipo`, databaseUseUK)
const databaseUseFindCaseLaw = databaseUseDatabase(`findcaselaw`, databaseUseUK)

const getCaseByName = (caseName: string): EventTarget => makeEventTarget(
caseName,
[
databaseUseFindCaseLaw(() => FindCaseLaw.getCaseByName(caseName)),
databaseUseBailii(() => BAILII.getCaseByName(caseName)),
databaseUseCommonLII(() => Common.CommonLII.getCaseByName(caseName, Constants.JURISDICTIONS.UK.name)),
databaseUseIPO(() => UKIPO.getCaseByName(caseName)),
Expand All @@ -30,6 +33,7 @@ const getCaseByCitation = (citation: string, court: string): EventTarget => make
databaseUseIPO(() => UKIPO.getCaseByCitation(citation)),
] : [
Custom.getCaseByCitation(citation, court),
databaseUseFindCaseLaw(() => FindCaseLaw.getCaseByCitation(citation)),
databaseUseBailii(() => BAILII.getCaseByCitation(citation)),
databaseUseCommonLII(() => Common.CommonLII.getCaseByCitation(citation)),
],
Expand Down

0 comments on commit d4effe2

Please sign in to comment.