How to write custom removePunctuation() function to better deal with Unicode chars?

后端 未结 2 520
闹比i
闹比i 2021-01-02 11:29

In the source code of the tm text-mining R-package, in file transform.R, there is the removePunctuation() function, currently defined as:

functi         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-02 11:59

    I had the same problem, custom function was not working, but actually the first line below has to be added

    Regards

    Susana

    replaceExpressions <- function(x) UseMethod("replaceExpressions", x)
    
    replaceExpressions.PlainTextDocument <- replaceExpressions.character  <- function(x) {
        x <- gsub(".", " ", x, ignore.case =FALSE, fixed = TRUE)
        x <- gsub(",", " ", x, ignore.case =FALSE, fixed = TRUE)
        x <- gsub(":", " ", x, ignore.case =FALSE, fixed = TRUE)
        return(x)
    }
    
    notes_pre_clean <- tm_map(notes, replaceExpressions, useMeta = FALSE)
    

提交回复
热议问题