Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김서영
/
searchGuide
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
bluejoyq
2019-12-05 23:01:33 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2f0131200cdb2d6a58f6887c64fec691761278fb
2f013120
1 parent
c1495cd3
finish backend server
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
55 deletions
api/apiRequest.js
api/cliConnection.js
api/machineRead.js
model/app.py
api/apiRequest.js
View file @
2f01312
...
...
@@ -77,11 +77,11 @@ apiRequest.Korean = async ( text ) => {
});
}
apiRequest
.
multi
ETRI
=
async
(
searchResults
,
keywordText
)
=>
{
apiRequest
.
multi
Request
=
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
(
);
});
});
};
...
...
api/cliConnection.js
View file @
2f01312
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
;
...
...
api/machineRead.js
View file @
2f01312
...
...
@@ -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
.
multi
ETRI
(
divideSearchResult
,
keywordText
);
await
apiRequest
.
multi
Request
(
divideSearchResult
,
keywordText
);
}
catch
(
err
)
{
throw
new
Error
(
err
.
message
);
...
...
model/app.py
View file @
2f01312
...
...
@@ -40,4 +40,4 @@ def parsetoken(sentence):
if
__name__
==
"__main__"
:
app
.
run
()
app
.
run
(
host
=
'0.0.0.0'
,
port
=
5000
,
debug
=
True
)
...
...
Please
register
or
login
to post a comment