Exemplo n.º 1
0
	def genSlotMatrix(self,words):
		matrix=[]
		
		for row in self.genWordMatrix(words):
			unitlist = []
			id=-1
			for word in row:
				syllnum=-1
				for unit in word.children:	# units = syllables
					syllnum+=1
					id+=1
					wordpos=(syllnum+1,len(word.children))
					unitlist.append(Slot(id, unit, word.sylls_text[syllnum], wordpos, word))
					
			if not self.splitheavies:
				matrix.append(unitlist)
			else:
				unitlist2=[]
				for slot in unitlist:
					if bool(slot.feature('prom.weight')):
						slot1=Slot(slot.i,slot.children[0],slot.token,slot.wordpos,slot.word)
						slot2=Slot(slot.i,slot.children[0],slot.token,slot.wordpos,slot.word)
						
						## mark as split
						slot1.issplit=True
						slot2.issplit=True
						
						## demote
						slot2.feats['prom.stress']=0.0
						slot1.feats['prom.weight']=0.0
						slot2.feats['prom.weight']=0.0
						
						## split token
						slot1.token= slot1.token[ : len(slot1.token)/2 ]
						slot2.token= slot2.token[len(slot1.token)/2 + 1 : ]
						
						unitlist2.append([slot,[slot1,slot2]])
					else:
						unitlist2.append([slot])
				
				#unitlist=[]
				for row in list(product(*unitlist2)):
					unitlist=[]
					for x in row:
						if type(x)==type([]):
							for y in x:
								unitlist.append(y)
						else:
							unitlist.append(x)
					matrix.append(unitlist)
			
			
				
		# for r in matrix:
		# 	for y in r:
		# 		print y
		# 	print
		# 	print	
		
		return matrix
Exemplo n.º 2
0
    def genSlotMatrix(self, wordtokens):
        matrix = []

        row_wordtokens = wordtokens
        rows_wordmatrix = self.genWordMatrix(wordtokens)

        for row in rows_wordmatrix:
            unitlist = []
            id = -1
            wordnum = -1
            for word in row:
                wordnum += 1
                syllnum = -1
                for unit in word.children:  # units = syllables
                    syllnum += 1
                    id += 1
                    wordpos = (syllnum + 1, len(word.children))
                    slot = Slot(id,
                                unit,
                                word.sylls_text[syllnum],
                                wordpos,
                                word,
                                i_word=wordnum,
                                i_syll_in_word=syllnum,
                                wordtoken=row_wordtokens[wordnum],
                                meter=self)
                    unitlist.append(slot)

            if not self.splitheavies:
                matrix.append(unitlist)
            else:
                unitlist2 = []
                for slot in unitlist:
                    if bool(slot.feature('prom.weight')):
                        slot1 = Slot(slot.i, slot.children[0], slot.token,
                                     slot.wordpos, slot.word)
                        slot2 = Slot(slot.i, slot.children[0], slot.token,
                                     slot.wordpos, slot.word)

                        ## mark as split
                        slot1.issplit = True
                        slot2.issplit = True

                        ## demote
                        slot2.feats['prom.stress'] = 0.0
                        slot1.feats['prom.weight'] = 0.0
                        slot2.feats['prom.weight'] = 0.0

                        ## split token
                        slot1.token = slot1.token[:len(slot1.token) / 2]
                        slot2.token = slot2.token[len(slot1.token) / 2 + 1:]

                        unitlist2.append([slot, [slot1, slot2]])
                    else:
                        unitlist2.append([slot])

                #unitlist=[]
                for row in list(product(*unitlist2)):
                    unitlist = []
                    for x in row:
                        if type(x) == type([]):
                            for y in x:
                                unitlist.append(y)
                        else:
                            unitlist.append(x)
                    matrix.append(unitlist)

        # for r in matrix:
        # 	for y in r:
        # 		print y
        # 	print
        # 	print

        return matrix