0
プレーンテキストでstrsplitを使用しようとすると、保存された値が文字列から文字列のベクトルに変換されるという望ましい特性があります。例えば、改行 " n"の後にコーパスコンテンツをベクターに変換するには
txt = "The fox is Brown.\nThe Fox has a tail."
strsplit(txt, "\n")
私は私のコーパスを作成するときに、私は、R 3.4.0でTM(v0.7-1)
7. Windows上でのNLPパッケージを使用している実際の問題のために content_transformerの機能を tmに使用しようとすると、コンテンツのベクターを返す代わりに、コーパスが破損します。上記のコードで
str(docs)
から
require(tm) #version 0.7-1
txt = "The fox is Brown.\nThe Fox has a tail."
docs = Corpus(VectorSource(txt))
to_newline = content_transformer(function (x) unlist(strsplit(x, "\n")))
docs = tm_map(docs, to_newline)
str(docs)
出力のようになります。私はそれが$ content
は、文字のベクトルであり、次のようになりたい
List of 2
$ 1:List of 2
..$ content: chr "The fox is Brown."
..$ meta :List of 7
.. ..$ author : chr(0)
.. ..$ datetimestamp: POSIXlt[1:1], format: "2017-06-25 15:11:55"
.. ..$ description : chr(0)
.. ..$ heading : chr(0)
.. ..$ id : chr "1"
.. ..$ language : chr "en"
.. ..$ origin : chr(0)
.. ..- attr(*, "class")= chr "TextDocumentMeta"
..- attr(*, "class")= chr [1:2] "PlainTextDocument" "TextDocument"
$ 2:List of 2
..$ content: chr "The Fox has a tail."
..$ meta :List of 7
.. ..$ author : chr(0)
.. ..$ datetimestamp: POSIXlt[1:1], format: "2017-06-25 15:11:55"
.. ..$ description : chr(0)
.. ..$ heading : chr(0)
.. ..$ id : chr "2"
.. ..$ language : chr "en"
.. ..$ origin : chr(0)
.. ..- attr(*, "class")= chr "TextDocumentMeta"
..- attr(*, "class")= chr [1:2] "PlainTextDocument" "TextDocument"
- attr(*, "class")= chr [1:2] "SimpleCorpus" "Corpus"
:
List of 1
$ 1:List of 2
..$ content: chr [1:2] "The fox is Brown." "The Fox has a tail."
..$ meta :List of 7
.. ..$ author : chr(0)
.. ..$ datetimestamp: POSIXlt[1:1], format: "2017-06-25 15:11:55"
.. ..$ description : chr(0)
.. ..$ heading : chr(0)
.. ..$ id : chr "1"
.. ..$ language : chr "en"
.. ..$ origin : chr(0)
.. ..- attr(*, "class")= chr "TextDocumentMeta"
..- attr(*, "class")= chr [1:2] "PlainTextDocument" "TextDocument"