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

add handing of subtitle

parent 6757e0ec
No related branches found
No related tags found
No related merge requests found
Pipeline #1485142 passed
......@@ -6,12 +6,13 @@ 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
from project.dalia.rdf.namespace import MoDalia, SCHEMA, content_inventory, educor, fabio
_VARIABLES = {
"lr": Variable("lr"),
"description": Variable("description"),
"title": Variable("title"),
"subtitle": Variable("subtitle"),
"created": Variable("created"),
"license": Variable("license"),
"fileSize": Variable("fileSize"),
......@@ -37,6 +38,7 @@ def prepare_query_for_one_to_one_metadata_for_resources(resource_uri_refs: List[
(var_lr, RDF.type, educor.EducationalResource),
OPTIONAL((var_lr, DCTERMS.description, _VARIABLES["description"])),
OPTIONAL((var_lr, DCTERMS.title, _VARIABLES["title"])),
OPTIONAL((var_lr, fabio.hasSubtitle, _VARIABLES["subtitle"])),
OPTIONAL((var_lr, SCHEMA.datePublished, _VARIABLES["created"])),
OPTIONAL((var_lr, DCTERMS.license, _VARIABLES["license"])),
OPTIONAL((var_lr, SCHEMA.fileSize, _VARIABLES["fileSize"])),
......@@ -56,7 +58,7 @@ def process_result_for_one_to_one_metadata_for_resources(result) -> Resource:
resource.id = str(result.lr).split("/")[-1]
resource.slug = str(result.slug)
resource.title = str(result.title)
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)
resource.license = get_license_info(result.license) if result.license else License(id="", name="", link="")
......
"""
Terms from FaBiO, the FRBR-aligned Bibliographic Ontology
"""
from rdflib import URIRef
NS = "http://purl.org/spar/fabio/"
# Properties
hasSubtitle = URIRef(NS + "hasSubtitle") # https://sparontologies.github.io/fabio/current/fabio.html#d4e1689
......@@ -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 ?created ?license ?fileSize ?url ?slug ?attachment
SELECT ?lr ?description ?title ?subtitle ?created ?license ?fileSize ?url ?slug ?attachment
WHERE {
VALUES ( ?lr ) {
( <abc> )
......@@ -27,6 +27,9 @@ def test_prepare_query_for_one_to_one_metadata_for_resources():
?lr <http://purl.org/dc/terms/title> ?title .
} .
OPTIONAL {
?lr <http://purl.org/spar/fabio/hasSubtitle> ?subtitle .
} .
OPTIONAL {
?lr <https://schema.org/datePublished> ?created .
} .
OPTIONAL {
......@@ -55,6 +58,7 @@ def test_process_result_for_one_to_one_metadata_for_resources_with_minimal_resul
result.lr = "http://some.domain/a/cool/id/is/42"
result.slug = "my-slug"
result.title = "My Title"
result.subtitle = None
result.description = None
result.url = "http://localhost/secret-document"
result.license = None
......@@ -95,6 +99,7 @@ def test_get_one_to_one_metadata_for_resources(triplestore):
resources = get_one_to_one_metadata_for_resources([
URIRef("https://id.dalia.education/learning-resource/00855e6b-ebc6-422b-a2d5-7caa58569a9b"),
URIRef("https://id.dalia.education/learning-resource/a195da8d-b19e-4934-9511-9369e60ccaa1"),
URIRef("https://id.dalia.education/learning-resource/65ae2d0f-7d94-4f0b-9714-470a2c372839"),
URIRef("http://does-not-exist/123"),
])
......@@ -162,6 +167,57 @@ def test_get_one_to_one_metadata_for_resources(triplestore):
views=None,
comments=None,
tags=None
),
URIRef('https://id.dalia.education/learning-resource/65ae2d0f-7d94-4f0b-9714-470a2c372839'): Resource(
type=None,
format=None,
license=License(
id='Proprietary',
name='Proprietary',
link=''
),
publication_date=None,
links=None,
languages=None,
file_size=None,
publisher=None,
doi=None,
learning_time=None,
versions=None,
id='65ae2d0f-7d94-4f0b-9714-470a2c372839',
slug='None',
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 "
"immutability and pure functions – enable parallel data processing (‘divide and conquer’), "
"which is necessary to manage big data. From this fundamental principle, we move forward. "
"Namely, how to recognize and put into practice the scalable solution that’s right for your "
"situation. The insights and tools of this course are regardless of programming language, "
"but user-friendly examples are provided in Python, Hadoop HDFS, and Apache Spark. Although "
"these principles can also be applied to other sectors, we will use examples from the "
"agri-food sector.\n\nAgri-food deserves special focus when it comes to choosing robust data "
"management technologies due to its inherent variability and uncertainty. Wageningen "
"University & Research’s knowledge domain is healthy food and the living environment. That "
"makes our data experts especially equipped to forge the bridge between the agri-food "
"business on the one hand, and data science, artificial intelligence (AI) on the other. "
"\nCombining data from the latest sensing technologies with machine learning/deep learning "
"methodologies, allows us to unlock insights we didn't have access to before. In the areas of "
"smart farming and precision agriculture, this allows us to:\nBetter manage dairy cattle by "
"combining animal-level data on behaviour, health and feed with milk production and "
"composition from milking machines. Reduce the amount of fertilizers (nitrogen), pesticides ("
"chemicals), and water used on crops by monitoring individual plants with a robot or drone. "
"More accurately predict crop yields on a continental scale by combining current with "
"historic data on soil, weather patterns and crop yields.\nIn short, this course’s "
"foundational knowledge and skills for big data prepare you for the next step: to find more "
"effective and scalable solutions for smarter, innovative insights.",
authors=None,
url='https://www.edx.org/learn/big-data/wageningen-university-research-big-data-for-agri-food-principles'
'-and-tools?',
image=None,
likes=None,
views=None,
comments=None,
tags=None,
)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment