Skip to content

Commit

Permalink
closes #49
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed Nov 10, 2022
1 parent 6e97995 commit 7bd7487
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
6 changes: 4 additions & 2 deletions vocabs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
except KeyError:
notation_for_uri = False

VOCABS_SEPARATOR = getattr(settings, 'VOCABS_SEPARATOR', '/')

DEFAULT_URI = "https://vocabs.acdh.oeaw.ac.at/"

Expand Down Expand Up @@ -628,9 +629,10 @@ def create_uri(self):
concept_uri = f"{self.legacy_id}"
else:
if notation_for_uri:
concept_uri = f"{mcs}#concept__{slugify(self.notation, allow_unicode=False)}__{self.id}"
tmp = slugify(self.notation, allow_unicode=False)
concept_uri = f"{mcs}{VOCABS_SEPARATOR}concept__{tmp}__{self.id}"
else:
concept_uri = f"{mcs}#concept{self.id}"
concept_uri = f"{mcs}{VOCABS_SEPARATOR}concept{self.id}"
return concept_uri

# change for template tag
Expand Down
30 changes: 25 additions & 5 deletions vocabs/rdf_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import rdflib
from rdflib import Literal, Namespace, RDF, URIRef, XSD
from django.conf import settings


SKOS = Namespace("http://www.w3.org/2004/02/skos/core#")
Expand All @@ -8,6 +9,8 @@
RDFS = Namespace("http://www.w3.org/2000/01/rdf-schema#")
OWL = Namespace("http://www.w3.org/2002/07/owl#")
VOCABS = Namespace("https://vocabs.acdh.oeaw.ac.at/create-concept-scheme/")
VOCABS_SEPARATOR = getattr(settings, 'VOCABS_SEPARATOR', '/')


RDF_FORMATS = {
"xml": "rdf",
Expand Down Expand Up @@ -88,7 +91,7 @@ def graph_construct_qs(results):
# if obj.legacy_id:
# concept = URIRef(obj.legacy_id)
# else:
# concept = URIRef(main_concept_scheme + "#concept" + str(obj.id))
# concept = URIRef(main_concept_scheme + VOCABS_SEPARATOR + "concept" + str(obj.id))
concept = URIRef(obj.create_uri())
g.add((concept, RDF.type, SKOS.Concept))
g.add((concept, SKOS.prefLabel, Literal(obj.pref_label, lang=obj.pref_label_lang)))
Expand All @@ -97,7 +100,7 @@ def graph_construct_qs(results):
g.add((concept, SKOS.inScheme, main_concept_scheme))
if obj.collection.all():
for x in obj.collection.all():
collection = URIRef(main_concept_scheme + "#collection" + str(x.id))
collection = URIRef(main_concept_scheme + VOCABS_SEPARATOR + "collection" + str(x.id))
g.add((collection, RDF.type, SKOS.Collection))
g.add((collection, DCT.created, Literal(x.date_created, datatype=XSD.dateTime)))
g.add((collection, DCT.modified, Literal(x.date_modified, datatype=XSD.dateTime)))
Expand Down Expand Up @@ -148,7 +151,13 @@ def graph_construct_qs(results):
if y.legacy_id:
g.add((collection, SKOS.member, URIRef(y.legacy_id)))
else:
g.add((collection, SKOS.member, URIRef(main_concept_scheme + "#concept" + str(y.id))))
g.add(
(
collection,
SKOS.member,
URIRef(main_concept_scheme + VOCABS_SEPARATOR + "concept" + str(y.id))
)
)
# Concept properties
if obj.has_labels.all():
for label in obj.has_labels.all():
Expand Down Expand Up @@ -191,13 +200,24 @@ def graph_construct_qs(results):
if obj.broader_concept.legacy_id:
g.add((concept, SKOS.broader, URIRef(obj.broader_concept.legacy_id)))
else:
g.add((concept, SKOS.broader, URIRef(main_concept_scheme + "#concept" + str(obj.broader_concept.id))))
g.add(
(
concept,
SKOS.broader,
URIRef(main_concept_scheme + VOCABS_SEPARATOR + "concept" + str(obj.broader_concept.id)))
)
if obj.narrower_concepts.all():
for x in obj.narrower_concepts.all():
if x.legacy_id:
g.add((concept, SKOS.narrower, URIRef(x.legacy_id)))
else:
g.add((concept, SKOS.narrower, URIRef(main_concept_scheme + "#concept" + str(x.id))))
g.add(
(
concept,
SKOS.narrower,
URIRef(main_concept_scheme + VOCABS_SEPARATOR + "concept" + str(x.id))
)
)
# modelling external matches
# skos:related
if obj.related:
Expand Down
1 change: 1 addition & 0 deletions vocabseditor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
REDMINE_ID = os.environ.get('REDMINE_ID', '12305')
PROJECT_NAME = os.environ.get('PROJECT_NAME', 'vocabseditor')
VOCABS_DEFAULT_PEFIX = os.environ.get('VOCABS_DEFAULT_PEFIX', 'vocabseditor')
VOCABS_SEPARATOR = os.environ.get('VOCABS_SEPARATOR', '/')
BASE_URL = f"https://{PROJECT_NAME}.acdh.oeaw.ac.at"

VOCABS_SETTINGS = {
Expand Down

0 comments on commit 7bd7487

Please sign in to comment.