-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subjects: minor refactor,updated docstrings and test
- Loading branch information
1 parent
c46de43
commit f9e30ae
Showing
6 changed files
with
223 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
tests/contrib/subjects/bodc/test_subjects_bodc_datastream.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2024 CERN. | ||
# | ||
# Invenio-Vocabularies is free software; you can redistribute it and/or | ||
# modify it under the terms of the MIT License; see LICENSE file for more | ||
# details. | ||
|
||
import io | ||
|
||
import pytest | ||
from rdflib import Graph | ||
|
||
from invenio_vocabularies.contrib.subjects.bodc.datastreams import ( | ||
BODCPUVSubjectsTransformer, | ||
) | ||
from invenio_vocabularies.datastreams.datastreams import StreamEntry | ||
from invenio_vocabularies.datastreams.readers import RDFReader | ||
|
||
XML_DATA = bytes( | ||
"""<?xml version="1.0" encoding="UTF-8"?><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:dc="http://purl.org/dc/terms/" xmlns:dce="http://purl.org/dc/elements/1.1/" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:grg="http://www.isotc211.org/schemas/grg/" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:void="http://rdfs.org/ns/void#" xmlns:pav="http://purl.org/pav/" xmlns:prov="https://www.w3.org/ns/prov#" xmlns:reg="http://purl.org/linked-data/registry#" xmlns:cpm="http://purl.org/voc/cpm#" xmlns:qudt="https://qudt.org/2.1/schema/qudt#" xmlns:semapv="http://w3id.org/semapv/vocab/" xmlns:iop="https://w3id.org/iadopt/ont#" xmlns:sssom="https://w3id.org/sssom/schema/" xmlns:puv="https://w3id.org/env/puv#"> | ||
<skos:Collection rdf:about="http://vocab.nerc.ac.uk/collection/P01/current/"> | ||
<skos:prefLabel>BODC Parameter Usage Vocabulary</skos:prefLabel> | ||
<dc:title>BODC Parameter Usage Vocabulary</dc:title> | ||
<skos:altLabel>BODC PUV</skos:altLabel> | ||
<dc:alternative>BODC PUV</dc:alternative> | ||
<dc:description>Terms built using the BODC parameter semantic model designed to describe individual measured phenomena. May be used to mark up sets of data such as a NetCDF array or spreadsheet column. Units must be specified when using a P01 code. The P06 unit that is linked to individual P01 in the NVS is the one used in BODC's systems but external users can use any appropriate units.</dc:description> | ||
<dc:license rdf:resource="https://creativecommons.org/licenses/by/4.0/"/> | ||
<skos:member> | ||
<skos:Concept xml:base="http://vocab.nerc.ac.uk/collection/P01/current/SAGEMSFM/" rdf:about="http://vocab.nerc.ac.uk/collection/P01/current/SAGEMSFM/"> | ||
<dc:identifier>SDN:P01::SAGEMSFM</dc:identifier> | ||
<dce:identifier>SDN:P01::SAGEMSFM</dce:identifier> | ||
<dc:date>2008-10-16 16:27:06.0</dc:date> | ||
<skos:notation>SDN:P01::SAGEMSFM</skos:notation> | ||
<skos:prefLabel xml:lang="en">14C age of Foraminiferida (ITIS: 44030: WoRMS 22528) [Subcomponent: tests] in sediment by picking and accelerator mass spectrometry</skos:prefLabel> | ||
<skos:altLabel>AMSSedAge</skos:altLabel> | ||
<skos:definition xml:lang="en">Accelerated mass spectrometry on picked tests</skos:definition> | ||
<owl:versionInfo>1</owl:versionInfo> | ||
<pav:hasCurrentVersion rdf:resource="http://vocab.nerc.ac.uk/collection/P01/current/SAGEMSFM/1/"/> | ||
<pav:version>1</pav:version> | ||
<pav:authoredOn>2008-10-16 16:27:06.0</pav:authoredOn> | ||
<skos:note xml:lang="en">accepted</skos:note> | ||
<owl:deprecated>false</owl:deprecated> | ||
<iop:hasMatrix rdf:resource="http://vocab.nerc.ac.uk/collection/S21/current/S21S022/"/> | ||
<skos:related rdf:resource="http://vocab.nerc.ac.uk/collection/P06/current/UYBP/"/> | ||
<skos:broader rdf:resource="http://vocab.nerc.ac.uk/collection/S25/current/BE002325/"/> | ||
<skos:broader rdf:resource="http://vocab.nerc.ac.uk/collection/S26/current/MAT00136/"/> | ||
<void:inDataset rdf:resource="http://vocab.nerc.ac.uk/.well-known/void"/> | ||
</skos:Concept> | ||
</skos:member> | ||
</skos:Collection> | ||
</rdf:RDF>""", | ||
encoding="utf-8", | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def expected_from_rdf(): | ||
return [ | ||
{ | ||
"id": "SDN:P01::SAGEMSFM", | ||
"scheme": "BODC-PUV", | ||
"subject": "AMSSedAge", | ||
"title": { | ||
"en": "14C age of Foraminiferida (ITIS: 44030: WoRMS 22528) [Subcomponent: tests] in sediment by picking and accelerator mass spectrometry", | ||
}, | ||
"props": {"definition": "Accelerated mass spectrometry on picked tests"}, | ||
"identifiers": [ | ||
{ | ||
"scheme": "url", | ||
"identifier": "http://vocab.nerc.ac.uk/collection/P01/current/SAGEMSFM/", | ||
} | ||
], | ||
} | ||
] | ||
|
||
|
||
def test_gemet_concept_transformer_pref_label(expected_from_rdf): | ||
reader = RDFReader() | ||
rdf_data = io.BytesIO(XML_DATA) | ||
rdf_graph = Graph() | ||
rdf_graph.parse(rdf_data, format="xml") | ||
stream_entries = list(reader._iter(rdf_graph)) | ||
assert len(stream_entries) > 0 | ||
transformer = BODCPUVSubjectsTransformer() | ||
result = [] | ||
for entry in stream_entries: | ||
entry = transformer.apply(StreamEntry(entry)).entry | ||
result.append(entry) | ||
assert expected_from_rdf == result | ||
Check failure on line 90 in tests/contrib/subjects/bodc/test_subjects_bodc_datastream.py GitHub Actions / Python / Tests (3.9, postgresql14, opensearch2)
Check failure on line 90 in tests/contrib/subjects/bodc/test_subjects_bodc_datastream.py GitHub Actions / Python / Tests (3.12, postgresql14, opensearch2)
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters