Difference between revisions of "R: tidytext RPJP BAPPENAS"

From OnnoWiki
Jump to navigation Jump to search
Line 6: Line 6:
 
   
 
   
 
  # create corpus from pdfs
 
  # create corpus from pdfs
  converted <- VCorpus(DirSource(directory), readerControl = list(reader = readPDF)) %>%
+
  docs <- VCorpus(DirSource(directory), readerControl = list(reader = readPDF))
  DocumentTermMatrix()
 
 
converted %>%
 
  tidy() %>%
 
  filter(!grepl("[0-9]+", term))
 
# converted adalah DocumentTermMatrix
 
  
 +
# docs <- VCorpus(DirSource("data", recursive=TRUE))
 +
# Get the document term matrices
  
 
docs <- VCorpus(DirSource("data", recursive=TRUE))
 
# Get the document term matrices
 
 
  BigramTokenizer <- function(x) NGramTokenizer(x, Weka_control(min = 2, max = 2))
 
  BigramTokenizer <- function(x) NGramTokenizer(x, Weka_control(min = 2, max = 2))
 
  dtm_unigram <- DocumentTermMatrix(docs, control = list(tokenize="words",  
 
  dtm_unigram <- DocumentTermMatrix(docs, control = list(tokenize="words",  
Line 30: Line 23:
 
  inspect(dtm_unigram)
 
  inspect(dtm_unigram)
 
  inspect(dtm_bigram)
 
  inspect(dtm_bigram)
 +
 +
 +
converted %>%
 +
  tidy() %>%
 +
  filter(!grepl("[0-9]+", term))
 +
# converted adalah DocumentTermMatrix
  
  

Revision as of 12:44, 6 November 2018

library(tidyverse)
library(tidytext)
library(tm)
directory <- "data-pdf"

# create corpus from pdfs
docs <- VCorpus(DirSource(directory), readerControl = list(reader = readPDF))
# docs <- VCorpus(DirSource("data", recursive=TRUE))
# Get the document term matrices
BigramTokenizer <- function(x) NGramTokenizer(x, Weka_control(min = 2, max = 2))
dtm_unigram <- DocumentTermMatrix(docs, control = list(tokenize="words", 
    removePunctuation = TRUE, 
    stopwords = stopwords("english"), 
    stemming = TRUE))
dtm_bigram <- DocumentTermMatrix(docs, control = list(tokenize = BigramTokenizer,
    removePunctuation = TRUE,
    stopwords = stopwords("english"),
    stemming = TRUE))
inspect(dtm_unigram)
inspect(dtm_bigram)


converted %>%
  tidy() %>%
  filter(!grepl("[0-9]+", term))
# converted adalah DocumentTermMatrix



Pranala Menarik