By Hilfit19


2018-04-16 13:14:20 8 Comments

I am trying to build term document matrix from one pdf text. When I inspect the term document matrix, I get this.

<<TermDocumentMatrix (terms: 7245, documents:342)>>

The number of document should 1 not 342, and 342 is number of pages in pdf files. I've tried use this code using R.

pdf_file <- file.path(("Lat/web"), "textpdf.pdf")
text <- pdf_text(pdf_file)
myCorpus <- Corpus(VectorSource(text))

mytdm <- TermDocumentMatrix(myCorpus, control = list
                         (removeNumbers = TRUE, 
                         removePunctuation = TRUE, 
                         stopwords=stopwords_en, 
                         stemming=TRUE)
)
inspect(mytdm)

1 comments

@phiver 2018-04-16 13:32:37

Use the following code to collapse the pdf pages into 1 document.

pdf_file <- file.path(("Lat/web"), "textpdf.pdf")
text <- pdf_text(pdf_file)
# collapse pdf pages into 1
text <- paste(unlist(text), collapse ="")
.....
rest of code

@Hilfit19 2018-04-16 13:59:46

very very thanks @phiver, its working, thank you again

@phiver 2018-04-16 14:20:22

@Hilfit19, You are welcome. If you accept the answer your reputation will also increase.

Related Questions

Sponsored Content

2 Answered Questions

[SOLVED] Maximum reasonable size for stemCompletion in tm?

  • 2013-06-07 15:50:11
  • ChristinaP
  • 1775 View
  • 6 Score
  • 2 Answer
  • Tags:   r tm

13 Answered Questions

[SOLVED] Merge / convert multiple PDF files into one PDF

2 Answered Questions

3 Answered Questions

[SOLVED] Proper MIME media type for PDF files

1 Answered Questions

[SOLVED] In R tm package, build corpus FROM Document-Term-Matrix

1 Answered Questions

[SOLVED] R tm/qdap - Get document based on term

  • 2014-06-09 09:31:30
  • JohnCoene
  • 173 View
  • 0 Score
  • 1 Answer
  • Tags:   r tm qdap

1 Answered Questions

[SOLVED] Lists of term-frequency pairs into a matrix in R

2 Answered Questions

[SOLVED] Finding most frequent term in each document of a corpus

1 Answered Questions

[SOLVED] Building a term-document matrix

  • 2013-12-13 00:26:12
  • Jusleong
  • 281 View
  • 0 Score
  • 1 Answer
  • Tags:   r tm

1 Answered Questions

[SOLVED] Making a term document matrix from an excel file using R

Sponsored Content