File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
package itn.let.komoran;
import java.util.ArrayList;
import java.util.List;
import itn.com.cmm.util.MJUtil;
import kr.co.shineware.nlp.komoran.constant.DEFAULT_MODEL;
import kr.co.shineware.nlp.komoran.core.Komoran;
import kr.co.shineware.nlp.komoran.model.KomoranResult;
import kr.co.shineware.nlp.komoran.model.Token;
public class KomoranUtils {
public List<String> parseKomoranTextByList(String ocrText, String filePath) throws Exception {
Komoran komoran = new Komoran(DEFAULT_MODEL.FULL);
/*
* 사용자 지정 단아를 추가 학습하기 위해 아래 파일을 추가 적용해 준다.
* 파일은 dic.user 이름으로 확장자까지 만들어 준다(확장자를 .user로 해야한다)
* 파일 내용으로는 적용할 단어와 품사를 탭 구분으로 입력하면 된다.
* Ex) 톡줘 NNP
* */
komoran.setUserDic(filePath + "komoran/dic.user");
String strToAnalyze = ocrText;
KomoranResult analyzeResultList = komoran.analyze(strToAnalyze); //형태소 분석 전체 문장
String resultText = analyzeResultList.getPlainText();
//형태소 분석 각 단어별 토큰화 시킴
List<Token> tokenList = analyzeResultList.getTokenList();
List<String> resultTokenList = new ArrayList<String>();
String[] split = resultText.split("\n");
//String[] split = resultText.split(System.getProperty("line.separator").toString());
/*for(String text : split) {
//text = text.replace(System.getProperty("line.separator").toString(), "");
text = text.replace("\r", "");
text = text.replaceAll("/SW ", "");
resultTokenList.add(text);
}*/
for (Token token : tokenList) {
//System.out.format("(%2d, %2d) %s/%s\n", token.getBeginIndex(), token.getEndIndex(), token.getMorph(), token.getPos());
String pos = token.getPos(); //형태소 종류
String mor = token.getMorph(); //분석 단어
/* NNG 일반명사
* NNP 고유명사
* NNB 의존명사
* NP 대명사
* NR 수사
* VV 동사
* VA 형용사
* SL 외국어
* SH 한자
* NF 명사추정범주
*
*/
if(pos.contains("NNG") ||
pos.contains("NNP") ||
pos.contains("NP") ||
pos.contains("VV") ||
pos.contains("VA") ||
pos.contains("SL") ||
pos.contains("SH") ||
pos.contains("NF")) {
resultTokenList.add(mor);
}
}
//토큰 단어에서 중복 단어는 제거 후 리턴
return MJUtil.getDuplicateList(resultTokenList);
}
public List<String> parseKomoranTextTypeNNGByList(String ocrText, String filePath) throws Exception {
Komoran komoran = new Komoran(DEFAULT_MODEL.FULL);
/*
* 사용자 지정 단아를 추가 학습하기 위해 아래 파일을 추가 적용해 준다.
* 파일은 dic.user 이름으로 확장자까지 만들어 준다(확장자를 .user로 해야한다)
* 파일 내용으로는 적용할 단어와 품사를 탭 구분으로 입력하면 된다.
* Ex) 톡줘 NNP
* */
komoran.setUserDic(filePath + "komoran/dic.user");
String strToAnalyze = ocrText;
KomoranResult analyzeResultList = komoran.analyze(strToAnalyze); //형태소 분석 전체 문장
String resultText = analyzeResultList.getPlainText();
//형태소 분석 각 단어별 토큰화 시킴
List<Token> tokenList = analyzeResultList.getTokenList();
List<String> resultTokenList = new ArrayList<String>();
String[] split = resultText.split("\n");
//String[] split = resultText.split(System.getProperty("line.separator").toString());
for(String text : split) {
//text = text.replace(System.getProperty("line.separator").toString(), "");
/*
text = text.replace("\r", "");
text = text.replaceAll("/SW ", "");
resultTokenList.add(text);*/
}
for (Token token : tokenList) {
//System.out.format("(%2d, %2d) %s/%s\n", token.getBeginIndex(), token.getEndIndex(), token.getMorph(), token.getPos());
String pos = token.getPos(); //형태소 종류
String mor = token.getMorph(); //분석 단어
/* NNG 일반명사
* NNP 고유명사
* NNB 의존명사
* NP 대명사
* NR 수사
* VV 동사
* VA 형용사
* SL 외국어
* SH 한자
* NF 명사추정범주
*
*/
if(pos.contains("NNG") ||
pos.contains("NNP") ||
pos.contains("NP") ||
pos.contains("SL") ||
pos.contains("NF")) {
resultTokenList.add(mor);
}
}
//토큰 단어에서 중복 단어는 제거 후 리턴
return MJUtil.getDuplicateList(resultTokenList);
}
public String parseKomoranTextByString(String ocrText, String filePath) throws Exception {
Komoran komoran = new Komoran(DEFAULT_MODEL.FULL);
/*
* 사용자 지정 단아를 추가 학습하기 위해 아래 파일을 추가 적용해 준다.
* 파일은 dic.user 이름으로 확장자까지 만들어 준다(확장자를 .user로 해야한다)
* 파일 내용으로는 적용할 단어와 품사를 탭 구분으로 입력하면 된다.
* Ex) 톡줘 NNP
* */
komoran.setUserDic(filePath + "komoran/dic.user");
String strToAnalyze = ocrText;
KomoranResult analyzeResultList = komoran.analyze(strToAnalyze); //형태소 분석 전체 문장
String resultText = analyzeResultList.getPlainText();
//형태소 분석 각 단어별 토큰화 시킴
List<Token> tokenList = analyzeResultList.getTokenList();
List<String> resultTokenList = new ArrayList<String>();
String[] split = resultText.split("\n");
for(String text : split) {
text = text.replace("\r", "");
text = text.replaceAll("/SW ", "");
resultText = text;
}
//System.out.println(resultText);
return resultText;
}
public List<String> parseKomoranWordCloudNNGByList(String ocrText, String filePath) throws Exception {
List<String> resultTokenList = new ArrayList<String>();
try {
Komoran komoran = new Komoran(DEFAULT_MODEL.FULL);
/*
* 사용자 지정 단아를 추가 학습하기 위해 아래 파일을 추가 적용해 준다.
* 파일은 dic.user 이름으로 확장자까지 만들어 준다(확장자를 .user로 해야한다)
* 파일 내용으로는 적용할 단어와 품사를 탭 구분으로 입력하면 된다.
* Ex) 톡줘 NNP
* */
komoran.setUserDic(filePath + "komoran/dic.user");
String strToAnalyze = ocrText;
KomoranResult analyzeResultList = komoran.analyze(strToAnalyze); //형태소 분석 전체 문장
String resultText = analyzeResultList.getPlainText();
//System.out.println("=============start====================");
//System.out.println(strToAnalyze);
//System.out.println("+++++++++");
//System.out.println(resultText);
//System.out.println("==============end=====================");
//형태소 분석 각 단어별 토큰화 시킴
List<Token> tokenList = analyzeResultList.getTokenList();
for (Token token : tokenList) {
String pos = token.getPos(); //형태소 종류
String mor = token.getMorph(); //분석 단어
/* NNG 일반명사
* NNP 고유명사
* NNB 의존명사
* NP 대명사
* NR 수사
* VV 동사
* VA 형용사
* SL 외국어
* SH 한자
* NF 명사추정범주
*
*/
if(mor.length() > 1 && (pos.contains("NNG") ||
pos.contains("NNP") ||
pos.contains("NNB") ||
pos.contains("NP") ||
pos.contains("SL") ||
pos.contains("VV") ||
pos.contains("VA") ||
pos.contains("NF"))) {
resultTokenList.add(mor);
}
}
} catch (Exception e) {
System.out.println("+++++++++++++++ parseKomoranWordCloudNNGByList Error !!! " + e);
}
//토큰 단어에서 중복 단어는 제거 후 리턴
return resultTokenList;
}
}