Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Django
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dalia
Backend
Django
Commits
22f6da54
Commit
22f6da54
authored
8 months ago
by
Frank Lange
Browse files
Options
Downloads
Patches
Plain Diff
exclude deprecated disciplines
parent
c39201a3
No related branches found
No related tags found
No related merge requests found
Pipeline
#1512569
passed
8 months ago
Stage: container
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
project/dalia/curation/suggest/disciplines.py
+15
-2
15 additions, 2 deletions
project/dalia/curation/suggest/disciplines.py
tests/project/dalia/curation/suggest/test_disciplines.py
+29
-2
29 additions, 2 deletions
tests/project/dalia/curation/suggest/test_disciplines.py
with
44 additions
and
4 deletions
project/dalia/curation/suggest/disciplines.py
+
15
−
2
View file @
22f6da54
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.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.
# 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
# ?broaderDiscipline skos:narrower ?discipline .
# }
# ?discipline a skos:Concept .
# FILTER NOT EXISTS {
# ?discipline owl:deprecated true .
# }
# ?discipline skos:prefLabel ?label .
# FILTER(LANG(?label) = "en") .
# ?discipline skos:notation ?notation .
...
...
@@ -57,6 +66,10 @@ def _prepare_query_to_get_disciplines_metadata(discipline_selection_bgp: Tuple)
).
WHERE
(
discipline_selection_bgp
,
(
var_discipline
,
RDF
.
type
,
SKOS
.
Concept
),
FILTER_EXISTS
(
(
var_discipline
,
OWL
.
deprecated
,
Literal
(
True
)),
state
=
False
),
(
var_discipline
,
SKOS
.
prefLabel
,
var_label
),
FILTER
(
Operators
.
EQ
(
...
...
This diff is collapsed.
Click to expand it.
tests/project/dalia/curation/suggest/test_disciplines.py
+
29
−
2
View file @
22f6da54
from
typing
import
List
from
django.urls
import
reverse
from
rdflib
import
URIRef
from
rest_framework
import
status
from
project.dalia.api_models.api_models
import
CurationSuggestDisciplinesResultItem
from
project.dalia.curation.suggest.disciplines
import
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.curation.suggest.disciplines
import
(
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
tests.project.dalia.utils
import
dedent_and_normalize
,
normalize
...
...
@@ -17,6 +23,9 @@ def test_prepare_query_to_get_all_top_disciplines():
WHERE {
?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> .
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 .
FILTER ( LANG ( ?label ) =
"
en
"
) .
?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():
WHERE {
<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> .
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 .
FILTER ( LANG ( ?label ) =
"
en
"
) .
?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
assert
n242
.
label
==
"
Interior Architecture
"
assert
n242
.
value
==
"
https://w3id.org/kim/hochschulfaechersystematik/n242
"
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment