forked from PolMine/RcppCWB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcwb_utils.Rd
More file actions
180 lines (156 loc) · 5.49 KB
/
Copy pathcwb_utils.Rd
File metadata and controls
180 lines (156 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cwb.R
\name{cwb_makeall}
\alias{cwb_makeall}
\alias{cwb_huffcode}
\alias{cwb_compress_rdx}
\alias{cwb_encode}
\title{CWB Tools for Creating Corpora}
\usage{
cwb_makeall(
corpus,
p_attribute,
registry = Sys.getenv("CORPUS_REGISTRY"),
quietly = FALSE
)
cwb_huffcode(
corpus,
p_attribute,
registry = Sys.getenv("CORPUS_REGISTRY"),
quietly = FALSE,
delete = TRUE
)
cwb_compress_rdx(
corpus,
p_attribute,
registry = Sys.getenv("CORPUS_REGISTRY"),
quietly = FALSE,
delete = TRUE
)
cwb_encode(
corpus,
registry = Sys.getenv("CORPUS_REGISTRY"),
data_dir,
vrt_dir,
encoding = "utf8",
p_attributes = c("word", "pos", "lemma"),
s_attributes,
skip_blank_lines = TRUE,
strip_whitespace = TRUE,
xml = TRUE,
quietly = FALSE,
verbose = FALSE
)
}
\arguments{
\item{corpus}{name of a CWB corpus (upper case)}
\item{p_attribute}{name p-attribute}
\item{registry}{path to the registry directory, defaults to the value of the
environment variable CORPUS_REGISTRY}
\item{quietly}{A \code{logical} value, whether to turn off messages (including
warnings).}
\item{delete}{A \code{logical} value, whether to remove redundant files after
compression.}
\item{data_dir}{The data directory where \code{cwb_encode} will save the binary
files of the indexed corpus. Tilde expansion is performed on \code{data_dir}
using \code{path.expand()} to avoid a crash.}
\item{vrt_dir}{Directory with input corpus files (verticalised format / file
ending *.vrt). Tilde expansion is performed on \code{vrt_dir} using
\code{path.expand()} to avoid a crash.}
\item{encoding}{The encoding of the files to be encoded. Needs to be an
encoding supported by CWB, see \code{cwb_charsets()}. "UTF-8" is taken as
"utf8". Defaults to "utf8" (recommended charset).}
\item{p_attributes}{Positional attributes (p-attributes) to be declared.}
\item{s_attributes}{A \code{list} of named \code{character} vectors to declare
structural attributes that shall be encoded. The names of the list are the
XML elements present in the corpus. Character vectors making up the list
declare the attributes that include the metadata of regions. To declare a
structural attribute without annotations, provide a zero-length character
vector using \code{character()} - see examples.}
\item{skip_blank_lines}{A \code{logical} value, whether to skip blank lines in the
input.}
\item{strip_whitespace}{A \code{logical} value, whether to strip whitespace from
tokens}
\item{xml}{A \code{logical} value, whether input is XML.}
\item{verbose}{A \code{logical} value, whether to show progress information
(counter of tokens processed).}
}
\description{
Wrappers for the CWB tools (\code{cwb-makeall}, \code{cwb-huffcode},
\code{cwb-compress-rdx}). Unlike the 'original' command line tools, these
wrappers will always perform a specific indexing/compression step on one
positional attribute, and produce all components.
}
\examples{
# The package includes and 'unfinished' corpus of debates in the UN General
# Assembly ("UNGA"), i.e. it does not yet include the reverse index, and it is
# not compressed.
#
# The first step in the following example is to copy the raw
# corpus to a temporary place.
home_dir <- system.file(package = "RcppCWB", "extdata", "cwb", "indexed_corpora", "unga")
tmp_data_dir <- file.path(tempdir(), "indexed_corpora")
tmp_unga_dir <- file.path(tmp_data_dir, "unga2")
if (!file.exists(tmp_data_dir)) dir.create(tmp_data_dir)
if (!file.exists(tmp_unga_dir)){
dir.create(tmp_unga_dir)
} else {
file.remove(list.files(tmp_unga_dir, full.names = TRUE))
}
regfile <- readLines(
system.file(package = "RcppCWB", "extdata", "cwb", "registry", "unga")
)
regfile[grep("^HOME", regfile)] <- sprintf('HOME "\%s"', tmp_unga_dir)
regfile[grep("^ID", regfile)] <- "ID unga2"
writeLines(text = regfile, con = file.path(get_tmp_registry(), "unga2"))
for (x in list.files(home_dir, full.names = TRUE)){
file.copy(from = x, to = tmp_unga_dir)
}
# perform cwb_makeall (equivalent to cwb-makeall command line utility)
cwb_makeall(corpus = "UNGA2", p_attribute = "word", registry = get_tmp_registry())
cl_load_corpus("UNGA2", registry = get_tmp_registry())
cqp_load_corpus("UNGA2", registry = get_tmp_registry())
# see whether it works
ids_sentence_1 <- cl_cpos2id(
corpus = "UNGA2", p_attribute = "word", registry = get_tmp_registry(),
cpos = 0:83
)
tokens_sentence_1 <- cl_id2str(
corpus = "UNGA2", p_attribute = "word",
registry = get_tmp_registry(), id = ids_sentence_1
)
sentence <- gsub("\\\\s+([\\\\.,])", "\\\\1", paste(tokens_sentence_1, collapse = " "))
# perform cwb_huffcode (equivalent to cwb-makeall command line utility)
cwb_huffcode(
corpus = "UNGA2",
p_attribute = "word",
registry = get_tmp_registry()
)
cwb_compress_rdx(
corpus = "UNGA2",
p_attribute = "word",
registry = get_tmp_registry()
)
data_dir <- file.path(tempdir(), "bt_data_dir")
dir.create(data_dir)
cwb_encode(
corpus = "BTMIN",
registry = Sys.getenv("CORPUS_REGISTRY"),
vrt_dir = system.file(package = "RcppCWB", "extdata", "vrt"),
data_dir = data_dir,
p_attributes = c("word", "pos", "lemma"),
s_attributes = list(
plenary_protocol = c(
"lp", "protocol_no", "date", "year", "birthday", "version",
"url", "filetype"
),
speaker = c(
"id", "type", "lp", "protocol_no", "date", "year", "ai_no", "ai_id",
"ai_type", "who", "name", "parliamentary_group", "party", "role"
),
p = character()
)
)
unlink(data_dir)
unlink(file.path(Sys.getenv("CORPUS_REGISTRY"), "btmin"))
}