Skip to content

Instantly share code, notes, and snippets.

@kakittwo
Created October 6, 2018 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakittwo/e8d0a5c51abff4b3d1f28a57a96d283a to your computer and use it in GitHub Desktop.
Save kakittwo/e8d0a5c51abff4b3d1f28a57a96d283a to your computer and use it in GitHub Desktop.
def decodeSpeechData(aircraftListMod, wordList):
'''
Example input
aircraftListMod = [['November', 'Eight', 'Tree', 'Two', 'One', 'Mike'], ['Juliet', 'Bravo', 'Uniform', 'Six', 'One', 'Six']]
wordList = ['November', 'Eight', 'Tree', 'Two', 'One', 'Mike', 'Monitoring']
'''
aircraft_name = []
speech = []
bestMatchScore = -1
for k in range(len(aircraftListMod)):
N = len(wordList)
M = len(aircraftListMod[k])
aircraft = aircraftListMod[k]
scoreMatrix = [ [0 for j in range(M+1)] for i in range(N+ 1)]
traceMatrix = [ [0 for j in range(M+1)] for i in range(N+ 1)]
maxScore = -1
maxPair = []
for ii in range(1, N+1):
for jj in range(1, M+1):
i = ii -1
j = jj -1
if wordList[i].lower() == aircraft[j].lower():
matchScore = 1
else:
matchScore = -1
maxValue = max([ scoreMatrix[i-1][j-1] + matchScore, scoreMatrix[i-1][j] -1 , scoreMatrix[i][j-1] -1, 0.0])
scoreMatrix[i][j] = maxValue
if maxValue == scoreMatrix[i-1][j-1] + matchScore:
direction = 1
elif maxValue == scoreMatrix[i-1][j] - 1 :
direction = 2
elif maxValue == scoreMatrix[i][j-1] - 1 :
direction = 3
else:
direction = 0
traceMatrix[i][j] = direction
if maxValue > maxScore:
maxScore = maxValue
maxPair = [i, j]
print("Call sign option ", k + 1 , " ", aircraft, " match score ", maxScore*1.0)
if maxScore > bestMatchScore :
bestMatchScore = maxScore
aircraft_name = aircraft
speech = wordList[maxPair[0]+1:]
print( "Best match call sign ", aircraft_name)
print( "Speech", speech)
print( "Score", bestMatchScore*1.0)
return aircraft_name, speech
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment