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 4
5 -/** 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 +}
15 +
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 );
16 - try { 27 +
17 - clientData = req.body.data; 28 + try {
18 - if( !clientData.text.replace( /\s/g, '' ).length ) { 29 + clientData = req.body.data;
19 - throw new Error( "client text empty" ); 30 + //clientData = req.body.data;
20 - } 31 + if( !clientData.text.replace( /\s/g, '' ).length ) {
21 - } 32 + throw new Error( "client text empty" );
22 - catch ( err ) { 33 + }
23 - console.log( err ); 34 + }
24 - res.json( { "return_code" : -1, "error_code" : err.message } ); 35 + catch ( err ) {
25 - res.status( 403 ); 36 + console.log( err );
26 - return false; 37 + res.json( { "return_code" : -1, "error_code" : err.message } );
27 - } 38 + res.status( 403 );
28 - 39 + return false;
29 - // analyzeData 40 + }
30 - try { 41 +
31 - analyzeData = await textAnalytic( clientData ); 42 + try {
32 - } 43 + analyzeData = await textAnalytic( clientData );
33 - catch ( err ) { 44 + }
34 - console.log( err ); 45 + catch ( err ) {
35 - res.json( { "return_code" : -1, "error_code" : err.message } ); 46 + console.log( err );
36 - res.status( 502 ); 47 + res.json( { "return_code" : -1, "error_code" : err.message } );
37 - return false; 48 + res.status( 502 );
38 - } 49 + return false;
39 - 50 + }
40 - // searchData 51 +
41 - searchData = searchData[ 0 ].concat( searchData[ 1 ] ); 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 +
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 );
44 } 65 }
...@@ -49,9 +70,11 @@ const cliConnection = async (req, res) => { ...@@ -49,9 +70,11 @@ const cliConnection = async (req, res) => {
49 return false; 70 return false;
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 );
55 -}; 76 + clearTimeout(timer);
77 + return true;
78 +};
56 79
57 -module.exports = cliConnection;
...\ No newline at end of file ...\ No newline at end of file
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++) 10 + try {
11 - { 11 + await apiRequest.multiRequest(searchResults,keywordText);
12 - try { 12 + }
13 - await apiRequest.DOCVECAPI(searchResults,keywordText,i); 13 + catch ( err ) {
14 - } 14 + throw new Error( err.message );
15 - catch ( err ) {
16 - throw new Error( err.message );
17 - }
18 } 15 }
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)
......