Использование python для преобразования вывода JSON - PullRequest
0 голосов
/ 06 июня 2018

Используя речь Ватсона к тексту, я получил следующий вывод.

{'results': [{'alternatives': [{'timestamps': [['I', 0.09, 0.16], ["can't", 0.16, 0.48], ['even', 0.48, 0.67], ['believe', 0.67, 0.96], ['Michigan', 0.96, 1.45], ['went', 1.45, 1.74], ['for', 1.74, 1.87], ['two', 1.87, 2.1], ['against', 2.1, 2.44], ['always', 2.44, 2.72], ['you', 2.72, 3.05], ['should', 3.29, 3.55], ['just', 3.55, 3.72], ['play', 3.72, 3.89], ['it', 3.89, 4.02], ['safe', 4.02, 4.24], ['with', 4.24, 4.36], ['a', 4.36, 4.4], ['field', 4.4, 4.77], ['goal', 4.77, 5.04], ['whatever', 5.09, 5.47], ['you', 5.47, 5.62], ['said', 5.62, 5.9], ['that', 5.9, 6.12], ['own', 6.62, 6.89], ['aging', 6.89, 7.23], ['Pearson', 7.23, 7.95], ['is', 7.98, 8.14], ['ten', 8.14, 8.36], ['thousand', 8.36, 8.72], ['yard', 8.72, 8.99], ['record', 8.99, 9.5]], 'confidence': 0.752, 'transcript': "I can't even believe Michigan went for two against always you should just play it safe with a field goal whatever you said that own aging Pearson is ten thousand yard record "}], 'final': True}, {'alternatives': [{'timestamps': [['while', 10.34, 11.06]], 'confidence': 0.417, 'transcript': 'while '}], 'final': True}, {'alternatives': [{'timestamps': [['yeah', 12.3, 12.81], ['sure', 13.34, 13.78]], 'confidence': 0.556, 'transcript': 'yeah sure '}], 'final': True}, {'alternatives': [{'timestamps': [['and', 14.42, 14.73], ["here's", 14.73, 15.12], ['our', 15.12, 15.21], ['calamari', 15.21, 15.86], ['Sir', 15.86, 16.24]], 'confidence': 0.959, 'transcript': "and here's our calamari Sir "}], 'final': True}, {'alternatives': [{'timestamps': [['faster', 17.56, 17.97], ['wow', 18.01, 18.36], ['this', 18.36, 18.55], ['food', 18.55, 18.78], ['looks', 18.78, 18.92], ['amazing', 18.92, 19.53], ['thank', 19.56, 19.82], ['you', 19.82, 20.03], ['south', 20.48, 21.02], ['let', 21.17, 21.33], ['me', 21.33, 21.46], ['just', 21.46, 21.71], ['tell', 21.71, 21.92], ['you', 21.92, 22.16], ['yesterday', 22.37, 23.12], ['when', 23.15, 23.37], ['means', 23.37, 23.73], ['easy', 23.73, 24.01], ['at', 24.01, 24.15], ['blackfriday', 24.15, 24.59], ['shopping', 24.59, 25.13], ['like', 25.19, 25.51], ['L.', 25.59, 25.82], ['M.', 25.82, 26.15], ['fricking', 26.18, 26.58], ['Gee', 26.58, 26.97], ['it', 27.0, 27.15], ['was', 27.15, 27.37], ['cruel', 27.53, 27.81], ['Razi', 27.97, 28.73], ['we', 28.85, 29.08], ['started', 29.08, 29.54], ['me', 29.54, 29.73], ['sis', 29.73, 30.04], ['and', 30.04, 30.17], ['like', 30.17, 30.47]], 'confidence': 0.648, 'transcript': 'faster wow this food looks amazing thank you south let me just tell you yesterday when means easy at blackfriday shopping like L. M. fricking Gee it was cruel Razi we started me sis and like '}], 'final': True}, {'alternatives': [{'timestamps': [['the', 31.31, 31.39], ['sales', 31.39, 31.77], ['were', 31.77, 32.03], ['horrendous', 32.09, 32.93], ['so', 33.19, 33.37], ['then', 33.37, 33.81], ['we', 33.88, 34.17], ['went', 34.17, 34.52], ['to', 34.52, 34.98], ['Charlotte', 35.01, 35.46], ['russe', 35.46, 35.81], ['and', 35.81, 35.97], ['let', 35.97, 36.08], ['me', 36.08, 36.17], ['tell', 36.17, 36.38], ['you', 36.38, 36.51], ['I', 36.51, 36.63], ['got', 36.63, 36.87], ['some', 36.87, 37.11], ['killer', 37.25, 37.86], ['deals', 37.89, 38.35], ['there', 38.35, 38.73], ['are', 39.13, 39.27], ['you', 39.27, 39.49], ['listening', 39.8, 40.33], ['to', 40.33, 40.47], ['everything', 40.47, 40.91], ["I'm", 40.91, 41.05], ['saying', 41.05, 41.61], ['yeah', 42.03, 42.39], ['yeah', 42.39, 42.8], ['no', 42.83, 43.2], ['of', 43.26, 43.37], ['course', 43.37, 43.85], ['not', 43.88, 44.12], ["it's", 44.12, 44.24], ['just', 44.24, 44.4], ['that', 44.4, 44.63], ['this', 44.63, 44.84], ['food', 44.84, 45.26], ['is', 45.26, 45.51], ['absolutely', 45.54, 46.17], ['fantastic', 46.17, 47.03], ['and', 47.35, 47.62], ['I', 47.62, 47.72], ['think', 47.72, 47.92], ['I', 47.92, 47.97], ['need', 47.97, 48.09], ['to', 48.09, 48.16], ['go', 48.16, 48.26], ['complement', 48.26, 48.71], ['the', 48.71, 48.77], ['chef', 48.77, 49.21]], 'confidence': 0.857, 'transcript': "the sales were horrendous so then we went to Charlotte russe and let me tell you I got some killer deals there are you listening to everything I'm saying yeah yeah no of course not it's just that this food is absolutely fantastic and I think I need to go complement the chef "}], 'final': True}, {'alternatives': [{'timestamps': [['our', 49.9, 50.04], ['son', 50.04, 50.5], ['son', 50.77, 51.21]], 'confidence': 0.491, 'transcript': 'our son son '}], 'final': True}, {'alternatives': [{'timestamps': [['yes', 51.8, 52.04], ['Sir', 52.04, 52.25], ['what', 52.25, 52.39], ['can', 52.39, 52.51], ['I', 52.51, 52.55], ['do', 52.55, 52.7], ['for', 52.7, 52.85], ['you', 52.85, 53.08], ["I'm", 53.44, 53.95], ['in', 53.98, 54.16], ['love', 54.16, 54.56], ['with', 54.56, 54.68], ['this', 54.68, 54.82], ['calamari', 54.82, 55.4], ['please', 55.4, 55.7], ['just', 55.7, 55.96], ['give', 56.21, 56.39], ['my', 56.39, 56.5], ['regards', 56.5, 56.92], ['the', 56.92, 57.03], ['shaft', 57.03, 57.38], ['of', 57.67, 57.87], ['course', 57.87, 58.39], ['Sir', 58.39, 58.63], ['we', 58.63, 58.77], ['love', 58.77, 59.2], ['to', 59.2, 59.3], ['hear', 59.3, 59.53], ['that', 59.53, 59.88], ['thank', 60.05, 60.35], ['you', 60.35, 60.47], ['again', 60.47, 60.85], ['for', 60.85, 61.01], ['your', 61.01, 61.15], ['business', 61.15, 61.87]], 'confidence': 0.92, 'transcript': "yes Sir what can I do for you I'm in love with this calamari please just give my regards the shaft of course Sir we love to hear that thank you again for your business "}], 'final': True}], 'result_index': 0, 'speaker_labels': [{'from': 0.09, 'to': 0.16, 'speaker': 0, 'confidence': 0.413, 'final': False}, {'from': 0.16, 'to': 0.48, 'speaker': 0, 'confidence': 0.413, 'final': False}, {'from': 0.48, 'to': 0.67, 'speaker': 0, 'confidence': 0.413, 'final': False}, {'from': 0.67, 'to': 0.96, 'speaker': 0, 'confidence': 0.413, 'final': False}, {'from': 0.96, 'to': 1.45, 'speaker': 0, 'confidence': 0.413, 'final': False}, {'from': 1.45, 'to': 1.74, 'speaker': 0, 'confidence': 0.413, 'final': False}, {'from': 1.74, 'to': 1.87, 'speaker': 0, 'confidence': 0.413, 'final': False}, {'from': 1.87, 'to': 2.1, 'speaker': 0, 'confidence': 0.413, 'final': False}, {'from': 2.1, 'to': 2.44, 'speaker': 0, 'confidence': 0.413, 'final': False}, {'from': 2.44, 'to': 2.72, 'speaker': 0, 'confidence': 0.413, 'final': False}, {'from': 2.72, 'to': 3.05, 'speaker': 0, 'confidence': 0.413, 'final': False}, {'from': 3.29, 'to': 3.55, 'speaker': 0, 'confidence': 0.448, 'final': False}, {'from': 3.55, 'to': 3.72, 'speaker': 0, 'confidence': 0.448, 'final': False}, {'from': 3.72, 'to': 3.89, 'speaker': 0, 'confidence': 0.448, 'final': False}, {'from': 3.89, 'to': 4.02, 'speaker': 0, 'confidence': 0.448, 'final': False}, {'from': 4.02, 'to': 4.24, 'speaker': 0, 'confidence': 0.448, 'final': False}, {'from': 4.24, 'to': 4.36, 'speaker': 0, 'confidence': 0.448, 'final': False}, {'from': 4.36, 'to': 4.4, 'speaker': 0, 'confidence': 0.448, 'final': False}, {'from': 4.4, 'to': 4.77, 'speaker': 0, 'confidence': 0.448, 'final': False}, {'from': 4.77, 'to': 5.04, 'speaker': 0, 'confidence': 0.448, 'final': False}, {'from': 5.09, 'to': 5.47, 'speaker': 1, 'confidence': 0.527, 'final': False}, {'from': 5.47, 'to': 5.62, 'speaker': 1, 'confidence': 0.527, 'final': False}, {'from': 5.62, 'to': 5.9, 'speaker': 1, 'confidence': 0.527, 'final': False}, {'from': 5.9, 'to': 6.12, 'speaker': 1, 'confidence': 0.527, 'final': False}, {'from': 6.62, 'to': 6.89, 'speaker': 0, 'confidence': 0.561, 'final': False}, {'from': 6.89, 'to': 7.23, 'speaker': 0, 'confidence': 0.561, 'final': False}, {'from': 7.23, 'to': 7.95, 'speaker': 0, 'confidence': 0.561, 'final': False}, {'from': 7.98, 'to': 8.14, 'speaker': 0, 'confidence': 0.501, 'final': False}, {'from': 8.14, 'to': 8.36, 'speaker': 0, 'confidence': 0.501, 'final': False}, {'from': 8.36, 'to': 8.72, 'speaker': 0, 'confidence': 0.501, 'final': False}, {'from': 8.72, 'to': 8.99, 'speaker': 0, 'confidence': 0.501, 'final': False}, {'from': 8.99, 'to': 9.5, 'speaker': 0, 'confidence': 0.501, 'final': False}, {'from': 10.34, 'to': 11.06, 'speaker': 1, 'confidence': 0.381, 'final': False}, {'from': 12.3, 'to': 12.81, 'speaker': 1, 'confidence': 0.462, 'final': False}, {'from': 13.34, 'to': 13.78, 'speaker': 1, 'confidence': 0.448, 'final': False}, {'from': 14.42, 'to': 14.73, 'speaker': 0, 'confidence': 0.369, 'final': False}, {'from': 14.73, 'to': 15.12, 'speaker': 0, 'confidence': 0.369, 'final': False}, {'from': 15.12, 'to': 15.21, 'speaker': 0, 'confidence': 0.369, 'final': False}, {'from': 15.21, 'to': 15.86, 'speaker': 0, 'confidence': 0.369, 'final': False}, {'from': 15.86, 'to': 16.24, 'speaker': 0, 'confidence': 0.369, 'final': False}, {'from': 17.56, 'to': 17.97, 'speaker': 1, 'confidence': 0.424, 'final': False}, {'from': 18.01, 'to': 18.36, 'speaker': 0, 'confidence': 0.623, 'final': False}, {'from': 18.36, 'to': 18.55, 'speaker': 0, 'confidence': 0.623, 'final': False}, {'from': 18.55, 'to': 18.78, 'speaker': 0, 'confidence': 0.623, 'final': False}, {'from': 18.78, 'to': 18.92, 'speaker': 0, 'confidence': 0.623, 'final': False}, {'from': 18.92, 'to': 19.53, 'speaker': 0, 'confidence': 0.623, 'final': False}, {'from': 19.56, 'to': 19.82, 'speaker': 0, 'confidence': 0.614, 'final': False}, {'from': 19.82, 'to': 20.03, 'speaker': 0, 'confidence': 0.614, 'final': False}, {'from': 20.48, 'to': 21.02, 'speaker': 1, 'confidence': 0.446, 'final': False}, {'from': 21.17, 'to': 21.33, 'speaker': 1, 'confidence': 0.458, 'final': False}, {'from': 21.33, 'to': 21.46, 'speaker': 1, 'confidence': 0.458, 'final': False}, {'from': 21.46, 'to': 21.71, 'speaker': 1, 'confidence': 0.458, 'final': False}, {'from': 21.71, 'to': 21.92, 'speaker': 1, 'confidence': 0.458, 'final': False}, {'from': 21.92, 'to': 22.16, 'speaker': 1, 'confidence': 0.458, 'final': False}, {'from': 22.37, 'to': 23.12, 'speaker': 1, 'confidence': 0.563, 'final': False}, {'from': 23.15, 'to': 23.37, 'speaker': 1, 'confidence': 0.612, 'final': False}, {'from': 23.37, 'to': 23.73, 'speaker': 1, 'confidence': 0.612, 'final': False}, {'from': 23.73, 'to': 24.01, 'speaker': 1, 'confidence': 0.612, 'final': False}, {'from': 24.01, 'to': 24.15, 'speaker': 1, 'confidence': 0.612, 'final': False}, {'from': 24.15, 'to': 24.59, 'speaker': 1, 'confidence': 0.612, 'final': False}, {'from': 24.59, 'to': 25.13, 'speaker': 1, 'confidence': 0.612, 'final': False}, {'from': 25.19, 'to': 25.51, 'speaker': 1, 'confidence': 0.568, 'final': False}, {'from': 25.59, 'to': 25.82, 'speaker': 1, 'confidence': 0.526, 'final': False}, {'from': 25.82, 'to': 26.15, 'speaker': 1, 'confidence': 0.526, 'final': False}, {'from': 26.18, 'to': 26.58, 'speaker': 1, 'confidence': 0.482, 'final': False}, {'from': 26.58, 'to': 26.97, 'speaker': 1, 'confidence': 0.482, 'final': False}, {'from': 27.0, 'to': 27.15, 'speaker': 1, 'confidence': 0.508, 'final': False}, {'from': 27.15, 'to': 27.37, 'speaker': 1, 'confidence': 0.508, 'final': False}, {'from': 27.53, 'to': 27.81, 'speaker': 1, 'confidence': 0.457, 'final': False}, {'from': 27.97, 'to': 28.73, 'speaker': 1, 'confidence': 0.466, 'final': False}, {'from': 28.85, 'to': 29.08, 'speaker': 1, 'confidence': 0.525, 'final': False}, {'from': 29.08, 'to': 29.54, 'speaker': 1, 'confidence': 0.525, 'final': False}, {'from': 29.54, 'to': 29.73, 'speaker': 1, 'confidence': 0.525, 'final': False}, {'from': 29.73, 'to': 30.04, 'speaker': 1, 'confidence': 0.525, 'final': False}, {'from': 30.04, 'to': 30.17, 'speaker': 1, 'confidence': 0.525, 'final': False}, {'from': 30.17, 'to': 30.47, 'speaker': 1, 'confidence': 0.525, 'final': False}, {'from': 31.31, 'to': 31.39, 'speaker': 1, 'confidence': 0.461, 'final': False}, {'from': 31.39, 'to': 31.77, 'speaker': 1, 'confidence': 0.461, 'final': False}, {'from': 31.77, 'to': 32.03, 'speaker': 1, 'confidence': 0.461, 'final': False}, {'from': 32.09, 'to': 32.93, 'speaker': 1, 'confidence': 0.616, 'final': False}, {'from': 33.19, 'to': 33.37, 'speaker': 1, 'confidence': 0.526, 'final': False}, {'from': 33.37, 'to': 33.81, 'speaker': 1, 'confidence': 0.526, 'final': False}, {'from': 33.88, 'to': 34.17, 'speaker': 1, 'confidence': 0.502, 'final': False}, {'from': 34.17, 'to': 34.52, 'speaker': 1, 'confidence': 0.502, 'final': False}, {'from': 34.52, 'to': 34.98, 'speaker': 1, 'confidence': 0.502, 'final': False}, {'from': 35.01, 'to': 35.46, 'speaker': 1, 'confidence': 0.609, 'final': False}, {'from': 35.46, 'to': 35.81, 'speaker': 1, 'confidence': 0.609, 'final': False}, {'from': 35.81, 'to': 35.97, 'speaker': 1, 'confidence': 0.609, 'final': False}, {'from': 35.97, 'to': 36.08, 'speaker': 1, 'confidence': 0.609, 'final': False}, {'from': 36.08, 'to': 36.17, 'speaker': 1, 'confidence': 0.609, 'final': False}, {'from': 36.17, 'to': 36.38, 'speaker': 1, 'confidence': 0.609, 'final': False}, {'from': 36.38, 'to': 36.51, 'speaker': 1, 'confidence': 0.609, 'final': False}, {'from': 36.51, 'to': 36.63, 'speaker': 1, 'confidence': 0.609, 'final': False}, {'from': 36.63, 'to': 36.87, 'speaker': 1, 'confidence': 0.609, 'final': False}, {'from': 36.87, 'to': 37.11, 'speaker': 1, 'confidence': 0.609, 'final': False}, {'from': 37.25, 'to': 37.86, 'speaker': 1, 'confidence': 0.466, 'final': False}, {'from': 37.89, 'to': 38.35, 'speaker': 1, 'confidence': 0.577, 'final': False}, {'from': 38.35, 'to': 38.73, 'speaker': 1, 'confidence': 0.577, 'final': False}, {'from': 39.13, 'to': 39.27, 'speaker': 1, 'confidence': 0.517, 'final': False}, {'from': 39.27, 'to': 39.49, 'speaker': 1, 'confidence': 0.517, 'final': False}, {'from': 39.8, 'to': 40.33, 'speaker': 1, 'confidence': 0.56, 'final': False}, {'from': 40.33, 'to': 40.47, 'speaker': 1, 'confidence': 0.56, 'final': False}, {'from': 40.47, 'to': 40.91, 'speaker': 1, 'confidence': 0.56, 'final': False}, {'from': 40.91, 'to': 41.05, 'speaker': 1, 'confidence': 0.56, 'final': False}, {'from': 41.05, 'to': 41.61, 'speaker': 1, 'confidence': 0.56, 'final': False}, {'from': 42.03, 'to': 42.39, 'speaker': 0, 'confidence': 0.542, 'final': False}, {'from': 42.39, 'to': 42.8, 'speaker': 0, 'confidence': 0.542, 'final': False}, {'from': 42.83, 'to': 43.2, 'speaker': 0, 'confidence': 0.441, 'final': False}, {'from': 43.26, 'to': 43.37, 'speaker': 0, 'confidence': 0.629, 'final': False}, {'from': 43.37, 'to': 43.85, 'speaker': 0, 'confidence': 0.629, 'final': False}, {'from': 43.88, 'to': 44.12, 'speaker': 0, 'confidence': 0.627, 'final': False}, {'from': 44.12, 'to': 44.24, 'speaker': 0, 'confidence': 0.627, 'final': False}, {'from': 44.24, 'to': 44.4, 'speaker': 0, 'confidence': 0.627, 'final': False}, {'from': 44.4, 'to': 44.63, 'speaker': 0, 'confidence': 0.627, 'final': False}, {'from': 44.63, 'to': 44.84, 'speaker': 0, 'confidence': 0.627, 'final': False}, {'from': 44.84, 'to': 45.26, 'speaker': 0, 'confidence': 0.627, 'final': False}, {'from': 45.26, 'to': 45.51, 'speaker': 0, 'confidence': 0.627, 'final': False}, {'from': 45.54, 'to': 46.17, 'speaker': 0, 'confidence': 0.585, 'final': False}, {'from': 46.17, 'to': 47.03, 'speaker': 0, 'confidence': 0.585, 'final': False}, {'from': 47.35, 'to': 47.62, 'speaker': 0, 'confidence': 0.622, 'final': False}, {'from': 47.62, 'to': 47.72, 'speaker': 0, 'confidence': 0.622, 'final': False}, {'from': 47.72, 'to': 47.92, 'speaker': 0, 'confidence': 0.622, 'final': False}, {'from': 47.92, 'to': 47.97, 'speaker': 0, 'confidence': 0.622, 'final': False}, {'from': 47.97, 'to': 48.09, 'speaker': 0, 'confidence': 0.622, 'final': False}, {'from': 48.09, 'to': 48.16, 'speaker': 0, 'confidence': 0.622, 'final': False}, {'from': 48.16, 'to': 48.26, 'speaker': 0, 'confidence': 0.622, 'final': False}, {'from': 48.26, 'to': 48.71, 'speaker': 0, 'confidence': 0.622, 'final': False}, {'from': 48.71, 'to': 48.77, 'speaker': 0, 'confidence': 0.622, 'final': False}, {'from': 48.77, 'to': 49.21, 'speaker': 0, 'confidence': 0.622, 'final': False}, {'from': 49.9, 'to': 50.04, 'speaker': 0, 'confidence': 0.5, 'final': False}, {'from': 50.04, 'to': 50.5, 'speaker': 0, 'confidence': 0.5, 'final': False}, {'from': 50.77, 'to': 51.21, 'speaker': 0, 'confidence': 0.532, 'final': False}, {'from': 51.8, 'to': 52.04, 'speaker': 0, 'confidence': 0.502, 'final': False}, {'from': 52.04, 'to': 52.25, 'speaker': 0, 'confidence': 0.502, 'final': False}, {'from': 52.25, 'to': 52.39, 'speaker': 0, 'confidence': 0.502, 'final': False}, {'from': 52.39, 'to': 52.51, 'speaker': 0, 'confidence': 0.502, 'final': False}, {'from': 52.51, 'to': 52.55, 'speaker': 0, 'confidence': 0.502, 'final': False}, {'from': 52.55, 'to': 52.7, 'speaker': 0, 'confidence': 0.502, 'final': False}, {'from': 52.7, 'to': 52.85, 'speaker': 0, 'confidence': 0.502, 'final': False}, {'from': 52.85, 'to': 53.08, 'speaker': 0, 'confidence': 0.502, 'final': False}, {'from': 53.44, 'to': 53.95, 'speaker': 0, 'confidence': 0.576, 'final': False}, {'from': 53.98, 'to': 54.16, 'speaker': 0, 'confidence': 0.636, 'final': False}, {'from': 54.16, 'to': 54.56, 'speaker': 0, 'confidence': 0.636, 'final': False}, {'from': 54.56, 'to': 54.68, 'speaker': 0, 'confidence': 0.636, 'final': False}, {'from': 54.68, 'to': 54.82, 'speaker': 0, 'confidence': 0.636, 'final': False}, {'from': 54.82, 'to': 55.4, 'speaker': 0, 'confidence': 0.636, 'final': False}, {'from': 55.4, 'to': 55.7, 'speaker': 0, 'confidence': 0.636, 'final': False}, {'from': 55.7, 'to': 55.96, 'speaker': 0, 'confidence': 0.636, 'final': False}, {'from': 56.21, 'to': 56.39, 'speaker': 0, 'confidence': 0.639, 'final': False}, {'from': 56.39, 'to': 56.5, 'speaker': 0, 'confidence': 0.639, 'final': False}, {'from': 56.5, 'to': 56.92, 'speaker': 0, 'confidence': 0.639, 'final': False}, {'from': 56.92, 'to': 57.03, 'speaker': 0, 'confidence': 0.639, 'final': False}, {'from': 57.03, 'to': 57.38, 'speaker': 0, 'confidence': 0.639, 'final': False}, {'from': 57.67, 'to': 57.87, 'speaker': 0, 'confidence': 0.631, 'final': False}, {'from': 57.87, 'to': 58.39, 'speaker': 0, 'confidence': 0.631, 'final': False}, {'from': 58.39, 'to': 58.63, 'speaker': 0, 'confidence': 0.631, 'final': False}, {'from': 58.63, 'to': 58.77, 'speaker': 0, 'confidence': 0.631, 'final': False}, {'from': 58.77, 'to': 59.2, 'speaker': 0, 'confidence': 0.631, 'final': False}, {'from': 59.2, 'to': 59.3, 'speaker': 0, 'confidence': 0.631, 'final': False}, {'from': 59.3, 'to': 59.53, 'speaker': 0, 'confidence': 0.631, 'final': False}, {'from': 59.53, 'to': 59.88, 'speaker': 0, 'confidence': 0.631, 'final': False}, {'from': 60.05, 'to': 60.35, 'speaker': 0, 'confidence': 0.581, 'final': False}, {'from': 60.35, 'to': 60.47, 'speaker': 0, 'confidence': 0.581, 'final': False}, {'from': 60.47, 'to': 60.85, 'speaker': 0, 'confidence': 0.581, 'final': False}, {'from': 60.85, 'to': 61.01, 'speaker': 0, 'confidence': 0.581, 'final': False}, {'from': 61.01, 'to': 61.15, 'speaker': 0, 'confidence': 0.581, 'final': False}, {'from': 61.15, 'to': 61.87, 'speaker': 0, 'confidence': 0.581, 'final': True}]}

