def _split_dialogue(tcache, doc, tid): """Split a dialogue at a turn Turns at or after the given tid are pushed into a new empty dialogue. Returns ------- Span for the dialogue that was split """ wanted_t = "turn %d" % tid wanted_d = "dialogue for " + wanted_t turn = _the(wanted_t, [x for x in doc.units if st.is_turn(x) and st.turn_id(x) == tid]) dialogue = _the(wanted_d, [x for x in doc.units if st.is_dialogue(x) and x.encloses(turn)]) dspan = dialogue.text_span() _actually_split(tcache, doc, dialogue, turn) return dspan
def _split_dialogue(tcache, doc, tid): """Split a dialogue at a turn Turns at or after the given tid are pushed into a new empty dialogue. Returns ------- Span for the dialogue that was split """ wanted_t = 'turn {}'.format(tid) wanted_d = 'dialogue for ' + wanted_t turn = _the(wanted_t, [x for x in doc.units if st.is_turn(x) and st.turn_id(x) == tid]) dialogue = _the(wanted_d, [x for x in doc.units if st.is_dialogue(x) and x.encloses(turn)]) dspan = dialogue.text_span() _actually_split(tcache, doc, dialogue, turn) return dspan
def _nudge_dialogue(doc, tid, direction): """ Move a turn either up or down. For feedback purposes, return the span of the affected region """ prev_turn, turn, next_turn = \ _window1(lambda x: st.turn_id(x) == tid, [x for x in doc.units if st.is_turn(x)]) if not turn: sys.exit("Could not find turn %d" % tid) tspan = turn.text_span() prev_dialogue, dialogue, next_dialogue = \ _window1(lambda x: x.text_span().encloses(tspan), [x for x in doc.units if st.is_dialogue(x)]) if direction == "up": return _nudge_up(turn, dialogue, next_turn, prev_dialogue) elif direction == "down": return _nudge_down(turn, dialogue, prev_turn, next_dialogue) else: raise Exception("Unknown direction " + direction)
def _nudge_dialogue(doc, tid, direction): """ Move a turn either up or down. For feedback purposes, return the span of the affected region """ prev_turn, turn, next_turn = _window1( lambda x: st.turn_id(x) == tid, [x for x in doc.units if st.is_turn(x)] ) if not turn: sys.exit("Could not find turn %d" % tid) tspan = turn.text_span() prev_dialogue, dialogue, next_dialogue = _window1( lambda x: x.text_span().encloses(tspan), [x for x in doc.units if st.is_dialogue(x)] ) if direction == "up": return _nudge_up(turn, dialogue, next_turn, prev_dialogue) elif direction == "down": return _nudge_down(turn, dialogue, prev_turn, next_dialogue) else: raise Exception("Unknown direction " + direction)