Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # bullets = [ '(a) gra tig', '(b) waad', '(1) anmp', '(2)(a) orce', '(b) that h', '(i) and he', '(ii) whd', '(3) so hwner', '(c) petpy']
- def process_hierarchy(context, subsection_content):
- stripped = [ split_all_strict(s) for s in subsection_content]
- bullets = []
- for s in stripped:
- for b in s[0]:
- bullets.append(b)
- parsed = [ Enum(b.strip()) for b in bullets]
- candidate_dict = {}
- last_in_level_stack = []
- previous = None
- for current in parsed:
- # if this is the first bullet
- if previous is None:
- last_in_level_stack.append(current)
- print(str(len(last_in_level_stack)) + ", current: " + current.text)
- # if we have a previous bullet to compare to
- else:
- maybe_first = current.maybe_first_in_scheme()
- maybe_consecutive = previous.get_comparison(current).maybe_consecutive()
- if maybe_consecutive == maybe_first == True:
- print("maybe_consecutive and maybe_first agreed for " + current.text)
- elif maybe_first:
- last_in_level_stack.append(current)
- print("new level!")
- elif maybe_consecutive:
- last_in_level_stack.pop()
- last_in_level_stack.append(current)
- print("consecutive - doing nothing")
- # if we have a bullet that is not consecutive
- else:
- found = False
- # look for which bullet it is consecutive with
- while len(last_in_level_stack) > 0 and (not found):
- bullet = last_in_level_stack.pop()
- prev_bullet_consecutive = bullet.get_comparison(current).maybe_consecutive()
- if (prev_bullet_consecutive):
- found = True
- last_in_level_stack.append(current)
- print("we've found the level")
- else:
- print("current " + current.text + " is not after " + bullet.text)
- # if it is not consecutive to any bullet in stack, we have a problem
- if not found:
- print("we found a bullet that is not first and not consecutive to anything in the stack: " + current.text)
- print(str(len(last_in_level_stack)) + ", current: " + current.text + ", maybe_first: " + str(maybe_first) + ", maybe_consecutive: " + str(maybe_consecutive))
- candidate_dict[current] = len(last_in_level_stack)
- previous = current
- print()
- print(candidate_dict)
- return candidate_dict
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement