Skip to content

Commit

Permalink
init apiserver
Browse files Browse the repository at this point in the history
  • Loading branch information
bluejoyq committed Sep 29, 2019
1 parent 11377cc commit 7a39023
Show file tree
Hide file tree
Showing 12 changed files with 940 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
temp
temp.js
*.env
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// IntelliSense를 사용하여 가능한 특성에 대해 알아보세요.
// 기존 특성에 대한 설명을 보려면 가리킵니다.
// 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요.
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "프로그램 시작",
"program": "${file}"
}
]
}
4 changes: 4 additions & 0 deletions api/STT.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const express = require('express');
const app = express();
const bodyParser=require('body-parser');
const busboy= require('busboy');
36 changes: 36 additions & 0 deletions api/apiConnect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require('dotenv').config();
const rp = require("request-promise");

const URL = "http://aiopen.etri.re.kr:8000/";
const requestJson = {
"request_id": "reserved field",
"access_key": process.env.API_KEY,
"argument": {
}
};

let apiConnect = {};

apiConnect.apiRequest=async(query,argument)=>{

return new Promise((resolve,reject)=>{
let reqJson = requestJson;
reqJson.argument = argument;

let option = {
uri: URL+query,
body: JSON.stringify(reqJson),
headers: {'Content-Type':'application/json; charset=UTF-8'}
}
rp.post(option)
.then((body)=>{
resolve(JSON.parse(body));
})
.catch((err)=>{
console.log("Http Request Error");
console.log(err.response.body);
});
});
}

module.exports = apiConnect;
23 changes: 23 additions & 0 deletions api/cliConnection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const express = require('express');
const app = express();
const bodyParser=require('body-parser');
const textAnalytic=require('./testAnalystic');

let cliConnection = {};

cliConnection.cliReq=(req,res)=>{ // 미완성 함수
let getData = JSON.parse(req.body.data);
if(getData.type == ("text")){
textAnalytic(getData)
.then()
}
};

//테스트용 지우지마
const run=async()=>{
let x = await textAnalytic({"text":"테스트용 문장입니다."});
console.log(x);
}

run();
module.exports=cliConnection;
4 changes: 4 additions & 0 deletions api/htmlHighlite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const express = require('express');
const app = express();
const bodyParser=require('body-parser');

4 changes: 4 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const express=require('express');
const router=express.Router();

module.exports=router;
4 changes: 4 additions & 0 deletions api/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const express = require('express');
const app = express();
const bodyParser=require('body-parser');

48 changes: 48 additions & 0 deletions api/testAnalystic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const apiConnect = require('./apiConnect');
const search = require('./search');

const apiRequest= apiConnect.apiRequest;

const wikiQA = "WikiQA";
const textMean = "WiseNLU";
const argumentWiki = {
"question":"" ,
"type":"hybridqa"// 걍 통합한걸로 했는데 수정
}
const argumnetMean = {
"analysis_code": "",
"text": ""
}

const mean=async(getData)=>{
return new Promise(async(resolve,reject)=>{

let tempMeanMorp = argumnetMean;
tempMeanMorp.analysis_code = "morp";
tempMeanMorp.text = getData.text;

let tempMeanSrl = argumnetMean;
tempMeanSrl.analysis_code = "srl";
tempMeanSrl.text =getData.text;

// 병렬처리 위해
let [morpResult,srlResult]=await Promise.all([apiRequest(textMean,tempMeanMorp),apiRequest(textMean,tempMeanSrl)]);

resolve({"morp":morpResult,"srl":srlResult});
});

};

const textAnalystic=(getData)=>{
return new Promise(async(resolve,reject)=>{
let tempWiki = argumentWiki;
tempWiki.question = getData.text;

let [wikiResult,etcResult]=await Promise.all([apiRequest(wikiQA,tempWiki),mean(getData)]); //원래 mean 다음에 then(search);

resolve({"wiki":wikiResult,"etc":etcResult});
});

}

module.exports = textAnalystic;
14 changes: 14 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const express = require('express');
const app = express();
const bodyParser=require('body-parser');
const fs= require('fs');
const morgan=require('morgan');

app.use(morgan('[:date[iso]] :method :status :url :response-time(ms) :user-agent'));
app.use(bodyParser.urlencoded({ extended: true }));

app.use('/api',require('./api'));

app.listen(3000,()=>{
console.log('Server On!');
});
Loading

0 comments on commit 7a39023

Please sign in to comment.