Skip to content

Commit bd31701

Browse files
author
Gerit Wagner
committed
bib-loader: robust field recognition
1 parent b642546 commit bd31701

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

colrev/loader/bib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def process_key_value(
203203
current_record: Dict[str, Any], current_key: str, current_value: str, line: str
204204
) -> tuple[str, str]:
205205
"""Processes a key-value pair inside an entry."""
206-
if "=" in line: # New key-value pair
206+
if re.match(r"^\s*[a-zA-Z0-9._-]+\s*=", line):
207207
if current_key:
208208
store_current_key_value(current_record, current_key, current_value)
209209
key, value = map(str.strip, line.split("=", 1))

tests/2_loader/bib_test.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import colrev.exceptions as colrev_exceptions
1010
import colrev.loader.bib
1111
import colrev.loader.load_utils
12-
import colrev.review_manager
13-
import colrev.settings
12+
13+
# flake8: noqa
1414

1515

1616
def test_load(tmp_path, helpers) -> None: # type: ignore
@@ -56,6 +56,7 @@ def test_load(tmp_path, helpers) -> None: # type: ignore
5656
)
5757
colrev.loader.bib.run_resolve_crossref(records, logger=logging.getLogger(__name__))
5858

59+
print(records)
5960
assert records == {
6061
"articlewriter_firstrandomword_2020": {
6162
"ID": "articlewriter_firstrandomword_2020",
@@ -108,12 +109,20 @@ def test_load(tmp_path, helpers) -> None: # type: ignore
108109
"title": "Mouse stories two",
109110
"crossref": "ICRC2016",
110111
},
112+
"WOS:000072095400011": {
113+
"ID": "WOS:000072095400011",
114+
"ENTRYTYPE": "article",
115+
"Author": "Andreica, D and Schmid, H",
116+
"Title": "Magnetic properties and phase transitions of iron boracites, Fe3B7O13X (X = Cl, Br OR I)",
117+
"Journal": "FERROELECTRICS",
118+
"Year": "1997",
119+
},
111120
}
112121

113122
nr_records = colrev.loader.load_utils.get_nr_records(
114123
Path("data/search/bib_data.bib")
115124
)
116-
assert 5 == nr_records
125+
assert 6 == nr_records
117126

118127
# if the file does not (yet) exist
119128
nr_records = colrev.loader.load_utils.get_nr_records(

tests/2_loader/data/bib_data.bib

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,14 @@ @inproceedings{mouse2016
4747
@proceedings{ICRC2015,
4848
booktitle = {Proceedings of the 34th International Cosmic Ray Conference},
4949
year = {2015},
50-
}
50+
}
51+
52+
53+
@article{ WOS:000072095400011,
54+
Author = {Andreica, D and
55+
Schmid, H},
56+
Title = {Magnetic properties and phase transitions of iron boracites,
57+
Fe3B7O13X (X = Cl, Br OR I)},
58+
Journal = {FERROELECTRICS},
59+
Year = {1997},
60+
}

0 commit comments

Comments
 (0)