Anonymization
The anonymize subcommand enables the sharing of RDF datasets, graphs and SPARQL queries with confidential information without leaking sensitive information.
The anonymization process removes identifying data while preserving the data's original structure.
How it works
The anonymization process uses a bijective function mapping input RDF terms to random terms of the same type (i.e., IRIs are assigned an anonymized IRI and a literal is assigned an anonymized literal).
The function is implemented based on an in-memory map.
When an RDF term T is anonymized for the first time, a new random IRI I is generated and associated with the term T; subsequent occurrences of T are replaced by I.
IRIs are created using a cryptographically secure random number generator from Botan.
Warning: There are some exceptions to this rule. In particular, the following kinds of terms are currently not anonymized:
- the values of numeric literals (e.g.
xsd:integer)- the values of datetime literals (e.g.
xsd:date)- the values of
xsd:booleanliterals- the language tag of
rdf:langStringliterals (Note: the string content itself is anonymized, just the language is kept)- the IRIs of known datatypes (e.g. the IRIs of XSD datatypes)
- the IRI
rdf:type
The anonymization process takes place fully in-memory. No information about the mapping or the original data is persisted in the database. The generated mapping is immediately discarded when the program exits. Different invocations of the program always result in different output; even with the same input data.
Source code
The source code of the anonymization algorithm is publicly available in rdf4cpp. The Tentris binary simply uses this algorithm; however, you can directly use rdf4cpp::Dataset::anonymize.
Examples
Anonymizing a Turtle file
tentris anonymize -d in=secret.ttl,out=anon.ttl
Anonymizing a Turtle file together with an associated query
tentris anonymize \
-d in=secret.ttl,out=anon.ttl \
-q in=secret.rq,out=anon.rq
Example Output for the Mona Lisa Graph
Below, the result of the anonymization process for the Mona Lisa graph from Introduction to Knowledge Graphs is provided.
Note: Each invocation results in a different graph.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://example.org/TMzafsnqKXlqffru>
a <http://example.org/AFsExUPkioGgTxai> ;
<http://example.org/crcXtfWnRpYXujqt> "http://example.org/wLahkAMwZpePvtPE" .
<http://example.org/aQFsvzdJgimhLDWv>
a <http://example.org/AFsExUPkioGgTxai> ;
<http://example.org/AWkVucAuDSTSAZfG> "1990-07-04"^^xsd:date ;
<http://example.org/crcXtfWnRpYXujqt> "http://example.org/myDfBslFoggKyaNA" ;
<http://example.org/YlcaWIGUVJMTWxWf> <http://example.org/TMzafsnqKXlqffru> ;
<http://example.org/XavwhthaPewdRYGh> <http://example.org/ZnIZOwKrtjqhjQsX> .
<http://example.org/ZnIZOwKrtjqhjQsX>
a <http://example.org/xuiAapqVfGJIPEgl> ;
<http://example.org/LijajMGSOYjyUARg> "http://example.org/fBvUyWbKblXsAfbg"@en ;
<http://example.org/BWGMdjjeKKgTyhNj> <http://example.org/ZJWojalNafyeGocJ> .
<http://example.org/ZJWojalNafyeGocJ>
a <http://example.org/AFsExUPkioGgTxai> ;
<http://example.org/crcXtfWnRpYXujqt> "http://example.org/zUGHEUPmStewMPan" .
<http://example.org/ZptXkuAyrQfoGiag>
a <http://example.org/AiJGGTmpbuYkjRaK> ;
<http://example.org/XEnpyeyvLJXwzhMc> <http://example.org/ZnIZOwKrtjqhjQsX> .
Options
-q/--query in=<IFILE>,out=<OFILE>: Specify a query file to anonymize. This option is repeatable.in=<IFILE>: Specifies the input file, e.g.in=secret.rq.out=<OFILE>: Specifies where the corresponding output file is written, e.g.out=anon.rq.
-d/--dataset in=<IFILE>,out=<OFILE>[,in_fmt=<IFMT>][,out_fmt=<OFMT>]: Specify a dataset file to anonymize. This option is repeatable.in=<IFILE>: Specifies the input file, e.g.in=secret.ttl.out=<OFILE>: Specifies where the corresponding output file is written, e.g.out=anon.ttl.in_fmt=<IFMT>: Explicitly specifies the format of the input file, e.g.in_fmt=turtle. The format is auto-detected if this option is not specified.out_fmt=<IFMT>: Explicitly specifies the format of the output file, e.g.out_fmt=turtle. The format is auto-detected if this option is not specified.