Skip to content
Snippets Groups Projects
Commit 22f6da54 authored by Frank Lange's avatar Frank Lange
Browse files

exclude deprecated disciplines

parent c39201a3
No related branches found
No related tags found
No related merge requests found
Pipeline #1512569 passed
from typing import List, Tuple from typing import List, Tuple
from rdflib import Literal, RDF, SKOS, URIRef, Variable from rdflib import Literal, OWL, RDF, SKOS, URIRef, Variable
from project.dalia.api_models.api_models import CurationSuggestDisciplinesResultItem from project.dalia.api_models.api_models import CurationSuggestDisciplinesResultItem
from project.dalia.query.utils import query_ontologies_dataset from project.dalia.query.utils import query_ontologies_dataset
from project.dalia.query_builder.query_builder import FILTER, FunctionExpressions, Operators, QueryBuilder from project.dalia.query_builder.query_builder import (
FILTER,
FILTER_EXISTS,
FunctionExpressions,
Operators,
QueryBuilder,
)
# Note: This algorithm is quite inefficient and results in a lot of SPARQL queries. # Note: This algorithm is quite inefficient and results in a lot of SPARQL queries.
# Another idea would be to pull all disciplines and their narrower/broader nodes at once, e.g. via # Another idea would be to pull all disciplines and their narrower/broader nodes at once, e.g. via
...@@ -19,6 +25,9 @@ from project.dalia.query_builder.query_builder import FILTER, FunctionExpression ...@@ -19,6 +25,9 @@ from project.dalia.query_builder.query_builder import FILTER, FunctionExpression
# ?broaderDiscipline skos:narrower ?discipline . # ?broaderDiscipline skos:narrower ?discipline .
# } # }
# ?discipline a skos:Concept . # ?discipline a skos:Concept .
# FILTER NOT EXISTS {
# ?discipline owl:deprecated true .
# }
# ?discipline skos:prefLabel ?label . # ?discipline skos:prefLabel ?label .
# FILTER(LANG(?label) = "en") . # FILTER(LANG(?label) = "en") .
# ?discipline skos:notation ?notation . # ?discipline skos:notation ?notation .
...@@ -57,6 +66,10 @@ def _prepare_query_to_get_disciplines_metadata(discipline_selection_bgp: Tuple) ...@@ -57,6 +66,10 @@ def _prepare_query_to_get_disciplines_metadata(discipline_selection_bgp: Tuple)
).WHERE( ).WHERE(
discipline_selection_bgp, discipline_selection_bgp,
(var_discipline, RDF.type, SKOS.Concept), (var_discipline, RDF.type, SKOS.Concept),
FILTER_EXISTS(
(var_discipline, OWL.deprecated, Literal(True)),
state=False
),
(var_discipline, SKOS.prefLabel, var_label), (var_discipline, SKOS.prefLabel, var_label),
FILTER( FILTER(
Operators.EQ( Operators.EQ(
......
from typing import List
from django.urls import reverse from django.urls import reverse
from rdflib import URIRef from rdflib import URIRef
from rest_framework import status from rest_framework import status
from project.dalia.api_models.api_models import CurationSuggestDisciplinesResultItem from project.dalia.api_models.api_models import CurationSuggestDisciplinesResultItem
from project.dalia.curation.suggest.disciplines import get_child_disciplines_of_discipline, get_top_disciplines, \ from project.dalia.curation.suggest.disciplines import (
prepare_query_to_get_all_narrower_disciplines_of_discipline, prepare_query_to_get_all_top_disciplines get_child_disciplines_of_discipline,
get_top_disciplines,
prepare_query_to_get_all_narrower_disciplines_of_discipline,
prepare_query_to_get_all_top_disciplines,
)
from project.dalia.serializers import CurationSuggestDisciplinesResultItemSerializer from project.dalia.serializers import CurationSuggestDisciplinesResultItemSerializer
from tests.project.dalia.utils import dedent_and_normalize, normalize from tests.project.dalia.utils import dedent_and_normalize, normalize
...@@ -17,6 +23,9 @@ def test_prepare_query_to_get_all_top_disciplines(): ...@@ -17,6 +23,9 @@ def test_prepare_query_to_get_all_top_disciplines():
WHERE { WHERE {
?discipline <http://www.w3.org/2004/02/skos/core#topConceptOf> <https://w3id.org/kim/hochschulfaechersystematik/scheme> . ?discipline <http://www.w3.org/2004/02/skos/core#topConceptOf> <https://w3id.org/kim/hochschulfaechersystematik/scheme> .
?discipline <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2004/02/skos/core#Concept> . ?discipline <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2004/02/skos/core#Concept> .
FILTER NOT EXISTS {
?discipline <http://www.w3.org/2002/07/owl#deprecated> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> .
} .
?discipline <http://www.w3.org/2004/02/skos/core#prefLabel> ?label . ?discipline <http://www.w3.org/2004/02/skos/core#prefLabel> ?label .
FILTER ( LANG ( ?label ) = "en" ) . FILTER ( LANG ( ?label ) = "en" ) .
?discipline <http://www.w3.org/2004/02/skos/core#notation> ?notation . ?discipline <http://www.w3.org/2004/02/skos/core#notation> ?notation .
...@@ -33,6 +42,9 @@ def test_prepare_query_to_get_all_narrower_disciplines_of_discipline(): ...@@ -33,6 +42,9 @@ def test_prepare_query_to_get_all_narrower_disciplines_of_discipline():
WHERE { WHERE {
<abc> <http://www.w3.org/2004/02/skos/core#narrower> ?discipline . <abc> <http://www.w3.org/2004/02/skos/core#narrower> ?discipline .
?discipline <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2004/02/skos/core#Concept> . ?discipline <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2004/02/skos/core#Concept> .
FILTER NOT EXISTS {
?discipline <http://www.w3.org/2002/07/owl#deprecated> "true"^^<http://www.w3.org/2001/XMLSchema#boolean> .
} .
?discipline <http://www.w3.org/2004/02/skos/core#prefLabel> ?label . ?discipline <http://www.w3.org/2004/02/skos/core#prefLabel> ?label .
FILTER ( LANG ( ?label ) = "en" ) . FILTER ( LANG ( ?label ) = "en" ) .
?discipline <http://www.w3.org/2004/02/skos/core#notation> ?notation . ?discipline <http://www.w3.org/2004/02/skos/core#notation> ?notation .
...@@ -142,3 +154,18 @@ def test_get_on_CurationSuggestDisciplinesView_returns_200_and_the_disciplines_t ...@@ -142,3 +154,18 @@ def test_get_on_CurationSuggestDisciplinesView_returns_200_and_the_disciplines_t
assert n242.label == "Interior Architecture" assert n242.label == "Interior Architecture"
assert n242.value == "https://w3id.org/kim/hochschulfaechersystematik/n242" assert n242.value == "https://w3id.org/kim/hochschulfaechersystematik/n242"
assert len(n242.children) == 0 assert len(n242.children) == 0
assert _has_item_with_uri(data, "https://w3id.org/kim/hochschulfaechersystematik/n077")
assert _has_item_with_uri(data, "https://w3id.org/kim/hochschulfaechersystematik/n194")
# deprecated items are not in the returned data
assert not _has_item_with_uri(data, "https://w3id.org/kim/hochschulfaechersystematik/n241")
assert not _has_item_with_uri(data, "https://w3id.org/kim/hochschulfaechersystematik/n237")
# DFS in nested data structure
def _has_item_with_uri(data: List[CurationSuggestDisciplinesResultItem], uri: str) -> bool:
for item in data:
if item.value == uri or _has_item_with_uri(item.children, uri):
return True
return False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment