Showing
1 changed file
with
60 additions
and
5 deletions
... | @@ -3,7 +3,6 @@ var app = express(); | ... | @@ -3,7 +3,6 @@ var app = express(); |
3 | const line = require('@line/bot-sdk'); | 3 | const line = require('@line/bot-sdk'); |
4 | const config = require('./config'); | 4 | const config = require('./config'); |
5 | 5 | ||
6 | - | ||
7 | //papago api | 6 | //papago api |
8 | var request = require('request'); | 7 | var request = require('request'); |
9 | 8 | ||
... | @@ -11,9 +10,22 @@ var request = require('request'); | ... | @@ -11,9 +10,22 @@ var request = require('request'); |
11 | var translate_api_url = 'https://openapi.naver.com/v1/papago/n2mt'; | 10 | var translate_api_url = 'https://openapi.naver.com/v1/papago/n2mt'; |
12 | 11 | ||
13 | //언어감지 api_url | 12 | //언어감지 api_url |
14 | -var languagedetect_api_url = 'https://openapi.naver.com/v1/papago/detectLangs' | 13 | +var languagedetect_api_url = 'https://openapi.naver.com/v1/papago/detectLangs'; |
14 | + | ||
15 | +//eng grammar check | ||
16 | + | ||
17 | +var EnGrammarCheck_api_url = 'https://api.textgears.com/check.php'; | ||
15 | 18 | ||
19 | +import textgears from 'textgears'; | ||
16 | 20 | ||
21 | +textgears({ | ||
22 | + key: '9WUGcY6ZayYMphG7', | ||
23 | + text: prompt('Text'), | ||
24 | +}).then(res => { | ||
25 | + for (const error of res.errors) { | ||
26 | + console.log('Bad: %s. Better: %s', error.bad, error.better.join(', ')); | ||
27 | + } | ||
28 | +}); | ||
17 | 29 | ||
18 | // create LINE SDK client | 30 | // create LINE SDK client |
19 | const client = new line.Client(config.line_config); | 31 | const client = new line.Client(config.line_config); |
... | @@ -28,11 +40,54 @@ app.post('/webhook', line.middleware(config), (req, res) => { | ... | @@ -28,11 +40,54 @@ app.post('/webhook', line.middleware(config), (req, res) => { |
28 | .all(req.body.events.map(handleEvent)) | 40 | .all(req.body.events.map(handleEvent)) |
29 | .then((result) => res.json(result)) | 41 | .then((result) => res.json(result)) |
30 | .catch((err) => { | 42 | .catch((err) => { |
31 | - console.error(err); | 43 | + console.error(err); res.status(200).end(); |
32 | - res.status(200).end(); | ||
33 | }); | 44 | }); |
34 | }); | 45 | }); |
35 | 46 | ||
47 | +// Imports the Google Cloud client library | ||
48 | +const vision = require('@google-cloud/vision'); | ||
49 | + | ||
50 | +// Creates a client | ||
51 | +const client = new vision.ImageAnnotatorClient(); | ||
52 | + | ||
53 | +/** | ||
54 | + * TODO(developer): Uncomment the following line before running the sample. | ||
55 | + */ | ||
56 | +// const fileName = 'Local image file, e.g. /path/to/image.png'; | ||
57 | + | ||
58 | +// Read a local image as a text document | ||
59 | +const [result] = await client.documentTextDetection(fileName); | ||
60 | +const fullTextAnnotation = result.fullTextAnnotation; | ||
61 | +//console.log(`Full text: ${fullTextAnnotation.text}`); | ||
62 | +fullTextAnnotation.pages.forEach(page => { | ||
63 | + paragraph.words.forEach(word => { | ||
64 | + const wordText = word.symbols.map(s => s.text).join(''); | ||
65 | + // console.log(`Word text: ${wordText}`); | ||
66 | + | ||
67 | + word.symbols.forEach(symbol => { | ||
68 | + // console.log(`Symbol text: ${symbol.text}`); | ||
69 | + | ||
70 | + }); | ||
71 | + }); | ||
72 | +}); | ||
73 | + | ||
74 | +const vision = require('@google-cloud/vision'); | ||
75 | + | ||
76 | +// Creates a client | ||
77 | +const client = new vision.ImageAnnotatorClient(); | ||
78 | + | ||
79 | +/** | ||
80 | + * TODO(developer): Uncomment the following line before running the sample. | ||
81 | + */ | ||
82 | +// const fileName = 'Local image file, e.g. /path/to/image.png'; | ||
83 | + | ||
84 | +// Performs text detection on the local file | ||
85 | +const [result] = await client.textDetection(fileName); | ||
86 | +const detections = result.textAnnotations; | ||
87 | +//console.log('Text:'); | ||
88 | +detections.forEach(text => console.log(text)); | ||
89 | + | ||
90 | + | ||
36 | // event handler | 91 | // event handler |
37 | function handleEvent(event) { | 92 | function handleEvent(event) { |
38 | if (event.type !== 'message' || event.message.type !== 'text') { | 93 | if (event.type !== 'message' || event.message.type !== 'text') { |
... | @@ -58,7 +113,7 @@ function handleEvent(event) { | ... | @@ -58,7 +113,7 @@ function handleEvent(event) { |
58 | 113 | ||
59 | //언어 감지가 제대로 됐는지 확인 | 114 | //언어 감지가 제대로 됐는지 확인 |
60 | console.log(detect_body.langCode); | 115 | console.log(detect_body.langCode); |
61 | - | 116 | + |
62 | 117 | ||
63 | //번역은 한국어->영어 / 영어->한국어만 지원 | 118 | //번역은 한국어->영어 / 영어->한국어만 지원 |
64 | if(detect_body.langCode == 'ko'||detect_body.langCode == 'en'){ | 119 | if(detect_body.langCode == 'ko'||detect_body.langCode == 'en'){ | ... | ... |
-
Please register or login to post a comment