[clml] r131 committed - Attempt to auto-generate missing tableaux file in pyphon_generate. Wil...

0 views
Skip to first unread message

cl...@googlecode.com

unread,
Jul 2, 2011, 5:19:04 PM7/2/11
to cl...@googlegroups.com
Revision: 131
Author: max....@gmail.com
Date: Sat Jul 2 14:18:31 2011
Log: Attempt to auto-generate missing tableaux file in
pyphon_generate. Will invoke auto-generation of model file by
pyphon_maketableaux if necessary.
http://code.google.com/p/clml/source/detail?r=131

Modified:
/trunk/pyphon/src/pyphon_generate.py
/trunk/pyphon/src/syllables-cv3-ot.csv

=======================================
--- /trunk/pyphon/src/pyphon_generate.py Tue Oct 12 13:25:21 2010
+++ /trunk/pyphon/src/pyphon_generate.py Sat Jul 2 14:18:31 2011
@@ -1,6 +1,6 @@
#!/usr/bin/env python

-import pyphon, csv, sys, pickle
+import pyphon, csv, sys, pickle, os
from pprint import pprint
from optparse import OptionParser

@@ -234,6 +234,44 @@

return grammars

+def autoCreateTableaux(tableauxfile):
+ print 'Attempting to auto-generate...'
+ # attempt to infer from tableaux filename: modelfile, inputfile, opt.
+ # assume filename of the sort created by maketableaux:
model-input-opt.csv
+ fname = os.path.split(tableauxfile)[1]
+ root = os.path.splitext(fname)[0]
+ toks = root.split('-')
+ if len(toks) != 3:
+ print 'Auto-generation failed. Unable to extract modelfile, '\
+ 'inputfile, opt from %s.' % tableauxfile
+ return False
+
+ modelFile = toks[0]
+ inputFile = toks[1]+'.csv'
+ opt = toks[2]
+ print 'Auto-generation: inferring: modelFile = %r, inputFile = %r, opt
= %r'\
+ % (modelFile, inputFile, opt)
+
+ try:
+ import pyphon_maketableaux
+ except ImportError:
+ myPath = os.path.split(__file__)[0]
+ if myPath not in sys.path:
+ sys.path.append(myPath)
+ try:
+ import pyphon_maketableaux
+ except ImportError:
+ print 'Auto-generation failed. Unable to import
pyphon_makemodel.'
+ return False
+
+ pyphon_maketableaux.main(modelFile, inputFile, opt,
outputFile=tableauxfile)
+
+ if os.path.exists(tableauxfile):
+ print 'Auto-generation successful.'
+ return True
+ else:
+ print 'Auto-generation failed.'
+ return False

def main(tableauxfile, outputfile, opt, grammarfile=None,
whichGrammar=None,
volumes=False):
@@ -242,6 +280,13 @@
print "opt must be one of \"OT\" or \"HG\" (case insensitive)."
return

+ if not os.path.exists(tableauxfile):
+ print 'Tableax file %s does not exist.' % (tableauxfile,)
+ if not autoCreateTableaux(tableauxfile):
+ print 'Aborting pyphon_generate: tableaux file %s not found '\
+ 'and unable to auto-generate.' % tableauxfile
+ raise SystemExit
+
contenderDict, constraints = parseTableaux(tableauxfile)
restriction = None

@@ -309,8 +354,8 @@
for name, lg in tlist:
lgERCs, forms = lg
surfaceOs = set()
- for i,os,v,e in forms:
- for o in os.split(' | '):
+ for i,outputs,v,e in forms:
+ for o in outputs.split(' | '):
surfaceOs.add("[%s]"%o)
w.writerow(['Language ID:', name])
w.writerow(['Surface forms:', '{'+', '.join(surfaceOs)+'}'])
=======================================
--- /trunk/pyphon/src/syllables-cv3-ot.csv Sat Jul 2 13:20:14 2011
+++ /trunk/pyphon/src/syllables-cv3-ot.csv Sat Jul 2 14:18:31 2011
@@ -8,9 +8,9 @@
#V#,##,,0,0,1,0,0

,,,depC,depV,max,noCoda,onset
-#CC#,##,,0,0,2,0,0
#CC#,#CVC#,,0,1,0,1,0
#CC#,#CV.CV#,,0,2,0,0,0
+#CC#,##,,0,0,2,0,0

,,,depC,depV,max,noCoda,onset
#CV#,#CV#,,0,0,0,0,0
@@ -31,9 +31,9 @@
#VV#,##,,0,0,2,0,0

,,,depC,depV,max,noCoda,onset
-#CCC#,#CV.CVC# | #CVC.CV#,,0,2,0,1,0
-#CCC#,#CV.CV.CV#,,0,3,0,0,0
#CCC#,##,,0,0,3,0,0
+#CCC#,#CV.CV.CV#,,0,3,0,0,0
+#CCC#,#CV.CVC# | #CVC.CV#,,0,2,0,1,0

,,,depC,depV,max,noCoda,onset
#CCV#,#CV.CV#,,0,1,0,0,0
@@ -45,9 +45,9 @@
#CVC#,#CV#,,0,0,1,0,0

,,,depC,depV,max,noCoda,onset
+#CVV#,#CV.CV#,,1,0,0,0,0
#CVV#,#CV#,,0,0,1,0,0
#CVV#,#CV.V#,,0,0,0,0,1
-#CVV#,#CV.CV#,,1,0,0,0,0

,,,depC,depV,max,noCoda,onset
#VCC#,#CV.CVC# | #CVC.CV#,,1,1,0,1,0
@@ -57,21 +57,21 @@
#VCC#,#VC.CV# | #V.CVC#,,0,1,0,1,1
#VCC#,#CVC#,,0,1,1,1,0
#VCC#,#VC#,,0,0,1,1,1
-#VCC#,#CV.CV#,,0,2,1,0,0
+#VCC#,#CV#,,1,0,2,0,0
#VCC#,##,,0,0,3,0,0
#VCC#,#V#,,0,0,2,0,1
-#VCC#,#CV#,,1,0,2,0,0
+#VCC#,#CV.CV#,,0,2,1,0,0

,,,depC,depV,max,noCoda,onset
+#VCV#,#CV.CV#,,1,0,0,0,0
#VCV#,#CV#,,0,0,1,0,0
#VCV#,#V.CV#,,0,0,0,0,1
-#VCV#,#CV.CV#,,1,0,0,0,0

,,,depC,depV,max,noCoda,onset
#VVC#,#CV.CV.CV#,,2,1,0,0,0
-#VVC#,#V.V#,,0,0,1,0,2
-#VVC#,#CV.CVC#,,2,0,0,1,0
#VVC#,#CV.CV#,,2,0,1,0,0
+#VVC#,#CV.CVC#,,2,0,0,1,0
+#VVC#,#V.V#,,0,0,1,0,2
#VVC#,##,,0,0,3,0,0
#VVC#,#CV#,,0,1,2,0,0
#VVC#,#V.VC#,,0,0,0,1,2
@@ -79,6 +79,6 @@

,,,depC,depV,max,noCoda,onset
#VVV#,##,,0,0,3,0,0
-#VVV#,#CV.CV.CV#,,3,0,0,0,0
#VVV#,#V.V.V#,,0,0,0,0,3
-
+#VVV#,#CV.CV.CV#,,3,0,0,0,0
+

Reply all
Reply to author
Forward
0 new messages