-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsemopenalex-dataset.py
147 lines (123 loc) · 7.66 KB
/
semopenalex-dataset.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from rdflib import Graph, URIRef, Literal, Dataset
from rdflib.namespace import RDFS, XSD, SKOS, RDF
from rdflib import Namespace
from datetime import datetime
from datetime import date
from pathlib import Path
import time
import os
start_time = time.ctime()
print('Start to create .trig parsing and graph serialization for SemOpenAlex dataset at: '+ start_time)
today = date.today()
absolute_path = os.path.dirname(__file__)
trig_output_dir_path = os.path.join(absolute_path, '../graphdb-preload/graphdb-import/')
trig_output_file_path = f'{trig_output_dir_path}semopenalex-dataset-{today}.trig'
DCAT = Namespace("http://www.w3.org/ns/dcat#")
DCTERMS = Namespace("http://purl.org/dc/terms/")
FOAF = Namespace("http://xmlns.com/foaf/0.1/")
# semopenalex dataset context
context = URIRef("https://semopenalex.org/dataset/context")
# semopenalex dataset subject IRI
dataset = URIRef("http://datasets.semopenalex.org/dcat/semopenalex")
# namedGraph predicate
namedGraph = URIRef("http://www.w3.org/ns/sparql-service-description#namedGraph")
# dataset issued time
data_issued_time = datetime.now()
# list of semopenalex predefined named graphs
concepts_context = URIRef("https://semopenalex.org/concepts/context")
institutions_context = URIRef("https://semopenalex.org/institutions/context")
sources_context = URIRef("https://semopenalex.org/sources/context")
authors_context = URIRef("https://semopenalex.org/authors/context")
works_context = URIRef("https://semopenalex.org/works/context")
publishers_context = URIRef("https://semopenalex.org/publishers/context")
funders_context = URIRef("https://semopenalex.org/funders/context")
topics_context = URIRef("https://semopenalex.org/topics/context")
keywords_context = URIRef("https://semopenalex.org/keywords/context")
#create empty graph
g = Graph(identifier=context)
g.add((dataset, RDF.type, DCAT.Dataset))
g.add((dataset, DCTERMS.title, Literal("SemOpenAlex", datatype = XSD.string)))
g.add((dataset, DCTERMS.description, Literal("SemOpenAlex is a scientific publications dataset, presently in the form of a knowledge graph. It also offered as the basis for Knowledge Graph augmentation together with some possible use-cases that can enable AI-driven decision making.", datatype = XSD.string)))
g.add((dataset, DCTERMS.issued, Literal(data_issued_time, datatype = XSD.dateTime)))
g.add((dataset, DCTERMS.license, Literal("https://creativecommons.org/publicdomain/zero/1.0/legalcode", datatype = XSD.anyURI)))
# keywords
g.add((dataset, DCAT.version, Literal("5.0.0", datatype = XSD.string)))
g.add((dataset, DCAT.keyword, Literal("concepts", datatype = XSD.string)))
g.add((dataset, DCAT.keyword, Literal("topics", datatype = XSD.string)))
g.add((dataset, DCAT.keyword, Literal("keywords", datatype = XSD.string)))
g.add((dataset, DCAT.keyword, Literal("institutions", datatype = XSD.string)))
g.add((dataset, DCAT.keyword, Literal("sources", datatype = XSD.string)))
g.add((dataset, DCAT.keyword, Literal("authors", datatype = XSD.string)))
g.add((dataset, DCAT.keyword, Literal("publishers", datatype = XSD.string)))
g.add((dataset, DCAT.keyword, Literal("works", datatype = XSD.string)))
g.add((dataset, DCAT.keyword, Literal("funders", datatype = XSD.string)))
g.add((dataset, DCAT.keyword, Literal("geo", datatype = XSD.string)))
# linked named graphs
g.add((dataset, namedGraph, concepts_context))
g.add((dataset, namedGraph, institutions_context))
g.add((dataset, namedGraph, sources_context))
g.add((dataset, namedGraph, authors_context))
g.add((dataset, namedGraph, works_context))
g.add((dataset, namedGraph, publishers_context))
g.add((dataset, namedGraph, funders_context))
g.add((dataset, namedGraph, topics_context))
g.add((dataset, namedGraph, keywords_context))
# creators
metaphacts = URIRef("http://www.wikidata.org/entity/Q22132500")
g.add((dataset, DCTERMS.creator, metaphacts))
g.add((metaphacts, RDF.type, FOAF.Organization))
g.add((metaphacts, FOAF.name, Literal("metaphacts GmbH", datatype = XSD.string)))
aifb = URIRef("http://dbpedia.org/resource/Karlsruhe_Institute_of_Technology")
g.add((dataset, DCTERMS.creator, aifb))
g.add((aifb, RDF.type, FOAF.Organization))
g.add((aifb, FOAF.name, Literal("Institute AIFB, Karlsruhe Institute of Technology (KIT)", datatype = XSD.string)))
tu_dresden = URIRef("http://www.wikidata.org/entity/Q158158")
g.add((dataset, DCTERMS.creator, tu_dresden))
g.add((tu_dresden, RDF.type, FOAF.Organization))
g.add((tu_dresden, FOAF.name, Literal("ScaDS.AI & TU Dresden", datatype = XSD.string)))
# distributions
format = URIRef("http://purl.org/dc/terms/format")
dist_v1 = URIRef("http://datasets.semopenalex.org/v1/semopenalex-distribution")
g.add((dataset, DCAT.distribution, dist_v1))
g.add((dist_v1, RDF.type, DCAT.Distribution))
g.add((dist_v1, DCTERMS.issued, Literal("2022-05-12", datatype = XSD.date)))
g.add((dist_v1, DCTERMS.title, Literal("SemOpenAlex RDF dump", datatype = XSD.string)))
g.add((dist_v1, format, Literal("N-Triples", datatype = XSD.string)))
g.add((dist_v1, DCAT.mediaType, Literal("text/plain", datatype = XSD.string)))
g.add((dist_v1, DCAT.accessURL, Literal("https://semopenalex.s3.amazonaws.com/browse.html", datatype = XSD.anyURI)))
dist_v2 = URIRef("http://datasets.semopenalex.org/v2/semopenalex-distribution")
g.add((dataset, DCAT.distribution, dist_v2))
g.add((dist_v2, RDF.type, DCAT.Distribution))
g.add((dist_v2, DCTERMS.issued, Literal("2022-11-21", datatype = XSD.date)))
g.add((dist_v2, DCTERMS.title, Literal("SemOpenAlex RDF dump", datatype = XSD.string)))
g.add((dist_v2, format, Literal("TriG", datatype = XSD.string)))
g.add((dist_v2, DCAT.mediaType, Literal("application/x-trig", datatype = XSD.string)))
g.add((dist_v2, DCAT.accessURL, Literal("https://semopenalex.s3.amazonaws.com/browse.html", datatype = XSD.anyURI)))
dist_v3 = URIRef("http://datasets.semopenalex.org/v3/semopenalex-distribution")
g.add((dataset, DCAT.distribution, dist_v3))
g.add((dist_v3, RDF.type, DCAT.Distribution))
g.add((dist_v3, DCTERMS.issued, Literal("2023-04-24", datatype = XSD.date)))
g.add((dist_v3, DCTERMS.title, Literal("SemOpenAlex RDF dump", datatype = XSD.string)))
g.add((dist_v3, format, Literal("TriG", datatype = XSD.string)))
g.add((dist_v3, DCAT.mediaType, Literal("application/x-trig", datatype = XSD.string)))
g.add((dist_v3, DCAT.accessURL, Literal("https://semopenalex.s3.amazonaws.com/browse.html", datatype = XSD.anyURI)))
dist_v4 = URIRef("http://datasets.semopenalex.org/v4/semopenalex-distribution")
g.add((dataset, DCAT.distribution, dist_v4))
g.add((dist_v4, RDF.type, DCAT.Distribution))
g.add((dist_v4, DCTERMS.issued, Literal("2023-10-28", datatype = XSD.date)))
g.add((dist_v4, DCTERMS.title, Literal("SemOpenAlex RDF dump", datatype = XSD.string)))
g.add((dist_v4, format, Literal("TriG", datatype = XSD.string)))
g.add((dist_v4, DCAT.mediaType, Literal("application/x-trig", datatype = XSD.string)))
g.add((dist_v4, DCAT.accessURL, Literal("https://semopenalex.s3.amazonaws.com/browse.html", datatype = XSD.anyURI)))
dist_v5 = URIRef("http://datasets.semopenalex.org/v5/semopenalex-distribution")
g.add((dataset, DCAT.distribution, dist_v5))
g.add((dist_v5, RDF.type, DCAT.Distribution))
g.add((dist_v5, DCTERMS.issued, Literal(today, datatype = XSD.date)))
g.add((dist_v5, DCTERMS.title, Literal("SemOpenAlex RDF dump", datatype = XSD.string)))
g.add((dist_v5, format, Literal("TriG", datatype = XSD.string)))
g.add((dist_v5, DCAT.mediaType, Literal("application/x-trig", datatype = XSD.string)))
g.add((dist_v5, DCAT.accessURL, Literal("https://semopenalex.s3.amazonaws.com/browse.html", datatype = XSD.anyURI)))
with open(trig_output_file_path, "w", encoding="utf-8") as dataset_file:
dataset_file.write(g.serialize(format='trig'))
dataset_file.close()
print("Done with .trig parsing and graph serialization for SemOpenAlex dataset.")