def create_frame(intent_label, slot_names_str, utterance): frame = Node( label=intent_label, span=Span(0, len(utterance)), children={ Node(label=slot.label, span=Span(slot.start, slot.end)) for slot in parse_slot_string(slot_names_str) }, ) return frame
def create_annotation(utterance: str, intent_label: str, slots_label: str) -> str: annotation_str = OPEN + escape_brackets(intent_label) + " " slots = parse_slot_string(slots_label) cur_index = 0 for slot in slots: annotation_str += escape_brackets(utterance[cur_index:slot.start]) annotation_str += ( OPEN + escape_brackets(slot.label) + " " + escape_brackets(utterance[slot.start:slot.end]) + " " + CLOSE) cur_index = slot.end annotation_str += escape_brackets(utterance[cur_index:]) + " " + CLOSE return annotation_str
def get_slots(word_names): slots = { Node(label=slot.label, span=Span(slot.start, slot.end)) for slot in parse_slot_string(word_names) } return Counter(slots)