Showing
1 changed file
with
32 additions
and
1 deletions
| ... | @@ -76,7 +76,33 @@ const divideMorpbyMean = ( tempMorps ) => { | ... | @@ -76,7 +76,33 @@ const divideMorpbyMean = ( tempMorps ) => { |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | /** | 78 | /** |
| 79 | - * 수정중... | 79 | + * @param {String} result - 결과 담던거 |
| 80 | + * @param {{text : string, begin : number, end : number }[]} words 단어 분석 결과를 담는 어레이 | ||
| 81 | + * @param {{lemma:string, position:number, type:string, id : number}[][]} needMorp - 공백 단위로 묶어둠 ex) [[{감기}],[{걸리},{었},{을}],[{때}]] | ||
| 82 | + * @returns {String} 필요한 단어만 남겨둔 문장입니다. | ||
| 83 | + * @description 필요한 morp와 원문 텍스트를 이용해 문장에서의 키워드를 분석해 문장으로 만들어 줍니다. | ||
| 84 | + */ | ||
| 85 | +const makeKeyword = ( result, words, needMorp ) => { | ||
| 86 | + let keywordText = ""; | ||
| 87 | + | ||
| 88 | + needMorp.forEach( ( morps ) => { | ||
| 89 | + words.forEach( ( word ) => { | ||
| 90 | + if( word.begin === morps[ 0 ].id ){ | ||
| 91 | + let tempByte = morps[ morps.length - 1 ].position - morps[0].position + Buffer.byteLength( morps[ morps.length - 1 ].lemma ); | ||
| 92 | + for( let ch of word.text ) { | ||
| 93 | + if( tempByte > 0 ) { | ||
| 94 | + keywordText += ch; | ||
| 95 | + tempByte -= Buffer.byteLength(ch) | ||
| 96 | + } | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | + }); | ||
| 100 | + keywordText += " "; | ||
| 101 | + }); | ||
| 102 | + result.keywordText = keywordText.trim(); | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | +/** | ||
| 80 | * @param {String} result - 결과 담던거 | 106 | * @param {String} result - 결과 담던거 |
| 81 | * @param {{NE : {}[], Morp : {}[]}} analysisResult 분석 결과가 담겼습니다. | 107 | * @param {{NE : {}[], Morp : {}[]}} analysisResult 분석 결과가 담겼습니다. |
| 82 | * @description morp를 처리하는 함수 입니다 ^^ | 108 | * @description morp를 처리하는 함수 입니다 ^^ |
| ... | @@ -96,6 +122,11 @@ const divideMorp = async ( result, analysisResult ) => { | ... | @@ -96,6 +122,11 @@ const divideMorp = async ( result, analysisResult ) => { |
| 96 | analysisResult.word.forEach( ( word ) => { | 122 | analysisResult.word.forEach( ( word ) => { |
| 97 | tempMorps.push( analysisResult.morp.slice( word.begin, word.end + 1 ) ); | 123 | tempMorps.push( analysisResult.morp.slice( word.begin, word.end + 1 ) ); |
| 98 | }); | 124 | }); |
| 125 | + | ||
| 126 | + tempResult.originalMorp = analysisResult.morp; | ||
| 127 | + [ tempResult.needMorp, tempResult.noNeedMorp ] = await divideMorpbyMean( tempMorps ); | ||
| 128 | + await makeKeyword( result, analysisResult.word, tempResult.needMorp ); | ||
| 129 | + result.morps = tempResult; | ||
| 99 | } | 130 | } |
| 100 | 131 | ||
| 101 | /** | 132 | /** | ... | ... |
-
Please register or login to post a comment