bluejoyq

finish backend server

...@@ -77,11 +77,11 @@ apiRequest.Korean = async ( text ) => { ...@@ -77,11 +77,11 @@ apiRequest.Korean = async ( text ) => {
77 }); 77 });
78 } 78 }
79 79
80 -apiRequest.multiETRI = async ( searchResults, keywordText ) => { 80 +apiRequest.multiRequest = async ( searchResults, keywordText ) => {
81 try { 81 try {
82 const Promises = await searchResults.map((searchResult, index)=>{ 82 const Promises = await searchResults.map((searchResult, index)=>{
83 //return makeOption( searchResults, keywordText, index ); 83 //return makeOption( searchResults, keywordText, index );
84 - return DOCVECAPI( searchResults, keywordText, index ); 84 + return apiRequest.DOCVECAPI( searchResults, keywordText, index );
85 }); 85 });
86 await Promise.all( Promises ); 86 await Promise.all( Promises );
87 } 87 }
...@@ -119,7 +119,7 @@ apiRequest.DOCVECAPI = (searchResults, keywordText, index) => { ...@@ -119,7 +119,7 @@ apiRequest.DOCVECAPI = (searchResults, keywordText, index) => {
119 }) 119 })
120 .catch(err => { 120 .catch(err => {
121 searchResults[index].confidence = 0; 121 searchResults[index].confidence = 0;
122 - throw new Error(err); 122 + resolve();
123 }); 123 });
124 }); 124 });
125 }; 125 };
......
1 -const textAnalytic = require("./textAnalystic"); 1 +const textAnalytic=require('./textAnalystic');
2 -const search = require("./search"); 2 +const search=require('./search');
3 -const machineRead = require("./machineRead"); 3 +const machineRead = require('./machineRead');
4 +
5 +
6 +let timer = ( ) => {
7 + try {
8 + throw new Error( "TIMEOUT ERROR" );
9 + } catch ( err ) {
10 + res.json( { "return_code" : -1, "error_code" : err.message } );
11 + res.status( 504 ); //Gateway Timeout
12 + return false;
13 + }
14 +}
4 15
5 /** 16 /**
6 * @param req - request 17 * @param req - request
7 * @param req.body.data - client에서 보내는 데이터 req.body.data.text에 검색할 문장을 담아야 합니다 18 * @param req.body.data - client에서 보내는 데이터 req.body.data.text에 검색할 문장을 담아야 합니다
8 * @description client와 데이터를 받아 통신하는 함수입니다 19 * @description client와 데이터를 받아 통신하는 함수입니다
9 - */ 20 +*/
10 -const cliConnection = async (req, res) => { 21 +const cliConnection = async ( req, res ) => {
11 let clientData = {}, 22 let clientData = {},
12 analyzeData = {}, 23 analyzeData = {},
13 searchData = []; 24 searchData = [];
14 25
15 - // clientData 26 + setTimeout(timer , 10000 );
27 +
16 try { 28 try {
17 clientData = req.body.data; 29 clientData = req.body.data;
30 + //clientData = req.body.data;
18 if( !clientData.text.replace( /\s/g, '' ).length ) { 31 if( !clientData.text.replace( /\s/g, '' ).length ) {
19 throw new Error( "client text empty" ); 32 throw new Error( "client text empty" );
20 } 33 }
...@@ -26,7 +39,6 @@ const cliConnection = async (req, res) => { ...@@ -26,7 +39,6 @@ const cliConnection = async (req, res) => {
26 return false; 39 return false;
27 } 40 }
28 41
29 - // analyzeData
30 try { 42 try {
31 analyzeData = await textAnalytic( clientData ); 43 analyzeData = await textAnalytic( clientData );
32 } 44 }
...@@ -37,7 +49,16 @@ const cliConnection = async (req, res) => { ...@@ -37,7 +49,16 @@ const cliConnection = async (req, res) => {
37 return false; 49 return false;
38 } 50 }
39 51
40 - // searchData 52 + try {
53 + searchData = await Promise.all( [ search.naver( analyzeData.keywordText ), search.google( analyzeData.keywordText ) ] );
54 + }
55 + catch ( err ) {
56 + console.log( err );
57 + res.json( { "return_code" : -1, "error_code" : err.message } );
58 + res.status( 503 );
59 + return false;
60 + }
61 +
41 searchData = searchData[ 0 ].concat( searchData[ 1 ] ); 62 searchData = searchData[ 0 ].concat( searchData[ 1 ] );
42 try { 63 try {
43 searchData = await machineRead( searchData, analyzeData.keywordText ); 64 searchData = await machineRead( searchData, analyzeData.keywordText );
...@@ -50,8 +71,10 @@ const cliConnection = async (req, res) => { ...@@ -50,8 +71,10 @@ const cliConnection = async (req, res) => {
50 } 71 }
51 72
52 analyzeData.searchResults = searchData; 73 analyzeData.searchResults = searchData;
53 - res.send({ return_code: 0, return_data: analyzeData }); 74 + res.send( { "return_code" : 0, "return_data" : analyzeData } );
54 - res.status(200); 75 + res.status( 200 );
76 + clearTimeout(timer);
77 + return true;
55 }; 78 };
56 79
57 module.exports = cliConnection; 80 module.exports = cliConnection;
......
...@@ -7,15 +7,13 @@ const apiRequest = require('./apiRequest'); ...@@ -7,15 +7,13 @@ const apiRequest = require('./apiRequest');
7 * @description 기계독해를 사용하는 함수 7 * @description 기계독해를 사용하는 함수
8 */ 8 */
9 const machineRead = async ( searchResults, keywordText ) => { 9 const machineRead = async ( searchResults, keywordText ) => {
10 - for(let i = 0; i < searchResults.length; i++)
11 - {
12 try { 10 try {
13 - await apiRequest.DOCVECAPI(searchResults,keywordText,i); 11 + await apiRequest.multiRequest(searchResults,keywordText);
14 } 12 }
15 catch ( err ) { 13 catch ( err ) {
16 throw new Error( err.message ); 14 throw new Error( err.message );
17 } 15 }
18 - } 16 +
19 return searchResults; 17 return searchResults;
20 } 18 }
21 19
...@@ -32,7 +30,7 @@ const oldMachineRead = async (searchResults,keywordText)=>{ ...@@ -32,7 +30,7 @@ const oldMachineRead = async (searchResults,keywordText)=>{
32 30
33 for( let divideSearchResult of divideSearchResults ) { 31 for( let divideSearchResult of divideSearchResults ) {
34 try{ 32 try{
35 - await apiRequest.multiETRI( divideSearchResult, keywordText ); 33 + await apiRequest.multiRequest( divideSearchResult, keywordText );
36 } 34 }
37 catch ( err ) { 35 catch ( err ) {
38 throw new Error( err.message ); 36 throw new Error( err.message );
......
...@@ -40,4 +40,4 @@ def parsetoken(sentence): ...@@ -40,4 +40,4 @@ def parsetoken(sentence):
40 40
41 41
42 if __name__ == "__main__": 42 if __name__ == "__main__":
43 - app.run() 43 + app.run(host='0.0.0.0', port=5000, debug=True)
......