diff --git a/project/dalia/query/communities/one_to_one_metadata.py b/project/dalia/query/communities/one_to_one_metadata.py index acccb7d4cf2769ba0941458287d07f1017369152..65d11f9f981e10135761723a7c5167814be6aef0 100644 --- a/project/dalia/query/communities/one_to_one_metadata.py +++ b/project/dalia/query/communities/one_to_one_metadata.py @@ -1,5 +1,6 @@ -from typing import Dict, Iterable, List +from typing import Dict, Iterable +from django.utils.text import slugify from rdflib import DCTERMS, Literal, RDF, URIRef, Variable from project.dalia.api_models.api_models import Community, SocialMedia @@ -12,7 +13,7 @@ from project.dalia.query_builder.query_builder import ( QueryBuilder, VALUES ) -from project.dalia.rdf.namespace import MoDalia, SCHEMA, content_inventory, wdt +from project.dalia.rdf.namespace import MoDalia, SCHEMA, wdt def get_one_to_one_metadata_for_communities(community_uri_refs: Iterable[URIRef]) -> Dict[URIRef, Community]: @@ -35,7 +36,6 @@ def process_result_for_one_to_one_metadata_for_community(result) -> Community: community = Community() community.id = str(result.community).split("/")[-1] - community.slug = str(result.slug) community.title = str(result.title) community.image = None community.url = str(result.url) if result.url else "" @@ -45,6 +45,9 @@ def process_result_for_one_to_one_metadata_for_community(result) -> Community: community.followers = 0 community.social_media = process_social_media_in_result(result) + # TODO: could this be moved to the dataclass definition using the @property decorator? + community.slug = slugify(community.title) + return community @@ -85,7 +88,6 @@ _VARIABLES = { "linkedin_id": Variable("linkedin_id"), "zenodo_community_id": Variable("zenodo_community_id"), "url": Variable("url"), - "slug": Variable("slug") } @@ -119,5 +121,4 @@ def prepare_query_for_one_to_one_metadata_for_communities(community_uri_refs: It OPTIONAL((var_community, wdt.LinkedIn_company_or_organization_ID, _VARIABLES["linkedin_id"])), OPTIONAL((var_community, wdt.Zenodo_communities_ID, _VARIABLES["zenodo_community_id"])), OPTIONAL((var_community, SCHEMA.url, _VARIABLES["url"])), - OPTIONAL((var_community, content_inventory.slug, _VARIABLES["slug"])), ).build() diff --git a/project/dalia/query/items/metadata/one_to_one_metadata.py b/project/dalia/query/items/metadata/one_to_one_metadata.py index f89c58c3dce7e0bad8708203394366238f0d2fe3..a4c52e1dbccef330a19e97ad710fbfe6b0002e9a 100644 --- a/project/dalia/query/items/metadata/one_to_one_metadata.py +++ b/project/dalia/query/items/metadata/one_to_one_metadata.py @@ -1,12 +1,13 @@ from typing import Dict, List +from django.utils.text import slugify from rdflib import DCTERMS, RDF, URIRef, Variable from project.dalia.api_models.api_models import License, Resource from project.dalia.query.items.metadata.license import get_license_info from project.dalia.query.utils import query_dalia_dataset from project.dalia.query_builder.query_builder import FILTER, FunctionExpressions, OPTIONAL, QueryBuilder, VALUES -from project.dalia.rdf.namespace import MoDalia, SCHEMA, content_inventory, educor, fabio +from project.dalia.rdf.namespace import MoDalia, SCHEMA, educor, fabio _VARIABLES = { "lr": Variable("lr"), @@ -17,7 +18,6 @@ _VARIABLES = { "license": Variable("license"), "fileSize": Variable("fileSize"), "url": Variable("url"), - "slug": Variable("slug"), "attachment": Variable("attachment"), } @@ -43,7 +43,6 @@ def prepare_query_for_one_to_one_metadata_for_resources(resource_uri_refs: List[ OPTIONAL((var_lr, DCTERMS.license, _VARIABLES["license"])), OPTIONAL((var_lr, SCHEMA.fileSize, _VARIABLES["fileSize"])), OPTIONAL((var_lr, SCHEMA.url, _VARIABLES["url"])), - OPTIONAL((var_lr, content_inventory.slug, _VARIABLES["slug"])), OPTIONAL( (var_lr, MoDalia.hasMediaType, var_attachment), FILTER( @@ -57,7 +56,6 @@ def process_result_for_one_to_one_metadata_for_resources(result) -> Resource: resource = Resource() resource.id = str(result.lr).split("/")[-1] - resource.slug = str(result.slug) resource.title = str(result.title) if not result.subtitle else str(result.title) + ": " + str(result.subtitle) resource.description = str(result.description) if result.description else "" resource.url = str(result.url) @@ -66,6 +64,9 @@ def process_result_for_one_to_one_metadata_for_resources(result) -> Resource: resource.file_size = str(result.fileSize) if result.fileSize else None resource.type = str(result.attachment) if result.attachment else None + # TODO: could this be moved to the dataclass definition using the @property decorator? + resource.slug = slugify(resource.title) + return resource diff --git a/project/dalia/rdf/namespace/content_inventory.py b/project/dalia/rdf/namespace/content_inventory.py deleted file mode 100644 index 2e318ddc46131a27a76c8df8efe358e1508db3b1..0000000000000000000000000000000000000000 --- a/project/dalia/rdf/namespace/content_inventory.py +++ /dev/null @@ -1,9 +0,0 @@ -""" -Terms from 'A Content Inventory Vocabulary' (https://vocab.methodandstructure.com/content-inventory) -""" -from rdflib import URIRef - -NS = "https://vocab.methodandstructure.com/content-inventory#" - -# Properties -slug = URIRef(NS + "slug") diff --git a/tests/project/dalia/query/communities/test_one_to_tone_metadata.py b/tests/project/dalia/query/communities/test_one_to_tone_metadata.py index d1c8b52dde4db039e63f779bc4e4b4e1d930623b..07c647092e335b4f1ab87037918ea3f5651ffbfc 100644 --- a/tests/project/dalia/query/communities/test_one_to_tone_metadata.py +++ b/tests/project/dalia/query/communities/test_one_to_tone_metadata.py @@ -12,7 +12,7 @@ def test_prepare_query_for_one_to_one_metadata_for_communities(): query = prepare_query_for_one_to_one_metadata_for_communities([URIRef("community1"), URIRef("community2")]) assert normalize(query) == dedent_and_normalize(""" - SELECT ?community ?description ?title ?bluesky_handle ?youtube_channel_id ?mastodon_address ?linkedin_id ?zenodo_community_id ?url ?slug + SELECT ?community ?description ?title ?bluesky_handle ?youtube_channel_id ?mastodon_address ?linkedin_id ?zenodo_community_id ?url WHERE { VALUES ( ?community ) { ( <community1> ) @@ -44,9 +44,6 @@ def test_prepare_query_for_one_to_one_metadata_for_communities(): OPTIONAL { ?community <https://schema.org/url> ?url . } . - OPTIONAL { - ?community <https://vocab.methodandstructure.com/content-inventory#slug> ?slug . - } . } """) @@ -66,7 +63,7 @@ def test_get_one_to_one_metadata_for_communities_with_many_community_uris(triple assert communities == { URIRef('https://id.dalia.education/community/51340f34-d6fc-4ed5-b37d-b00a4d6f663a'): Community( id='51340f34-d6fc-4ed5-b37d-b00a4d6f663a', - slug='None', + slug='data-carpentry', title='Data Carpentry', image=None, url='', diff --git a/tests/project/dalia/query/items/metadata/test_one_to_one_metadata.py b/tests/project/dalia/query/items/metadata/test_one_to_one_metadata.py index 4874e6c08e0457ec65679bf014e221f517ab2af7..4265b7bf4cdd8dc76f84f2056591b3f4ca576a8d 100644 --- a/tests/project/dalia/query/items/metadata/test_one_to_one_metadata.py +++ b/tests/project/dalia/query/items/metadata/test_one_to_one_metadata.py @@ -13,7 +13,7 @@ def test_prepare_query_for_one_to_one_metadata_for_resources(): query = prepare_query_for_one_to_one_metadata_for_resources([URIRef("abc"), URIRef("def")]) assert normalize(query) == dedent_and_normalize(""" - SELECT ?lr ?description ?title ?subtitle ?created ?license ?fileSize ?url ?slug ?attachment + SELECT ?lr ?description ?title ?subtitle ?created ?license ?fileSize ?url ?attachment WHERE { VALUES ( ?lr ) { ( <abc> ) @@ -42,9 +42,6 @@ def test_prepare_query_for_one_to_one_metadata_for_resources(): ?lr <https://schema.org/url> ?url . } . OPTIONAL { - ?lr <https://vocab.methodandstructure.com/content-inventory#slug> ?slug . - } . - OPTIONAL { ?lr <https://purl.org/ontology/modalia#hasMediaType> ?attachment . FILTER ( ISLITERAL ( ?attachment ) ) . } . @@ -56,7 +53,7 @@ def test_process_result_for_one_to_one_metadata_for_resources_with_minimal_resul result = type('', (), {})() # https://stackoverflow.com/a/24448351 result.lr = "http://some.domain/a/cool/id/is/42" - result.slug = "my-slug" + result.slug = "my-title" result.title = "My Title" result.subtitle = None result.description = None @@ -81,7 +78,7 @@ def test_process_result_for_one_to_one_metadata_for_resources_with_minimal_resul learning_time=None, versions=None, id='42', - slug='my-slug', + slug='my-title', title='My Title', communities=None, description='', @@ -185,7 +182,7 @@ def test_get_one_to_one_metadata_for_resources(triplestore): learning_time=None, versions=None, id='65ae2d0f-7d94-4f0b-9714-470a2c372839', - slug='None', + slug='wageningenx-big-data-for-agri-food-principles-and-tools', title='WageningenX: Big Data for Agri-Food: Principles and Tools', communities=None, description="During this course, you will understand how and why certain principles – such as "