Skip to content

Commit

Permalink
change linked_book to linked_books and add pages
Browse files Browse the repository at this point in the history
  • Loading branch information
karolina-siemieniuk-morawska committed Mar 12, 2024
1 parent bd408f0 commit 3c0ad7f
Show file tree
Hide file tree
Showing 14 changed files with 438 additions and 95 deletions.
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ repos:
rev: '22.8.0'
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: 'v2.7.1'
hooks:
- id: prettier
- repo: https://github.com/pycqa/isort
rev: '5.12.0'
hooks:
Expand Down
213 changes: 213 additions & 0 deletions backend/data/records/literature/2610328.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
{
"_collections": [
"Literature"
],
"publication_info": [
{
"year": 1938,
"page_end": "334",
"page_start": "333",
"journal_issue": "3564",
"journal_title": "Nature",
"journal_record": {
"$ref": "https://inspirehep.net/api/journals/1214565"
},
"journal_volume": "141",
"curated_relation": true
},
{
"year": 1937,
"page_end": "306",
"page_start": "305",
"journal_issue": "6",
"journal_title": "Compt.Rend.Acad.Sci.URSS",
"journal_record": {
"$ref": "https://inspirehep.net/api/journals/1213104"
},
"journal_volume": "17",
"curated_relation": true
},
{
"year": 1937,
"page_end": "302",
"page_start": "301",
"journal_issue": "6",
"journal_title": "Dokl.Akad.Nauk SSSR",
"journal_record": {
"$ref": "https://inspirehep.net/api/journals/1214770"
},
"journal_volume": "17",
"curated_relation": true
},
{
"year": 1965,
"page_end": "186",
"page_start": "185",
"parent_isbn": "9780080105864",
"parent_record": {
"$ref": "https://inspirehep.net/api/literature/1787272"
},
"curated_relation": true
},
{
"year": 1969,
"page_end": "226",
"page_start": "224",
"parent_record": {
"$ref": "https://inspirehep.net/api/literature/1649231"
},
"curated_relation": true
}
],
"core": false,
"dois": [
{
"value": "10.1038/141333b0"
},
{
"value": "10.1016/b978-0-08-010586-4.50032-8"
}
],
"titles": [
{
"title": "On the origin of stellar energy",
"source": "submitter"
}
],
"$schema": "https://inspirehep.net/schemas/records/hep.json",
"authors": [
{
"ids": [
{
"value": "L.D.Landau.1",
"schema": "INSPIRE BAI"
},
{
"value": "INSPIRE-00147020",
"schema": "INSPIRE ID"
},
{
"value": "HEPNAMES-419974",
"schema": "SPIRES"
}
],
"uuid": "82a5ac21-af55-4b6b-a09b-1f3630844d61",
"record": {
"$ref": "https://inspirehep.net/api/authors/1019139"
},
"full_name": "Landau, Lev Davidovich",
"signature_block": "LANDl",
"curated_relation": true,
"alternative_names": [
"Ландау, Л.Д."
]
}
],
"curated": true,
"texkeys": [
"Landau:1937fjr",
"Landau:1965ujg"
],
"citeable": true,
"refereed": true,
"abstracts": [
{
"value": "It is well known that matter consists of nuclei and electrons. Nevertheless it can be shown that in bodies of very large mass, this usual 'electronic' state of matter can become unstable. The reason for this lies in the fact that the 'electronic' state of matter does not lead to extremely great densities, because at such densities electrons form a Fermi gas having an immense pressure. On the other hand, it is easy to see that matter can go into another state which is much more compressible—the state where all the nuclei and electrons have combined to form neutrons.1 Even if we assume that neutrons repel each other, this repulsion can become appreciable only at densities of the order of magnitude of nuclear densities, that is, $10^{14}$ gm/cm$^3$, and the pressure of a Fermi gas consisting of neutrons is much less than that of an electronic gas of the same density, because of the greater mass of the neutrons."
}
],
"references": [
{
"raw_refs": [
{
"value": "1. Cf.",
"schema": "text"
}
],
"reference": {
"misc": [
"Cf."
],
"label": "1"
}
},
{
"raw_refs": [
{
"value": "Hund, F., Erg. d. exakten Natwis. 15, 189 (1936).",
"schema": "text"
}
],
"reference": {
"label": "1",
"authors": [
{
"full_name": "Hund, F."
}
],
"publication_info": {
"year": 1936,
"artid": "189",
"page_start": "189",
"journal_title": "Ergeb.Exakt.Naturwiss.",
"journal_volume": "15"
}
},
"curated_relation": true
},
{
"record": {
"$ref": "https://inspirehep.net/api/literature/2609859"
},
"raw_refs": [
{
"value": "2. Landau, L., Sov. Phys., 1, 285 (1932).",
"schema": "text"
}
],
"reference": {
"label": "2",
"authors": [
{
"full_name": "Landau, L."
}
],
"publication_info": {
"year": 1932,
"artid": "285",
"page_start": "285",
"journal_title": "Phys.Z.Sowjetunion",
"journal_volume": "1"
}
},
"curated_relation": true
}
],
"public_notes": [
{
"value": "References drawn from Nature 141(1938)333. Reprinted (in Russian) in: Л. Д. Ландау [L. D. Landau]: Собрание трудов [Sobranie trudov], Vol. 1. Наука [Nauka], Moscow, 1969, item 26, pp. 224-226 (available online at the following site of the Russian Academy of Sciences: http://www.e-heritage.ru/Book/10079744 ). Reprint of the English translation [Nature 141(1938)333] in: D. ter Haar (Ed.): Collected Papers of L D Landau. Edited and with an introduction by D ter Haar. Pergamon Press, Oxford, 1965, item 27, pp. 185-186 (ISBN-13: 978-0-08-010586-4)."
}
],
"document_type": [
"article",
"book chapter"
],
"control_number": 2610328,
"number_of_pages": 2,
"inspire_categories": [
{
"term": "Phenomenology-HEP"
},
{
"term": "Astrophysics"
},
{
"term": "Theory-Nucl"
}
],
"title_translations": [
{
"title": "Об источниках звездной энергии [Ob istochnikakh zvezdnoĭ ènergii]",
"language": "ru"
}
]
}
58 changes: 37 additions & 21 deletions backend/inspirehep/records/marshmallow/literature/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# the terms of the MIT License; see LICENSE file for more details.

import orjson
from flask import current_app, request, url_for
from flask import current_app, request
from inspire_dojson.utils import get_record_ref
from inspire_utils.date import format_date
from inspire_utils.record import get_value, get_values_for_schema
from marshmallow import fields, missing, pre_dump
Expand All @@ -17,11 +18,14 @@
)
from inspirehep.assign.utils import can_claim, is_assign_view_enabled
from inspirehep.files.api import current_s3_instance
from inspirehep.pidstore.api import PidStoreBase
from inspirehep.records.marshmallow.common.mixins import (
CanEditByCollectionPermissionMixin,
)
from inspirehep.records.marshmallow.literature.utils import get_parent_record
from inspirehep.records.marshmallow.literature.utils import (
get_authors_without_emails,
get_pages,
get_parent_records,
)
from inspirehep.records.utils import get_literature_earliest_date

from ..base import EnvelopeSchema
Expand All @@ -39,7 +43,6 @@
PublicationInfoItemSchemaV1,
ThesisInfoSchemaV1,
)
from .utils import get_authors_without_emails
from .pdg_identifiers import PDG_IDS_TO_DESCRIPTION_MAPPING

DATASET_SCHEMA_TO_URL_PREFIX_MAP = {
Expand Down Expand Up @@ -102,8 +105,8 @@ class Meta:
)
fulltext_links = fields.Method("get_fulltext_links", dump_only=True)
isbns = fields.List(fields.Nested(IsbnSchemaV1, dump_only=True))
linked_book = fields.Method(
"get_linked_book", dump_only=True, attribute="publication_info"
linked_books = fields.Method(
"get_linked_books", dump_only=True, attribute="publication_info"
)
number_of_authors = fields.Method("get_number_of_authors")
number_of_references = fields.Method("get_number_of_references")
Expand Down Expand Up @@ -185,18 +188,26 @@ def get_number_of_references(self, data):
references = data.get("references")
return self.get_len_or_missing(references)

def get_linked_book(self, data):
parent = get_parent_record(data)
if parent and "titles" in parent and "control_number" in parent:
endpoint = PidStoreBase.get_endpoint_from_pid_type(
PidStoreBase.get_pid_type_from_schema(data["$schema"])
)
endpoint_item = f"invenio_records_rest.{endpoint}_item"
ref = get_value(parent, "self.$ref") or url_for(
endpoint_item, pid_value=parent["control_number"], _external=True
def get_linked_books(self, data):
parents = get_parent_records(data)
pages = get_pages(data)

records = [
{
**parent["titles"][0],
"record": get_record_ref(parent["control_number"], "literature"),
}
for parent in parents
if parent and "titles" in parent and "control_number" in parent
]
merged_list = [
{"page_start": start, "page_end": end, **record}
for start, end, record in zip(
pages["page_start"], pages["page_end"], records
)
return {**parent["titles"][0], "record": {"$ref": ref}}
return None
]

return merged_list

@staticmethod
def get_len_or_missing(maybe_none_list):
Expand Down Expand Up @@ -268,10 +279,15 @@ def get_pdg_keywords(self, data):
pdg_keywords = []

for keyword_entry in keywords:
if keyword_entry.get('schema') != 'PDG':
if keyword_entry.get("schema") != "PDG":
continue
pdg_identifier = keyword_entry['value']
pdg_keywords.append({'value': pdg_identifier, 'description': PDG_IDS_TO_DESCRIPTION_MAPPING[pdg_identifier]})
pdg_identifier = keyword_entry["value"]
pdg_keywords.append(
{
"value": pdg_identifier,
"description": PDG_IDS_TO_DESCRIPTION_MAPPING[pdg_identifier],
}
)

return pdg_keywords

Expand All @@ -280,7 +296,7 @@ def get_keywords(self, data):
keywords_without_pdg = []

for keyword_entry in keywords:
if keyword_entry.get('schema') != 'PDG':
if keyword_entry.get("schema") != "PDG":
keywords_without_pdg.append(keyword_entry)

return keywords_without_pdg
Expand Down
22 changes: 22 additions & 0 deletions backend/inspirehep/records/marshmallow/literature/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@
MATH_EXPRESSION_REGEX = re.compile(r"((?<!\\)\$.*?(?<!\\)\$|(?<!\\)\\\(.*?(?<!\\)\\\))")


def get_pages(data):
pub_info = InspireRecord.get_value(data, "publication_info")
page_start_list = []
page_end_list = []

if pub_info:
for entry in pub_info:
if "parent_record" in entry:
page_start_list.append(entry.get("page_start", None))
page_end_list.append(entry.get("page_end", None))

return {"page_start": page_start_list, "page_end": page_end_list}


def get_parent_records(data):
book_records = InspireRecord.get_linked_records_from_dict_field(
data, "publication_info.parent_record"
)
books = list(book_records)
return books


def get_parent_record(data):
if data.get("doc_type") == "inproceedings":
conference_records = InspireRecord.get_linked_records_from_dict_field(
Expand Down
Loading

0 comments on commit 3c0ad7f

Please sign in to comment.