-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_licensing.py
70 lines (54 loc) · 2 KB
/
check_licensing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
"""
[Martinez-Gil2023d] Framework to Automatically Determine the Quality of Open Data Catalogs, arXiv preprint arXiv:2307.15464, 2023
@author: Jorge Martinez-Gil
"""
import sys
from rdflib import Graph, RDF, Namespace
# Define the RDF namespaces
dcat = Namespace("http://www.w3.org/ns/dcat#")
foaf = Namespace("http://xmlns.com/foaf/0.1/")
rdf = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
rdfs = Namespace("http://www.w3.org/2000/01/rdf-schema#")
xsd = Namespace("http://www.w3.org/2001/XMLSchema#")
dcterms = Namespace("http://purl.org/dc/terms/")
prov = Namespace("http://www.w3.org/ns/prov#")
def check_licensing(rdf_data):
"""
Check the licensing of an RDF data string and return the percentage of datasets that have a license.
Args:
rdf_data (str): The RDF data string to check.
Returns:
float: The percentage of datasets that have a license, between 0 and 100.
"""
graph = Graph()
graph.parse(data=rdf_data, format="turtle")
# Count licensed items and total items in all datasets
licensed_items = 0
total_items = 0
for subject in graph.subjects(RDF.type, dcat.Dataset):
for s, p, o in graph.triples((subject, dcterms.license, None)):
licensed_items += 1
total_items += 1
# Calculate percentage of licensed items
if total_items == 0:
return 0
else:
return licensed_items / total_items * 100
"""
This program checks the licensing of a Data Catalog.
Usage: python check_licensing.py filepath
"""
def main():
# Get path to RDF data file from command line argument
if len(sys.argv) < 2:
print("Usage: python check_licensing.py filepath")
sys.exit(1)
rdf_data_path = sys.argv[1]
# Load RDF data from file
with open(rdf_data_path, "r", encoding="utf-8") as f:
rdf_data = f.read()
result = check_licensing(rdf_data)
print(f"The licensing of {rdf_data_path} is {result}.")
if __name__ == "__main__":
main()