Skip to content

Commit

Permalink
LDF->sample set script, ex-part of LCI
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@210 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Aug 22, 2008
1 parent 3b03867 commit 387c320
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
6 changes: 6 additions & 0 deletions topics/extraction/ldf2set/Makefile
@@ -0,0 +1,6 @@
test:
xsltproc ../../../shared/xsl/ldf2samples.xslt ../../fl/ldf/fl.ldf > samples.xml
python xml2set.py samples.xml samples

clean:
rm -rf samples/* samples.xml *.pyc
61 changes: 61 additions & 0 deletions topics/extraction/ldf2set/xml2set.py
@@ -0,0 +1,61 @@
#!/usr/bin/python
import sys
from elementtree import ElementTree

def copyfile(x,y):
xh=open(x,'r')
yh=open(y,'w')
yh.writelines(xh.readlines())
xh.close()
yh.close()

def unpacksamples(where,dir):
library={}
cx = 0
tree = ElementTree.parse(where)
for outline in tree.findall("//sample"):
cx+=1
torun = open (dir+'/sample'+`cx`+'.src',"w")
for line in outline.text.split('\n'):
if line.strip()!='':
torun.write(line.strip()+'\n')
torun.close()
if outline.attrib.has_key('id'):
library[outline.attrib['id']]=outline.text
if outline.attrib.has_key('sort'):
sort=outline.attrib['sort']
else:
sort=None
# All executions
for outline in tree.findall("//runnable"):
if outline.findtext('context'):
if not library.has_key(outline.findtext('context')):
print "No context found for sample",cx,'('+outline.findtext('context')+'), test case not used'
continue
else:
con = open (dir+'/sample'+`cx`+'.src','w')
for line in library[outline.findtext('context')].split('\n'):
if line.strip()!='':
con.write(line.strip()+'\n')
con.close()
if outline.findtext('yields'):
con = open (dir+'/sample'+`cx`+'.val','w')
con.write(outline.findtext('yields'))
con.close()
cx+=1
torun = open (dir+'/sample'+`cx`+'.run','w')
line = outline.findtext('main')
for arg in outline.findall("argument"):
line += ' ' + arg.text
torun.write(line+'\n')
torun.close()
print cx,'samples in the test set.'

if __name__ == "__main__":
print 'Sample Set Extractor'
if len(sys.argv) == 3:
unpacksamples(sys.argv[1],sys.argv[2])
else:
print 'Usage:'
print ' ',sys.argv[0],'<configuration file>','<output pdf>'
sys.exit(1)

0 comments on commit 387c320

Please sign in to comment.