readTagged: Read In a POS-Tagged Word Text Document

Description Usage Arguments Details Value See Also Examples

View source: R/reader.R

Description

Return a function which reads in a text document containing POS-tagged words.

Usage

1

Arguments

...

Arguments passed to TaggedTextDocument.

Details

Formally this function is a function generator, i.e., it returns a function (which reads in a text document) with a well-defined signature, but can access passed over arguments (...) via lexical scoping.

Value

A function with the following formals:

elem

a named list with the component content which must hold the document to be read in or the component uri holding a connection object or a character string.

language

a string giving the language.

id

a character giving a unique identifier for the created text document.

The function returns a TaggedTextDocument representing the text and metadata extracted from elem$content or elem$uri. The argument id is used as fallback if elem$uri is null.

See Also

Reader for basic information on the reader infrastructure employed by package tm.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# See http://www.nltk.org/book/ch05.html or file ca01 in the Brown corpus
x <- paste("The/at grand/jj jury/nn commented/vbd on/in a/at number/nn of/in",
           "other/ap topics/nns ,/, among/in them/ppo the/at Atlanta/np and/cc",
           "Fulton/np-tl County/nn-tl purchasing/vbg departments/nns which/wdt",
           "it/pps said/vbd ``/`` are/ber well/ql operated/vbn and/cc follow/vb",
           "generally/rb accepted/vbn practices/nns which/wdt inure/vb to/in the/at",
           "best/jjt interest/nn of/in both/abx governments/nns ''/'' ./.")
vs <- VectorSource(x)
elem <- getElem(stepNext(vs))
(doc <- readTagged()(elem, language = "en", id = "id1"))
tagged_words(doc)

Example output

Loading required package: NLP
<<TaggedTextDocument>>
Metadata:  2
Content:  words: 43, sents: 1, paras: 1
The/AT
grand/JJ
jury/NN
commented/VBD
on/IN
a/AT
number/NN
of/IN
other/AP
topics/NNS
,/,
among/IN
them/PPO
the/AT
Atlanta/NP
and/CC
Fulton/NP-TL
County/NN-TL
purchasing/VBG
departments/NNS
which/WDT
it/PPS
said/VBD
``/``
are/BER
well/QL
operated/VBN
and/CC
follow/VB
generally/RB
accepted/VBN
practices/NNS
which/WDT
inure/VB
to/IN
the/AT
best/JJT
interest/NN
of/IN
both/ABX
governments/NNS
''/''
./.

tm documentation built on April 7, 2021, 3:01 a.m.