I have a array of javascript objects of indefinite size:
var arr = [
{
"Entities":
[
{
"BeginOffset": 28,
"EndOffset": 35,
"Score": 0.9945663213729858,
"Text": "Tunisie",
"Type": "LOCATION"
},
{
"BeginOffset": 60,
"EndOffset": 71,
"Score": 0.8412493228912354,
"Text": "Al HuffPost",
"Type": "PERSON"
},
{
"BeginOffset": 60,
"EndOffset": 71,
"Score": 0.9412493228912354,
"Text": "trump",
"Type": "PERSON"
}
],
"File": "article1.com"
},
{
"Entities":
[
{
"BeginOffset": 28,
"EndOffset": 35,
"Score": 0.9945663213729858,
"Text": "france",
"Type": "LOCATION"
},
{
"BeginOffset": 60,
"EndOffset": 71,
"Score": 0.7412493228912354,
"Text": "john locke",
"Type": "PERSON"
},
{
"BeginOffset": 60,
"EndOffset": 71,
"Score": 0.9412493228912354,
"Text": "sawyer",
"Type": "PERSON"
}
],
"File": "anotherarticle.com"
},
{
//and so on ...
}
]
How to transform it to a key/value Javascript object where each file gives an array of the Persons tied to it while this data and filtering only on type="person" and score > 0.8 and sorting inside the array the Persons by starting with the highest scores (when there are more than 1 PERSON for Entities).
For example, the example above should output:
var finalObject = {
"article1.com": ["trump", "Al HuffPost"],//tunisisa not here because entity is a LOCATION
"anotherarticle.com": ["sawyer"] //john locke not here because score <0.8
}
I tried reducing, mapping and filtering in all ways but always fail.