mirror of
https://github.com/wassname/pysle.git
synced 2026-09-09 11:31:42 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
985d68da6c | ||
|
|
0e53ed654e | ||
|
|
ce633d0590 | ||
|
|
e2a2025f5b | ||
|
|
c10e3cf05f | ||
|
|
06222bf176 | ||
|
|
6353e0172e |
+1
-1
@@ -46,7 +46,7 @@ Requirements
|
|||||||
`ISLEX project page <http://www.isle.illinois.edu/sst/data/dict/>`_
|
`ISLEX project page <http://www.isle.illinois.edu/sst/data/dict/>`_
|
||||||
|
|
||||||
`Direct link to the ISLEX file used in this project
|
`Direct link to the ISLEX file used in this project
|
||||||
<http://www.isle.illinois.edu/sst/data/dict/islev2.txt)>`_ (islev2.txt)
|
<http://www.isle.illinois.edu/sst/data/dict/islex/islev2.txt>`_ (islev2.txt)
|
||||||
|
|
||||||
- ``Python 2.7.*`` or above
|
- ``Python 2.7.*`` or above
|
||||||
|
|
||||||
|
|||||||
+24
-24
@@ -5,41 +5,41 @@ Created on Oct 11, 2012
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
vowelList = ['a', '@', 'e', 'i', 'o', 'u', '^', '&', '>',]
|
vowelList = ['a', '@', 'e', 'i', 'o', 'u', '^', '&', '>', ]
|
||||||
|
|
||||||
|
|
||||||
class WordNotInISLE(Exception):
|
class WordNotInISLE(Exception):
|
||||||
|
|
||||||
def __init__(self, word):
|
def __init__(self, word):
|
||||||
|
super(WordNotInISLE, self).__init__()
|
||||||
self.word = word
|
self.word = word
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Word '%s' not in ISLE dictionary. Please add it to continue." % self.word
|
return ("Word '%s' not in ISLE dictionary. "
|
||||||
|
"Please add it to continue." % self.word)
|
||||||
|
|
||||||
|
|
||||||
class LexicalTool():
|
class LexicalTool():
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, islePath):
|
def __init__(self, islePath):
|
||||||
self.islePath = islePath
|
self.islePath = islePath
|
||||||
self.data = self._buildDict()
|
self.data = self._buildDict()
|
||||||
|
|
||||||
|
|
||||||
def _buildDict(self):
|
def _buildDict(self):
|
||||||
'''
|
'''
|
||||||
Builds the isle textfile into a dictionary for fast searching
|
Builds the isle textfile into a dictionary for fast searching
|
||||||
'''
|
'''
|
||||||
dict = {}
|
lexDict = {}
|
||||||
wordList = open(self.islePath, "r").read().split("\n")
|
wordList = [line.rstrip('\n') for line in open(self.islePath, "rU")]
|
||||||
|
|
||||||
for row in wordList:
|
for row in wordList:
|
||||||
word, pronunciation = row.split(" ", 1)
|
word, pronunciation = row.split(" ", 1)
|
||||||
word = word.split("(")[0]
|
word = word.split("(")[0]
|
||||||
|
|
||||||
dict.setdefault(word, [])
|
lexDict.setdefault(word, [])
|
||||||
dict[word].append(pronunciation)
|
lexDict[word].append(pronunciation)
|
||||||
|
|
||||||
return dict
|
return lexDict
|
||||||
|
|
||||||
|
|
||||||
def lookup(self, word):
|
def lookup(self, word):
|
||||||
'''
|
'''
|
||||||
@@ -52,10 +52,10 @@ class LexicalTool():
|
|||||||
|
|
||||||
pronList = self.data.get(word, None)
|
pronList = self.data.get(word, None)
|
||||||
|
|
||||||
if pronList == None:
|
if pronList is None:
|
||||||
raise WordNotInISLE(word)
|
raise WordNotInISLE(word)
|
||||||
else:
|
else:
|
||||||
pronList = [_parsePronunciation(pronunciationStr)
|
pronList = [_parsePronunciation(pronunciationStr)
|
||||||
for pronunciationStr in pronList]
|
for pronunciationStr in pronList]
|
||||||
|
|
||||||
return pronList
|
return pronList
|
||||||
@@ -65,8 +65,8 @@ def _parsePronunciation(pronunciationStr):
|
|||||||
'''
|
'''
|
||||||
Parses the pronunciation string
|
Parses the pronunciation string
|
||||||
|
|
||||||
Returns the list of syllables and a list of primary and
|
Returns the list of syllables and a list of primary and
|
||||||
secondary stress locations
|
secondary stress locations
|
||||||
'''
|
'''
|
||||||
syllableTxt = pronunciationStr.split("#")[1].strip()
|
syllableTxt = pronunciationStr.split("#")[1].strip()
|
||||||
syllableList = [x for x in syllableTxt.split(' . ')]
|
syllableList = [x for x in syllableTxt.split(' . ')]
|
||||||
@@ -89,7 +89,7 @@ def _parsePronunciation(pronunciationStr):
|
|||||||
def getNumPhones(isleDict, label, maxFlag):
|
def getNumPhones(isleDict, label, maxFlag):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
If maxFlag=True, use the longest pronunciation. Otherwise, take the
|
If maxFlag=True, use the longest pronunciation. Otherwise, take the
|
||||||
average length.
|
average length.
|
||||||
'''
|
'''
|
||||||
phoneCount = 0
|
phoneCount = 0
|
||||||
@@ -99,25 +99,28 @@ def getNumPhones(isleDict, label, maxFlag):
|
|||||||
phoneListOfLists = isleDict.lookup(word)
|
phoneListOfLists = isleDict.lookup(word)
|
||||||
|
|
||||||
syllableCountList = []
|
syllableCountList = []
|
||||||
for syllableList, stressIndex in phoneListOfLists:
|
for row in phoneListOfLists:
|
||||||
|
syllableList = row[0]
|
||||||
syllableCountList.append(len(syllableList))
|
syllableCountList.append(len(syllableList))
|
||||||
|
|
||||||
# In ISLE, there can be multiple pronunciations for each word
|
# In ISLE, there can be multiple pronunciations for each word
|
||||||
# as we have no reason to believe one pronunciation is more
|
# as we have no reason to believe one pronunciation is more
|
||||||
# likely than another, we take the average of all of them
|
# likely than another, we take the average of all of them
|
||||||
phoneCountList = []
|
phoneCountList = []
|
||||||
for syllableList, stressIndex in phoneListOfLists:
|
for row in phoneListOfLists:
|
||||||
phoneCountList.append(len([phon for phoneList in syllableList for
|
syllableList = row[0]
|
||||||
|
phoneCountList.append(len([phon for phoneList in syllableList for
|
||||||
phon in phoneList]))
|
phon in phoneList]))
|
||||||
|
|
||||||
# The average number of phones for all possible pronunciations
|
# The average number of phones for all possible pronunciations
|
||||||
# of this word
|
# of this word
|
||||||
if maxFlag == True:
|
if maxFlag is True:
|
||||||
syllableCount += max(syllableCountList)
|
syllableCount += max(syllableCountList)
|
||||||
phoneCount += max(phoneCountList)
|
phoneCount += max(phoneCountList)
|
||||||
else:
|
else:
|
||||||
syllableCount += sum(syllableCountList) / float(len(syllableCountList))
|
syllableCount += (sum(syllableCountList) /
|
||||||
phoneCount += sum(phoneCountList) / float(len(phoneCountList))
|
float(len(syllableCountList)))
|
||||||
|
phoneCount += sum(phoneCountList) / float(len(phoneCountList))
|
||||||
|
|
||||||
return syllableCount, phoneCount
|
return syllableCount, phoneCount
|
||||||
|
|
||||||
@@ -137,6 +140,3 @@ def findOODWords(isleDict, wordList):
|
|||||||
oodList.sort()
|
oodList.sort()
|
||||||
|
|
||||||
return oodList
|
return oodList
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+21
-18
@@ -4,6 +4,7 @@ Created on Oct 22, 2014
|
|||||||
@author: tmahrt
|
@author: tmahrt
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
class OptionalFeatureError(ImportError):
|
class OptionalFeatureError(ImportError):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@@ -18,7 +19,7 @@ from pysle import isletool
|
|||||||
from pysle import pronunciationtools
|
from pysle import pronunciationtools
|
||||||
|
|
||||||
|
|
||||||
def syllabifyTextgrid(isleDict, tg, wordTierName, phoneTierName,
|
def syllabifyTextgrid(isleDict, tg, wordTierName, phoneTierName,
|
||||||
skipLabelList=None):
|
skipLabelList=None):
|
||||||
'''
|
'''
|
||||||
Given a textgrid, syllabifies the phones in the textgrid
|
Given a textgrid, syllabifies the phones in the textgrid
|
||||||
@@ -34,7 +35,7 @@ def syllabifyTextgrid(isleDict, tg, wordTierName, phoneTierName,
|
|||||||
wordTier = tg.tierDict[wordTierName]
|
wordTier = tg.tierDict[wordTierName]
|
||||||
phoneTier = tg.tierDict[phoneTierName]
|
phoneTier = tg.tierDict[phoneTierName]
|
||||||
|
|
||||||
if skipLabelList == None:
|
if skipLabelList is None:
|
||||||
skipLabelList = []
|
skipLabelList = []
|
||||||
|
|
||||||
syllableEntryList = []
|
syllableEntryList = []
|
||||||
@@ -46,28 +47,31 @@ def syllabifyTextgrid(isleDict, tg, wordTierName, phoneTierName,
|
|||||||
|
|
||||||
subPhoneTier = phoneTier.crop(start, stop, True, False)[0]
|
subPhoneTier = phoneTier.crop(start, stop, True, False)[0]
|
||||||
|
|
||||||
phoneList = [phone for startP, endP, phone in subPhoneTier.entryList if phone != '']
|
# entry = (start, stop, phone)
|
||||||
|
phoneList = [entry[2] for entry in subPhoneTier.entryList
|
||||||
|
if entry[2] != '']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
returnList = pronunciationtools.findBestSyllabification(isleDict,
|
returnList = pronunciationtools.findBestSyllabification(isleDict,
|
||||||
word,
|
word,
|
||||||
phoneList)
|
phoneList)
|
||||||
except isletool.WordNotInISLE:
|
except isletool.WordNotInISLE:
|
||||||
print "Word ('%s') not is isle -- skipping syllabification" % word
|
print("Word ('%s') not is isle -- skipping syllabification" % word)
|
||||||
continue
|
continue
|
||||||
except (pronunciationtools.NullPronunciationError):
|
except (pronunciationtools.NullPronunciationError):
|
||||||
print "Word ('%s') has no provided pronunciation" % word
|
print("Word ('%s') has no provided pronunciation" % word)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
stressedSyllable, syllableList, syllabification, stressIndexList = returnList
|
syllableList = returnList[1]
|
||||||
|
stressIndexList = returnList[3]
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
# print syllableList
|
# print(syllableList)
|
||||||
for k, syllable in enumerate(syllableList):
|
for k, syllable in enumerate(syllableList):
|
||||||
|
|
||||||
# Create the syllable tier entry
|
# Create the syllable tier entry
|
||||||
j = len(syllable)
|
j = len(syllable)
|
||||||
stubEntryList = subPhoneTier.entryList[i:i+j]
|
stubEntryList = subPhoneTier.entryList[i:i + j]
|
||||||
i += j
|
i += j
|
||||||
|
|
||||||
# The whole syllable was deleted
|
# The whole syllable was deleted
|
||||||
@@ -76,29 +80,28 @@ def syllabifyTextgrid(isleDict, tg, wordTierName, phoneTierName,
|
|||||||
|
|
||||||
syllableStart = stubEntryList[0][0]
|
syllableStart = stubEntryList[0][0]
|
||||||
syllableEnd = stubEntryList[-1][1]
|
syllableEnd = stubEntryList[-1][1]
|
||||||
label = "-".join([phone for start, end, phone in stubEntryList])
|
label = "-".join([entry[2] for entry in stubEntryList])
|
||||||
|
|
||||||
syllableEntryList.append( (syllableStart, syllableEnd, label) )
|
syllableEntryList.append((syllableStart, syllableEnd, label))
|
||||||
|
|
||||||
# Create the tonic tier entry
|
# Create the tonic tier entry
|
||||||
try:
|
try:
|
||||||
stressIndex = stressIndexList[0]
|
stressIndex = stressIndexList[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
stressIndex = None # Function word probably
|
stressIndex = None # Function word probably
|
||||||
|
|
||||||
tonicLabel = ''
|
tonicLabel = ''
|
||||||
if k == stressIndex:
|
if k == stressIndex:
|
||||||
tonicLabel = 'T'
|
tonicLabel = 'T'
|
||||||
|
|
||||||
tonicEntryList.append( (syllableStart, syllableEnd, tonicLabel) )
|
tonicEntryList.append((syllableStart, syllableEnd, tonicLabel))
|
||||||
|
|
||||||
# Create a textgrid with the two syllable-level tiers
|
# Create a textgrid with the two syllable-level tiers
|
||||||
syllableTier = praatio.TextgridTier("syllable", syllableEntryList, praatio.INTERVAL_TIER)
|
syllableTier = praatio.IntervalTier("syllable", syllableEntryList)
|
||||||
tonicTier = praatio.TextgridTier('tonic', tonicEntryList, praatio.INTERVAL_TIER)
|
tonicTier = praatio.IntervalTier('tonic', tonicEntryList)
|
||||||
|
|
||||||
syllableTG = praatio.Textgrid()
|
syllableTG = praatio.Textgrid()
|
||||||
syllableTG.addTier(syllableTier)
|
syllableTG.addTier(syllableTier)
|
||||||
syllableTG.addTier(tonicTier)
|
syllableTG.addTier(tonicTier)
|
||||||
|
|
||||||
return syllableTG
|
return syllableTG
|
||||||
|
|
||||||
|
|||||||
+37
-47
@@ -9,10 +9,10 @@ import itertools
|
|||||||
from pysle import isletool
|
from pysle import isletool
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class NullPronunciationError(Exception):
|
class NullPronunciationError(Exception):
|
||||||
|
|
||||||
def __init__(self, word):
|
def __init__(self, word):
|
||||||
|
super(NullPronunciationError, self).__init__()
|
||||||
self.word = word
|
self.word = word
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@@ -49,7 +49,7 @@ def _lcs(xs, ys):
|
|||||||
ll_b = _lcs_lens(xb, ys)
|
ll_b = _lcs_lens(xb, ys)
|
||||||
ll_e = _lcs_lens(xe[::-1], ys[::-1])
|
ll_e = _lcs_lens(xe[::-1], ys[::-1])
|
||||||
_, k = max((ll_b[j] + ll_e[ny - j], j)
|
_, k = max((ll_b[j] + ll_e[ny - j], j)
|
||||||
for j in range(ny + 1))
|
for j in range(ny + 1))
|
||||||
yb, ye = ys[:k], ys[k:]
|
yb, ye = ys[:k], ys[k:]
|
||||||
return _lcs(xb, yb) + _lcs(xe, ye)
|
return _lcs(xb, yb) + _lcs(xe, ye)
|
||||||
|
|
||||||
@@ -58,14 +58,13 @@ def _prepPronunciation(phoneList):
|
|||||||
retList = []
|
retList = []
|
||||||
for phone in phoneList:
|
for phone in phoneList:
|
||||||
if 'r' in phone:
|
if 'r' in phone:
|
||||||
phone = ['r',]
|
phone = ['r', ]
|
||||||
try:
|
try:
|
||||||
phone = phone[0] # Only represent the str by its first letter
|
phone = phone[0] # Only represent the string by its first letter
|
||||||
|
phone = phone.lower()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise NullPhoneError()
|
raise NullPhoneError()
|
||||||
|
|
||||||
phone = phone.lower()
|
|
||||||
|
|
||||||
if phone in isletool.vowelList:
|
if phone in isletool.vowelList:
|
||||||
phone = 'V'
|
phone = 'V'
|
||||||
retList.append(phone)
|
retList.append(phone)
|
||||||
@@ -85,14 +84,14 @@ def _adjustSyllabification(adjustedPhoneList, syllableList):
|
|||||||
retSyllableList = []
|
retSyllableList = []
|
||||||
for syllable in syllableList:
|
for syllable in syllableList:
|
||||||
j = len(syllable)
|
j = len(syllable)
|
||||||
tmpPhoneList = adjustedPhoneList[i:i+j]
|
tmpPhoneList = adjustedPhoneList[i:i + j]
|
||||||
numBlanks = -1
|
numBlanks = -1
|
||||||
phoneList = tmpPhoneList[:]
|
phoneList = tmpPhoneList[:]
|
||||||
while numBlanks != 0:
|
while numBlanks != 0:
|
||||||
|
|
||||||
numBlanks = tmpPhoneList.count("''")
|
numBlanks = tmpPhoneList.count("''")
|
||||||
if numBlanks > 0:
|
if numBlanks > 0:
|
||||||
tmpPhoneList = adjustedPhoneList[i+j:i+j+numBlanks]
|
tmpPhoneList = adjustedPhoneList[i + j:i + j + numBlanks]
|
||||||
phoneList.extend(tmpPhoneList)
|
phoneList.extend(tmpPhoneList)
|
||||||
j += numBlanks
|
j += numBlanks
|
||||||
|
|
||||||
@@ -116,27 +115,32 @@ def _findBestPronunciation(isleDict, wordText, aPron):
|
|||||||
|
|
||||||
isleWordList = isleDict.lookup(wordText)
|
isleWordList = isleDict.lookup(wordText)
|
||||||
|
|
||||||
aP = _prepPronunciation(aPron) # Mapping to simplified phone inventory
|
aP = _prepPronunciation(aPron) # Mapping to simplified phone inventory
|
||||||
|
|
||||||
origPronDict = dict((newPron,oldPron) for newPron, oldPron in zip(aP, aPron))
|
origPronDict = dict((newPron, oldPron)
|
||||||
|
for newPron, oldPron in zip(aP, aPron))
|
||||||
|
|
||||||
numDiffList = []
|
numDiffList = []
|
||||||
withStress = []
|
withStress = []
|
||||||
i = 0
|
i = 0
|
||||||
alignedSyllabificationList = []
|
alignedSyllabificationList = []
|
||||||
alignedActualPronunciationList = []
|
alignedActualPronunciationList = []
|
||||||
for syllableList, stressList in isleWordList:
|
for wordTuple in isleWordList:
|
||||||
|
syllableList = wordTuple[0] # syllableList, stressList
|
||||||
|
|
||||||
iP = [phone for phoneList in syllableList for phone in phoneList]
|
iP = [phone for phoneList in syllableList for phone in phoneList]
|
||||||
iP = _prepPronunciation(iP)
|
iP = _prepPronunciation(iP)
|
||||||
|
|
||||||
alignedIP, alignedAP = alignPronunciations(iP, aP)
|
alignedIP, alignedAP = alignPronunciations(iP, aP)
|
||||||
alignedAP = [origPronDict.get(phon, "''") for phon in alignedAP] # Remapping to actual phones
|
|
||||||
|
# Remapping to actual phones
|
||||||
|
alignedAP = [origPronDict.get(phon, "''") for phon in alignedAP]
|
||||||
alignedActualPronunciationList.append(alignedAP)
|
alignedActualPronunciationList.append(alignedAP)
|
||||||
|
|
||||||
# Adjusting the syllabification for differences between the dictionary
|
# Adjusting the syllabification for differences between the dictionary
|
||||||
# pronunciation and the actual pronunciation
|
# pronunciation and the actual pronunciation
|
||||||
alignedSyllabification = _adjustSyllabification(alignedIP, syllableList)
|
alignedSyllabification = _adjustSyllabification(alignedIP,
|
||||||
|
syllableList)
|
||||||
alignedSyllabificationList.append(alignedSyllabification)
|
alignedSyllabificationList.append(alignedSyllabification)
|
||||||
|
|
||||||
# Count the number of misalignments between the two
|
# Count the number of misalignments between the two
|
||||||
@@ -147,7 +151,7 @@ def _findBestPronunciation(isleDict, wordText, aPron):
|
|||||||
hasStress = False
|
hasStress = False
|
||||||
for syllable in syllableList:
|
for syllable in syllableList:
|
||||||
for phone in syllable:
|
for phone in syllable:
|
||||||
hasStress = "'" in phone or hasStress
|
hasStress = "'" in phone or hasStress
|
||||||
|
|
||||||
if hasStress:
|
if hasStress:
|
||||||
withStress.append(i)
|
withStress.append(i)
|
||||||
@@ -164,16 +168,16 @@ def _findBestPronunciation(isleDict, wordText, aPron):
|
|||||||
for i, numDiff in enumerate(numDiffList):
|
for i, numDiff in enumerate(numDiffList):
|
||||||
if numDiff != minDiff:
|
if numDiff != minDiff:
|
||||||
continue
|
continue
|
||||||
if bestIndex == None:
|
if bestIndex is None:
|
||||||
bestIndex = i
|
bestIndex = i
|
||||||
bestIsStressed = i in withStress
|
bestIsStressed = i in withStress
|
||||||
else:
|
else:
|
||||||
if not bestIsStressed and i in withStress:
|
if not bestIsStressed and i in withStress:
|
||||||
bestIndex = i
|
bestIndex = i
|
||||||
bestIsStressed = True
|
bestIsStressed = True
|
||||||
|
|
||||||
|
|
||||||
return isleWordList, alignedActualPronunciationList, alignedSyllabificationList, bestIndex
|
return (isleWordList, alignedActualPronunciationList,
|
||||||
|
alignedSyllabificationList, bestIndex)
|
||||||
|
|
||||||
|
|
||||||
def _syllabifyPhones(phoneList, syllableList, isleStressList):
|
def _syllabifyPhones(phoneList, syllableList, isleStressList):
|
||||||
@@ -193,9 +197,9 @@ def _syllabifyPhones(phoneList, syllableList, isleStressList):
|
|||||||
|
|
||||||
start = 0
|
start = 0
|
||||||
syllabifiedList = []
|
syllabifiedList = []
|
||||||
for i, end in enumerate(numPhoneList):
|
for end in numPhoneList:
|
||||||
|
|
||||||
syllable = phoneList[start:start+end]
|
syllable = phoneList[start:start + end]
|
||||||
syllabifiedList.append(syllable)
|
syllabifiedList.append(syllable)
|
||||||
|
|
||||||
start += end
|
start += end
|
||||||
@@ -212,21 +216,6 @@ def alignPronunciations(pronI, pronA):
|
|||||||
pronI = [char for char in pronI]
|
pronI = [char for char in pronI]
|
||||||
pronA = [char for char in pronA]
|
pronA = [char for char in pronA]
|
||||||
|
|
||||||
# -- allow for some flexibility in pronunciation
|
|
||||||
correctionsTuple = (('d', 't'), ('t', 'd'), ('s', 'z'), ('z', 's'),
|
|
||||||
('m', 'n'), ('n', 'm'),)
|
|
||||||
|
|
||||||
doMatch = lambda i, a: ((i == a) or
|
|
||||||
((i, a) in correctionsTuple))
|
|
||||||
|
|
||||||
def matchExists(targetPhone, pron):
|
|
||||||
match = False
|
|
||||||
for phone in pron:
|
|
||||||
match = match or doMatch(targetPhone, phone)
|
|
||||||
return match
|
|
||||||
|
|
||||||
# Remove vowels
|
|
||||||
|
|
||||||
# Remove any elements not in the other list (but maintain order)
|
# Remove any elements not in the other list (but maintain order)
|
||||||
pronITmp = pronI
|
pronITmp = pronI
|
||||||
pronATmp = pronA
|
pronATmp = pronA
|
||||||
@@ -244,7 +233,7 @@ def alignPronunciations(pronI, pronA):
|
|||||||
startA = pronA.index(phone, startA)
|
startA = pronA.index(phone, startA)
|
||||||
startI = pronI.index(phone, startI)
|
startI = pronI.index(phone, startI)
|
||||||
|
|
||||||
sequenceIndexListA.append(startA)
|
sequenceIndexListA.append(startA)
|
||||||
sequenceIndexListI.append(startI)
|
sequenceIndexListI.append(startI)
|
||||||
|
|
||||||
# An index on the tail of both will be used to create output strings
|
# An index on the tail of both will be used to create output strings
|
||||||
@@ -257,14 +246,16 @@ def alignPronunciations(pronI, pronA):
|
|||||||
for x in xrange(len(sequenceIndexListA)):
|
for x in xrange(len(sequenceIndexListA)):
|
||||||
indexA = sequenceIndexListA[x]
|
indexA = sequenceIndexListA[x]
|
||||||
indexI = sequenceIndexListI[x]
|
indexI = sequenceIndexListI[x]
|
||||||
if indexA < indexI :
|
if indexA < indexI:
|
||||||
for x in xrange(indexI - indexA):
|
for x in xrange(indexI - indexA):
|
||||||
pronA.insert(indexA, "''")
|
pronA.insert(indexA, "''")
|
||||||
sequenceIndexListA = [val + indexI - indexA for val in sequenceIndexListA]
|
sequenceIndexListA = [val + indexI - indexA
|
||||||
|
for val in sequenceIndexListA]
|
||||||
elif indexA > indexI:
|
elif indexA > indexI:
|
||||||
for x in xrange(indexA - indexI):
|
for x in xrange(indexA - indexI):
|
||||||
pronI.insert(indexI, "''")
|
pronI.insert(indexI, "''")
|
||||||
sequenceIndexListI = [val + indexA - indexI for val in sequenceIndexListI]
|
sequenceIndexListI = [val + indexA - indexI
|
||||||
|
for val in sequenceIndexListI]
|
||||||
|
|
||||||
return pronI, pronA
|
return pronI, pronA
|
||||||
|
|
||||||
@@ -273,11 +264,12 @@ def findBestSyllabification(isleDict, wordText, actualPronunciationList):
|
|||||||
'''
|
'''
|
||||||
Find the best syllabification for a word
|
Find the best syllabification for a word
|
||||||
|
|
||||||
First find the closest pronunciation to a given pronunciation. Then take
|
First find the closest pronunciation to a given pronunciation. Then take
|
||||||
the syllabification for that pronunciation and map it onto the
|
the syllabification for that pronunciation and map it onto the
|
||||||
input pronunciation.
|
input pronunciation.
|
||||||
'''
|
'''
|
||||||
retList = _findBestPronunciation(isleDict, wordText, actualPronunciationList)
|
retList = _findBestPronunciation(isleDict, wordText,
|
||||||
|
actualPronunciationList)
|
||||||
isleWordList, alignedAPronList, alignedSyllableList, bestIndex = retList
|
isleWordList, alignedAPronList, alignedSyllableList, bestIndex = retList
|
||||||
|
|
||||||
alignedPhoneList = alignedAPronList[bestIndex]
|
alignedPhoneList = alignedAPronList[bestIndex]
|
||||||
@@ -285,8 +277,8 @@ def findBestSyllabification(isleDict, wordText, actualPronunciationList):
|
|||||||
syllabification = isleWordList[bestIndex][0]
|
syllabification = isleWordList[bestIndex][0]
|
||||||
stressedIndex = isleWordList[bestIndex][1]
|
stressedIndex = isleWordList[bestIndex][1]
|
||||||
|
|
||||||
stressedSyllable, syllableList = _syllabifyPhones(alignedPhoneList,
|
stressedSyllable, syllableList = _syllabifyPhones(alignedPhoneList,
|
||||||
alignedSyllables,
|
alignedSyllables,
|
||||||
stressedIndex)
|
stressedIndex)
|
||||||
|
|
||||||
return stressedSyllable, syllableList, syllabification, stressedIndex
|
return stressedSyllable, syllableList, syllabification, stressedIndex
|
||||||
@@ -298,9 +290,7 @@ def findClosestPronunciation(isleDict, wordText, aPron):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
retList = _findBestPronunciation(isleDict, wordText, aPron)
|
retList = _findBestPronunciation(isleDict, wordText, aPron)
|
||||||
isleWordList, actualPronunciationList, bestIndex = retList
|
isleWordList = retList[0]
|
||||||
|
bestIndex = retList[3]
|
||||||
|
|
||||||
return isleWordList[bestIndex]
|
return isleWordList[bestIndex]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ firstEntry = lookupResults[0]
|
|||||||
firstSyllableList = firstEntry[0]
|
firstSyllableList = firstEntry[0]
|
||||||
firstStressList = firstEntry[1]
|
firstStressList = firstEntry[1]
|
||||||
|
|
||||||
print searchWord
|
print(searchWord)
|
||||||
print firstSyllableList, firstStressList # 3rd syllable carries stress
|
print(firstSyllableList, firstStressList) # 3rd syllable carries stress
|
||||||
|
|
||||||
|
|
||||||
# Here we determine the syllabification of a word, as it was said.
|
# Here we determine the syllabification of a word, as it was said.
|
||||||
# (Of course, this is just a guess)
|
# (Of course, this is just a guess)
|
||||||
print '-'*50
|
print('-'*50)
|
||||||
|
|
||||||
searchWord = 'another'
|
searchWord = 'another'
|
||||||
anotherPhoneList = ['n', '@', 'th', 'r']
|
anotherPhoneList = ['n', '@', 'th', 'r']
|
||||||
@@ -37,8 +37,8 @@ returnList = pronunciationtools.findBestSyllabification(isleDict,
|
|||||||
|
|
||||||
stressedSyllable, syllableList, syllabification, stressedIndex = returnList
|
stressedSyllable, syllableList, syllabification, stressedIndex = returnList
|
||||||
|
|
||||||
print searchWord
|
print(searchWord)
|
||||||
print anotherPhoneList
|
print(anotherPhoneList)
|
||||||
print syllableList # We can see the first syllable was elided
|
print(syllableList) # We can see the first syllable was elided
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ path = join('.', 'files')
|
|||||||
path = "/Users/tmahrt/Dropbox/workspace/pysle/test/files"
|
path = "/Users/tmahrt/Dropbox/workspace/pysle/test/files"
|
||||||
|
|
||||||
tg = praatio.openTextGrid(join(path, "pumpkins.TextGrid"))
|
tg = praatio.openTextGrid(join(path, "pumpkins.TextGrid"))
|
||||||
isleDict = isletool.LexicalTool('/Users/tmahrt/Dropbox/workspace/pysle/test/islev2.txt') # Needs the full path to the file
|
|
||||||
|
# Needs the full path to the file
|
||||||
|
islevPath = '/Users/tmahrt/Dropbox/workspace/pysle/test/islev2.txt'
|
||||||
|
isleDict = isletool.LexicalTool(islevPath)
|
||||||
|
|
||||||
# Get the syllabification tiers and add it to the textgrid
|
# Get the syllabification tiers and add it to the textgrid
|
||||||
syllableTG = praattools.syllabifyTextgrid(isleDict, tg, "word", "phone",
|
syllableTG = praattools.syllabifyTextgrid(isleDict, tg, "word", "phone",
|
||||||
|
|||||||
Reference in New Issue
Block a user