machineRead.js
1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const apiRequest = require('./apiRequest');
/**
* @param {{url:string,title:string,passage:string}[]} searchResults 검색 결과 정리한것.
* @param {string} keywordText 기계독해 시킬 질문의 텍스트
* @returns {{url:string,title:string,passage:string,confidence:number}[]} searchResults의 각 object에 confidence 속성을 추가해 돌려준다.
* @description 기계독해를 사용하는 함수
*/
const machineRead = async ( searchResults, keywordText ) => {
try {
await apiRequest.multiRequest(searchResults,keywordText);
}
catch ( err ) {
throw new Error( err.message );
}
return searchResults;
}
const oldMachineRead = async (searchResults,keywordText)=>{
let keyNum = 6,
ResultArray = [],
divideSearchResults = [];
for( let i = 0; i <= searchResults.length; i += keyNum ) {
divideSearchResults.push( searchResults.slice( i, i + keyNum ) );
}
for( let divideSearchResult of divideSearchResults ) {
try{
await apiRequest.multiRequest( divideSearchResult, keywordText );
}
catch ( err ) {
throw new Error( err.message );
}
ResultArray = ResultArray.concat( divideSearchResult );
}
searchResults = ResultArray;
return searchResults;
}
module.exports = machineRead;