Пример #1
0
    def duplicate_structure(current_root, default_tag):
        duplicated_node = MathSymbol(default_tag)

        if current_root.next is not None:
            child = Query.duplicate_structure(current_root.next, default_tag)
            duplicated_node.next = child

        if current_root.above is not None:
            child = Query.duplicate_structure(current_root.above, default_tag)
            duplicated_node.above = child

        if current_root.below is not None:
            child = Query.duplicate_structure(current_root.below, default_tag)
            duplicated_node.below = child

        if current_root.pre_above is not None:
            child = Query.duplicate_structure(current_root.pre_above, default_tag)
            duplicated_node.pre_above = child

        if current_root.pre_below is not None:
            child = Query.duplicate_structure(current_root.pre_below, default_tag)
            duplicated_node.pre_below = child

        if current_root.within is not None:
            child = Query.duplicate_structure(current_root.within, default_tag)
            duplicated_node.within = child

        if current_root.element is not None:
            child = Query.duplicate_structure(current_root.element, default_tag)
            duplicated_node.element = child

        return duplicated_node
Пример #2
0
def get_child_path(parent_loc, child_loc):
    if parent_loc == "-" or parent_loc == "":
        extended = ""
    elif "0" <= parent_loc[0] <= "9":
        extended = MathSymbol.rldecode(parent_loc)
    else:
        extended = parent_loc

    if len(child_loc) > 0 and "0" <= child_loc[0] <= "9":
        extended += MathSymbol.rldecode(child_loc)
    else:
        extended += child_loc

    if len(extended) > 5:
        return MathSymbol.rlencode(extended)
    elif len(extended) > 0:
        return extended
    else:
        return "-"
Пример #3
0
    def __create_tree_from_string(cls, tree_substring):
        #assume first and last characters are [ and ]
        #read name until , [, or ] appears
        #print("sub: " + tree_substring)

        pos = 1
        while not tree_substring[pos] in ["[", "]"]:
            if tree_substring[pos] == "," and pos > 1:
                break

            if tree_substring[pos:pos + 2] == "M!":
                #special case of matrices...
                pos += 2
            else:
                #everything else
                pos += 1

        label = tree_substring[1:pos]
        current_next = None
        current_above = None
        current_below = None
        current_over = None
        current_under = None
        current_within = None
        current_pre_above = None
        current_pre_below = None
        current_element = None

        #check the case...
        while tree_substring[pos] != "]":
            if tree_substring[pos] == "[":
                #child next...
                child_end = cls.__find_matching_bracket(tree_substring, pos)
                child_text = tree_substring[pos:child_end]
                pos = child_end

                current_next = cls.__create_tree_from_string(child_text)
                                
            if tree_substring[pos] == ",":
                #child other than next...
                child_relation = tree_substring[pos + 1]
                child_end = cls.__find_matching_bracket(tree_substring, pos + 2)
                child_text = tree_substring[(pos + 2):child_end]
                pos = child_end
                
                child_node = cls.__create_tree_from_string(child_text)

                if child_relation == "a":
                    current_above = child_node
                elif child_relation == "b":
                    current_below = child_node
                elif child_relation == "o":
                    current_over = child_node
                elif child_relation == "u":
                    current_under = child_node
                elif child_relation == "c":
                    current_pre_above = child_node
                elif child_relation == "d":
                    current_pre_below = child_node
                elif child_relation == "w":
                    current_within = child_node
                elif child_relation == "e":
                    current_element = child_node
                else:
                    print("Invalid child relation found: " + chid_relation)

        
        root = MathSymbol(label, current_next, current_above, current_below, current_over, current_under,
                          current_within, current_pre_above, current_pre_below, current_element)
        if tree_substring != root.tostring():
            print("Mismatch: " + tree_substring + " -> " + root.tostring(), flush=True)
            exit(1)
            
        return root
Пример #4
0
    def duplicate_structure(current_root, default_tag):
        duplicated_node = MathSymbol(default_tag)

        if current_root.next is not None:
            child = Query.duplicate_structure(current_root.next, default_tag)
            duplicated_node.next = child

        if current_root.above is not None:
            child = Query.duplicate_structure(current_root.above, default_tag)
            duplicated_node.above = child

        if current_root.below is not None:
            child = Query.duplicate_structure(current_root.below, default_tag)
            duplicated_node.below = child

        if current_root.over is not None:
            child = Query.duplicate_structure(current_root.over, default_tag)
            duplicated_node.over = child

        if current_root.under is not None:
            child = Query.duplicate_structure(current_root.under, default_tag)
            duplicated_node.under = child

        if current_root.pre_above is not None:
            child = Query.duplicate_structure(current_root.pre_above,
                                              default_tag)
            duplicated_node.pre_above = child

        if current_root.pre_below is not None:
            child = Query.duplicate_structure(current_root.pre_below,
                                              default_tag)
            duplicated_node.pre_below = child

        if current_root.within is not None:
            child = Query.duplicate_structure(current_root.within, default_tag)
            duplicated_node.within = child

        if current_root.element is not None:
            child = Query.duplicate_structure(current_root.element,
                                              default_tag)
            duplicated_node.element = child

        return duplicated_node