Skip to content

Commit

Permalink
Merge pull request #41 from ternaustralia/edmond/regression-tern-voca…
Browse files Browse the repository at this point in the history
…bs-label

Regression: add back service query to grab labels from tern_vocabs_core repo
  • Loading branch information
edmondchuc authored Nov 6, 2022
2 parents 4d96af5 + 7f3b591 commit 2b066f2
Showing 1 changed file with 52 additions and 17 deletions.
69 changes: 52 additions & 17 deletions src/linkeddata_api/domain/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def get(
"""
Returns a label or None if no label found.
"""
# TODO: Currently, we try and fetch from TERN's controlled vocabularies.
# We may want to also fetch with a SERVICE query from other repositories in the future.
template = Template(
"""
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
Expand All @@ -22,15 +24,32 @@ def get(
SELECT DISTINCT ?label
WHERE {
VALUES (?labelProperty) {
(skos:prefLabel)
(rdfs:label)
(dcterms:title)
(schema:name)
(sdo:name)
(dcterms:identifier)
{
BIND(<{{ uri }}> as ?uri)
VALUES (?labelProperty) {
(skos:prefLabel)
(rdfs:label)
(dcterms:title)
(schema:name)
(sdo:name)
(dcterms:identifier)
}
?uri ?labelProperty ?label .
}
UNION {
SERVICE <https://graphdb.tern.org.au/repositories/tern_vocabs_core> {
BIND(<{{ uri }}> as ?uri)
VALUES (?labelProperty) {
(skos:prefLabel)
(rdfs:label)
(dcterms:title)
(schema:name)
(sdo:name)
(dcterms:identifier)
}
?uri ?labelProperty ?label .
}
}
<{{ uri }}> ?labelProperty ?label .
}
LIMIT 1
"""
Expand Down Expand Up @@ -66,16 +85,32 @@ def _get_from_list_query(uris: list[str]) -> str:
{
SELECT DISTINCT ?uri ?label
WHERE {
BIND(<{{ uri }}> as ?uri)
VALUES (?labelProperty) {
(skos:prefLabel)
(rdfs:label)
(dcterms:title)
(schema:name)
(sdo:name)
(dcterms:identifier)
{
BIND(<{{ uri }}> as ?uri)
VALUES (?labelProperty) {
(skos:prefLabel)
(rdfs:label)
(dcterms:title)
(schema:name)
(sdo:name)
(dcterms:identifier)
}
?uri ?labelProperty ?label .
}
UNION {
SERVICE <https://graphdb.tern.org.au/repositories/tern_vocabs_core> {
BIND(<{{ uri }}> as ?uri)
VALUES (?labelProperty) {
(skos:prefLabel)
(rdfs:label)
(dcterms:title)
(schema:name)
(sdo:name)
(dcterms:identifier)
}
?uri ?labelProperty ?label .
}
}
?uri ?labelProperty ?label .
}
LIMIT 1
}
Expand Down

0 comments on commit 2b066f2

Please sign in to comment.