Skip to content

Commit

Permalink
more skos uri playing
Browse files Browse the repository at this point in the history
  • Loading branch information
LasseMempel committed Sep 19, 2024
1 parent 6ada632 commit ef097f3
Show file tree
Hide file tree
Showing 2 changed files with 275 additions and 273 deletions.
26 changes: 14 additions & 12 deletions addSchemeToConcepts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
# declare namespace for annotation ontology
AO = rdflib.Namespace("http://www.w3.org/ns/oa#")


# load "annotationScheme.ttl" into the triplestore
with open("annotationScheme.ttl", "r") as f:
annotationScheme = f.read()
g = rdflib.Graph()
uri1 = "annotations/ConceptScheme1/"

schemeURI = "https://restaurierungsvokabular.solidweb.org/annotations/ConceptSchemes/ConceptScheme1"
conceptURI = "https://restaurierungsvokabular.solidweb.org/annotations/ConceptSchemes/ConceptScheme1/Concepts/"
annotationURI = "https://restaurierungsvokabular.solidweb.org/annotations/ConceptScheme1/Annotations/"

# parse the annotationScheme into the triplestore
g.parse(data=annotationScheme, format="turtle")
Expand All @@ -19,33 +21,33 @@
h = rdflib.Graph()

#add conceptSchemes uri1 to the new triplestore
h.add((URIRef(uri1), RDF.type, SKOS.ConceptScheme))
h.add((URIRef(schemeURI), RDF.type, SKOS.ConceptScheme))
# add title "LEIZA Restaurierungs- und Konservierungsthesaurus" to the new triplestore
h.add((URIRef(uri1), DCTERMS.title, Literal("LEIZA Restaurierungs- und Konservierungsthesaurus")))
h.add((URIRef(schemeURI), DCTERMS.title, Literal("LEIZA Restaurierungs- und Konservierungsthesaurus")))

#iterate over all concepts in the triplestore
for concept in g.subjects(RDF.type, SKOS.Concept):
id = concept.split("/concept")[-1]
# add concept to the new triplestore as a skos:Concept as uri+id
h.add((URIRef(uri1+id), RDF.type, SKOS.Concept))
h.add((URIRef(conceptURI+id), RDF.type, SKOS.Concept))
# add property skos:inScheme to the concept
h.add((URIRef(uri1+id), SKOS.inScheme, URIRef(uri1)))
h.add((URIRef(conceptURI+id), SKOS.inScheme, URIRef(schemeURI)))

# iterate over all annotations in the triplestore
for annotation in g.subjects(RDF.type, AO.Annotation):
id = annotation.split("/")[-1]
# add annotation to the new triplestore as a oa:Annotation as uri+id
h.add((URIRef(uri1+id), RDF.type, AO.Annotation))
h.add((URIRef(annotationURI+id), RDF.type, AO.Annotation))
# read properties dct:creator, dct:created, oa:hasBody, oa:hasTarget from the annotation
creator = g.value(annotation, DCTERMS.creator)
created = g.value(annotation, DCTERMS.created)
body = g.value(annotation, AO.bodyValue)
target = uri1+g.value(annotation, AO.hasTarget).split("concept")[-1]
target = conceptURI+g.value(annotation, AO.hasTarget).split("concept")[-1]
# add properties dct:creator, dct:created, oa:hasBody, oa:hasTarget to the annotation
h.add((URIRef(uri1+id), DCTERMS.creator, creator))
h.add((URIRef(uri1+id), DCTERMS.created, created))
h.add((URIRef(uri1+id), AO.bodyValue, body))
h.add((URIRef(uri1+id), AO.hasTarget, URIRef(target)))
h.add((URIRef(annotationURI+id), DCTERMS.creator, creator))
h.add((URIRef(annotationURI+id), DCTERMS.created, created))
h.add((URIRef(annotationURI+id), AO.bodyValue, body))
h.add((URIRef(annotationURI+id), AO.hasTarget, URIRef(target)))

# serialize the new triplestore
h.serialize(destination="annotationConceptScheme.ttl", format="turtle")
Expand Down
Loading

0 comments on commit ef097f3

Please sign in to comment.