bluejoyq

finish backend server

......@@ -77,11 +77,11 @@ apiRequest.Korean = async ( text ) => {
});
}
apiRequest.multiETRI = async ( searchResults, keywordText ) => {
apiRequest.multiRequest = async ( searchResults, keywordText ) => {
try {
const Promises = await searchResults.map((searchResult, index)=>{
//return makeOption( searchResults, keywordText, index );
return DOCVECAPI( searchResults, keywordText, index );
return apiRequest.DOCVECAPI( searchResults, keywordText, index );
});
await Promise.all( Promises );
}
......@@ -119,7 +119,7 @@ apiRequest.DOCVECAPI = (searchResults, keywordText, index) => {
})
.catch(err => {
searchResults[index].confidence = 0;
throw new Error(err);
resolve();
});
});
};
......
const textAnalytic = require("./textAnalystic");
const search = require("./search");
const machineRead = require("./machineRead");
const textAnalytic=require('./textAnalystic');
const search=require('./search');
const machineRead = require('./machineRead');
/**
let timer = ( ) => {
try {
throw new Error( "TIMEOUT ERROR" );
} catch ( err ) {
res.json( { "return_code" : -1, "error_code" : err.message } );
res.status( 504 ); //Gateway Timeout
return false;
}
}
/**
* @param req - request
* @param req.body.data - client에서 보내는 데이터 req.body.data.text에 검색할 문장을 담아야 합니다
* @description client와 데이터를 받아 통신하는 함수입니다
*/
const cliConnection = async (req, res) => {
let clientData = {},
analyzeData = {},
searchData = [];
// clientData
try {
clientData = req.body.data;
if( !clientData.text.replace( /\s/g, '' ).length ) {
throw new Error( "client text empty" );
}
}
catch ( err ) {
console.log( err );
res.json( { "return_code" : -1, "error_code" : err.message } );
res.status( 403 );
return false;
}
// analyzeData
try {
analyzeData = await textAnalytic( clientData );
}
catch ( err ) {
console.log( err );
res.json( { "return_code" : -1, "error_code" : err.message } );
res.status( 502 );
return false;
}
// searchData
searchData = searchData[ 0 ].concat( searchData[ 1 ] );
*/
const cliConnection = async ( req, res ) => {
let clientData = {},
analyzeData = {},
searchData = [];
setTimeout(timer , 10000 );
try {
clientData = req.body.data;
//clientData = req.body.data;
if( !clientData.text.replace( /\s/g, '' ).length ) {
throw new Error( "client text empty" );
}
}
catch ( err ) {
console.log( err );
res.json( { "return_code" : -1, "error_code" : err.message } );
res.status( 403 );
return false;
}
try {
analyzeData = await textAnalytic( clientData );
}
catch ( err ) {
console.log( err );
res.json( { "return_code" : -1, "error_code" : err.message } );
res.status( 502 );
return false;
}
try {
searchData = await Promise.all( [ search.naver( analyzeData.keywordText ), search.google( analyzeData.keywordText ) ] );
}
catch ( err ) {
console.log( err );
res.json( { "return_code" : -1, "error_code" : err.message } );
res.status( 503 );
return false;
}
searchData = searchData[ 0 ].concat( searchData[ 1 ] );
try {
searchData = await machineRead( searchData, analyzeData.keywordText );
}
......@@ -49,9 +70,11 @@ const cliConnection = async (req, res) => {
return false;
}
analyzeData.searchResults = searchData;
res.send({ return_code: 0, return_data: analyzeData });
res.status(200);
};
analyzeData.searchResults = searchData;
res.send( { "return_code" : 0, "return_data" : analyzeData } );
res.status( 200 );
clearTimeout(timer);
return true;
};
module.exports = cliConnection;
\ No newline at end of file
module.exports = cliConnection;
......
......@@ -7,15 +7,13 @@ const apiRequest = require('./apiRequest');
* @description 기계독해를 사용하는 함수
*/
const machineRead = async ( searchResults, keywordText ) => {
for(let i = 0; i < searchResults.length; i++)
{
try {
await apiRequest.DOCVECAPI(searchResults,keywordText,i);
}
catch ( err ) {
throw new Error( err.message );
}
try {
await apiRequest.multiRequest(searchResults,keywordText);
}
catch ( err ) {
throw new Error( err.message );
}
return searchResults;
}
......@@ -32,7 +30,7 @@ const oldMachineRead = async (searchResults,keywordText)=>{
for( let divideSearchResult of divideSearchResults ) {
try{
await apiRequest.multiETRI( divideSearchResult, keywordText );
await apiRequest.multiRequest( divideSearchResult, keywordText );
}
catch ( err ) {
throw new Error( err.message );
......
......@@ -40,4 +40,4 @@ def parsetoken(sentence):
if __name__ == "__main__":
app.run()
app.run(host='0.0.0.0', port=5000, debug=True)
......