File size: 921 Bytes
acd7cf4
 
0b9d8c7
acd7cf4
 
 
0b9d8c7
acd7cf4
 
0b9d8c7
 
 
 
 
 
 
 
 
 
 
 
 
 
283e483
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from hashlib import md5


def compute_args_hash(*args):
    return md5(str(args).encode()).hexdigest()


def compute_content_hash(content, prefix: str = ""):
    return prefix + md5(content.encode()).hexdigest()


def compute_mm_hash(item, prefix: str = ""):
    if item.get("type") == "text" and item.get("text"):
        content = item["text"].strip()
    elif item.get("type") == "image" and item.get("img_path"):
        content = f"image:{item['img_path']}"
    elif item.get("type") == "table" and item.get("table_body"):
        content = f"table:{item['table_body']}"
    elif item.get("type") == "equation" and item.get("text"):
        content = f"equation:{item['text']}"
    else:
        content = str(item)
    return prefix + md5(content.encode()).hexdigest()


def compute_dict_hash(d: dict, prefix: str = ""):
    items = tuple(sorted(d.items()))
    return prefix + md5(str(items).encode()).hexdigest()