Skip to content

Commit

Permalink
Fix a minor bug in .collect_loc_codes_by_initial()
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeqfu committed Mar 1, 2021
1 parent b951594 commit ca7bd71
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions pyrcs/line_data/loc_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,18 +637,27 @@ def strip_others_note(other_note_x):

# Parse STANOX note
def parse_stanox_note(x):
if x == '-':
if x in ('-', ''):
dat, note = '', ''
else:
d = re.search(r'[\w *,]+(?= [\[(\'])', x)
dat = d.group() if d is not None else x
note = 'Pseudo STANOX' if '*' in dat else ''
n = re.search(r'(?<=[\[(\'])[\w, ]+.(?=[)\]\'])', x)
if n is not None:
note = '; '.join(x for x in [note, n.group()] if x != '')
if '(' not in note and note.endswith(')'):
note = note.rstrip(')')
dat = dat.rstrip('*') if '*' in dat else dat
if re.match(r'\d{5}$', x):
dat = x
note = ''
elif re.match(r'\d{5}\*$', x):
dat = x.rstrip('*')
note = 'Pseudo STANOX'
elif re.match(r'\d{5} \w.*', x):
dat = re.search(r'\d{5}', x).group()
note = re.search(r'(?<= )\w.*', x).group()
else:
d = re.search(r'[\w *,]+(?= [\[(\'])', x)
dat = d.group() if d is not None else x
note = 'Pseudo STANOX' if '*' in dat else ''
n = re.search(r'(?<=[\[(\'])[\w, ]+.(?=[)\]\'])', x)
if n is not None:
note = '; '.join(x for x in [note, n.group()] if x != '')
if '(' not in note and note.endswith(')'):
note = note.rstrip(')')
return dat, note

if not loc_codes.empty:
Expand Down

0 comments on commit ca7bd71

Please sign in to comment.