Skip to content

Commit

Permalink
better handling @string and other corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchenlin committed Jan 27, 2021
1 parent e422d3e commit 3218bae
Show file tree
Hide file tree
Showing 4 changed files with 1,552 additions and 1,534 deletions.
10 changes: 6 additions & 4 deletions bib2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ def normalize_title(title_str):
return title_str.lower().replace(" ", "").strip()


def load_bib_file(bibpath="acl.bib"):
def load_bib_file(bibpath):
all_bib_entries = []
with open(bibpath) as f:
bib_entry_buffer = []
for line in f.readlines():
# line = line.strip()
if "@string" in line:
continue
bib_entry_buffer.append(line)
if line == "}\n":
if line.strip() == "}":
all_bib_entries.append(bib_entry_buffer)
bib_entry_buffer = []
return all_bib_entries

def buil_json(all_bib_entries):
def build_json(all_bib_entries):
all_bib_dict = {}
num_expections = 0
for bib_entry in tqdm(all_bib_entries[:]):
Expand All @@ -48,6 +50,6 @@ def buil_json(all_bib_entries):
args = parser.parse_args()

all_bib_entries = load_bib_file(args.input_bib)
all_bib_dict = buil_json(all_bib_entries)
all_bib_dict = build_json(all_bib_entries)
with open(args.output_json, "w") as f:
json.dump(all_bib_dict, f, indent=2)
Loading

0 comments on commit 3218bae

Please sign in to comment.