Skip to content

Commit

Permalink
resolves #49 GDPR legal basis to rights mapping
Browse files Browse the repository at this point in the history
The mappings are added using dpv:hasRight to legal basis module in
DPV-GDPR, and are rendered in a separate section in HTML listing the
applicable rights for each legal basis.
  • Loading branch information
coolharsh55 committed Sep 20, 2023
1 parent bc4f72d commit eb69b62
Show file tree
Hide file tree
Showing 558 changed files with 295,015 additions and 281,736 deletions.
241 changes: 121 additions & 120 deletions documentation-generator/001_download_vocab_in_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,137 +16,138 @@
# Format of this data structure is
# (DOCUMENT_NAME, ((DOCUMENT_ID, SHEET_NAME)+)
#
('base', '1x5Wfl-2Xp22R89lhNwNpYP0xN0zfQLFlNe3On6pwNM4',
(
'Namespaces',
'Namespaces_Other',
'BaseOntology',
'BaseOntology_properties',
)),
('dpv-pd','1SI6gZh9-dq1rf_etfrlYHj0QZwq9Vd25f_OHPX5hbSQ',
(
'PersonalData',
'PersonalData_properties',
'dpv-pd',
)),
('purpose_processing', '1ePg6BU2Zp9fiSDuEnKuVi6dIRrFLEVdatbVxjHRk-8s',
(
'Purpose',
'Purpose_properties',
'Processing',
'Processing_properties',
'ProcessingContext',
'ProcessingContext_properties',
'ProcessingScale',
'ProcessingScale_properties',
)),
('context_status', '1VPQW1DanprQhMwnhSqyKSGbEXdTmLHdc6UjpWJhyLMA',
(
'Context',
'Context_properties',
'Status',
'Status_properties',
)),
('toms', '16d0_k6ueoXxXRTgecih9Ny7NpeXYF8icm4QX99cPYJA',
(
'TechnicalOrganisationalMeasure',
'TechnicalOrganisationalMeasure_properties',
'TechnicalMeasure',
'OrganisationalMeasure',
)),
('entities', '1g6zLqVt5FlNlgsXq_NW2W9INv3KdGEFjJCyOd03UmOg',
(
'Entities',
'Entities_properties',
'Entities_Authority',
'Entities_Authority_properties',
'Entities_LegalRole',
'Entities_LegalRole_properties',
'Entities_Organisation',
'Entities_DataSubject',
'Entities_DataSubject_properties',
)),
('location_jurisdiction', '19exhY34jq6VDApRp2abHD-br6rpm6Q7BOP7H_pm5sKM',
(
'Jurisdiction',
'Jurisdiction_properties',
'legal_properties',
'legal_Locations',
'legal_Laws',
'legal_Authorities',
'legal_EU_EEA',
'legal_EU_Adequacy',
)),
('legal_basis', '13Ub4LXHruocffYnd7JKCMvzi1MYv3Gy61d3UmQBhARc',
(
'LegalBasis',
'LegalBasis_properties',
'ConsentTypes',
'ConsentStatus',
'Consent_properties',
)),
# ('base', '1x5Wfl-2Xp22R89lhNwNpYP0xN0zfQLFlNe3On6pwNM4',
# (
# 'Namespaces',
# 'Namespaces_Other',
# 'BaseOntology',
# 'BaseOntology_properties',
# )),
# ('dpv-pd','1SI6gZh9-dq1rf_etfrlYHj0QZwq9Vd25f_OHPX5hbSQ',
# (
# 'PersonalData',
# 'PersonalData_properties',
# 'dpv-pd',
# )),
# ('purpose_processing', '1ePg6BU2Zp9fiSDuEnKuVi6dIRrFLEVdatbVxjHRk-8s',
# (
# 'Purpose',
# 'Purpose_properties',
# 'Processing',
# 'Processing_properties',
# 'ProcessingContext',
# 'ProcessingContext_properties',
# 'ProcessingScale',
# 'ProcessingScale_properties',
# )),
# ('context_status', '1VPQW1DanprQhMwnhSqyKSGbEXdTmLHdc6UjpWJhyLMA',
# (
# 'Context',
# 'Context_properties',
# 'Status',
# 'Status_properties',
# )),
# ('toms', '16d0_k6ueoXxXRTgecih9Ny7NpeXYF8icm4QX99cPYJA',
# (
# 'TechnicalOrganisationalMeasure',
# 'TechnicalOrganisationalMeasure_properties',
# 'TechnicalMeasure',
# 'OrganisationalMeasure',
# )),
# ('entities', '1g6zLqVt5FlNlgsXq_NW2W9INv3KdGEFjJCyOd03UmOg',
# (
# 'Entities',
# 'Entities_properties',
# 'Entities_Authority',
# 'Entities_Authority_properties',
# 'Entities_LegalRole',
# 'Entities_LegalRole_properties',
# 'Entities_Organisation',
# 'Entities_DataSubject',
# 'Entities_DataSubject_properties',
# )),
# ('location_jurisdiction', '19exhY34jq6VDApRp2abHD-br6rpm6Q7BOP7H_pm5sKM',
# (
# 'Jurisdiction',
# 'Jurisdiction_properties',
# 'legal_properties',
# 'legal_Locations',
# 'legal_Laws',
# 'legal_Authorities',
# 'legal_EU_EEA',
# 'legal_EU_Adequacy',
# )),
# ('legal_basis', '13Ub4LXHruocffYnd7JKCMvzi1MYv3Gy61d3UmQBhARc',
# (
# 'LegalBasis',
# 'LegalBasis_properties',
# 'ConsentTypes',
# 'ConsentStatus',
# 'Consent_properties',
# )),
('gdpr', '1lDJZpl0UND8Bm_4iWKVQtgmMUz0YwP2R63CgP7Gro-U',
(
'GDPR_LegalBasis',
'GDPR_LegalBasis_SpecialCategory',
'GDPR_LegalBasis_DataTransfer',
'GDPR_LegalRights',
'GDPR_LegalBasis_Rights_Mapping',
'GDPR_DataTransfers',
'GDPR_DPIA',
'GDPR_DPIA_properties',
'GDPR_compliance'
)),
('dpv-tech', '1GVmF4c7b-9xMSs0TyT45kXoCLLUVs8bbW34tfcozbuA',
(
'tech-core',
'tech-core-properties',
'tech-data',
'tech-ops',
'tech-security',
'tech-surveillance',
'tech-provision',
'tech-provision-properties',
'tech-actors',
'tech-actors-properties',
'tech-comms',
'tech-comms-properties',
'tech-tools',
'tech_algorithms',
)),
('risk', '1y8r3Vk-_Gi1MqbyAM6Ot4DoNDJpa2ZVhCyCyFQkGBy0',
(
'Risk',
'Risk_properties',
'RiskConsequences',
'RiskLevels',
'RiskMatrix',
'RiskControls',
'RiskAssessmentTechniques',
'RiskManagement',
'RiskMethodology',
'Justifications',
)),
('rights', '1XW-L6rGWbgGGp62q8eA22SWvh4wUWK5BpC0zfD6wAxM',
(
'Rights',
'Rights_properties',
'EUFundamentalRights',
)),
('rules', '1SDmlzSo1Ax_35v754Jzx4oFGKvGo5nyNtEAL0vSBbM0',
(
'Rules',
'Rules_properties',
)),
('standards', '1z-qaB2m6lD1ROmPVf9yhfG05D68Z7H4glYLERj6ZCRk',
(
'Standards_ISO',
)),
('ucr', '1__STWvOEZRc1u2J-8teOYjLpnTPlZ80_ebTytrUlWgQ',
(
'UseCase',
'Requirement',
'Example',
)),
# ('dpv-tech', '1GVmF4c7b-9xMSs0TyT45kXoCLLUVs8bbW34tfcozbuA',
# (
# 'tech-core',
# 'tech-core-properties',
# 'tech-data',
# 'tech-ops',
# 'tech-security',
# 'tech-surveillance',
# 'tech-provision',
# 'tech-provision-properties',
# 'tech-actors',
# 'tech-actors-properties',
# 'tech-comms',
# 'tech-comms-properties',
# 'tech-tools',
# 'tech_algorithms',
# )),
# ('risk', '1y8r3Vk-_Gi1MqbyAM6Ot4DoNDJpa2ZVhCyCyFQkGBy0',
# (
# 'Risk',
# 'Risk_properties',
# 'RiskConsequences',
# 'RiskLevels',
# 'RiskMatrix',
# 'RiskControls',
# 'RiskAssessmentTechniques',
# 'RiskManagement',
# 'RiskMethodology',
# 'Justifications',
# )),
# ('rights', '1XW-L6rGWbgGGp62q8eA22SWvh4wUWK5BpC0zfD6wAxM',
# (
# 'Rights',
# 'Rights_properties',
# 'EUFundamentalRights',
# )),
# ('rules', '1SDmlzSo1Ax_35v754Jzx4oFGKvGo5nyNtEAL0vSBbM0',
# (
# 'Rules',
# 'Rules_properties',
# )),
# ('standards', '1z-qaB2m6lD1ROmPVf9yhfG05D68Z7H4glYLERj6ZCRk',
# (
# 'Standards_ISO',
# )),
# ('ucr', '1__STWvOEZRc1u2J-8teOYjLpnTPlZ80_ebTytrUlWgQ',
# (
# 'UseCase',
# 'Requirement',
# 'Example',
# )),
)


