-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit_bigram_ex.py
44 lines (33 loc) · 1.38 KB
/
unit_bigram_ex.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
""" Experimenting with automated unit bigram handling """
import json
# load database:
with open("extracted_db.json", 'r', encoding='utf-8') as db_file:
database: dict = json.load(db_file)
inst_id = "b001"
instance = database[inst_id]
print(f"Extracted information of text {inst_id}:")
print(instance)
def sublist_match(main_list, sub_list) -> bool:
if not sub_list:
return False
first_idx: int = int()
for item_idx, item in enumerate(main_list):
if item == sub_list[0]:
first_idx = item_idx
break
if main_list[first_idx:first_idx+len(sub_list)] == sub_list:
return True
else:
return False
for unit_idx, unit in enumerate(instance['units']):
print(f"Checking unit {unit}...")
if unit['attach_dist'] == -1:
if sublist_match(unit['arg_trace'], instance['units'][unit_idx-1]['arg_trace']):
print(f"relation overlap with prior unit {unit_idx}")
if unit['attach_dist']:
if sublist_match(unit['arg_trace'], instance['units'][unit_idx+unit['attach_dist']]['arg_trace']):
print(f"relation overlap with unit {unit_idx}")
for other_unit_idx, other_unit in enumerate(instance['units']):
if other_unit_idx != unit_idx:
if sublist_match(unit['arg_trace'], other_unit['arg_trace']):
print(f"relation overlap with unit {other_unit['adu_id']}")