1

NTSB から数千の PDF ファイルから適切な情報を抽出するのに本当に苦労しています (特定の日付と数字)。これらの PDF は OCR する必要はなく、各レポートの長さとレイアウト情報はほぼ同じです。

事故の日時 (最初のページ) と、パイロットの年齢や飛行経験などのその他の情報を抽出する必要があります。私が試したことは、いくつかのファイルに対してジョブを実行しますが、使用しているコードが不十分に記述されているため、各ファイルに対しては機能しません。

# an example with a single file
library(pdftools)
library(readr)

# Download the file and read it row by row
file <- 'http://data.ntsb.gov/carol-repgen/api/Aviation/ReportMain/GenerateNewestReport/89789/pdf' # less than 100 kb
destfile <- paste0(getwd(),"/example.pdf")
download.file(file, destfile)

pdf <- pdf_text(destfile)
rows <-scan(textConnection(pdf), 
            what="character", sep = "\n")

# Extract the date of the accident based on the 'Date & Time' occurrence.
date <-rows[grep(pattern = 'Date & Time', x = rows, ignore.case = T, value = F)]
date <- strsplit(date, "  ")
date[[1]][9] #this method is not desirable since the date will not be always in that position

# Pilot age 
age <- rows[grep(pattern = 'Age', x = rows, ignore.case = F, value = F)]
age <- strsplit(age, split = '  ')
age <- age[[1]][length(age[[1]])] # again, I'm using the exact position in that list
age <- readr::parse_number(age) #

私が得た主な問題は、事故の日時を抽出しようとしているときです。ここで行ったようにリストの使用を避けることで、その正確な情報を抽出することは可能ですか?

4

1 に答える 1