Expand Down
14 changes: 13 additions & 1 deletion documentation-generator/002_parse_csv_to_rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,18 @@ def serialize_graph(graph, filepath):
for concept, _, _ in graph.triples((None, RDF.type, SKOS.Concept)):
graph.add((BASE[f'{name.title()}Concepts'], SKOS.member, concept))
DPV_GDPR_GRAPH.add((concept, SKOS.inScheme, DPV_GDPR['']))
# SPECIAL: Legal Basis to Rights Mappings
if name == "legal_basis":
DEBUG(f'Processing LegalBasis-Rights Mappings')
with open(f'{IMPORT_CSV_PATH}/GDPR_LegalBasis_Rights_Mapping.csv', 'r') as fd:
csvreader = csv.reader(fd)
terms = {}
labels = next(csvreader)
for row in csvreader:
for index, mapping in enumerate(row):
if mapping != "Y":
continue
graph.add((BASE[row[0]], DPV.hasRight, BASE[labels[index]]))
# serialize
serialize_graph(graph, f'{EXPORT_DPV_GDPR_MODULE_PATH}/{name}')
if 'topconcept' in module:
Expand Down Expand Up @@ -1037,7 +1049,7 @@ def serialize_graph(graph, filepath):
}

DPV_TECH_GRAPH = Graph()
proposed_terms = []
proposed_terms = {}
DEBUG('------')
DEBUG(f'Processing DPV-TECH')
for prefix, namespace in NAMESPACES.items():
Expand Down
12 changes: 12 additions & 0 deletions documentation-generator/002_parse_csv_to_rdf_owl.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,18 @@ def serialize_graph(graph, filepath):
proposed.extend(returnval)
if proposed:
proposed_terms[name] = proposed
# SPECIAL: Legal Basis to Rights Mappings
if name == "legal_basis":
DEBUG(f'Processing LegalBasis-Rights Mappings')
with open(f'{IMPORT_CSV_PATH}/GDPR_LegalBasis_Rights_Mapping.csv', 'r') as fd:
csvreader = csv.reader(fd)
terms = {}
labels = next(csvreader)
for row in csvreader:
for index, mapping in enumerate(row):
if mapping != "Y":
continue
graph.add((BASE[row[0]], DPVO.hasRight, BASE[labels[index]]))
# serialize
serialize_graph(graph, f'{EXPORT_DPV_GDPR_MODULE_PATH}/{name}')
DPV_GDPR_GRAPH += graph
Expand Down
14 changes: 13 additions & 1 deletion documentation-generator/002_parse_csv_to_rdf_skos.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,18 @@ def serialize_graph(graph, filepath):
for concept, _, _ in graph.triples((None, RDF.type, SKOS.Concept)):
graph.add((BASE[f'{name.title()}Concepts'], SKOS.member, concept))
DPV_GDPR_GRAPH.add((concept, SKOS.inScheme, DPV_GDPR['']))
# SPECIAL: Legal Basis to Rights Mappings
if name == "legal_basis":
DEBUG(f'Processing LegalBasis-Rights Mappings')
with open(f'{IMPORT_CSV_PATH}/GDPR_LegalBasis_Rights_Mapping.csv', 'r') as fd:
csvreader = csv.reader(fd)
terms = {}
labels = next(csvreader)
for row in csvreader:
for index, mapping in enumerate(row):
if mapping != "Y":
continue
graph.add((BASE[row[0]], DPVS.hasRight, BASE[labels[index]]))
# serialize
serialize_graph(graph, f'{EXPORT_DPV_GDPR_MODULE_PATH}/{name}')
if topconcept:
Expand Down Expand Up @@ -1086,7 +1098,7 @@ def serialize_graph(graph, filepath):
}

