Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. # bullets = [ '(a) gra tig', '(b) waad', '(1) anmp', '(2)(a) orce', '(b) that h', '(i) and he', '(ii) whd', '(3) so hwner', '(c) petpy']
  2. def process_hierarchy(context, subsection_content):
  3. stripped = [ split_all_strict(s) for s in subsection_content]
  4. bullets = []
  5. for s in stripped:
  6. for b in s[0]:
  7. bullets.append(b)
  8.  
  9. parsed = [ Enum(b.strip()) for b in bullets]
  10. candidate_dict = {}
  11. last_in_level_stack = []
  12. previous = None
  13. for current in parsed:
  14. # if this is the first bullet
  15. if previous is None:
  16. last_in_level_stack.append(current)
  17. print(str(len(last_in_level_stack)) + ", current: " + current.text)
  18. # if we have a previous bullet to compare to
  19. else:
  20. maybe_first = current.maybe_first_in_scheme()
  21. maybe_consecutive = previous.get_comparison(current).maybe_consecutive()
  22.  
  23. if maybe_consecutive == maybe_first == True:
  24. print("maybe_consecutive and maybe_first agreed for " + current.text)
  25. elif maybe_first:
  26. last_in_level_stack.append(current)
  27. print("new level!")
  28. elif maybe_consecutive:
  29. last_in_level_stack.pop()
  30. last_in_level_stack.append(current)
  31. print("consecutive - doing nothing")
  32. # if we have a bullet that is not consecutive
  33. else:
  34. found = False
  35. # look for which bullet it is consecutive with
  36. while len(last_in_level_stack) > 0 and (not found):
  37. bullet = last_in_level_stack.pop()
  38. prev_bullet_consecutive = bullet.get_comparison(current).maybe_consecutive()
  39. if (prev_bullet_consecutive):
  40. found = True
  41. last_in_level_stack.append(current)
  42. print("we've found the level")
  43. else:
  44. print("current " + current.text + " is not after " + bullet.text)
  45.  
  46. # if it is not consecutive to any bullet in stack, we have a problem
  47. if not found:
  48. print("we found a bullet that is not first and not consecutive to anything in the stack: " + current.text)
  49.  
  50. print(str(len(last_in_level_stack)) + ", current: " + current.text + ", maybe_first: " + str(maybe_first) + ", maybe_consecutive: " + str(maybe_consecutive))
  51.  
  52. candidate_dict[current] = len(last_in_level_stack)
  53. previous = current
  54. print()
  55.  
  56. print(candidate_dict)
  57. return candidate_dict
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement