Example #1
0
def parse_to_layout_helper(parse, internal):
    if isinstance(parse, str):
        #return (DetectModule, LAYOUT_INDEX.index(parse))
        return (DetectModule, LAYOUT_INDEX.get_or_else(parse,
                                                       LAYOUT_INDEX[UNK]))
    else:
        head = parse[0]
        #head_idx = LAYOUT_INDEX.index(parse)
        head_idx = LAYOUT_INDEX.get_or_else(head, LAYOUT_INDEX[UNK])
        if internal:
            if head == "and":
                mod_head = ConjModule
            else:
                mod_head = RedetectModule
        else:
            if head == "count":
                mod_head = DenseAnswerModule
            else:
                mod_head = AttAnswerModule

        below = [
            parse_to_layout_helper(child, internal=True) for child in parse[1:]
        ]
        mods_below, indices_below = zip(*below)
        return (mod_head, ) + tuple(mods_below), (
            head_idx, ) + tuple(indices_below)
Example #2
0
def parse_to_layout_helper(parse, internal):
    if isinstance(parse, str):
        #return (DetectModule, LAYOUT_INDEX.index(parse))
        return (DetectModule, LAYOUT_INDEX.get_or_else(parse, LAYOUT_INDEX[UNK]))
    else:
        head = parse[0]
        #head_idx = LAYOUT_INDEX.index(parse)
        head_idx = LAYOUT_INDEX.get_or_else(head, LAYOUT_INDEX[UNK])
        if internal:
            if head == "and":
                mod_head = ConjModule
            else:
                mod_head = RedetectModule
        else:
            if head == "count":
                mod_head = DenseAnswerModule
            else:
                mod_head = AttAnswerModule

        below = [parse_to_layout_helper(child, internal=True) for child in parse[1:]]
        mods_below, indices_below = zip(*below)
        return (mod_head,) + tuple(mods_below), (head_idx,) + tuple(indices_below)