-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathCurrent.py
129 lines (125 loc) · 5.04 KB
/
Current.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
def count_predict_right_num(ptag,ttag):
rmpair={}
masktag = np.zeros(len(ptag))
for i in range(0,len(ptag)):
tag = ptag[i]
if not tag.__eq__("O") and not tag.__eq__(""):
type_e = tag.split("__")
if not rmpair.__contains__(type_e[0]):
eelist=[]
e1=[]
e2=[]
if type_e[1].__contains__("1"):
if type_e[1].__contains__("S"):
e1.append((i,i+1))
elif type_e[1].__contains__("B"):
j=i+1
while j < len(ptag):
if ptag[j].__contains__("1") and \
( ptag[j].__contains__("I") or ptag[j].__contains__("L")):
j+=1
else:
break
e1.append((i, j))
elif type_e[1].__contains__("2"):
if type_e[1].__contains__("S"):
e2.append((i,i+1))
elif type_e[1].__contains__("B"):
j=i+1
while j < len(ptag):
if ptag[j].__contains__("2") and \
( ptag[j].__contains__("I") or ptag[j].__contains__("L")):
j+=1
else:
break
e2.append((i, j))
eelist.append(e1)
eelist.append(e2)
rmpair[type_e[0]] = eelist
else:
eelist=rmpair[type_e[0]]
e1=eelist[0]
e2=eelist[1]
if type_e[1].__contains__("1"):
if type_e[1].__contains__("S"):
e1.append((i,i+1))
elif type_e[1].__contains__("B"):
j=i+1
while j < len(ptag):
if ptag[j].__contains__("1") and \
( ptag[j].__contains__("I") or ptag[j].__contains__("L")):
j+=1
else:
break
e1.append((i, j))
elif type_e[1].__contains__("2"):
if type_e[1].__contains__("S"):
e2.append((i,i+1))
elif type_e[1].__contains__("B"):
j=i+1
while j < len(ptag):
if ptag[j].__contains__("2") and \
( ptag[j].__contains__("I") or ptag[j].__contains__("L")):
j+=1
else:
break
e2.append((i, j))
eelist[0]=e1
eelist[1]=e2
rmpair[type_e[0]] = eelist
rightnum=0
rightnume1 = 0
rightnume2 = 0
predictnum=0
predictnume1 = 0
predictnume2 = 0
doublecount=0
for type in rmpair:
eelist = rmpair[type]
e1 = eelist[0]
e2 = eelist[1]
if len(e1)>1 and len(e2)>1:
doublecount+=min(len(e1),len(e2))
if len(e1)>0 and len(e2)==0:
predictnume1 = 1
if len(e2) > 0 and len(e1) == 0:
predictnume2 = 1
for i in range(0,min(len(e1),len(e2))):
predictnum+=1
truemark=1
truemarke1 = 1
truemarke2 = 1
for j in range(e1[i][0],e1[i][1]):
if e1[i][0]>0 and ttag[e1[i][0]-1].__contains__(type):
truemark = 0
truemarke1 = 0
break
if e1[i][1]<len(ttag) and ttag[e1[i][1]].__contains__(type):
truemark = 0
truemarke1 = 0
break
if not ttag[j].__contains__(type) or not ttag[j].__contains__("1"):
truemark = 0
truemarke1 = 0
break
for j in range(e2[i][0],e2[i][1]):
if e2[i][0]>0 and ttag[e2[i][0]-1].__contains__(type):
truemark = 0
truemarke2 = 0
break
if e2[i][1]<len(ttag) and ttag[e2[i][1]].__contains__(type):
truemark = 0
truemarke2 = 0
break
if not ttag[j].__contains__(type) or not ttag[j].__contains__("2"):
truemark = 0
truemarke2 = 0
break
if truemark ==1:
rightnum+=1
if truemarke1 ==1:
rightnume1+=1
if truemarke2 ==1:
rightnume2+=1
#print rightnum,predictnum
return rightnum,predictnum,doublecount,rightnume1,rightnume2,predictnume1,predictnume2