-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_change_table_1.py
108 lines (82 loc) · 2.92 KB
/
build_change_table_1.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
import re
import json
EMPTY_PREFIX = ' -'
CHANGE_PREFIX = 'CHANGE-'
def extract_change_items( pmd_item ):
output = []
index = 0
while( index < len( pmd_item ) ):
name, value = pmd_item[ index ]
if( name[ : len( CHANGE_PREFIX ) ] == CHANGE_PREFIX ):
item = []
item.append( (name, value) )
index += 1
if (index >= len(pmd_item)):
output.append(item)
break
name, value = pmd_item[index]
while( ( index < len( pmd_item ) ) and ( name[ : len( CHANGE_PREFIX ) ] != CHANGE_PREFIX )):
item.append( (name, value) )
index += 1
if(index >= len( pmd_item )):
break
name, value = pmd_item[index]
#print name
#print item
#print "---"
output.append( item )
else:
index += 1
return output
def process_change_item( item, type_name, type_count, property_name ):
name, value = item[0]
#print "type_name = %s, type_count = %u, property_name = %s" % (type_name, type_count, property_name)
#print name
if( name != type_name ):
#print "---"
return False
current_type_count = 1
has_property = False
index = 1
while( index < len( item ) ):
name, value = item[ index ]
#print name
if( name[ : len(EMPTY_PREFIX)] == EMPTY_PREFIX ):
if( name[ len(EMPTY_PREFIX) : ] != type_name[ len( EMPTY_PREFIX ) : ] ):
#print "---"
return False
else:
current_type_count += 1
elif( name == property_name ):
has_property = True
index += 1
#print current_type_count
#print "%s, %s" % (str(has_property), str(current_type_count == type_count))
#print "---"
return has_property and (current_type_count == type_count)
change_list = [
('CHANGE-POINT',1),
('CHANGE-POINT',2),
('CHANGE-DELETE',1),
('CHANGE-INSERT',1)]
property_list = ['FUNCTION', 'STRUCTURE', 'STABILITY']
#handle = open( 'test2.result-thermal-all', 'w' )
pmd = json.loads( open( 'pmd07Mar26.json', 'rb' ).read() )
count = 0
max_count = 0
output = []
change_items = []
for pmd_item in pmd:
change_items.extend( extract_change_items( pmd_item ) )
result = {}
for change_item in change_items:
for type_name, type_count in change_list:
for property_name in property_list:
name = "%s %u %s" % (type_name, type_count, property_name)
if(not result.has_key(name)):
result[name] = 0
if(process_change_item(change_item, type_name, type_count, property_name)):
result[name] += 1
for key, value in result.iteritems():
print "%s -> %s" % (key, value)
#print change_items