コード例 #1
0
def word_length (pylinguistObj):
	if (pylinguistObj.language == "pt"):
		#from source.syllable import silva2011
		#import source.syllable.silva2011
		from resources.syllable.silva2011 import syllable_separator

		array = []
		count_error=0
		for w in pylinguistObj.tokens:
			count=0

			w = tools.clear_string(w.encode('utf-8'))
			if len(w)>1:
				#print ('separando palavra:%s' %w_clean)
				try:
					syllables = syllable_separator.separate(w)
					leng = len(syllables)
					count+=leng
					#print ('word:%s syllables:%s %i ' %(w, syllables,leng))
				except:
					count_error+=1
					#print ('ERROR ON WORD: %s' %w)
			array.append(count)
			
		#pylinguistObj.word_length = array 			#Not working
		return array
	else:
		#print "ELSE"
		array = []
		count_error=0
		for w in pylinguistObj.tokens:
			count=0
			#w_clean = tools.clear_string(w)
			w = tools.clear_string(w.encode('utf-8'))
			if len(w)>1:
				#result = 
				#print ('separando palavra:%s' %w_clean)
				try:
					leng = syllable_counter_english(w)
					count+=leng
					#print ('word:%s syllables:%i ' %(w,leng))
				except:
					count_error+=1
					#print ('ERROR ON WORD: %s' %w)
			array.append(count)
			
		return array
コード例 #2
0
def syllable_count (pylinguistObj):
	x=0
	if (pylinguistObj.language == "pt"):
		#from source.syllable import silva2011
		#import source.syllable.silva2011
		from resources.syllable.silva2011 import syllable_separator
		count=0
		count_error=0
		for w in pylinguistObj.tokens:
			w_clean = tools.clear_string(w)
			w = tools.clear_string(w.encode('utf-8'))
			if len(w)>1:
				#result = 
				#print ('separando palavra:%s' %w_clean)
				try:
					syllables = syllable_separator.separate(w)
					leng = len(syllables)
					count+=leng
					#print ('word:%s syllables:%s %i ' %(w, syllables,leng))
				except:
					count_error+=1
					#print ('ERROR ON WORD: %s' %w)
			
		pylinguistObj.syllable_count = count
		return count
	else:
		#print "ELSE"
		count=0
		count_error=0
		for w in pylinguistObj.tokens:
			#w_clean = tools.clear_string(w)
			w = tools.clear_string(w.encode('utf-8'))
			if len(w)>1:
				#result = 
				#print ('separando palavra:%s' %w_clean)
				try:
					leng = syllable_counter_english(w)
					count+=leng
					#print ('word:%s syllables:%i ' %(w,leng))
				except:
					count_error+=1
					#print ('ERROR ON WORD: %s' %w)
			
		pylinguistObj.syllable_count = count
		return count
	# try:

	# 	count = 0
	# 	vowels = 'aeiouy'
	# 	text = pylinguistObj.text.lower().strip(".:;?!)(")
	# 	if text is not None and text != "":
	# 		if text[0] in vowels:
	# 			count += 1
	# 		for index in range(1, len(text)):
	# 			if text[index] in vowels and text[index-1] not in vowels:
	# 				count += 1
	# 		if text.endswith('e'):
	# 			count -= 1
	# 		if text.endswith('le'):
	# 			count += 1
	# 		if count == 0:
	# 			count += 1
	# 		count = count - (0.1*count)
	# 	x= (round(count))
	# except:
	# 	x=0
	# pylinguistObj.syllable_count = x
	return x