std00nan commited on
Commit
15d2706
·
verified ·
1 Parent(s): 05a6268

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -7
main.py CHANGED
@@ -25,8 +25,8 @@ def make_body(file):
25
 
26
  def index_to_ref_id(reference_text, reference_ids):
27
  reference_text = reference_text.strip('[]')
28
- dash_separator = "–"
29
- comma_separator = ','
30
  id_max = len(reference_ids)
31
  ids = []
32
  refs = []
@@ -36,7 +36,7 @@ def index_to_ref_id(reference_text, reference_ids):
36
  for i in range(s,e+1):
37
  ids.append(i)
38
  elif reference_text.find(comma_separator) != -1:
39
- ids = [int(x) for x in reference_text.split(comma_separator)]
40
  else:
41
  ids.append(int(reference_text))
42
 
@@ -65,16 +65,16 @@ def xref_generator(reference_text, reference_ids):
65
  return generated_xref
66
 
67
  def make_refs(article_body, reference_ids):
68
- citations_set = set()
69
 
70
- citations_raw = re.findall(r'(\[\d+–\d+\]|\[\d+(, \d+)*\])', contents)
71
 
72
  for cit in citations_raw:
73
- citations_set.add(cit[0])
74
 
75
  x = contents
76
 
77
- for cit in citations_set:
78
  x = x.replace(str(cit), str(xref_generator(cit, reference_ids)))
79
 
80
  return x
 
25
 
26
  def index_to_ref_id(reference_text, reference_ids):
27
  reference_text = reference_text.strip('[]')
28
+ dash_separator = "–" # long dash here
29
+ comma_separator = ", " # workaound
30
  id_max = len(reference_ids)
31
  ids = []
32
  refs = []
 
36
  for i in range(s,e+1):
37
  ids.append(i)
38
  elif reference_text.find(comma_separator) != -1:
39
+ ids = [int(x) for x in reference_text.split(comma_separator)]
40
  else:
41
  ids.append(int(reference_text))
42
 
 
65
  return generated_xref
66
 
67
  def make_refs(article_body, reference_ids):
68
+ citations_list = []
69
 
70
+ citations_raw = re.findall(r"\[\d+(?:–\d+)?(?:,\s?\d+)*\]", contents)
71
 
72
  for cit in citations_raw:
73
+ citations_list.append(cit) # bugfix
74
 
75
  x = contents
76
 
77
+ for cit in citations_list:
78
  x = x.replace(str(cit), str(xref_generator(cit, reference_ids)))
79
 
80
  return x