Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
## load/write-load text
if os.path.exists(filename):
self.filename = filename
self.name = filename.split("/").pop().strip()
else:
fn=os.path.join(sys.path[0],'.directinput.txt')
write(fn,filename.replace('//','\n\n').replace('/','\n'))
self.filename=fn
filename=fn
self.name = '_directinput_'
## set language
if lang==None:
if self.name[2]=="." and (self.name[0:2] in prosodic.dict):
lang=self.name[0:2]
elif prosodic.lang:
lang=prosodic.lang
else:
lang=choose(prosodic.languages,"in what language is '"+self.name+"' written?")
if not lang:
lang=prosodic.languages[0]
print "!! language choice not recognized. defaulting to: "+lang
else:
lang=lang.pop()
try:
self.dict=prosodic.dict[lang]
except KeyError:
lang0=lang
lang=prosodic.languages[0]
print "!! language "+lang0+" not recognized. defaulting to: "+lang
self.dict=prosodic.dict[lang]
self.lang=lang
if os.path.exists(filename):
self.filename = filename
self.name = filename.split("/").pop().strip()
else:
fn=os.path.join(sys.path[0],'.directinput.txt')
write(fn,filename.replace('//','\n\n').replace('/','\n'))
self.filename=fn
filename=fn
self.name = '_directinput_'
## set language
if lang==None:
if self.name[2]=="." and (self.name[0:2] in prosodic.dict):
lang=self.name[0:2]
elif prosodic.lang:
lang=prosodic.lang
else:
lang=choose(prosodic.languages,"in what language is '"+self.name+"' written?")
if not lang:
lang=prosodic.languages[0]
print "!! language choice not recognized. defaulting to: "+lang
else:
lang=lang.pop()
try:
self.dict=prosodic.dict[lang]
except KeyError:
lang0=lang
lang=prosodic.languages[0]
print "!! language "+lang0+" not recognized. defaulting to: "+lang
self.dict=prosodic.dict[lang]
self.lang=lang
def set_lang(self,filename):
if not filename: return 'en'
filename=os.path.basename(filename)
import prosodic
if self.isFromFile and len(filename)>2 and filename[2]=="." and (filename[0:2] in prosodic.dict):
lang=filename[0:2]
elif prosodic.lang:
lang=prosodic.lang
else:
lang=choose(prosodic.languages,"in what language is '"+self.name+"' written?")
if not lang:
lang=prosodic.languages[0]
print("!! language choice not recognized. defaulting to: "+lang)
else:
lang=lang.pop()
if not lang in prosodic.dict:
lang0=lang
lang=prosodic.languages[0]
print("!! language "+lang0+" not recognized. defaulting to: "+lang)
return lang
def set_lang(self,filename):
if not filename: return 'en'
filename=os.path.basename(filename)
import prosodic
if self.isFromFile and len(filename)>2 and filename[2]=="." and (filename[0:2] in prosodic.dict):
lang=filename[0:2]
elif prosodic.lang:
lang=prosodic.lang
else:
lang=choose(prosodic.languages,"in what language is '"+self.name+"' written?")
if not lang:
lang=prosodic.languages[0]
print("!! language choice not recognized. defaulting to: "+lang)
else:
lang=lang.pop()
if not lang in prosodic.dict:
lang0=lang
lang=prosodic.languages[0]
print("!! language "+lang0+" not recognized. defaulting to: "+lang)
return lang
def __init__(self,token,syllables=None,sylls_text=[],broken=False,lang=None):
if syllables==None:
import prosodic
if lang==None:
lang=prosodic.lang
w=prosodic.dict[lang].get(token)[0]
if not len(w.__dict__):
self.broken=True
else:
for k,v in list(w.__dict__.items()):
setattr(self,k,v)
return
self.token = token.lower() # the case-sensitive, non-punctuation representation
self.punct = "" # the right-aligned punctuation (if any)
self.sylls_text=sylls_text # a list of strings, representing this word's syllabification
self.finished = False # finished parameter
self.children = syllables # pre-loaded Syllable objects
self.numSyll = len(syllables) # the number of syllables