From 1b4ae079b4a6deb4474be43ad66fafdab47a5eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Ja=C5=A1ek?= Date: Wed, 17 Apr 2024 16:55:45 +0200 Subject: [PATCH] map onclusive category to index (#231) SDCP-750 --- server/cp/ingest/parser/cp_onclusive.py | 21 +++++++++++++------ .../formatter/cp_ninjs_newsroom_formatter.py | 1 - server/data/vocabularies.json | 6 ++++-- .../tests/ingest/parser/cp_onclusive_test.py | 18 +++++++++++++--- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/server/cp/ingest/parser/cp_onclusive.py b/server/cp/ingest/parser/cp_onclusive.py index 89eb2ffb..c062c659 100644 --- a/server/cp/ingest/parser/cp_onclusive.py +++ b/server/cp/ingest/parser/cp_onclusive.py @@ -66,16 +66,25 @@ def parse(self, content, provider=None): "translations": anpa_category["translations"], } ) + if onclusive_category.get("cp_index"): + subj = self.find_cv_item( + subjects, onclusive_category["cp_index"] + ) + else: + subj = { + "name": onclusive_category["name"], + "qcode": onclusive_category["qcode"].zfill(8), + "scheme": "subject_custom", + "translations": onclusive_category.get( + "translations" + ), + } + if subj: + item["subject"].append(item_value(subj)) if subject["scheme"] == "onclusive_event_types": event_type = self.find_event_type(event_types, subject["qcode"]) if event_type: item["subject"].append(item_value(event_type)) - if event_type.get("subject"): - for subject_name in event_type["subject"]: - subj = self.find_subject(subjects, subject_name) - if subj: - item["subject"].append(item_value(subj)) - # remove duplicates item["anpa_category"] = unique(category) item["subject"] = unique(item["subject"]) diff --git a/server/cp/output/formatter/cp_ninjs_newsroom_formatter.py b/server/cp/output/formatter/cp_ninjs_newsroom_formatter.py index 9b359a76..637ed2c4 100644 --- a/server/cp/output/formatter/cp_ninjs_newsroom_formatter.py +++ b/server/cp/output/formatter/cp_ninjs_newsroom_formatter.py @@ -33,7 +33,6 @@ def __init__(self): def update_ninjs_subjects(self, ninjs, language="en-CA"): try: - # Fetch the vocabulary cv = superdesk.get_resource_service("vocabularies").find_one( req=None, _id="subject_custom" diff --git a/server/data/vocabularies.json b/server/data/vocabularies.json index bfa7a127..2027464e 100644 --- a/server/data/vocabularies.json +++ b/server/data/vocabularies.json @@ -24145,7 +24145,8 @@ "name": {}, "qcode": {}, "parent": {}, - "cp_category": {} + "cp_category": {}, + "cp_index": {} }, "init_version": 2, "items": [ @@ -24879,7 +24880,8 @@ "name": "Law & Order", "cp_category": "g", "qcode": "88", - "is_active": true + "is_active": true, + "cp_index": "02000000" }, { "name": "Luxury Goods / Brands", diff --git a/server/tests/ingest/parser/cp_onclusive_test.py b/server/tests/ingest/parser/cp_onclusive_test.py index 3cc64ed3..9448fa6e 100644 --- a/server/tests/ingest/parser/cp_onclusive_test.py +++ b/server/tests/ingest/parser/cp_onclusive_test.py @@ -99,15 +99,27 @@ def test_content(self): "scheme": "event_types", }, { - "qcode": "04000000", + "qcode": "00000035", "scheme": "subject_custom", }, { - "qcode": "20000638", + "qcode": "00000050", "scheme": "subject_custom", }, { - "qcode": "11000000", + "qcode": "00000097", + "scheme": "subject_custom", + }, + { + "qcode": "00000133", + "scheme": "subject_custom", + }, + { + "qcode": "00000159", + "scheme": "subject_custom", + }, + { + "qcode": "02000000", # mapped via cp_index "scheme": "subject_custom", }, ]