DPV_TECH_GRAPH = Graph()
proposed_terms = []
proposed_terms = {}
DEBUG('------')
DEBUG(f'Processing DPV-TECH')
for prefix, namespace in NAMESPACES.items():
Expand Down
19 changes: 14 additions & 5 deletions documentation-generator/003_generate_respec_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,21 @@ def get_namespace_reference(term):
load_data('legal_basis', f'{IMPORT_DPV_GDPR_MODULES_PATH}/legal_basis.ttl')
load_data('legal_basis_special', f'{IMPORT_DPV_GDPR_MODULES_PATH}/legal_basis_special.ttl')
load_data('legal_basis_data_transfer', f'{IMPORT_DPV_GDPR_MODULES_PATH}/legal_basis_data_transfer.ttl')
load_data('rights', f'{IMPORT_DPV_GDPR_MODULES_PATH}/rights.ttl')
load_data('data_transfers', f'{IMPORT_DPV_GDPR_MODULES_PATH}/data_transfers.ttl')
load_data('rights', f'{IMPORT_DPV_GDPR_MODULES_PATH}/rights.ttl')
load_data('dpia', f'{IMPORT_DPV_GDPR_MODULES_PATH}/dpia.ttl')
load_data('compliance', f'{IMPORT_DPV_GDPR_MODULES_PATH}/compliance.ttl')
g = Graph()
g.parse(f'{IMPORT_DPV_GDPR_PATH}', format='turtle')
G.parse(g)

