김서영

check morp and add divide morp by MAG tag

1 const apiRequest = require('./apiRequest'); 1 const apiRequest = require('./apiRequest');
2 2
3 +const allowMorpChecklist = [ "NNG","NNP","NNB","VA","MM","MAG","SL","SH","SN","XPN","XSN","XSA","ETM","NOG" ];
4 +const vvMorpChecklist = ["ETM","ETN"]; // 명사형 전성어미(ex) '-(으)ㅁ', '-기'), 관형사형 전성어미(ex) '-ㄴ', '-', '-던', '-ㄹ'), 지정자(VCP,VCN, ex) '-이다', '-아니다')
5 +const npMorpCecklist = ['어디','언제']; // 필요한 의문사 리스트
6 +/**
7 + * @param {{lemma:string, position:number, type:string}[]} word - 한 단어의 형태소 ex) [{걸리},{었},{을}]
8 + * @param {{lemma:string, position:number, type:string}[][]} needMorp - 공백 단위로 묶어둠 ex) [[{감기}],[{걸리},{었},{을}],[{때}]
9 + * @param {{lemma:string, position:number, type:string}[][]} noNeedMorp - 공백 단위로 묶어둠 ex) [[{감기}],[{걸리},{었},{을}],[{때}]
10 + * @description word의 각 형태소의 type이 allowMorpChecklist에 있는지 확인하고 있으면 needMorp, 없으면 noNeedMorp에 추가합니다.
11 + */
12 +const checkMorp = ( word, needMorp, noNeedMorp ) => {
13 + let needMorpTemp = [],
14 + noNeedMorpTemp = [];
15 + word.forEach( ( morp ) => {
16 + if( allowMorpChecklist.indexOf( morp.type ) !== -1 ) {
17 + needMorpTemp.push( morp );
18 + } else if(npMorpCecklist.indexOf( morp.lemma ) !== -1 ) {
19 + needMorpTemp.push( morp );
20 + }
21 + else {
22 + noNeedMorpTemp.push( morp );
23 + }
24 + });
25 + if( noNeedMorpTemp.length > 0) {
26 + noNeedMorp.push( noNeedMorpTemp );
27 + }
28 + if( needMorpTemp.length > 0) {
29 + needMorp.push( needMorpTemp );
30 + }
31 +}
32 +
33 +
3 /** 34 /**
4 * @param {{lemma:string, position:number, type:string}[][]} tempMorps - 공백 단위로 묶어둠 ex) [[{감기}],[{걸리},{었},{을}],[{때}]] 35 * @param {{lemma:string, position:number, type:string}[][]} tempMorps - 공백 단위로 묶어둠 ex) [[{감기}],[{걸리},{었},{을}],[{때}]]
5 * @returns {{needMorp : {}[][], noNeedMorp : {}[][]}} morp를 needMorp와 noNeedMorp로 나눴습니다. 36 * @returns {{needMorp : {}[][], noNeedMorp : {}[][]}} morp를 needMorp와 noNeedMorp로 나눴습니다.
...@@ -12,7 +43,8 @@ const divideMorpbyMean = ( tempMorps ) => { ...@@ -12,7 +43,8 @@ const divideMorpbyMean = ( tempMorps ) => {
12 tempMorps.forEach( ( word, j ) => { 43 tempMorps.forEach( ( word, j ) => {
13 44
14 if( word[ 0 ].type === "VV" || word[ 0 ].type === "VA" || word[ 0 ].type === "MAG") { // 동사, 형용사, 부사 45 if( word[ 0 ].type === "VV" || word[ 0 ].type === "VA" || word[ 0 ].type === "MAG") { // 동사, 형용사, 부사
15 - let checkV = true 46 + let checkV = true,
47 + checkM = true;
16 word.find( ( Morp ) => { 48 word.find( ( Morp ) => {
17 if( Morp.type === "EF" ) { // 종결어미 49 if( Morp.type === "EF" ) { // 종결어미
18 checkV = false; 50 checkV = false;
...@@ -24,8 +56,17 @@ const divideMorpbyMean = ( tempMorps ) => { ...@@ -24,8 +56,17 @@ const divideMorpbyMean = ( tempMorps ) => {
24 } 56 }
25 }); 57 });
26 } 58 }
59 + } else if( word[ 0 ].type === "MAG") {
60 + if( Morp.type === "XSV" ) { // 동사파생 접미사 ex) -하다
61 + checkM = false;
62 + }
27 } 63 }
28 }); 64 });
65 + if( checkV && checkM) {
66 + needMorp.push( word );
67 + } else {
68 + noNeedMorp.push( word );
69 + }
29 } 70 }
30 else { 71 else {
31 checkMorp( word, needMorp, noNeedMorp ); 72 checkMorp( word, needMorp, noNeedMorp );
......