Я хочу преобразовать его в удобный формат и с трудом.

Идеальным форматом будет группировка и объединение временных меток слов по динамику и перечисление метки динамика, минимальное значение от и максимальное значение до.Создание списка предложений ораторов.Аналогично ниже:

Пример таблицы

Любая помощь будет принята с благодарностью.

Ответы [ 2 ]

0 голосов
/ 06 июня 2018

Как ответил Кулкарни, для достижения желаемого результата вам придется использовать фрейм данных panda.Вы можете обратиться к примеру кода ниже.Для вашего удобства я использовал записную книжку в watson studio, чтобы добиться этого, импортировав ваш json и используя panda, чтобы придать ему желаемую структуру данных.

 import json
    import pandas as pd
    from botocore.client import Config
    import ibm_boto3


    # @hidden_cell
    # The following code contains the credentials for a file in your IBM Cloud Object Storage.
    # You might want to remove those credentials before you share your notebook.
    credentials_1 = {
        'IBM_API_KEY_ID': 'AsauselesssajHY_zsdfQxDc-gsss8M-gxcxw_2asd',
        'IAM_SERVICE_ID': 'iam-ServiceId-fenotnf6-3dsd-4125-3116-5f131119d',
        'ENDPOINT': 'https://s3-api.us-geo.objectstorage.service.networklayer.com',
        'IBM_AUTH_ENDPOINT': 'https://iam.ng.bluemix.net/oidc/token',
        'BUCKET': 'asd1231sdsd-donotdelete-pr-4ecvinl7uiurbu',
        'FILE': 'samplejson02.json'
    }
