forked from PolMine/RcppCWB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfastdecode.cpp
More file actions
48 lines (37 loc) · 1.15 KB
/
fastdecode.cpp
File metadata and controls
48 lines (37 loc) · 1.15 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
// [[Rcpp::depends(RcppCWB)]]
#include <Rcpp.h>
#include <RcppCWB.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstdlib>
// [[Rcpp::export]]
int write_token_stream(SEXP corpus, SEXP p_attribute, SEXP s_attribute, SEXP registry, SEXP attribute_type, Rcpp::StringVector filename) {
int i, n, region_size;
Rcpp::IntegerVector region(2);
std::ofstream outdata;
n = RcppCWB::attribute_size(corpus, s_attribute, attribute_type, registry);
outdata.open(filename[0]);
if( !outdata ) {
std::cerr << "Error: file could not be opened" << std::endl;
exit(1);
}
for (i = 0; i < n; i++){
region = RcppCWB::struc2cpos(corpus, s_attribute, registry, i);
region_size = region[1] - region[0] + 1;
Rcpp::IntegerVector cpos(region_size);
cpos = Rcpp::seq(region[0], region[1]);
Rcpp::StringVector values(region_size);
values = RcppCWB::cpos2str(corpus, p_attribute, registry, cpos);
int j;
for (j = 0; j < values.length(); j++){
outdata << values(j);
if (j < values.length() - 1){
outdata << " ";
}
}
outdata << std::endl;
}
outdata.close();
return 0;
}