Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Print the string passed via argument 'breath',
and store the string for saving in prosodic.being.om.
[accessed interactively using the '/save' command]
(The string just prior to this one will remain available at prosodic.being.omm).
"""
#force_silence = conscious == False
#import prosodic
#if (not conscious) and bool(being.config['print_to_screen']):
if not type(breath)==str: breath=str(breath)
being.om+=breath+"\n"
#if not force_silence and bool(being.config['print_to_screen']):
if bool(being.config['print_to_screen']):
print(self.u2s(breath))
return breath
def om(self,breath,conscious=True):
"""
Print the string passed via argument 'breath',
and store the string for saving in prosodic.being.om.
[accessed interactively using the '/save' command]
(The string just prior to this one will remain available at prosodic.being.omm).
"""
import prosodic
if (not conscious) or bool(prosodic.config['print_to_screen']):
being.om+=str(breath)+"\n"
print self.u2s(breath)
nodetypes=[]
linelens=[]
for parse in parses:
node1=None
node2=None
posnum=0
linelens.append(len(parse.positions))
for pos in parse.positions:
has_viol = bool(sum(pos.constraintScores.values()))
for unit in pos.slots:
spelling=unit.children[0].str_orth()
posnum+=1
if hasattr(being,'line_maxsylls'):
if posnum>int(being.line_maxsylls):
break
nodestr=""
unit.meter=pos.meterVal
for strcaller in sorted(gs[gtype]):
z=unit.findattr(strcaller,'children')
if type(z)==type([]):
nodestr+="".join( [str(x()) for x in z] )
else:
nodestr+=str(z())
if not nodestr: continue
if use_labels:
nodestr+='_'+ (spelling.upper() if unit.meter=='s' else spelling.lower())
nodestr=str(posnum)+"_"+str(nodestr)
def scansion(self,meter=None,conscious=False):
"""Print out scansion for a given meter. """
if (hasattr(self,'bestParse')):
bp=self.bestParse(meter)
if not bp: return
lowestScore=bp.score()
self.om("\t".join( [ str(x) for x in [makeminlength(str(self),being.linelen), makeminlength(str(bp), being.linelen),len(self.allParses(meter)),lowestScore,bp.str_ot()] ] ),conscious=conscious)
else:
if not self.children:
return ""
elif type(self.children[0])==type([]):
return "\t??"+str(self) ## no parse on the word level (where optionality begins?) -- then no parses for this line
else:
[child.scansion(meter=meter,conscious=conscious) for child in self.children]
if (numSyll < config['line_minsylls']):
#print "\t>skipping ("+str(numSyll)+" is fewer than minimum of "+str(config['parse_line_numsyll_min'])+" sylls)"
return []
elif(numSyll > config['line_maxsylls']):
#print "\t>skipping ("+str(numSyll)+" is more than maximum of "+str(config['parse_line_numsyll_max'])+" sylls)"
return []
#print "\n\t>parsing:\t"+str(self)+"\t("+str(numSyll)+" sylls)"
self.parses=init.meter.parse(words,numSyll)
self.numparses=len(self.parses)
self.__bestparse=self.parses[0]
if hasattr(being,'line_headedness'):
for parse in self.parses:
if parse.str_meter().startswith(str(being.line_headedness)):
self.__bestparse=parse
break
init.bestparses.append(self.__bestparse)
if being.omms:
self.scansion()
textname=self.findattr('name')
if not textname:
textname=str(self).replace(" ","_")
## store stats
if (not textname in init.meter_stats['lines']):
#print "\t>skipping ("+str(numSyll)+" is fewer than minimum of "+str(config['parse_line_numsyll_min'])+" sylls)"
return []
elif(numSyll > config['line_maxsylls']):
#print "\t>skipping ("+str(numSyll)+" is more than maximum of "+str(config['parse_line_numsyll_max'])+" sylls)"
return []
#print "\n\t>parsing:\t"+str(self)+"\t("+str(numSyll)+" sylls)"
self.parses=init.meter.parse(words,numSyll)
self.numparses=len(self.parses)
self.__bestparse=self.parses[0]
if hasattr(being,'line_headedness'):
for parse in self.parses:
if parse.str_meter().startswith(str(being.line_headedness)):
self.__bestparse=parse
break
init.bestparses.append(self.__bestparse)
if being.omms:
self.scansion()
textname=self.findattr('name')
if not textname:
textname=str(self).replace(" ","_")
## store stats
if (not textname in init.meter_stats['lines']):
init.meter_stats['lines'][textname]={}
if (not textname in init.meter_stats['positions']):