How to use prosodic - 10 common examples

To help you get started, we’ve selected a few prosodic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github quadrismegistus / prosodic / prosodic / lib / entity.py View on Github external
assert len(xydict['x'])==len(xydict['y'])

				xs.append(x_avg)
				ys.append(y_avg)
				tsv+="\t".join(str(bb) for bb in [(posnum+1),len(xydict['x']),x_avg,y_avg,x_std,y_std])+"\n"


			ccmsg=""
			cc=None
			p=None
			try:
				from statlib import stats
				(cc,p)=stats.pearsonr(xs,ys)

				aa=makeminlength("    correlation coefficient: ",int(being.linelen/1.4))+str(cc)
				bb=makeminlength("    p-value: ",int(being.linelen/1.4))+str(p)

				tsv+=aa.strip().replace(":",":\t")+"\n"
				tsv+=bb.strip().replace(":",":\t")+"\n"

				for l in tsv.split("\n"):
					totaltsvs.append(textname+"_"+l)

				ccmsg+=aa+"\n"+bb+"\n"

			except:
				pass

			writeToFile(textname,init.pkey,tsv,extension="tsv")
			totaltsvs.append(tsv)
github quadrismegistus / prosodic / prosodic / lib / Corpus.py View on Github external
def __init__(self,corpusRoot,lang=None,printout=None,corpusFiles="*.txt",phrasebreak=',;:.?!()[]{}<>',limWord=None):
		import prosodic
		## entity-shared attribtues

		self.lang=prosodic.config['lang'] if not lang else lang
		self.dict=prosodic.dict[self.lang]
		self.parent=False
		#self.foldername=corpusRoot.split("/").pop().strip()
		self.children=[]	# texts
		self.feats = {}
		self.featpaths={}
		self.finished = False
		self.config=prosodic.config
		self.meter=None
		if printout==None: printout=being.printout

		## corpus attributes
		self.corpusRoot = corpusRoot
		self.corpusFiles = corpusFiles
		self.name=os.path.split(os.path.abspath(self.corpusRoot))[-1]
		self.foldername=self.name
		self.dir_results = prosodic.dir_results

		## language may be **, ie, determinable by the first two character of the textfile ("en" for english, "fi" for finnish, etc)
		if not lang:
			lang=being.lang
		self.lang = lang

		## [loop] through filenames
github quadrismegistus / prosodic / prosodic / lib / Corpus.py View on Github external
def __init__(self,corpusRoot,lang=None,printout=None,corpusFiles="*.txt",phrasebreak=',;:.?!()[]{}<>',limWord=None):
		import prosodic
		## entity-shared attribtues

		self.lang=prosodic.config['lang'] if not lang else lang
		self.dict=prosodic.dict[self.lang]
		self.parent=False
		#self.foldername=corpusRoot.split("/").pop().strip()
		self.children=[]	# texts
		self.feats = {}
		self.featpaths={}
		self.finished = False
		self.config=prosodic.config
		self.meter=None
		if printout==None: printout=being.printout

		## corpus attributes
		self.corpusRoot = corpusRoot
		self.corpusFiles = corpusFiles
		self.name=os.path.split(os.path.abspath(self.corpusRoot))[-1]
		self.foldername=self.name
github quadrismegistus / prosodic / prosodic / lib / entity.py View on Github external
def parse(self,arbiter='Line',init=None,namestr=[]):
		"""Parse this object metrically."""
		
		import time
		if entity.time==0:
			entity.time=time.clock()
		
		if self.classname().lower()=="corpus":
			for child in self.children:
				child.parse()
			return None
		
		if not init:
			init=self
			if not hasattr(init,'meter_stats'):
				init.meter_stats={'lines':{},'positions':{},'texts':{}, '_ot':{},'_constraints':{}}
			if not hasattr(init,'bestparses'):
				init.bestparses=[]
			from Meter import Meter
			init.meter=Meter(config['constraints'].split(),(config['maxS'],config['maxW']),config['splitheavies'])
			init.meter_stats['_constraints']=sorted(init.meter.constraints)
github quadrismegistus / prosodic / prosodic / lib / MaxEnt2.py View on Github external
frequency = 0.0
                    else:
                        frequency = float(split[3])

                else:
                    line = line.strip()
                    split = line.split(delimeter)
                    text = split[0]
                    frequency = float(split[1])
                    scansion = split[2]

                if text not in data:
                    data[text] = []
                    self.lines+=[text]

                datum = DataPoint(text, scansion, None, frequency)
                data[text].append(datum)

        return data
github quadrismegistus / prosodic / prosodic / lib / Text.py View on Github external
## 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
github quadrismegistus / prosodic / prosodic / lib / Text.py View on Github external
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
github quadrismegistus / prosodic / prosodic / lib / MaxEnt.py View on Github external
if split[3] == "":
                        frequency = 0.0
                    else:
                        frequency = float(split[3])

                else:
                    line = line.strip()
                    split = line.split(delimeter)
                    text = split[0]
                    frequency = float(split[1])
                    scansion = split[2]

                if text not in data:
                    data[text] = []

                datum = DataPoint(text, scansion, None, frequency)
                data[text].append(datum)

        return data
github quadrismegistus / prosodic / prosodic / lib / entity.py View on Github external
#doc=inspect.getdoc(attr)
			doc = attr.__doc__
			if not doc:
				doc=""
			#else:
			#	docsplit=[z for z in doc.replace("\r","\n").split("\n") if z]
			#	if len(docsplit)>1:
			#		doc = docsplit[0] + "\n" + makeminlength(" ",being.linelen) + "\n".join( makeminlength(" ",being.linelen)+"\t"+z for z in docsplit[1:])
			#	else:
			#		doc = docsplit[0]
			y=describe_func(attr)
			if not y:
				y=""
			else:
				y=", ".join(a+"="+str(b) for (a,b) in y)
			print makeminlength("."+x+"("+y+")",being.linelen),"\t", doc
			if showall: print
github quadrismegistus / prosodic / prosodic / lib / Corpus.py View on Github external
def __init__(self,corpusRoot,lang=None,printout=None,corpusFiles="*.txt",phrasebreak=',;:.?!()[]{}<>',limWord=None):
		import prosodic
		## entity-shared attribtues

		self.lang=prosodic.config['lang'] if not lang else lang
		self.dict=prosodic.dict[self.lang]
		self.parent=False
		#self.foldername=corpusRoot.split("/").pop().strip()
		self.children=[]	# texts
		self.feats = {}
		self.featpaths={}
		self.finished = False
		self.config=prosodic.config
		self.meter=None
		if printout==None: printout=being.printout

		## corpus attributes
		self.corpusRoot = corpusRoot
		self.corpusFiles = corpusFiles
		self.name=os.path.split(os.path.abspath(self.corpusRoot))[-1]
		self.foldername=self.name
		self.dir_results = prosodic.dir_results