【发布时间】:2021-11-03 07:10:54
【问题描述】:
您好,我正在尝试使用以下文本示例创建具有某些功能的令牌并以某种 JSON 格式排列它们:
words = ['The study of aviation safety report in the aviation industry usually relies',
'The experimental results show that compared with traditional',
'Heterogeneous Aviation Safety Cases: Integrating the Formal and the Non-formal']
{"sentence": [
{
indexSentence:0,
tokens: [{
"indexWord": 1,
"word": "The",
"len": 3
},
{ "indexWord": 2,
"word": "study",
"len": 5},
{"indexWord": 3,
"word": "of",
"len": 2
},
{"indexWord": 4,
"word": "aviation",
"len": 8},
...
]
},
{
"indexSentence" : 1,
"tokens" : [{
...
}]
},
....
]}
我尝试使用以下代码但没有成功...
t_d = {len(i):i for i in words}
[{'Lon' : len(t_d[i]),
'tex' : t_d[i],
'Sub' : [{'index' : j,
'token': [{
'word':['word: ' + j for i,j in enumerate(str(t_d[i]).split(' '))]
}],
'lenTo' : len(str(t_d[i]).split(' '))
}
],
'Sub1':[{'index' : j}]
} for j,i in enumerate(t_d)]
【问题讨论】:
标签: python json dictionary nlp token