add textAnalystic.js/ compleate fix spelling check / proceed anlystic text
Showing
1 changed file
with
52 additions
and
0 deletions
api/textAnalystic.js
0 → 100644
| 1 | +const apiRequest = require('./apiRequest'); | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 수정중... | ||
| 5 | + * @param {String} result - 결과 담던거 | ||
| 6 | + * @param {{NE : {}[], Morp : {}[]}} analysisResult 분석 결과가 담겼습니다. | ||
| 7 | + * @description morp를 처리하는 함수 입니다 ^^ | ||
| 8 | + */ | ||
| 9 | +const divideMorp = async ( result, analysisResult ) => { | ||
| 10 | + let tempResult = {}, | ||
| 11 | + tempMorps = []; | ||
| 12 | + | ||
| 13 | + analysisResult.NE.forEach( ( word ) => { | ||
| 14 | + analysisResult.morp.forEach( ( morp, index ) => { | ||
| 15 | + if( word.begin <= index && word.end >= index ) { | ||
| 16 | + morp.type = "NOG"; | ||
| 17 | + } | ||
| 18 | + }); | ||
| 19 | + }); | ||
| 20 | + | ||
| 21 | + analysisResult.word.forEach( ( word ) => { | ||
| 22 | + tempMorps.push( analysisResult.morp.slice( word.begin, word.end + 1 ) ); | ||
| 23 | + }); | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * @param {Object} clientData - 클라이언트에서 받아온 데이터 | ||
| 28 | + * @param {String} clientData.text - 분석할 텍스트 | ||
| 29 | + * @returns {Object} 분석 결과 데이터 | ||
| 30 | + * @description 클라이언트 데이터를 받아 의미를 분석하고 맞춤법을 교정해 돌려줍니다. | ||
| 31 | + */ | ||
| 32 | +const textAnalystic = async ( clientData ) => { | ||
| 33 | + let result = { "originalText" : clientData.text }, | ||
| 34 | + fixedClientData, | ||
| 35 | + textAnalystic; | ||
| 36 | + | ||
| 37 | + fixedClientData = await apiRequest.Korean( result.originalText ); | ||
| 38 | + | ||
| 39 | + result.korean = fixedClientData; | ||
| 40 | + result.fixedText = result.korean.notag_html; | ||
| 41 | + try { | ||
| 42 | + textAnalystic = await apiRequest.ETRI( "WiseNLU", { "analysis_code" : "ner", "text" : result.fixedText } ); | ||
| 43 | + } | ||
| 44 | + catch( err ) { | ||
| 45 | + throw new Error( err.message ); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + await divideMorp( result, textAnalystic.return_object.sentence[ 0 ] ); | ||
| 49 | + return result; | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +module.exports = textAnalystic; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment