Skip to content

Commit b1a825a

Browse files
committed
markdown comment conversion
1 parent 3c721cb commit b1a825a

7 files changed

Lines changed: 212 additions & 62 deletions

File tree

data.ttl

Lines changed: 81 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
PREFIX ont: <https://paulduchesne.github.io/state/ontology/>
22
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
33

4+
<https://paulduchesne.github.io/state/resource/ad8600ce-fe98-4212-b3d8-0105abdaa567>
5+
a ont:Organisation ;
6+
rdfs:label "International Federation of Film Archives"@en ;
7+
rdfs:comment "Primary international association of film archives."@en ;
8+
ont:wikidataIdentifier "Q586693" ;
9+
.
10+
411
<https://paulduchesne.github.io/state/resource/10f8d9fa-2da2-449b-9946-3126c9584052>
512
a ont:Institution ;
613
rdfs:label "Bundesarchiv" ;
@@ -13,6 +20,7 @@ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
1320
a ont:Person ;
1421
rdfs:label "Mariana Enríquez"@en ;
1522
rdfs:comment "Argentinian writer."@en ;
23+
ont:authorOf <https://paulduchesne.github.io/state/resource/90c8c4ca-4ccf-4aca-b021-d480efd1abb6> ;
1624
ont:wikidataIdentifier "Q5997426" ;
1725
.
1826

@@ -24,21 +32,11 @@ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
2432
ont:wikidataIdentifier "Q42369365" ;
2533
.
2634

27-
<https://paulduchesne.github.io/state/resource/2ed97264-8762-4f68-a8ab-06b6e3b1adfe>
28-
a ont:ReadingEvent ;
29-
rdfs:label "Reading 'The School of Night'"@en ;
30-
rdfs:comment "Reading event."@en ;
31-
ont:endDate "2025-12-03" ;
32-
ont:hasParticipant
33-
<https://paulduchesne.github.io/state/resource/0ef53722-52ca-49c8-873d-3549a74914e8> ,
34-
<https://paulduchesne.github.io/state/resource/6b433c3a-855a-4ddd-bf14-6ed6d75b472f> ;
35-
ont:startDate "2025-11-23" ;
36-
.
37-
3835
<https://paulduchesne.github.io/state/resource/3b811069-fff1-4393-b16b-ef02de3b5ff9>
3936
a ont:Person ;
4037
rdfs:label "Anna Kavan" ;
4138
rdfs:comment "British writer." ;
39+
ont:authorOf <https://paulduchesne.github.io/state/resource/727f0b29-fd9c-429d-a264-5af913651d73> ;
4240
ont:wikidataIdentifier "Q287679" ;
4341
.
4442

@@ -54,15 +52,61 @@ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
5452
a ont:Person ;
5553
rdfs:label "Annie Ernaux" ;
5654
rdfs:comment "French Nobel-prize winning author." ;
55+
ont:authorOf <https://paulduchesne.github.io/state/resource/ec0545af-f371-4df8-a0ef-5196c8a27859> ;
5756
ont:wikidataIdentifier "Q1153825" ;
5857
.
5958

