Skip to content

Commit

Permalink
some more presentation utilities needed for next papers
Browse files Browse the repository at this point in the history
  • Loading branch information
grammarware committed Jul 1, 2012
1 parent 0e37c58 commit 073abd5
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
99 changes: 99 additions & 0 deletions shared/python/exbgf_detailed_overview.py
@@ -0,0 +1,99 @@
#!/usr/bin/python
import os
import sys
import slpsns
import slpsXPath
import elementtree.ElementTree as ET

names = []
targets = {}
results = {}

def report(keys,key,note):
s = note.replace('exbgf:','')
cx = 0
for x in keys:
cx += results[key][x]
if results[key][x]:
s += '&'+`results[key][x]`
else:
s += '& ---'
if cx:
print s+'&'+`cx`+'\\\\'

if __name__ == "__main__":
if len(sys.argv) != 4:
print 'This tool generates an overview of a bunch of EXBGF scripts.'
print 'Usage:'
print ' exbgfover <exbgf.xsd> <lcf> <exbgfs-path>'
sys.exit(1)
xsd = ET.parse(sys.argv[1])
gn = 0
for x in xsd.findall('/'+slpsns.xsd_('element')+'/'+slpsns.xsd_('complexType')+'/'+slpsns.xsd_('choice')):
names.append([])
for y in x.findall(slpsns.xsd_('element')):
if y.attrib.has_key('ref'):
names[gn].append(y.attrib['ref'])
# print 'added',y.attrib['ref']
gn += 1
# names.remove([])
lcf = ET.parse(sys.argv[2])
for x in lcf.findall('/target'):
name = x.findtext('name')
targets[name] = []
for y in x.findall('branch/*/perform'):
targets[name].append(y.text)
path = sys.argv[3]
if path[-1] != '/':
path += '/'
results['LOC'] = {}
results['NOI'] = {}
results['NOX'] = {}
for x in names:
for y in x:
results[y] = {}
for z in targets.keys():
results[y][z] = 0
for x in targets.keys():
results['LOC'][x] = 0
results['NOI'][x] = 0
results['NOX'][x] = 0
for y in targets[x]:
results['LOC'][x] += slpsXPath.loc(path+y+'.exbgf')
results['NOI'][x] += slpsXPath.noi(path+y+'.exbgf')
xbgf = ET.parse(path+y+'.exbgf')
results['NOX'][x] += len(xbgf.findall('/*'))
for z in names:
for q in z:
# print q
qr = q.replace('exbgf:',slpsns.exbgf_(''))
# qr = '*'
results[q][x] += len(xbgf.findall(qr))
# for w in xbgf.findall(qr)
# print slpsns.exbgf_('*')+'/'+qr
results[q][x] += len(xbgf.findall('*/'+qr))
# print slpsns.exbgf_('*')+'/'+slpsns.exbgf_('*')+'/'+qr
results[q][x] += len(xbgf.findall('*/*/'+qr))
# results[q][x] += len(xbgf.findall(q.replace('xbgf:',slpsns.xbgf_(''))))
# print names
for x in names:
for y in x:
used = False
for z in targets.keys():
if results[y][z]:
used = True
if not used:
print '%%',y,'not used in any EXBGF script'
sorted = targets.keys()[:]
sorted.sort()
print '\\begin{tabular}{l|'+('c|'*len(targets))+'|c}'
for x in sorted:
print '&\\textbf{'+x+'}',
print '&\\textbf{Total}\\\\\\hline'
for x in names:
for y in x:
report(sorted,y,'\\xbgfNumber{'+y+'}')
print '\\hline'
print '\\end{tabular}'
sys.exit(0)

3 changes: 3 additions & 0 deletions shared/python/slpsns.py
Expand Up @@ -5,6 +5,7 @@
xldfns = 'http://planet-sl.org/xldf'
bgfns = 'http://planet-sl.org/bgf'
xbgfns = 'http://planet-sl.org/xbgf'
exbgfns= 'http://planet-sl.org/exbgf'
cbgfns = 'http://planet-sl.org/cbgf'
mbgfns = 'http://planet-sl.org/mbgf'
eddns = 'http://planet-sl.org/edd'
Expand All @@ -19,6 +20,7 @@ def init(ET):
ET._namespace_map[xldfns] = 'xldf'
ET._namespace_map[bgfns] = 'bgf'
ET._namespace_map[xbgfns] = 'xbgf'
ET._namespace_map[exbgfns]='exbgf'
ET._namespace_map[cbgfns] = 'cbgf'
ET._namespace_map[mbgfns] = 'mbgf'
ET._namespace_map[eddns] = 'edd'
Expand All @@ -32,6 +34,7 @@ def ldf_(x): return '{'+ldfns+'}' +x
def xldf_(x): return '{'+xldfns+'}'+x
def bgf_(x): return '{'+bgfns+'}' +x
def xbgf_(x): return '{'+xbgfns+'}'+x
def exbgf_(x):return '{'+exbgfns+'}'+x
def cbgf_(x): return '{'+cbgfns+'}'+x
def mbgf_(x): return '{'+mbgfns+'}'+x
def xsd_(x): return '{'+xsdns+'}' +x
Expand Down
2 changes: 1 addition & 1 deletion shared/rascal/src/export/LaTeX.rsc
Expand Up @@ -80,6 +80,6 @@ default str pp(BGFExpression e) = "?<e>?";
public void main()
{
//<_,g> = converge::Guided::loadSimpleGrammar(|home:///projects/slps/topics/convergence/guided/bgf/master.bgf|);
<_,g> = converge::Guided::loadSimpleGrammar(|home:///projects/slps/topics/convergence/guided/bgf/jaxb.normal.bgf|);
<_,g> = converge::Guided::loadSimpleGrammar(|home:///projects/slps/topics/convergence/guided/bgf/xsd.normal.bgf|);
println(pp(g));
}
12 changes: 12 additions & 0 deletions shared/tools/exbgfover
@@ -0,0 +1,12 @@
#!/bin/sh

# Get our hands on basedir
LOCAL1=${PWD}
cd `dirname $0`
cd ../..
SLPS=${PWD}
cd ${LOCAL1}

# python ${SLPS}/shared/python/xbgf_overview.py $1 $2 $3 >$4
python ${SLPS}/shared/python/exbgf_detailed_overview.py $1 $2 $3 >$5

0 comments on commit 073abd5

Please sign in to comment.