2017-04-05 15 views
0

pdfファイルからテキストを抽出し、コーパスオブジェクトを作成しました。tm_map条件付き行をマージする

テキスト内には、 "、"または " - "で終わる行があり、同じ文に属するので、次の行を追加したいと思います。例えば

私は

[1566] "this and other southeastern states (Eukerria saltensis,"  
[1567] "Sparganophilus helenae, Sp. tennesseensis). In the" 

を持っていると私は改行を置き換えるようなものを試してみました代わりに

[1566] "this and other southeastern states (Eukerria saltensis, Sparganophilus helenae, Sp. tennesseensis). In the" 

を持っていると思いますが、成功しません:

tm_map(myCorpus, content_transformer(gsub), pattern =",$\n",replacement = "") 

どれでも私はRでこれをどうやってやることができるのか?ここで

答えて

0

おかげで、それは動作しません!

私も、それはtm_mapで動作するように機能して、それを入れていた:

clean.X <- function(X){ 

    X2 <- paste0(X,collapse="\n") 
    X2 <- gsub(",\\n",", ",X2) 
    X2 <- gsub("\\-\\n","-",X2) 
    X2 <- unlist(strsplit(X2,"\\n")) 
    return(X2) 

} 

txt2 <- tm_map(txt, content_transformer(clean.X)) 
0

は改行で分割のあなたの考えに基づいて一つのアプローチ、...

txt <- c("aaa","bbc,","df","fgh-","jkh-","dfsf","gghf") 

txt2 <- paste0(txt,collapse="\n") 
txt2 <- gsub(",\\n",", ",txt2) 
txt2 <- gsub("\\-\\n","-",txt2) 
txt2 <- unlist(strsplit(txt2,"\\n")) 

txt2 
[1] "aaa" "bbc, df" "fgh-jkh-dfsf" "gghf"