59+
<https://paulduchesne.github.io/state/resource/90d15936-a042-4151-944d-ac2ab282a448>
60+
a ont:Person ;
61+
rdfs:label "Paul Bowles"@en ;
62+
rdfs:comment "American writer."@en ;
63+
ont:authorOf <https://paulduchesne.github.io/state/resource/b300b5e9-1250-43d4-81db-7fe0e3946bc9> ;
64+
ont:wikidataIdentifier "Q358342" ;
65+
.
66+
67+
<https://paulduchesne.github.io/state/resource/b7315610-4737-4c68-934a-0a1fbe09d281>
68+
a ont:Person ;
69+
rdfs:label "Slavoj Zizek" ;
70+
rdfs:comment "Slovenian neo-Marxist philosopher." ;
71+
ont:authorOf <https://paulduchesne.github.io/state/resource/ba8048d3-a13c-4964-9d80-a04e0c50c0ba> ;
72+
ont:wikidataIdentifier "Q184750" ;
73+
.
74+
75+
<https://paulduchesne.github.io/state/resource/de97655c-95a8-4cfe-954f-a48142b3ca83>
76+
a ont:Person ;
77+
rdfs:label "Karl Ove Knausgaard"@en ;
78+
rdfs:comment "Norwegian writer."@en ;
79+
ont:authorOf <https://paulduchesne.github.io/state/resource/6b433c3a-855a-4ddd-bf14-6ed6d75b472f> ;
80+
ont:wikidataIdentifier "Q609317" ;
81+
.
82+
83+
<https://paulduchesne.github.io/state/resource/2ebe1653-01bb-4558-97eb-3f1ce794dd5a>
84+
a ont:Event ;
85+
rdfs:label "iPRES 2025" ;
86+
rdfs:comment "The 2025 iteration of the [iPRES]() conference, held in [Wellington]()." ;
87+
ont:hasParticipant
88+
<https://paulduchesne.github.io/state/resource/0ef53722-52ca-49c8-873d-3549a74914e8> ,
89+
<https://paulduchesne.github.io/state/resource/d2d8ae17-8d48-4256-931e-4f24ecf61f60> ;
90+
.
91+
92+
<https://paulduchesne.github.io/state/resource/2ed97264-8762-4f68-a8ab-06b6e3b1adfe>
93+
a ont:ReadingEvent ;
94+
rdfs:label "Reading 'The School of Night'"@en ;
95+
rdfs:comment "Reading event."@en ;
96+
ont:endDate "2025-12-03" ;
97+
ont:hasParticipant
98+
<https://paulduchesne.github.io/state/resource/0ef53722-52ca-49c8-873d-3549a74914e8> ,
99+
<https://paulduchesne.github.io/state/resource/6b433c3a-855a-4ddd-bf14-6ed6d75b472f> ;
100+
ont:startDate "2025-11-23" ;
101+
.
102+
60103
<https://paulduchesne.github.io/state/resource/6b433c3a-855a-4ddd-bf14-6ed6d75b472f>
61104
a ont:Book ;
62105
rdfs:label "The School of Night"@en ;
63106
rdfs:comment "Book by Karl Ove Knausgaard"@en ;
64107
ont:hasAuthor <https://paulduchesne.github.io/state/resource/de97655c-95a8-4cfe-954f-a48142b3ca83> ;
65108
ont:identifier "9781787304215" ;
109+
ont:participatedIn <https://paulduchesne.github.io/state/resource/2ed97264-8762-4f68-a8ab-06b6e3b1adfe> ;
66110
.
67111

68112
<https://paulduchesne.github.io/state/resource/6b440e4a-fbcd-45b9-a3fd-8a2dbf930877>
@@ -96,19 +140,24 @@ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
96140
ont:startDate "2025-12-04" ;
97141
.
98142

143+
<https://paulduchesne.github.io/state/resource/86477d45-4c1a-4f95-841d-a3fc2d8ffa25>
144+
a ont:ReadingEvent ;
145+
rdfs:label "Reading 'I Remain in Darkness'" ;
146+
rdfs:comment "Reading event." ;
147+
ont:endDate "2025-11-10" ;
148+
ont:hasParticipant
149+
<https://paulduchesne.github.io/state/resource/0ef53722-52ca-49c8-873d-3549a74914e8> ,
150+
<https://paulduchesne.github.io/state/resource/ec0545af-f371-4df8-a0ef-5196c8a27859> ;
151+
ont:startDate "2025-11-09" ;
152+
.
153+
99154
<https://paulduchesne.github.io/state/resource/90c8c4ca-4ccf-4aca-b021-d480efd1abb6>
100155
a ont:Book ;
101156
rdfs:label "Our Share of Night"@en ;
102157
rdfs:comment "Book by Mariana Enríquez"@en ;
103158
ont:hasAuthor <https://paulduchesne.github.io/state/resource/15ba58be-34a3-4380-baed-733ae0c5f07a> ;
104159
ont:identifier "9780451495150" ;
105-
.
106-
107-
<https://paulduchesne.github.io/state/resource/90d15936-a042-4151-944d-ac2ab282a448>
108-
a ont:Person ;
109-
rdfs:label "Paul Bowles"@en ;
110-
rdfs:comment "American writer."@en ;
111-
ont:wikidataIdentifier "Q358342" ;
160+
ont:participatedIn <https://paulduchesne.github.io/state/resource/6b440e4a-fbcd-45b9-a3fd-8a2dbf930877> ;
112161
.
113162

114163
<https://paulduchesne.github.io/state/resource/b300b5e9-1250-43d4-81db-7fe0e3946bc9>
@@ -117,13 +166,7 @@ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
117166
rdfs:comment "Book by Paul Bowles"@en ;
118167
ont:hasAuthor <https://paulduchesne.github.io/state/resource/90d15936-a042-4151-944d-ac2ab282a448> ;
119168
ont:identifier "9780141187778" ;
120-
.
121-
122-
<https://paulduchesne.github.io/state/resource/b7315610-4737-4c68-934a-0a1fbe09d281>
123-
a ont:Person ;
124-
rdfs:label "Slavoj Zizek" ;
125-
rdfs:comment "Slovenian neo-Marxist philosopher." ;
126-
ont:wikidataIdentifier "Q184750" ;
169+
ont:participatedIn <https://paulduchesne.github.io/state/resource/780a127f-b83f-4ecf-9e05-752a82faecf8> ;
127170
.
128171

129172
<https://paulduchesne.github.io/state/resource/b8744ea7-c182-47c2-bf31-37e6ed6df396>
@@ -154,39 +197,6 @@ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
154197
ont:wikidataIdentifier "Q57970405" ;
155198
.
156199

157-
<https://paulduchesne.github.io/state/resource/de97655c-95a8-4cfe-954f-a48142b3ca83>
158-
a ont:Person ;
159-
rdfs:label "Karl Ove Knausgaard"@en ;
160-
rdfs:comment "Norwegian writer."@en ;
161-
ont:wikidataIdentifier "Q609317" ;
162-
.
163-
164-
<https://paulduchesne.github.io/state/resource/ec0545af-f371-4df8-a0ef-5196c8a27859>
165-
a ont:Book ;
166-
rdfs:label "I Remain in Darkness" ;
167-
rdfs:comment "1997 book by Annie Ernaux." ;
168-
ont:hasAuthor <https://paulduchesne.github.io/state/resource/585e1cc0-3883-40f9-a036-7e9bae25077e> ;
169-
ont:identifier "9781910695975" ;
170-
ont:participatedIn <https://paulduchesne.github.io/state/resource/86477d45-4c1a-4f95-841d-a3fc2d8ffa25> ;
171-
.
172-
173-
<https://paulduchesne.github.io/state/resource/2ebe1653-01bb-4558-97eb-3f1ce794dd5a>
174-
a ont:Event ;
175-
rdfs:label "iPRES 2025" ;
176-
rdfs:comment "The 2025 iteration of the [iPRES]() conference, held in [Wellington]()." ;
177-
.
178-
179-
<https://paulduchesne.github.io/state/resource/86477d45-4c1a-4f95-841d-a3fc2d8ffa25>
180-
a ont:ReadingEvent ;
181-
rdfs:label "Reading 'I Remain in Darkness'" ;
182-
rdfs:comment "Reading event." ;
183-
ont:endDate "2025-11-10" ;
184-
ont:hasParticipant
185-
<https://paulduchesne.github.io/state/resource/0ef53722-52ca-49c8-873d-3549a74914e8> ,
186-
<https://paulduchesne.github.io/state/resource/ec0545af-f371-4df8-a0ef-5196c8a27859> ;
187-
ont:startDate "2025-11-09" ;
188-
.
189-
190200
<https://paulduchesne.github.io/state/resource/df0b77c1-6b2c-4bd4-904e-9921848978d0>
191201
a ont:ReadingEvent ;
192202
rdfs:label "Reading 'Machines in the Head'"@en ;
@@ -208,6 +218,15 @@ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
208218
ont:wikidataIdentifier "Q2565882" ;
209219
.
210220

