Skip to content

Commit

Permalink
workflows: add uk curation step
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalEgn committed Apr 22, 2024
1 parent 7c9cbbd commit 17ff37e
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 10 deletions.
9 changes: 9 additions & 0 deletions inspirehep/modules/workflows/tasks/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,15 @@ def check_if_france_in_raw_affiliations(obj, eng):
return True


def check_if_core_and_uk_in_fulltext(obj, eng):
fulltext = get_fulltext(obj)
if not fulltext or not is_core(obj, eng):
return
regex = re.compile(
r"\b(UK|United\s+Kingdom|England|Scotland|Northern\s+Ireland)\b", re.UNICODE | re.IGNORECASE)
return regex.search(fulltext)


def load_record_from_hep(obj, wf):
control_number = obj.data['control_number']
pid_type = get_pid_type_from_schema(obj.data['$schema'])
Expand Down
30 changes: 21 additions & 9 deletions inspirehep/modules/workflows/workflows/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
create_core_selection_wf,
check_if_france_in_fulltext,
check_if_france_in_raw_affiliations,
link_institutions_with_affiliations
link_institutions_with_affiliations,
check_if_core_and_uk_in_fulltext
)

from inspirehep.modules.workflows.tasks.classifier import (
Expand Down Expand Up @@ -261,15 +262,26 @@
is_marked('is-update'),
IF_ELSE(
is_arxiv_paper,
IF(
check_if_france_in_fulltext,
create_ticket(
template='literaturesuggest/tickets/curation_core.html',
queue='HAL_curation',
context_factory=curation_ticket_context,
ticket_id_key='curation_ticket_id',
[
IF(
check_if_france_in_fulltext,
create_ticket(
template='literaturesuggest/tickets/curation_core.html',
queue='HAL_curation',
context_factory=curation_ticket_context,
ticket_id_key='curation_ticket_id',
),
),
),
IF(
check_if_core_and_uk_in_fulltext,
create_ticket(
template='literaturesuggest/tickets/curation_core.html',
queue='UK_curation',
context_factory=curation_ticket_context,
ticket_id_key='curation_ticket_id',
),
)
],
IF(
check_if_france_in_raw_affiliations,
create_ticket(
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/workflows/test_article_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ def test_create_ticket_when_source_is_not_publishing(
"inspirehep.modules.workflows.tasks.actions.check_if_france_in_fulltext",
return_value=False,
)
@mock.patch(
"inspirehep.modules.workflows.tasks.actions.check_if_core_and_uk_in_fulltext",
return_value=False,
)
@mock.patch("inspirehep.modules.workflows.tasks.submission.send_robotupload")
def test_set_fermilab_collection_from_report_number(
mocked_api_request_magpie,
Expand Down
80 changes: 79 additions & 1 deletion tests/unit/workflows/test_workflows_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

from inspirehep.modules.workflows.tasks.actions import jlab_ticket_needed, load_from_source_data, \
extract_authors_from_pdf, is_suitable_for_pdf_authors_extraction, is_fermilab_report, add_collection, \
check_if_france_in_fulltext, check_if_france_in_raw_affiliations
check_if_france_in_fulltext, check_if_france_in_raw_affiliations, check_if_core_and_uk_in_fulltext


def test_match_approval_gets_match_recid():
Expand Down Expand Up @@ -579,3 +579,81 @@ def test_check_if_france_in_fulltext_when_france_in_text_body(mocked_get_documen
france_in_fulltext = check_if_france_in_fulltext(obj, eng)

assert france_in_fulltext


@patch("inspirehep.modules.workflows.tasks.actions.get_document_in_workflow")
def test_check_if_uk_in_fulltext_not_core(mocked_get_document, app):
fake_grobid_response = "<country key=\"UK\">England</country>"
obj = MagicMock()
obj.data = {
'core': False
}
obj.extra_data = {}
eng = None
new_config = {"GROBID_URL": "http://grobid_url.local"}
with patch.dict(current_app.config, new_config):
with requests_mock.Mocker() as requests_mocker:
requests_mocker.register_uri(
'POST', 'http://grobid_url.local/api/processFulltextDocument',
text=fake_grobid_response,
headers={'content-type': 'application/xml'},
status_code=200,
)
with tempfile.NamedTemporaryFile() as tmp_file:
mocked_get_document.return_value.__enter__.return_value = tmp_file.name
uk_in_fulltext_and_core = check_if_core_and_uk_in_fulltext(
obj, eng)

assert not uk_in_fulltext_and_core


@patch("inspirehep.modules.workflows.tasks.actions.get_document_in_workflow")
def test_check_if_uk_in_fulltext_core(mocked_get_document, app):
fake_grobid_response = "<country key=\"UK\">England</country>"
obj = MagicMock()
obj.data = {
'core': True
}
obj.extra_data = {}
eng = None
new_config = {"GROBID_URL": "http://grobid_url.local"}
with patch.dict(current_app.config, new_config):
with requests_mock.Mocker() as requests_mocker:
requests_mocker.register_uri(
'POST', 'http://grobid_url.local/api/processFulltextDocument',
text=fake_grobid_response,
headers={'content-type': 'application/xml'},
status_code=200,
)
with tempfile.NamedTemporaryFile() as tmp_file:
mocked_get_document.return_value.__enter__.return_value = tmp_file.name
uk_in_fulltext_and_core = check_if_core_and_uk_in_fulltext(
obj, eng)

assert uk_in_fulltext_and_core


@patch("inspirehep.modules.workflows.tasks.actions.get_document_in_workflow")
def test_check_if_uk_in_fulltext_core_case_insensitive(mocked_get_document, app):
fake_grobid_response = "<country>unitEd KiNgdOm</country>"
obj = MagicMock()
obj.data = {
'core': True
}
obj.extra_data = {}
eng = None
new_config = {"GROBID_URL": "http://grobid_url.local"}
with patch.dict(current_app.config, new_config):
with requests_mock.Mocker() as requests_mocker:
requests_mocker.register_uri(
'POST', 'http://grobid_url.local/api/processFulltextDocument',
text=fake_grobid_response,
headers={'content-type': 'application/xml'},
status_code=200,
)
with tempfile.NamedTemporaryFile() as tmp_file:
mocked_get_document.return_value.__enter__.return_value = tmp_file.name
uk_in_fulltext_and_core = check_if_core_and_uk_in_fulltext(
obj, eng)

assert uk_in_fulltext_and_core

0 comments on commit 17ff37e

Please sign in to comment.