mirror of
https://github.com/wassname/pysle.git
synced 2026-06-27 16:10:05 +08:00
d88ff7d8d9
It made the code a little more complex and now the system is less typing friendly but is more intuitive (no more guessing how to pronounce a character). Update includes changes to documentation.
52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
#encoding: utf-8
|
|
'''
|
|
Created on Oct 22, 2014
|
|
|
|
@author: tmahrt
|
|
|
|
Basic examples of common usage.
|
|
'''
|
|
|
|
from pysle import isletool
|
|
from pysle import pronunciationtools
|
|
|
|
# In this first example we look up the syllabification of a word and get it's
|
|
# stress information.
|
|
|
|
searchWord = 'catatonic'
|
|
isleDict = isletool.LexicalTool('ISLEdict.txt')
|
|
lookupResults = isleDict.lookup(searchWord)
|
|
|
|
firstEntry = lookupResults[0]
|
|
firstSyllableList = firstEntry[0]
|
|
firstSyllableList = ".".join([u" ".join(syllable) for syllable in firstSyllableList])
|
|
firstStressList = firstEntry[1]
|
|
|
|
print(searchWord)
|
|
print(firstSyllableList)
|
|
print(firstStressList) # 3rd syllable carries stress
|
|
|
|
|
|
# Here we determine the syllabification of a word, as it was said.
|
|
# (Of course, this is just a guess)
|
|
print('-'*50)
|
|
|
|
searchWord = 'another'
|
|
anotherPhoneList = ['n', '@', 'th', 'r']
|
|
|
|
returnList = pronunciationtools.findBestSyllabification(isleDict,
|
|
searchWord,
|
|
anotherPhoneList)
|
|
|
|
(stressedSyllable, syllableList, syllabification,
|
|
stressedSyllableIndexList, stressedPhoneIndexList,
|
|
flattenedStressIndexList) = returnList
|
|
print(searchWord)
|
|
print(anotherPhoneList)
|
|
print(stressedSyllableIndexList) # We can see the first syllable was elided
|
|
print(stressedPhoneIndexList)
|
|
print(flattenedStressIndexList)
|
|
print(syllableList)
|
|
print(syllabification)
|
|
|