forked from sroertgen/oeh-framework-bb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml_to_skos_kompetenzen.py
47 lines (34 loc) · 1.12 KB
/
xml_to_skos_kompetenzen.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
from lxml import etree as ET
from rdflib import Graph, Literal, Namespace, RDF, URIRef, BNode
from rdflib.namespace import SKOS, DCTERMS
from pathlib import Path
import re
import uuid
import os
from xml_to_skos import parseXML, sortData, addToNode, buildSkos, writeGraph, writeLog
log = []
tree = ET.parse("data/rlp-bb-edited.xml")
# remove <themainhalt>
for themainhalt in tree.xpath("//themainhalt"):
themainhalt.getparent().remove(themainhalt)
xmlRoot = tree.getroot()
parsedXML, logging = parseXML(xmlRoot, tree)
log.extend(logging)
data, logging = sortData(parsedXML)
log.extend(logging)
nodes = addToNode(data)
serialized_graph = buildSkos(
nodes,
name_of_graph="RLP Berlin-Brandenburg Kompetenzen",
base_url="http://opencurricula/berlin-brandenburg/competences/"
)
# create data dir if not there
Path(Path.cwd() / "data").mkdir(exist_ok=True)
# write graph
graphname = (Path.cwd() / "data" / "curriculum_bb_competences_skos.ttl")
writeGraph(graphname, serialized_graph)
# write error log
print(log)
log_filename = (Path.cwd() / "log-competences.txt")
writeLog(log_filename, log)
print("I'm done. Goodbye!")