java 정규식 관련 질문드립니다.

조회수 1313회

java로 "(한글,한글자음,영어,숫자,특수문자) + / + 품사태그" 이런 형식만 추출을 하려고 하는데요

다른건 다 문제가 없는데 한글 자음이 추출이 안되서 질문드립니다. 혹시나 해서 유니코드로 바꿔서 추출하려고 했는데 그것도 마땅치가 않네요.. 도와주시면 감사하겠습니다!

package text;

import org.jetbrains.annotations.NotNull;

import java.io.*;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class makeWord2Vec {

    public static void main(String[] args) throws IOException {

        String path="C:\\Users\\skarl\\Desktop\\형태분석 말뭉치\\전체";
        File dirFile=new File(path);
        File []fileList=dirFile.listFiles();
        for(File tempFile : fileList) {
            if(tempFile.isFile()) {
                String name=tempFile.getName();
                BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\skarl\\Desktop\\형태분석 말뭉치\\전체\\"+name));
                BufferedWriter fw = new BufferedWriter(new FileWriter("C:\\Users\\skarl\\Desktop\\전체.txt",true));
                while (true) {

                    String line = br.readLine();
                    if (line == null) break;
                    if(line.contains("<")||line.contains(">")) line = "";

                    //fw.write(line);
                    //if(line!="")fw.write("\r\n");

                    String matchLine = null;
                    Pattern regex=Pattern.compile("([a-zA-Z0-9!@#$%^&*()_+/.,'?~…]|[\"]|[가-힣ㄱ-ㅎㅏ-ㅣ])+\\/+[A-Z]+");
                    Matcher regexMatcher=regex.matcher(line);
                    while(regexMatcher.find()) {
                        matchLine = regexMatcher.group();
                        fw.write(matchLine + " ");
                    }
                }
                br.close();
                fw.close();
            }
        }
    }
}

  • (•́ ✖ •̀)
    알 수 없는 사용자
  • 제 기준에서 첨언 하겠습니다. break; 해주는 구문이 없어서 while 문을 못 벗어 나는거 같습니다. 이도근 2018.8.7 17:24

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)