GRANSKA

Masking documents

Before you send a document for review you can mask the personal details in it, in your own system: names, Swedish, Norwegian and Danish identity numbers, addresses, phone numbers and e-mail addresses. Each one is replaced by a label such as [Name 1] or [ID number], so the review can still tell people apart and quote the document.

The masking runs on your machine. We never receive the original: you send only the masked copy, and there is no masking endpoint, because one would have to receive the document unmasked.

The download

granska-mask-1.1.0.tgz is the masking code, for Node.js 20 or later, about 14 MB. It works offline: it needs no account, makes no network call and writes nothing but what you ask it to. It masks exactly as the masking in the web application does, with the same rules, name lists and labels, scanned pages included.

It is provided to GRANSKA customers for use with the GRANSKA API under your customer agreement. The name lists inside come from the national statistics offices of Sweden, Norway and Denmark, and the text recognition is tesseract.js with tessdata_fast's language data, each under the terms and with the attribution in its NOTICE file.

Install it from the downloaded file, or straight from the link's address:

npm install ./granska-mask-1.1.0.tgz

What it finds, and what it does not

It finds:

  • Names, from the official first-name and surname statistics of Sweden, Norway and Denmark, and a capitalised word right after a word such as "mamma", "handläggare" or "saksbehandler". Every mention of one person gets the same number, [Name 1], [Name 2] and so on.
  • Identity numbers: Swedish personnummer and samordningsnummer, Norwegian fødselsnummer and D-nummer, Danish CPR numbers, each checked by its check digits or date.
  • Addresses: a street with its house number, and a postcode.
  • Phone numbers and e-mail addresses.
  • Words you add, such as a town, everywhere they occur.

Scanned pages are read too. A page with too little text of its own is read from its picture with text recognition on your machine, in Swedish, Danish, Norwegian or English, as the web application reads it, and masked like any other page; the masked copy's text there carries the labels, so the review can still quote it. The command says how many pages it read this way, and names any page it could read nothing on, such as a blank page or a photograph: nothing on such a page is masked.

It does not find place names unless you add them, or handwriting. Check the result before you send it. The web application's checking view is the easy way to look a masked document over.

The command

npx granska-mask in.pdf out.pdf [--language en|sv|nb|da] [--add word …] [--list findings.json]
  • --language writes the labels in English, Swedish, Norwegian or Danish (en by default).
  • --add masks more words everywhere they occur.
  • --list also writes what was masked, with its kind, page, text and label, to a file on your machine. Nothing is written unless you ask for it.
npx granska-mask utredning.pdf utredning-masked.pdf --language sv --add Östersund --list masked.json

The function

maskPdf(pdfBytes, { language, added }) answers the masked PDF as bytes, counts (how many different people, identity numbers, addresses, phone numbers, e-mail addresses and added words were masked), findings (every masked place), recognisedPages (how many pages were read with text recognition) and unreadablePages (the pages it could read nothing on).

import { readFile, writeFile } from "node:fs/promises";
import { maskPdf } from "granska-mask";

const { pdf, counts } = await maskPdf(await readFile("utredning.pdf"), {
  language: "sv",
  added: ["Östersund"],
});
await writeFile("utredning-masked.pdf", pdf);
console.log(`${counts.person} people masked`);

Sending the masked copy

Send the masked file exactly as you would any document: POST /v1/upload-url, a PUT of the masked bytes to the URL it answers, then POST /v1/analyze with the job id. See Get an upload URL and Start an analysis. The review quotes the labels where the document had the details, so a finding about [Name 1] is about the same person everywhere in the report.