Skip to content

Commit

Permalink
subjects: renamed bodc to nvs
Browse files Browse the repository at this point in the history
  • Loading branch information
0einstein0 committed Jan 31, 2025
1 parent 7a926b3 commit 5633b85
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 32 deletions.
4 changes: 2 additions & 2 deletions invenio_vocabularies/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ def is_edmo(val):
)
"""Subject GEMET file download link."""

VOCABULARIES_SUBJECTS_BODC_PUV_FILE_URL = "http://vocab.nerc.ac.uk/collection/P02/current/?_profile=nvs&_mediatype=application/rdf+xml"
"""Subject BODC-PUV file download link."""
VOCABULARIES_SUBJECTS_NVS_FILE_URL = "http://vocab.nerc.ac.uk/collection/P02/current/?_profile=nvs&_mediatype=application/rdf+xml"
"""Subject NVS-P02 file download link."""

VOCABULARIES_AFFILIATIONS_EDMO_COUNTRY_MAPPING = {
"Cape Verde": "Cabo Verde",
Expand Down
4 changes: 2 additions & 2 deletions invenio_vocabularies/contrib/subjects/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
lambda: current_app.config["VOCABULARIES_SUBJECTS_EUROSCIVOC_FILE_URL"]
)

bodc_puv_file_url = LocalProxy(
lambda: current_app.config["VOCABULARIES_SUBJECTS_BODC_PUV_FILE_URL"]
nvs_file_url = LocalProxy(
lambda: current_app.config["VOCABULARIES_SUBJECTS_NVS_FILE_URL"]
)


Expand Down
4 changes: 2 additions & 2 deletions invenio_vocabularies/contrib/subjects/datastreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
from invenio_i18n import lazy_gettext as _

from ...datastreams.writers import ServiceWriter
from .bodc import datastreams as bodc_datastreams
from .euroscivoc import datastreams as euroscivoc_datastreams
from .gemet import datastreams as gemet_datastreams
from .mesh import datastreams as mesh_datastreams
from .nvs import datastreams as nvs_datastreams


class SubjectsServiceWriter(ServiceWriter):
Expand All @@ -40,7 +40,7 @@ def _entry_id(self, entry):
**mesh_datastreams.VOCABULARIES_DATASTREAM_TRANSFORMERS,
**euroscivoc_datastreams.VOCABULARIES_DATASTREAM_TRANSFORMERS,
**gemet_datastreams.VOCABULARIES_DATASTREAM_TRANSFORMERS,
**bodc_datastreams.VOCABULARIES_DATASTREAM_TRANSFORMERS,
**nvs_datastreams.VOCABULARIES_DATASTREAM_TRANSFORMERS,
}
"""Subjects Data Streams transformers."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""BODC Subjects module."""
"""NVS Subjects module."""
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""BODC subjects datastreams, readers, transformers, and writers."""
"""NVS subjects datastreams, readers, transformers, and writers."""

from invenio_vocabularies.datastreams.errors import TransformerError
from invenio_vocabularies.datastreams.readers import RDFReader
from invenio_vocabularies.datastreams.transformers import RDFTransformer

from ..config import bodc_puv_file_url
from ..config import nvs_file_url

# Available with the "rdf" extra
try:
Expand All @@ -21,9 +21,9 @@
rdflib = None


class BODCPUVSubjectsTransformer(RDFTransformer):
class NVSSubjectsTransformer(RDFTransformer):
"""
Transformer class to convert BODC-PUV RDF data to a dictionary format.
Transformer class to convert NVS RDF data to a dictionary format.
Input:
- Relevant fields:
Expand All @@ -36,8 +36,8 @@ class BODCPUVSubjectsTransformer(RDFTransformer):
Output:
- A dictionary with the following structure:
{
"id": "SDN:P01::SAGEMSFM", # BODC-specific parameter ID (skos:notation).
"scheme": "BODC-PUV", # The scheme name indicating this is a BODC Parameter Usage Vocabulary concept.
"id": "SDN:P01::SAGEMSFM", # NVS-specific parameter ID (skos:notation).
"scheme": "NVS-P01", # The scheme name indicating this is a collection P01 from NERC Vocabulary Server (NVS).
"subject": "AMSSedAge", # The alternative label (skos:altLabel), if available, or None.
"title": {
"en": "14C age of Foraminiferida" # English preferred label (skos:prefLabel).
Expand Down Expand Up @@ -87,7 +87,7 @@ def _transform_entry(self, subject, rdf_graph):

return {
"id": id,
"scheme": "BODC-PUV",
"scheme": "NVS-P02",
"subject": subject_text,
"title": labels,
"props": {"definition": definition} if definition else {},
Expand All @@ -97,18 +97,18 @@ def _transform_entry(self, subject, rdf_graph):

# Configuration for datastream

VOCABULARIES_DATASTREAM_TRANSFORMERS = {"bodc-transformer": BODCPUVSubjectsTransformer}
VOCABULARIES_DATASTREAM_TRANSFORMERS = {"nvs-transformer": NVSSubjectsTransformer}

DATASTREAM_CONFIG = {
"readers": [
{
"type": "http",
"args": {
"origin": bodc_puv_file_url,
"origin": nvs_file_url,
},
},
{"type": "rdf"},
],
"transformers": [{"type": "bodc-transformer"}],
"transformers": [{"type": "nvs-transformer"}],
"writers": [{"args": {"writer": {"type": "subjects-service"}}, "type": "async"}],
}
14 changes: 7 additions & 7 deletions invenio_vocabularies/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
)
from .contrib.funders.datastreams import DATASTREAM_CONFIG as funders_ds_config
from .contrib.names.datastreams import DATASTREAM_CONFIG as names_ds_config
from .contrib.subjects.bodc.datastreams import DATASTREAM_CONFIG as bodc_ds_config
from .contrib.subjects.datastreams import DATASTREAM_CONFIG as subjects_ds_config
from .contrib.subjects.euroscivoc.datastreams import (
DATASTREAM_CONFIG as euroscivoc_ds_config,
)
from .contrib.subjects.gemet.datastreams import DATASTREAM_CONFIG as gemet_ds_config
from .contrib.subjects.nvs.datastreams import DATASTREAM_CONFIG as nvs_ds_config


class VocabularyConfig:
Expand Down Expand Up @@ -164,15 +164,15 @@ def get_service(self):
raise NotImplementedError("Service not implemented for GEMET Subjects")


class SubjectsBODCVocabularyConfig(VocabularyConfig):
"""BODC Subjects Vocabulary Config."""
class SubjectsNVSVocabularyConfig(VocabularyConfig):
"""NVS Subjects Vocabulary Config."""

config = bodc_ds_config
vocabulary_name = "subjects:bodc-puv"
config = nvs_ds_config
vocabulary_name = "subjects:nvs"

def get_service(self):
"""Get the service for the vocabulary."""
raise NotImplementedError("Service not implemented for BODC Subjects")
raise NotImplementedError("Service not implemented for NVS Subjects")


def get_vocabulary_config(vocabulary):
Expand All @@ -187,7 +187,7 @@ def get_vocabulary_config(vocabulary):
"affiliations:edmo": AffiliationsEDMOVocabularyConfig,
"subjects": SubjectsVocabularyConfig,
"subjects:gemet": SubjectsGEMETVocabularyConfig,
"subjects:bodc": SubjectsBODCVocabularyConfig,
"subjects:nvs": SubjectsNVSVocabularyConfig,
"subjects:euroscivoc": SubjectsEuroSciVocVocabularyConfig,
}
return vocab_config.get(vocabulary, VocabularyConfig)()
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
import pytest
from rdflib import Graph

from invenio_vocabularies.contrib.subjects.bodc.datastreams import (
BODCPUVSubjectsTransformer,
)
from invenio_vocabularies.contrib.subjects.nvs.datastreams import NVSSubjectsTransformer
from invenio_vocabularies.datastreams.datastreams import StreamEntry
from invenio_vocabularies.datastreams.errors import TransformerError
from invenio_vocabularies.datastreams.readers import RDFReader
Expand Down Expand Up @@ -68,7 +66,7 @@ def expected_from_rdf():
return [
{
"id": "SDN:P02::QDMD",
"scheme": "BODC-PUV",
"scheme": "NVS-P02",
"subject": "Quantity of material dumped",
"title": {
"en": "Quantity of material dumped",
Expand All @@ -94,21 +92,21 @@ def parse_rdf_data(rdf_data):
return list(reader._iter(rdf_graph))[0]


def test_bodc_puv_transformer_pref_label(expected_from_rdf):
def test_nvs_transformer_pref_label(expected_from_rdf):
stream_entry = parse_rdf_data(VALID_XML_DATA)
assert len(stream_entry) > 0
transformer = BODCPUVSubjectsTransformer()
transformer = NVSSubjectsTransformer()
result = []
entry = transformer.apply(StreamEntry(stream_entry)).entry
result.append(entry)
assert expected_from_rdf == result


def test_bodc_puv_transformer_missing_id():
def test_nvs_transformer_missing_id():
stream_entry = parse_rdf_data(INVALID_XML_DATA)
assert len(stream_entry) > 0

transformer = BODCPUVSubjectsTransformer()
transformer = NVSSubjectsTransformer()

with pytest.raises(TransformerError) as err:
transformer.apply(StreamEntry(stream_entry))
Expand Down

0 comments on commit 5633b85

Please sign in to comment.