Data models for bib-checker (plain dataclasses, no external deps).
BibEntry
dataclass
A single entry parsed from a .bib file.
| Attributes: |
-
key
(str)
–
Citation key, e.g. Spolyar:2007qv.
-
entry_type
(str)
–
BibTeX entry type, e.g. article or preprint.
-
fields
(dict[str, str])
–
Raw field values keyed by field name.
|
Source code in src/bib_checker/models.py
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 | @dataclass
class BibEntry:
"""A single entry parsed from a .bib file.
Attributes
----------
key : str
Citation key, e.g. ``Spolyar:2007qv``.
entry_type : str
BibTeX entry type, e.g. ``article`` or ``preprint``.
fields : dict[str, str]
Raw field values keyed by field name.
"""
key: str
entry_type: str # article, preprint, inproceedings, …
fields: dict[str, str] = field(default_factory=dict)
# Convenience accessors for commonly compared fields.
@property
def title(self) -> str:
"""Title field value, or an empty string if absent."""
return self.fields.get("title", "")
@property
def doi(self) -> str:
"""DOI field value, or an empty string if absent."""
return self.fields.get("doi", "")
@property
def eprint(self) -> str:
"""ArXiv eprint field value, or an empty string if absent."""
return self.fields.get("eprint", "")
@property
def year(self) -> str:
"""Year field value, or an empty string if absent."""
return self.fields.get("year", "")
@property
def authors(self) -> list[str]:
"""List of author strings split on " and "."""
raw = self.fields.get("author", "")
return [a.strip() for a in raw.split(" and ") if a.strip()]
|
authors
property
List of author strings split on " and ".
doi
property
DOI field value, or an empty string if absent.
eprint
property
ArXiv eprint field value, or an empty string if absent.
title
property
Title field value, or an empty string if absent.
year
property
Year field value, or an empty string if absent.
FieldMismatch
dataclass
A single field difference between a local bib entry and a remote record.
| Attributes: |
-
field_name
(str)
–
Name of the differing field, e.g. doi or year.
-
local_value
(str)
–
The value found in the local .bib file.
-
remote_value
(str)
–
The value returned by the remote source (InspireHEP or ADS).
|
Source code in src/bib_checker/models.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 | @dataclass
class FieldMismatch:
"""A single field difference between a local bib entry and a remote record.
Attributes
----------
field_name : str
Name of the differing field, e.g. ``doi`` or ``year``.
local_value : str
The value found in the local .bib file.
remote_value : str
The value returned by the remote source (InspireHEP or ADS).
"""
field_name: str
local_value: str
remote_value: str
|
CheckResult
dataclass
The result of checking one BibEntry against InspireHEP.
| Attributes: |
-
key
(str)
–
Citation key of the checked entry.
-
status
(str)
–
Outcome: "ok", "missing", "mismatch", or
"found_via_ads" (missing by texkey but located on InspireHEP
via the entry's adsurl bibcode).
-
nonstandard_key
(bool)
–
True when the citation key does not follow the InspireHEP
Author:YYYYxx convention.
-
mismatches
(list[FieldMismatch])
–
Fields that differ from the InspireHEP record. Empty when
status is not "mismatch".
-
local_entry
(dict[str, Any] or None)
–
Flat dict representation of the local bib entry.
-
inspire_record
(dict[str, Any] or None)
–
Raw API record from InspireHEP, or None when missing.
|
Source code in src/bib_checker/models.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 | @dataclass
class CheckResult:
"""The result of checking one BibEntry against InspireHEP.
Attributes
----------
key : str
Citation key of the checked entry.
status : str
Outcome: ``"ok"``, ``"missing"``, ``"mismatch"``, or
``"found_via_ads"`` (missing by texkey but located on InspireHEP
via the entry's ``adsurl`` bibcode).
nonstandard_key : bool
``True`` when the citation key does not follow the InspireHEP
``Author:YYYYxx`` convention.
mismatches : list[FieldMismatch]
Fields that differ from the InspireHEP record. Empty when
status is not ``"mismatch"``.
local_entry : dict[str, Any] or None
Flat dict representation of the local bib entry.
inspire_record : dict[str, Any] or None
Raw API record from InspireHEP, or ``None`` when missing.
"""
key: str
status: str # "ok" | "missing" | "mismatch" | "found_via_ads"
nonstandard_key: bool = False
mismatches: list[FieldMismatch] = field(default_factory=list)
local_entry: dict[str, Any] | None = None
inspire_record: dict[str, Any] | None = None
ads_record: dict[str, Any] | None = None
def to_dict(self) -> dict[str, Any]:
"""Serialise the result to a JSON-compatible dict."""
return {
"key": self.key,
"status": self.status,
"nonstandard_key": self.nonstandard_key,
"mismatches": [
{
"field": m.field_name,
"local": m.local_value,
"remote": m.remote_value,
}
for m in self.mismatches
],
"local_entry": self.local_entry,
"inspire_record": self.inspire_record,
"ads_record": self.ads_record,
}
|
to_dict
Serialise the result to a JSON-compatible dict.
Source code in src/bib_checker/models.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 | def to_dict(self) -> dict[str, Any]:
"""Serialise the result to a JSON-compatible dict."""
return {
"key": self.key,
"status": self.status,
"nonstandard_key": self.nonstandard_key,
"mismatches": [
{
"field": m.field_name,
"local": m.local_value,
"remote": m.remote_value,
}
for m in self.mismatches
],
"local_entry": self.local_entry,
"inspire_record": self.inspire_record,
"ads_record": self.ads_record,
}
|
Suggestion
dataclass
A candidate InspireHEP record suggested for a missing or mismatched entry.
| Attributes: |
-
for_key
(str)
–
Citation key from the original bib file this suggestion targets.
-
texkey
(str)
–
InspireHEP texkey of the candidate record.
-
title
(str)
–
Title of the candidate record.
-
authors
(list[str])
–
Author full names from InspireHEP.
-
year
(str)
–
-
doi
(str)
–
DOI of the candidate record.
-
local_title
(str)
–
Title from the local .bib file, for side-by-side comparison.
-
eprint
(str)
–
-
inspire_id
(str)
–
InspireHEP internal record ID.
|
Source code in src/bib_checker/models.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174 | @dataclass
class Suggestion:
"""A candidate InspireHEP record suggested for a missing or mismatched entry.
Attributes
----------
for_key : str
Citation key from the original bib file this suggestion targets.
texkey : str
InspireHEP texkey of the candidate record.
title : str
Title of the candidate record.
authors : list[str]
Author full names from InspireHEP.
year : str
Publication year.
doi : str
DOI of the candidate record.
local_title : str
Title from the local .bib file, for side-by-side comparison.
eprint : str
ArXiv eprint identifier.
inspire_id : str
InspireHEP internal record ID.
"""
for_key: str
texkey: str
title: str
local_title: str
authors: list[str]
year: str
doi: str
eprint: str
inspire_id: str
def to_dict(self) -> dict[str, Any]:
"""Serialise the suggestion to a JSON-compatible dict."""
return {
"for_key": self.for_key,
"texkey": self.texkey,
"local_title": self.local_title,
"title": self.title,
"authors": self.authors,
"year": self.year,
"doi": self.doi,
"eprint": self.eprint,
"inspire_id": self.inspire_id,
}
|
to_dict
Serialise the suggestion to a JSON-compatible dict.
Source code in src/bib_checker/models.py
162
163
164
165
166
167
168
169
170
171
172
173
174 | def to_dict(self) -> dict[str, Any]:
"""Serialise the suggestion to a JSON-compatible dict."""
return {
"for_key": self.for_key,
"texkey": self.texkey,
"local_title": self.local_title,
"title": self.title,
"authors": self.authors,
"year": self.year,
"doi": self.doi,
"eprint": self.eprint,
"inspire_id": self.inspire_id,
}
|