2016-07-20 3 views
-4

나는 IMDB에서 TSV를 시도하고있어 구문 분석 :탭으로 구분 된 파일

$hutter    Battle of the Sexes (2017) (as $hutter Boy) [Bobby Riggs Fan] <10> 
        NVTION: The Star Nation Rapumentary (2016) (as $hutter Boy) [Himself] <1> 
        Secret in Their Eyes (2015) (uncredited) [2002 Dodger Fan] 
        Steve Jobs (2015) (uncredited) [1988 Opera House Patron] 
        Straight Outta Compton (2015) (uncredited) [Club Patron/Dopeman] 



$lim, Bee Moe  Fatherhood 101 (2013) (as Brandon Moore) [Himself - President, Passages] 
        For Thy Love 2 (2009) [Thug 1] 
        Night of the Jackals (2009) (V) [Trooth] 
        "Idle Talk" (2013) (as Brandon Moore) [Himself] 
        "Idle Times" (2012) {(#1.1)} (as Brandon Moore) [Detective Ryan Turner] 
일부 라인 탭으로 시작하지 않는 몇 가지로

enter image description here

. 저는 배우의 이름을 키로하고 영화 목록을 값으로 사용하여지도를 원합니다. 배우의 이름 사이에는 동영상 목록까지의 하나 이상의 탭이 있습니다.

내 코드 :

 while ((line = reader.readLine()) != null) { 

      Matcher matcher = headerPattern.matcher(line); 
      boolean headerMatchFound = matcher.matches(); 

      if (headerMatchFound) { 
       Logger.getLogger(ActorListParser.class.getName()).log(Level.INFO, "Header for actor list found"); 

       String newline; 

       reader.readLine(); 

       while ((newline = reader.readLine()) != null) { 
        String[] fullLine = null; 

        String actor; 
        String title; 

        Pattern startsWithTab = Pattern.compile("^\t.*"); 
        Matcher tab = startsWithTab.matcher(newline); 
        boolean tabStartMatcher = tab.matches(); 

        if (!tabStartMatcher) { 

         fullLine = newline.split("\t.*"); 

        System.out.println("Actor: " + fullLine[0] + 
          "Movie: " + fullLine[1]); 

        }//this line will have code to match lines that start with tabs. 
       } 
      } 

     } 

내가 얻을 arrayoutofbounds 예외 전에 내가 몇 줄이 비로소 작동을 수행 한 방법. 줄을 파싱하고 하나 이상의 탭이있는 경우 최대 2 줄로 분할 할 수 있습니까?

+3

데이터 목록을 스크린 샷으로 게시하지 마십시오. 복사/붙여 넣기 데이터 및 고정 너비 서식을 4 칸 들여 쓰기. –

+0

데이터 목록 문제가 실제로 SO 규칙입니까? 데이터를 붙여 넣기 복사가 엉망이며 수정하는 데 오랜 시간이 걸립니다. – user465001

+1

매우 강력하게 추천합니다. 전체 화면이 아닌 질문을 전달하기에 충분할 정도로 몇 줄의 데이터 만 표시하면됩니다. 이미지는 진정한 이미지 인 경우에만 예약해야합니다. 텍스트 인 경우 게시물에 텍스트로 포함됩니다. –

답변

1

따옴표 붙이기 및 이스케이프 처리와 관련하여 탭/쉼표로 구분 된 데이터 파일을 구문 분석 할 때 미묘한 차이가 있습니다.

OpenCSV 또는 Apache Commons CSV와 같은 기존 CSV 구문 분석 라이브러리 중 하나를 사용해보아야 할 많은 업무, 좌절감 및 두통을 스스로 해결할 수 있습니다.

OP가 휠 재발 사 이유를 밝히지 않았기 때문에 의견 대신 대답으로 게시되었으며 실제로는 "해결 된"일부 작업이 있습니다.

+0

나는 일반적으로 CSV 라이브러리를 사용하는 것에 동의하지만,이 포맷은 CSVish를 보지 못합니다. – Robert

관련 문제