const fsExtra = require('fs-extra')
const chromeLauncher = require('lighthouse/chrome-launcher/chrome-launcher');
const CDP = require('chrome-remote-interface');
const fs = require('fs');
const windowWidth = 6200;
const windowHeight = 6060;
headless=false
const launchConfig = {
chromeFlags: [
`--window-size=${windowWidth},${windowHeight}`,
'--disable-gpu',
headless ? '--headless' : ''
]
}
async function launchChrome(headless = true) {
return await chromeLauncher.launch(launchConfig);
}
const chrome = launchChrome();
console.log(chrome)
这4个元素是 (4) [{…}, {…}, {…}, {…}]
0: {entity: "lovely meeting", type: "Calendar.Subject", startIndex: 53, endIndex: 66, score: 0.9183444}
1: {entity: "california", type: "Calendar.Location", startIndex: 27, endIndex: 36, score: 0.922538459}
2: {entity: "today", type: "builtin.datetimeV2.date", startIndex: 18, endIndex: 22, resolution: {…}}
3: {entity: "4am", type: "builtin.datetimeV2.time", startIndex: 41, endIndex: 43, resolution: {…}}length: 4__proto__: Array(0)
的一部分,我想要的是检查类型是否等于让我们说Entities
并且值得注意的是我们并不总是有4个元素我们可以有一个或者没有,即使我们确实有4个实体类型Calender.Location
也不一定是索引号Calender.Location
,我试过的内容包括1
和testvar.entities.length
不知道每个testvar.entities[0].type
都不可能。
我想要的例子:
我想在实体中解析类型ID
的{{1}}输入,它可能存在且可能不存在且其确切ID未知(范围在0到4之间),如果我找到的话我应该返回与此相关联的实体Json
。
答案 0 :(得分:0)
const test =[
{entity: "lovely meeting", type: "Calendar.Subject", startIndex: 53, endIndex: 66, score: 0.9183444},
{entity: "california", type: "Calendar.Location", startIndex: 27, endIndex: 36, score: 0.922538459},
{entity: "today", type: "builtin.datetimeV2.date", startIndex: 18, endIndex: 22, resolution: {}},
{entity: "4am", type: "builtin.datetimeV2.time", startIndex: 41, endIndex: 43, resolution: {}}
]
const getentitiesByType = (arr,type) => {
for(let i in arr ){
if(arr[i].type === type){
return arr[i].entity;
}
}
};
console.log(getentitiesByType(test,"Calendar.Location"))