Skip to content

Commit

Permalink
map onclusive category to index (#231)
Browse files Browse the repository at this point in the history
SDCP-750
  • Loading branch information
petrjasek authored Apr 17, 2024
1 parent 6268e42 commit 1b4ae07
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
21 changes: 15 additions & 6 deletions server/cp/ingest/parser/cp_onclusive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
1 change: 0 additions & 1 deletion server/cp/output/formatter/cp_ninjs_newsroom_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions server/data/vocabularies.json
Original file line number Diff line number Diff line change
Expand Up @@ -24145,7 +24145,8 @@
"name": {},
"qcode": {},
"parent": {},
"cp_category": {}
"cp_category": {},
"cp_index": {}
},
"init_version": 2,
"items": [
Expand Down Expand Up @@ -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",
Expand Down
18 changes: 15 additions & 3 deletions server/tests/ingest/parser/cp_onclusive_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
]
Expand Down

0 comments on commit 1b4ae07

Please sign in to comment.