forked from inspirehep/inspire-next
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
matcher: refactor code and add tests
Signed-off-by: Antonio Cesarano <[email protected]>
- Loading branch information
Showing
3 changed files
with
239 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
{ | ||
"$schema": "http://localhost:5000/schemas/records/hep.json", | ||
"_collections": [ | ||
"Literature" | ||
], | ||
"abstracts": [ | ||
{ | ||
"source": "arXiv", | ||
"value": "We discuss the implications of studies of partition function zeros and equimodular curves for the analytic properties of the Ising model on a square lattice in a magnetic field. In particular we consider the dense set of singularities in the susceptibility of the Ising model at $H=0$ found by Nickel and its relation to the analyticity of the field theory computations of Fonseca and Zamolodchikov. Curator change.\n" | ||
} | ||
], | ||
"accelerator_experiments": [ | ||
{ | ||
"legacy_name": "CERN-LHC-ALICE" | ||
} | ||
], | ||
"acquisition_source": { | ||
"datetime": "2017-05-11T08:50:25.184741", | ||
"method": "hepcrawl", | ||
"source": "arXiv", | ||
"submission_number": "db9325b2362611e78bfd0242ac12000b" | ||
}, | ||
"arxiv_eprints": [ | ||
{ | ||
"categories": [ | ||
"math-ph", | ||
"cond-mat.stat-mech", | ||
"math.MP" | ||
], | ||
"value": "1705.02541" | ||
} | ||
], | ||
"authors": [ | ||
{ | ||
"affiliations": [ | ||
{ | ||
"curated_relation": true, | ||
"record": { | ||
"$ref": "http://localhost:5000/api/institutions/902725" | ||
}, | ||
"value": "CERN" | ||
} | ||
], | ||
"full_name": "Assis, Mathieu", | ||
"signature_block": "ASm", | ||
"uuid": "e3b0a6e6-5950-41c4-ba8a-76cd597cb0d5" | ||
}, | ||
{ | ||
"affiliations": [ | ||
{ | ||
"curated_relation": true, | ||
"record": { | ||
"$ref": "http://localhost:5000/api/institutions/902725" | ||
}, | ||
"value": "CERN" | ||
} | ||
], | ||
"full_name": "Jacobsen, J.L.", | ||
"signature_block": "JACABSANj", | ||
"uuid": "3f4cc9b7-ade5-4b9c-885c-f20bba88f5e2" | ||
} | ||
], | ||
"citeable": true, | ||
"collaborations": [ | ||
{ | ||
"value": "ALICE" | ||
} | ||
], | ||
"control_number": 1, | ||
"core": true, | ||
"document_type": [ | ||
"article" | ||
], | ||
"dois": [ | ||
{ | ||
"value": "10.0001/test_doi" | ||
} | ||
], | ||
"inspire_categories": [ | ||
{ | ||
"source": "arxiv", | ||
"term": "Math and Math Physics" | ||
}, | ||
{ | ||
"source": "arxiv", | ||
"term": "General Physics" | ||
}, | ||
{ | ||
"term": "Instrumentation" | ||
} | ||
], | ||
"keywords": [ | ||
{ | ||
"source": "magpie", | ||
"value": "Ising model" | ||
}, | ||
{ | ||
"source": "magpie", | ||
"value": "partition function" | ||
}, | ||
{ | ||
"source": "magpie", | ||
"value": "lattice field theory" | ||
} | ||
], | ||
"license": [ | ||
{ | ||
"license": "arXiv-1.0", | ||
"url": "http://arxiv.org/licenses/nonexclusive-distrib/1.0/" | ||
} | ||
], | ||
"number_of_pages": 21, | ||
"preprint_date": "2017-05-06", | ||
"public_notes": [ | ||
{ | ||
"source": "arXiv", | ||
"value": "21 pages, 13 figures" | ||
}, | ||
{ | ||
"value": "*Temporary entry*" | ||
}, | ||
{ | ||
"value": "This is a test public note by the curator\n" | ||
} | ||
], | ||
"refereed": true, | ||
"report_numbers": [ | ||
{ | ||
"source": "hepcrawl", | ||
"value": "LPTENS/17/12" | ||
}, | ||
{ | ||
"value": "CURATOR-001" | ||
} | ||
], | ||
"titles": [ | ||
{ | ||
"source": "arXiv", | ||
"title": "Analyticity of the Ising curation: An interpretation" | ||
} | ||
] | ||
} |
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,73 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of INSPIRE. | ||
# Copyright (C) 2014-2017 CERN. | ||
# | ||
# INSPIRE is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# INSPIRE is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with INSPIRE. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# In applying this license, CERN does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an Intergovernmental Organization | ||
# or submit itself to any jurisdiction. | ||
|
||
from __future__ import absolute_import, division, print_function | ||
|
||
import os | ||
import json | ||
import pytest | ||
|
||
from invenio_search import current_search_client as es | ||
from invenio_workflows import workflow_object_class | ||
from inspirehep.modules.migrator.tasks import record_insert_or_replace | ||
from inspirehep.modules.workflows.tasks.matching import ( | ||
match_with_invenio_matcher | ||
) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def setup_record(): | ||
parent_folder = os.path.abspath(os.path.join(__file__, os.pardir)) | ||
with open(os.path.join(parent_folder, 'fixtures', 'matcher_rec.json')) as f: | ||
rec = record_insert_or_replace(json.loads(f.read())) | ||
es.indices.refresh('records-hep') | ||
return rec | ||
|
||
|
||
def _create_hep_wf(to_match): | ||
return workflow_object_class.create( | ||
data_type='hep', | ||
id_user=1, | ||
data=to_match | ||
) | ||
|
||
|
||
def test_match_with_invenio_matcher_matches_a_record(setup_record): | ||
to_match = setup_record | ||
to_match['titles'][0]['title'] += ' - different title' | ||
|
||
obj = _create_hep_wf(to_match) | ||
matcher = match_with_invenio_matcher() | ||
assert matcher(obj=obj, eng=None) is True | ||
|
||
|
||
def test_match_with_invenio_matcher_does_not_match_any_record(setup_record): | ||
to_match = setup_record | ||
|
||
# matcher won't match this record having different dois and arxiv eprints | ||
del to_match['control_number'] | ||
to_match['dois'][0]['value'] = 'test' | ||
to_match['arxiv_eprints'][0]['value'] = 'test' | ||
|
||
obj = _create_hep_wf(to_match) | ||
matcher = match_with_invenio_matcher() | ||
assert matcher(obj=obj, eng=None) is False |