sampleTextFileName = "samplejson02.json"

cos = ibm_boto3.client('s3',
                    ibm_api_key_id=credentials_1['IBM_API_KEY_ID'],
                    ibm_service_instance_id=credentials_1['IAM_SERVICE_ID'],
                    ibm_auth_endpoint=credentials_1['IBM_AUTH_ENDPOINT'],
                    config=Config(signature_version='oauth'),
                    endpoint_url=credentials_1['ENDPOINT'])

def get_file(filename):
    fileobject = cos.get_object(Bucket=credentials_1['BUCKET'], Key=filename)['Body']
    return fileobject

def load_string(fileobject):
    text = fileobject.read()
    return text.decode('utf-8')

Вставьте следующую часть в ваш код.

sampletext = load_string(get_file(sampleTextFileName))
jsontext = json.loads(sampletext);
df=pd.DataFrame(jsontext['results'][0]['alternatives'][0]['timestamps'])
print(df)

Ожидаемый результат:

cross_reference_image

Чтобы получить нужный вложенный результат, попробуйте следующий бит кода.

df1 = pd.DataFrame()
for result in jsontext['results']:
    for alternative in result['alternatives']:
        for timestamp in alternative['timestamps']:
            for speaker_label in jsontext['speaker_labels']:
                if(timestamp[1]==speaker_label.get('from') and timestamp[2]==speaker_label.get('to')):
                    frame = [timestamp[0],timestamp[1],timestamp[2],speaker_label.get('speaker')]
                    df=pd.DataFrame(frame)
                    df1=df1.append(df.transpose())
print(df1)

Логика, которую я собрал, перебирает каждую метку, а затем, для каждого соответствующего «от» и «к», создает новый фрейм, который будет объединен в уже инициализированном объекте фрейма данных «df1».

Ожидаемый результат будет:

cross_reference_image_02

GL!

0 голосов
/ 06 июня 2018

Вы можете использовать этот json и создать Pandas dataframe.Он имеет методы для группировки, агрегирования и сортировки данных в соответствии с вашими потребностями.

...