How to use the prosodic.lib.entity.entity function in prosodic

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
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 / entity.py View on Github external
def dir(self,methods=True,showall=True):
		"""Show this object's attributes and methods."""
		import inspect
		#print "[attributes]"
		for k,v in sorted(self.__dict__.items()):
			if k.startswith("_"): continue
			print makeminlength("."+k,being.linelen),"\t",v
		
		if not methods:
			return
		
		entmethods=dir(entity)
		
		print
		#print "[methods]" 		
		for x in [x for x in dir(self) if ("bound method "+self.classname() in str(getattr(self,x))) and not x.startswith("_")]:
			if (not showall) and (x in entmethods): continue
			
			attr=getattr(self,x)
			
			#print attr.__dict__
			#print dir(attr)
	
			#doc=inspect.getdoc(attr)
			doc = attr.__doc__
			if not doc:
				doc=""
			#else:
github quadrismegistus / prosodic / prosodic / lib / entity.py View on Github external
def reduce_word(word0):
			word=word0
			sylls=word.syllables()
			stress_yet=False
			to_keep=[]
			if sylls[-2].feature('prom.stress') and not sylls[-1].feature('prom.stress'):
				for i in reversed(list(range(len(sylls)))):
					to_keep.insert(0,i)
					if sylls[i].feature('prom.stress'): break
			else:
				to_keep=[list(range(len(sylls)))[-1]]

			obj=entity()
			children=[word.children[i] for i in to_keep]
			#print "KEEPING:",children
			sbody=children[0].children[0] # first syllable's syllable body
			for x in sbody.children[1:]: # all but onset (only rime)
				obj.children+=x.phonemes()
			for x in children[1:]:
				obj.children+=x.phonemes()
			return obj
github quadrismegistus / prosodic / prosodic / lib / entity.py View on Github external
def str_ipasyllstress(self):
		"""
		Returns a string representation of the self-object
		in a syllabified, stressed, IPA form. For example:
		if I am the Word('abandonment'), this method will return:
		ə.'bæn.dən.mənt
		"""

		phonsylls=["".join([str(x) for x in child.phonemes()]) for child in self.children]
		try:
			if hasattr(self,'stress'):
				for i in range(len(self.stress)):
					phonsylls[i]=entity.stress_str2strikes[self.stress[i]]+phonsylls[i]
		except IndexError:
			print("<"+self.classname()+" creation failed on:\n"+str(self)+"\n")
		return ".".join(phonsylls)
github quadrismegistus / prosodic / prosodic / lib / entity.py View on Github external
def dir(self,methods=True,showall=True):
		"""Show this object's attributes and methods."""
		import inspect
		#print "[attributes]"
		for k,v in sorted(self.__dict__.items()):
			if k.startswith("_"): continue
			print(makeminlength("."+k,being.linelen),"\t",v)

		if not methods:
			return

		entmethods=dir(entity)

		print()
		#print "[methods]"
		for x in [x for x in dir(self) if ("bound method "+self.classname() in str(getattr(self,x))) and not x.startswith("_")]:
			if (not showall) and (x in entmethods): continue

			attr=getattr(self,x)

			#print attr.__dict__
			#print dir(attr)

			#doc=inspect.getdoc(attr)
			doc = attr.__doc__
			if not doc:
				doc=""
			#else:
github quadrismegistus / prosodic / prosodic / lib / entity.py View on Github external
def givebirth(self):
		"""
		The default method for getting an object of type (A)
		to return a brand new object of type (child_of_A)
		**This method must be rewritten by each object class!**
		Can be called directly, or indirectly using method newchild().
		"""
		
		return entity()				#### needs to be rewritten by each entity (eg, Word would give birth to Syllables, its children)