lb_rights_map = []
for legalbasis in TEMPLATE_DATA['legal_basis_classes']:
rights = []
for right in legalbasis.dpv_hasRight:
for o_right in TEMPLATE_DATA['rights_classes']:
if right.iri != o_right.iri:
continue
rights.append((right.iri, o_right.skos_prefLabel))
lb_rights_map.append((legalbasis, sorted(rights, key=lambda x: x[0])))
TEMPLATE_DATA['legal_basis_rights_mapping'] = lb_rights_map

template = template_env.get_template('template_dpv_gdpr.jinja2')
with open(f'{EXPORT_DPV_GDPR_HTML_PATH}/index.html', 'w+') as fd:
Expand All @@ -197,7 +205,8 @@ def get_namespace_reference(term):
fd.write(template.render(**TEMPLATE_DATA))
DEBUG(f'wrote DPV-GDPR spec at f{EXPORT_DPV_GDPR_HTML_PATH}/dpv-gdpr.html')


import sys
sys.exit(0)
# DPV-PD: generate HTML

with open(f'{EXPORT_DPV_PD_HTML_PATH}/proposed.json') as fd:
Expand Down
16 changes: 12 additions & 4 deletions documentation-generator/003_generate_respec_html_owl.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,24 @@ def get_namespace_reference(term):
with open(f'{EXPORT_DPV_GDPR_HTML_PATH}/proposed.json', 'r') as fd:
TEMPLATE_DATA['proposed'] = json.load(fd)

load_data('rights', f'{IMPORT_DPV_GDPR_MODULES_PATH}/rights.ttl')
load_data('legal_basis', f'{IMPORT_DPV_GDPR_MODULES_PATH}/legal_basis.ttl')
load_data('legal_basis_special', f'{IMPORT_DPV_GDPR_MODULES_PATH}/legal_basis_special.ttl')
load_data('legal_basis_data_transfer', f'{IMPORT_DPV_GDPR_MODULES_PATH}/legal_basis_data_transfer.ttl')
load_data('rights', f'{IMPORT_DPV_GDPR_MODULES_PATH}/rights.ttl')
load_data('data_transfers', f'{IMPORT_DPV_GDPR_MODULES_PATH}/data_transfers.ttl')
load_data('dpia', f'{IMPORT_DPV_GDPR_MODULES_PATH}/dpia.ttl')
load_data('compliance', f'{IMPORT_DPV_GDPR_MODULES_PATH}/compliance.ttl')
g = Graph()
g.parse(f'{IMPORT_DPV_GDPR_PATH}', format='turtle')
G.parse(g)

lb_rights_map = []
for legalbasis in TEMPLATE_DATA['legal_basis_classes']:
rights = []
for right in legalbasis.dpvo_hasRight:
for o_right in TEMPLATE_DATA['rights_classes']:
if right.iri != o_right.iri:
continue
rights.append((right.iri, o_right.rdfs_label))
lb_rights_map.append((legalbasis, sorted(rights, key=lambda x: x[0])))
TEMPLATE_DATA['legal_basis_rights_mapping'] = lb_rights_map

template = template_env.get_template('template_dpv_gdpr_owl.jinja2')
with open(f'{EXPORT_DPV_GDPR_HTML_PATH}/index.html', 'w+') as fd:
Expand Down
Loading

0 comments on commit eb69b62

Please sign in to comment.