Example #1
0
def test_match_reference_doesnt_touch_curated(inspire_app):
    cited_record_json = {
        "$schema": "http://localhost:5000/schemas/records/hep.json",
        "_collections": ["Literature"],
        "control_number": 1,
        "document_type": ["article"],
        "dois": [{
            "value": "10.1371/journal.pone.0188398"
        }],
    }

    create_record("lit", cited_record_json)
    reference = {
        "curated_relation": True,
        "record": {
            "$ref": "http://localhost:5000/api/literature/42"
        },
        "reference": {
            "dois": ["10.1371/journal.pone.0188398"]
        },
    }

    schema = load_schema("hep")
    subschema = schema["properties"]["references"]

    assert validate([reference], subschema) is None
    reference = match_reference(reference)

    assert reference["record"][
        "$ref"] == "http://localhost:5000/api/literature/42"

    expected_control_number = [42]
    result_coontrol_number = match_reference_control_numbers(reference)

    assert expected_control_number == result_coontrol_number
Example #2
0
def test_match_reference_on_texkey(inspire_app):
    cited_record_json = {
        "$schema": "http://localhost:5000/schemas/records/hep.json",
        "_collections": ["Literature"],
        "control_number": 1,
        "document_type": ["article"],
        "texkeys": ["Giudice:2007fh"],
        "titles": [{
            "title": "The Strongly-Interacting Light Higgs"
        }],
    }
    create_record("lit", cited_record_json)

    reference = {"reference": {"texkey": "Giudice:2007fh"}}

    schema = load_schema("hep")
    subschema = schema["properties"]["references"]

    assert validate([reference], subschema) is None
    reference = match_reference(reference)

    assert reference["record"][
        "$ref"] == "http://localhost:5000/api/literature/1"
    assert validate([reference], subschema) is None

    expected_control_number = [1]
    result_coontrol_number = match_reference_control_numbers(reference)

    assert expected_control_number == result_coontrol_number
Example #3
0
def test_match_reference_for_data_config(inspire_app):
    """Test reference matcher for the JCAP and JHEP configuration"""

    cited_record_json = {
        "$schema": "http://localhost:5000/schemas/records/data.json",
        "_collections": ["Data"],
        "control_number": 1,
        "dois": [{
            "value": "10.5281/zenodo.11020"
        }],
    }

    create_record("dat", cited_record_json)

    reference = {
        "reference": {
            "dois": ["10.5281/zenodo.11020"],
            "publication_info": {
                "year": 2007
            },
        }
    }

    reference = match_reference(reference)

    assert reference["record"]["$ref"] == "http://localhost:5000/api/data/1"

    expected_control_number = [1]
    result_coontrol_number = match_reference_control_numbers(reference)

    assert expected_control_number == result_coontrol_number
Example #4
0
    def match_reference(self, query_string):
        if not query_string:
            return None

        reference = self.query_string_to_reference_object_or_none(query_string)
        if not reference:
            return None

        reference = self.normalize_journal_title(reference)
        reference = self.convert_old_publication_info_to_new(reference)

        reference_match_control_numbers = match_reference_control_numbers(
            reference)
        if not reference_match_control_numbers:
            LOGGER.info(
                "Reference didn't match.",
                query_string=query_string,
                reference=reference,
            )
            return None
        must = []
        for reference in reference_match_control_numbers:
            must.append(Q("term", control_number=reference))
        return (InspireSearch().params(version=True).query(Q(
            "bool", must=must)).execute())
Example #5
0
def test_match_reference_on_texkey_has_lower_priority_than_pub_info(inspire_app):
    cited_record_with_texkey_json = {
        "$schema": "http://localhost:5000/schemas/records/hep.json",
        "_collections": ["Literature"],
        "control_number": 1,
        "document_type": ["article"],
        "texkeys": ["MyTexKey:2008fh"],
        "titles": [{"title": "The Strongly-Interacting Light Higgs"}],
    }

    create_record("lit", cited_record_with_texkey_json)

    cited_record_with_pub_info_json = {
        "$schema": "http://localhost:5000/schemas/records/hep.json",
        "_collections": ["Literature"],
        "control_number": 2,
        "document_type": ["article"],
        "publication_info": [
            {
                "artid": "100",
                "journal_title": "JHEP",
                "journal_volume": "100",
                "page_start": "100",
                "year": 2020,
            }
        ],
        "titles": [{"title": "The Strongly-Interacting Light Higgs"}],
    }

    create_record("lit", cited_record_with_pub_info_json)

    reference = {
        "reference": {
            "texkey": "MyTexKey:2008fh",
            "publication_info": {
                "artid": "100",
                "journal_title": "JHEP",
                "journal_volume": "100",
                "page_start": "100",
                "year": 2020,
            },
        }
    }

    schema = load_schema("hep")
    subschema = schema["properties"]["references"]

    assert validate([reference], subschema) is None
    reference = match_reference(reference)

    assert reference["record"]["$ref"] == "http://localhost:5000/api/literature/2"
    assert validate([reference], subschema) is None

    expected_control_number = [2, 1]
    result_coontrol_number = match_reference_control_numbers(reference)

    assert set(expected_control_number) == set(result_coontrol_number)
    assert len(expected_control_number) == len(result_coontrol_number)
Example #6
0
def test_match_reference_for_jcap_and_jhep_config(inspire_app):
    """Test reference matcher for the JCAP and JHEP configuration"""

    cited_record_json = {
        "$schema":
        "http://localhost:5000/schemas/records/hep.json",
        "_collections": ["Literature"],
        "control_number":
        1,
        "document_type": ["article"],
        "publication_info": [{
            "artid": "045",
            "journal_title": "JHEP",
            "journal_volume": "06",
            "page_start": "045",
            "year": 2007,
        }],
        "titles": [{
            "title": "The Strongly-Interacting Light Higgs"
        }],
    }

    create_record("lit", cited_record_json)
    reference = {
        "reference": {
            "publication_info": {
                "artid": "045",
                "journal_title": "JHEP",
                "journal_volume": "06",
                "page_start": "045",
                "year": 2007,
            }
        }
    }

    schema = load_schema("hep")
    subschema = schema["properties"]["references"]

    assert validate([reference], subschema) is None
    reference = match_reference(reference)

    assert reference["record"][
        "$ref"] == "http://localhost:5000/api/literature/1"
    assert validate([reference], subschema) is None

    expected_control_number = [1]
    result_coontrol_number = match_reference_control_numbers(reference)

    assert expected_control_number == result_coontrol_number
Example #7
0
def test_match_pubnote_info_when_journal_is_missing_a_letter(inspire_app):
    cited_record_with_pub_info_json = {
        "$schema":
        "http://localhost:5000/schemas/records/hep.json",
        "_collections": ["Literature"],
        "control_number":
        1,
        "document_type": ["article"],
        "publication_info": [{
            "artid": "101",
            "journal_title": "Phys. Rev. B.",
            "journal_volume": "100",
            "page_start": "100",
            "year": 2020,
        }],
        "titles": [{
            "title": "The Strongly-Interacting Light Higgs"
        }],
    }

    create_record("lit", cited_record_with_pub_info_json)

    reference = {
        "reference": {
            "publication_info": {
                "journal_title": "Phys. Rev.",
                "journal_volume": "100",
                "page_start": "100",
            },
        }
    }
    reference = match_reference(reference)
    assert reference["record"][
        "$ref"] == "http://localhost:5000/api/literature/1"

    expected_control_number = [1]
    result_control_number = match_reference_control_numbers(reference)

    assert expected_control_number == result_control_number
Example #8
0
def test_match_references_returns_five_references(inspire_app):
    cited_record_with_pub_info_json_1 = {
        "$schema":
        "http://localhost:5000/schemas/records/hep.json",
        "_collections": ["Literature"],
        "control_number":
        1,
        "document_type": ["article"],
        "publication_info": [{
            "artid": "100",
            "journal_title": "Phys. Rev. D.",
            "journal_volume": "100",
            "page_start": "100",
            "year": 2020,
        }],
        "titles": [{
            "title": "A cool title"
        }],
    }

    create_record("lit", cited_record_with_pub_info_json_1)

    cited_record_with_pub_info_json_2 = {
        "$schema":
        "http://localhost:5000/schemas/records/hep.json",
        "_collections": ["Literature"],
        "control_number":
        2,
        "document_type": ["article"],
        "publication_info": [{
            "artid": "100",
            "journal_title": "Phys. Rev. A.",
            "journal_volume": "100",
            "page_start": "100",
            "year": 2020,
        }],
        "titles": [{
            "title": "A cool title"
        }],
    }

    create_record("lit", cited_record_with_pub_info_json_2)

    cited_record_with_pub_info_json_3 = {
        "$schema":
        "http://localhost:5000/schemas/records/hep.json",
        "_collections": ["Literature"],
        "control_number":
        3,
        "document_type": ["article"],
        "publication_info": [{
            "artid": "100",
            "journal_title": "Phys. Rev. B.",
            "journal_volume": "100",
            "page_start": "100",
            "year": 2020,
        }],
        "titles": [{
            "title": "A cool title"
        }],
    }

    create_record("lit", cited_record_with_pub_info_json_3)

    cited_record_with_pub_info_json_4 = {
        "$schema":
        "http://localhost:5000/schemas/records/hep.json",
        "_collections": ["Literature"],
        "control_number":
        4,
        "document_type": ["article"],
        "publication_info": [{
            "artid": "100",
            "journal_title": "Phys. Rev. C.",
            "journal_volume": "100",
            "page_start": "100",
            "year": 2020,
        }],
        "titles": [{
            "title": "A cool title"
        }],
    }

    create_record("lit", cited_record_with_pub_info_json_4)

    cited_record_with_pub_info_json_5 = {
        "$schema":
        "http://localhost:5000/schemas/records/hep.json",
        "_collections": ["Literature"],
        "control_number":
        5,
        "document_type": ["article"],
        "publication_info": [{
            "artid": "100",
            "journal_title": "Phys. Rev. E.",
            "journal_volume": "100",
            "page_start": "100",
            "year": 2020,
        }],
        "titles": [{
            "title": "A cool title"
        }],
    }

    cited_record_with_pub_info_json_6 = {
        "$schema":
        "http://localhost:5000/schemas/records/hep.json",
        "_collections": ["Literature"],
        "control_number":
        6,
        "document_type": ["article"],
        "publication_info": [{
            "artid": "100",
            "journal_title": "Phys. Rev. E.",
            "journal_volume": "100",
            "page_start": "100",
            "year": 2020,
        }],
        "titles": [{
            "title": "A cool title"
        }],
    }

    create_record("lit", cited_record_with_pub_info_json_5)
    create_record("lit", cited_record_with_pub_info_json_6)

    reference = {
        "reference": {
            "publication_info": {
                "journal_title": "Phys. Rev.",
                "journal_volume": "100",
                "page_start": "100",
            },
        }
    }
    reference = match_reference_control_numbers(reference)
    assert len(reference) == 5