コード例 #1
0
    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 sorted(slots, key=lambda slot: slot.start):
            annotation_str += escape_brackets(
                get_substring_from_offsets(utterance, cur_index, slot.start)
            )
            annotation_str += (
                OPEN
                + escape_brackets(slot.label)
                + " "
                + escape_brackets(
                    get_substring_from_offsets(utterance, slot.start, slot.end)
                )
                + " "
                + CLOSE
            )
            cur_index = slot.end
        annotation_str += (
            escape_brackets(get_substring_from_offsets(utterance, cur_index, None))
            + " "
            + CLOSE
        )

        return annotation_str
コード例 #2
0
    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 sorted(slots, key=lambda slot: slot.start):
            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
コード例 #3
0
def frame_to_str(frame: Node):
    annotation_str = OPEN + escape_brackets(frame.label) + " "
    cur_index = 0
    for slot in sorted(frame.children, key=lambda slot: slot.span.start):
        annotation_str += escape_brackets(
            get_substring_from_offsets(frame.text, cur_index, slot.span.start))
        annotation_str += (
            OPEN + escape_brackets(slot.label) + " " + escape_brackets(
                get_substring_from_offsets(frame.text, slot.span.start,
                                           slot.span.end)) + " " + CLOSE)
        cur_index = slot.span.end
    annotation_str += (escape_brackets(
        get_substring_from_offsets(frame.text, cur_index, None)) + " " + CLOSE)

    return annotation_str