221+
<https://paulduchesne.github.io/state/resource/ec0545af-f371-4df8-a0ef-5196c8a27859>
222+
a ont:Book ;
223+
rdfs:label "I Remain in Darkness" ;
224+
rdfs:comment "1997 book by Annie Ernaux." ;
225+
ont:hasAuthor <https://paulduchesne.github.io/state/resource/585e1cc0-3883-40f9-a036-7e9bae25077e> ;
226+
ont:identifier "9781910695975" ;
227+
ont:participatedIn <https://paulduchesne.github.io/state/resource/86477d45-4c1a-4f95-841d-a3fc2d8ffa25> ;
228+
.
229+
211230
<https://paulduchesne.github.io/state/resource/fe923883-a71b-460f-99a0-d8abf05a2281>
212231
a ont:ReadingEvent ;
213232
rdfs:label "Reading 'Against Progress'" ;
@@ -222,8 +241,10 @@ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
222241
<https://paulduchesne.github.io/state/resource/0ef53722-52ca-49c8-873d-3549a74914e8>
223242
a ont:Person ;
224243
rdfs:label "Paul Duchesne" ;
225-
rdfs:comment "Paul Duchesne is a film archivist and software developer, based in Canberra. He has worked for the <a href='https://paulduchesne.github.io/state/resource/e5e95fdb-dda9-4c40-9273-395fe34aba3c'>NFSA</a> and <a href='https://paulduchesne.github.io/state/resource/b8744ea7-c182-47c2-bf31-37e6ed6df396'>TIB</a>, and is a member of the <a href=''>FIAF</a> <a href=''>Cataloguing and Documentation Commission</a>." ;
226-
ont:memberOf <https://paulduchesne.github.io/state/resource/e5e95fdb-dda9-4c40-9273-395fe34aba3c> ;
244+
rdfs:comment "Paul Duchesne is a film archivist and software developer, based in Canberra. He has worked for the [NFSA](https://paulduchesne.github.io/state/resource/e5e95fdb-dda9-4c40-9273-395fe34aba3c) and [TIB](https://paulduchesne.github.io/state/resource/b8744ea7-c182-47c2-bf31-37e6ed6df396), and is a member of the [FIAF](https://paulduchesne.github.io/state/resource/ad8600ce-fe98-4212-b3d8-0105abdaa567) [Cataloguing and Documentation Commission]()." ;
245+
ont:memberOf
246+
<https://paulduchesne.github.io/state/resource/b8744ea7-c182-47c2-bf31-37e6ed6df396> ,
247+
<https://paulduchesne.github.io/state/resource/e5e95fdb-dda9-4c40-9273-395fe34aba3c> ;
227248
ont:participatedIn
228249
<https://paulduchesne.github.io/state/resource/2ebe1653-01bb-4558-97eb-3f1ce794dd5a> ,
229250
<https://paulduchesne.github.io/state/resource/2ed97264-8762-4f68-a8ab-06b6e3b1adfe> ,

main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from flask import Flask, render_template
22
from flask_frozen import Freezer
3+
import markdown
34
import pathlib
45
import pydash
56
import rdflib
@@ -51,7 +52,7 @@ def extract_text(uriref, prop):
5152
# node comment.
5253

5354
for x in node_array.keys():
54-
node_array[x]['comment'] = extract_text(x, rdflib.RDFS.comment)
55+
node_array[x]['comment'] = markdown.markdown(extract_text(x, rdflib.RDFS.comment))
5556

5657
# node statements.
5758

ontology.ttl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,17 @@ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
127127
rdfs:label "Has Author"@en ;
128128
rdfs:comment "Person responsible for the text of a book."@en ;
129129
rdfs:domain ont:Book ;
130-
rdfs:range ont:Person ;
130+
rdfs:range ont:Person ;
131+
owl:inverseOf ont:authorOf ;
132+
.
133+
134+
<https://paulduchesne.github.io/state/ontology/authorOf>
135+
a owl:ObjectProperty ;
136+
rdfs:label "Author Of"@en ;
137+
rdfs:comment "Books written by the author."@en ;
138+
rdfs:domain ont:Person ;
139+
rdfs:range ont:Book ;
140+
owl:inverseOf ont:hasAuthor ;
131141
.
132142

133143
# owl:DatatypeProperty

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ requires-python = ">=3.13"
77
dependencies = [
88
"flask>=3.1.2",
99
"frozen-flask>=1.0.2",
10+
"markdown>=3.10",
1011
"pydash>=8.0.5",
1112
"rdflib>=7.4.0",
1213
]

utilities/add_organisation.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
# add organisation to graph.
3+
# note that this assumes no two individuals with the same name!
4+
5+
import pathlib
6+
import rdflib
7+
import uuid
8+
9+
# information to be added.
10+
11+
org = {
12+
"label": "International Federation of Film Archives",
13+
"comment": "Primary international association of film archives.",
14+
"wikidata": "Q586693",
15+
}
16+
17+
# load existing graph.
18+
19+
data_path = pathlib.Path.cwd().parent / 'data.ttl'
20+
if not data_path.exists():
21+
raise Exception('File not found.')
22+
data = rdflib.Graph().parse(data_path)
23+
24+
# pull or mind id.
25+
26+
org['id'] = f"https://paulduchesne.github.io/state/resource/{str(uuid.uuid4())}"
27+
orgs = [s for s,p,o in data.triples((None, rdflib.RDF.type, rdflib.URIRef('https://paulduchesne.github.io/state/ontology/Organisation')))]
28+
for p in orgs:
29+
for a,b,c in data.triples((p, rdflib.RDFS.label, None)):
30+
if str(c) == org['label']:
31+
org['id'] = p
32+
33+
print(org)
34+
35+
# add label.
36+
37+
data.add((rdflib.URIRef(org['id']), rdflib.RDF.type, rdflib.URIRef('https://paulduchesne.github.io/state/ontology/Organisation')))
38+
data.add((rdflib.URIRef(org['id']), rdflib.RDFS.label, rdflib.Literal(org['label'], lang='en')))
39+
40+
# add comment.
41+
42+
if len(org['comment']):
43+
comment = [o for s,p,o in data.triples((rdflib.URIRef(org['id']), rdflib.RDFS.comment, None))]
44+
if not len(comment):
45+
data.add((rdflib.URIRef(org['id']), rdflib.RDFS.comment, rdflib.Literal(org['comment'], lang='en')))
46+
47+
# add wikidata.
48+
49+
if len(org['wikidata']):
50+
wikidata = [o for s,p,o in data.triples((rdflib.URIRef(org['id']), rdflib.URIRef('https://paulduchesne.github.io/state/ontology/wikidataIdentifier'), None))]
51+
if not len(wikidata):
52+
data.add((rdflib.URIRef(org['id']), rdflib.URIRef('https://paulduchesne.github.io/state/ontology/wikidataIdentifier'), rdflib.Literal(org['wikidata'])))
53+
54+
# write to graph.
55+
56+
data.serialize(data_path, format='longturtle')
57+

utilities/validate_inverse.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
# validate inverse properties.
3+
4+
import pathlib
5+
import pydash
6+
import rdflib
7+
8+
def raise_exception(s,p,o):
9+
s_name = pathlib.Path(s).name
10+
p_name = pathlib.Path(p).name
11+
o_name = pathlib.Path(o).name
12+
raise Exception(f'Inverse of {s_name} {p_name} {o_name} not found.')
13+
14+
# load ontology.
15+
16+
ontology_path = pathlib.Path.cwd().parent / 'ontology.ttl'
17+
if not ontology_path.exists():
18+
raise Exception('File not found.')
19+
ontology = rdflib.Graph().parse(ontology_path)
20+
21+
# detect inverse properties.
22+
23+
inverse_pairs = list()
24+
for s,p,o in ontology.triples((None, rdflib.RDF.type, rdflib.OWL.ObjectProperty)):
25+
for a,b,c in ontology.triples((s, rdflib.OWL.inverseOf, None)):
26+
inverse_pairs.append(sorted([s, c]))
27+
28+
inverse_pairs = pydash.uniq(inverse_pairs)
29+
30+
# load data.
31+
32+
data_path = pathlib.Path.cwd().parent / 'data.ttl'
33+
if not data_path.exists():
34+
raise Exception('File not found.')
35+
data = rdflib.Graph().parse(data_path)
36+
37+
38+
for props in inverse_pairs:
39+
for s,p,o in data.triples((None, props[0], None)):
40+
inverse = [(a,b,c) for a,b,c in data.triples((o, props[1], s))]
41+
if len(inverse) != 1:
42+
raise_exception(s,p,o)
43+
44+
for s,p,o in data.triples((None, props[1], None)):
45+
inverse = [(a,b,c) for a,b,c in data.triples((o, props[0], s))]
46+
if len(inverse) != 1:
47+
raise_exception(s,p,o)
48+
49+

0 commit comments

Comments
 (0)