Skip to content

Commit

Permalink
TIMP: tree impurity metric
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@934 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Feb 2, 2011
1 parent 7811c7e commit 912cf56
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions topics/investigation/structural/testperform
Expand Up @@ -7,4 +7,5 @@ echo [Test Case] `basename $1`
./rlev.py $1 >> $1.out || exit -1
./nlev.py $1 >> $1.out || exit -1
./hei.py $1 >> $1.out || exit -1
./timp.py $1 >> $1.out || exit -1
diff $1.out $1.baseline || exit -1
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/antlr.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
1
1
3
44.5
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/dcg.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
1
1
3
28.6
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/ecore.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
1
1
3
67.4
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/ecore2.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
1
1
3
48.6
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/fl_ldf.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
0
0
2
15.0
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/impl1.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
20
20
22
37.7
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/impl2.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
1
1
9
59.1
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/impl3.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
2
2
8
71.8
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/jaxb.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
1
1
2
16.4
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/ldf.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
0
0
2
15.0
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/om.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
1
1
2
21.1
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/read1.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
26
26
22
31.9
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/read2.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
21
21
13
56.8
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/read3.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
19
19
14
58.7
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/sdf.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
1
1
3
21.4
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/txl.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
1
1
3
21.4
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/xml.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
1
1
3
45.6
1 change: 1 addition & 0 deletions topics/investigation/structural/tests/xsd.bgf.baseline
Expand Up @@ -4,3 +4,4 @@
1
1
3
45.6
26 changes: 26 additions & 0 deletions topics/investigation/structural/timp.py
@@ -0,0 +1,26 @@
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import sys
import levels
sys.path.append('../../../shared/python')
import BGF

if __name__ == "__main__":
if len(sys.argv) != 2:
print 'This tool calculates a TIMP metric for any given BGF grammar.'
print 'Usage:'
print ' '+sys.argv[0]+' <bgf-input>'
sys.exit(1)
bgf = BGF.Grammar()
bgf.parse(sys.argv[1])
cg = levels.getClosure(levels.getCallGraph(bgf))
n = len(cg)
e = sum(map(len,cg.values()))
# Power and Malloy made two mistakes:
# (1) the number of edges in a complete directed graph is n(n-1), not n(n-1)/2, as in a complete undirected graph!
# (2) we don't have to substract another 1 from the number of nonterminals to account for a start symbol
# To compute TIMP exactly as they intended to, run this:
# print '%.1f' % (100*2*(e-n+1)/(0.0+(n-1)*(n-2)))
# To run our fixed version, uncomment this:
print '%.1f' % (100*(e-n+1)/(0.0+n*(n-1)))
sys.exit(0)

0 comments on commit 912cf56

Please sign in to comment.