Python/문서 데이터 분석

[Python] [tika-python] PDF, Powerpoint 정보 추출

데이터 세상 2022. 1. 10. 13:22

tika-python

[tika-pyhon @github]

 

GitHub - chrismattmann/tika-python: Tika-Python is a Python binding to the Apache Tika™ REST services allowing Tika to be call

Tika-Python is a Python binding to the Apache Tika™ REST services allowing Tika to be called natively in the Python community. - GitHub - chrismattmann/tika-python: Tika-Python is a Python binding ...

github.com

Apach Tika REST 서비스에 대한 Python 바인딩으로 tika를 Python 언어로 기본적으로 호출할 수 있다.

Apach Tika

  • 다양한 파일 형식(ppt, xls, pdf)에서 문서 유형 감지 및 콘텐츠 추출에 사용되는 라이브러리

tika-python 설치

pip install tika

※ Tika는 Java로 작성되었으므로 Java 런타임을 설치해야 한다.

 

tika-python  사용

구문 : parser.from_file (filename, additional)
매개 변수 :
  • 파일 이름 : 파일의 위치이며 rb 모드로 열립니다. 즉, 바이너리 모드 읽기
  • 추가 : param 서비스 : tika 서버에서 요청 된 서비스, 기본값은 'all'이며 결과적으로 재귀 텍스트 콘텐츠 + 메타 데이터
    • 'meta'는 메타 데이터만 반환. 'text'는 콘텐츠만 반환.
    • param xmlContent : XML 콘텐츠를 가질 수 있으며, 기본값은 False
반환 유형 : 사전
from tika import parser

parsed = parser.from_file("sample.pptx")
# Get the content of the file
print(parsed["content"])
# Get the metadata of the file
print(parsed["metadata"])

결과 (parsed["content"])

PowerPoint 프레젠테이션

텍스트 상자: 슬라이드 내의 텍스트 데이터 추출 확인
        테이블 컬럼1    테이블 컬럼2    테이블 컬러3
        데이터1_1       데이터2_1       데이터3_1
        데이터1_2       데이터2_2       데이터3_2
        데이터1_3       데이터2_3       데이터3_3
        
샘플데이터
        컬럼1   컬럼2   컬럼3
        샘플 데이터 1_1 샘플 데이터 1_2 샘플 데이터 1_3
        샘플 데이터 1_2 샘플 데이터 1_2 샘플 데이터 1_2
        샘플 데이터 1_3 샘플 데이터 1_3 샘플 데이터 1_3        
        
/docProps/thumbnail.jpeg

결과 (parsed["metadata"])

{
    'Application-Name': ['Microsoft Office PowerPoint', 'Microsoft Excel'], 
    'Application-Version': ['15.0000', '15.0300'], 
    'Author': ['...', '...'], 
    'Content-Type': [
        'application/vnd.openxmlformats-officedocument.presentationml.presentation', 
        'image/wmf', 
        'image/png', 
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 
        'image/jpeg'
    ],
    ...
}

 

반응형