Javascript 将文档中的单词数组及其坐标转换为句子
我在文档中有一组单词及其坐标,我想把它们变成句子。 我的数组输入:Javascript 将文档中的单词数组及其坐标转换为句子,javascript,algorithm,machine-learning,ocr,document,Javascript,Algorithm,Machine Learning,Ocr,Document,我在文档中有一组单词及其坐标,我想把它们变成句子。 我的数组输入: [ { "bounds": [ { "x": 10, "y": 10 }, { "x": 15, "y": 10 }, { "x": 15, "y": 15
[
{
"bounds": [
{
"x": 10,
"y": 10
},
{
"x": 15,
"y": 10
},
{
"x": 15,
"y": 15
},
{
"x": 10,
"y": 15
}
],
"desc": "Hey"
},
{
"bounds": [
{
"x": 18,
"y": 10
},
{
"x": 24,
"y": 10
},
{
"x": 24,
"y": 15
},
{
"x": 18,
"y": 15
}
],
"desc": "Name"
},
{
"bounds": [
{
"x": 18,
"y": 20
},
{
"x": 24,
"y": 20
},
{
"x": 24,
"y": 25
},
{
"x": 18,
"y": 25
}
],
"desc": "What"
},
{
"bounds": [
{
"x": 18,
"y": 20
},
{
"x": 24,
"y": 20
},
{
"x": 24,
"y": 25
},
{
"x": 18,
"y": 25
}
],
"desc": "Sup"
}
]
程序输出应为:
Hey Name
What Sup
坐标不准确,只是一个例子,算法也需要处理句子中间的单词和其他极端情况。
理想情况下使用JavaScript实现的最佳方式是什么?您可以使用哈希表,对行和位置进行排序,然后按此顺序返回文本 {x:15,y:15},{x:15,y:15,y:15},{x:15,y:15},{x:15,y:10,y:15},{x:10,y:10,y:10,y:10,y:10,y:10},{{边界:{{{边界:{{0:10,0:10,10,10,10:{0:{{x:10:10,10,10:10,10,10,{{边界:{学校:{{0:10:{0:10,10,10,10,10:{{0:10,{{x:10:10:10:10,10,10,10,10,10,10,10,10,10,10,y:10,10,10,y:10,y:10,y:10,y:10,y:10,y:10,y:10,y:10,y{x:18,y:20},{x:24,y:20},{x:24,y:25},{x:18,y:25}],desc:Sup}, 哈希={}, 后果 data.foreacha函数{ hash[a.bounds[0].y]=hash[a.bounds[0].y]|{}; hash[a.bounds[0].y][a.bounds[0].x]=hash[a.bounds[0].y][a.bounds[0].x]|; hash[a.bounds[0].y][a.bounds[0].x].push{desc:a.desc,end:a.bounds[2]}; }; 结果=Object.keyshash .sorta,b=>a-b .mapk=>Object.keyshash[k] .sorta,b=>a-b .reducer,l=>[…r,…散列[k][l].mapc=>c.desc],] .加入“ 。加入“\n”; console.logresult; console.loghash;
.作为控制台包装器{max height:100%!important;top:0;}请解释您希望如何实现此目标。用机器学习或算法标记这个问题并不能解释你想做什么。@MichaelHirschler我正在寻找最好的方法…@gal这对问题毫无意义。这是怎么一回事?你想把一系列单词变成句子。阵列的结构是什么?你想造出什么样的句子?@victor很抱歉搞混了。。数组在问题内容和输出中,我想根据单词位置而不是其含义创建句子。我有一个OCR模型来查找单词的位置,但我不知道如何将它们与句子连接起来!