import sys
import re
from itertools import combinations_with_replacement as rcb
from itertools import combinations as cb
if __name__ == '__main__':
all_vt = set()
group_list = {}
i = 0
with open('vt.txt') as f:
lines = f.readlines()
for line in lines:
group_list[i] = {}
p_list = []
n_list = []
for l in str(line).split():
if re.search('P', l):
p_list.append(l)
else:
n_list.append(l)
all_vt.add(l)
group_list[i]['P'] = p_list
group_list[i]['N'] = n_list
i = i + 1
print(group_list)
for vt in all_vt:
vt_type = 'P'
adj_type = 'N'
if re.search('N', vt):
vt_type = 'N'
adj_type = 'P'
adj_vt = re.sub(vt_type, adj_type, vt)
for key in group_list:
print(group_list[key])
group = group_list[key]
if adj_vt not in group[adj_type]:
continue
if vt in group[vt_type]:
continue
risk_types = list(rcb(group[vt_type], 2))
for risk_type in risk_types:
if vt in risk_type:
continue
if re.sub(vt_type, adj_type, risk_type[0]) in group[adj_type] and re.sub(vt_type, adj_type, risk_type[1]) in group[adj_type]:
continue
print("Violate Group: ", adj_vt, risk_type)
沒有留言:
張貼留言