-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerate_Document_Word_Matrix.cpp
More file actions
35 lines (33 loc) · 1.14 KB
/
Copy pathGenerate_Document_Word_Matrix.cpp
File metadata and controls
35 lines (33 loc) · 1.14 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
#include <RcppArmadillo.h>
//[[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
// [[Rcpp::export]]
arma::mat Generate_Document_Word_Matrix(int number_of_docs,
int number_of_unique_words,
std::vector<std::string> unique_words,
List Document_Words,
arma::vec Document_Lengths
){
arma::mat document_word_matrix = arma::zeros(number_of_docs,number_of_unique_words);
for(int n = 0; n < number_of_docs; ++n){
Rcpp::Rcout << "Current Document: " << n << std::endl;
std::vector<std::string> current = Document_Words[n];
int length = Document_Lengths[n];
for(int i = 0; i < length; ++i){
int already = 0;
int counter = 0;
while(already == 0){
if(counter == number_of_unique_words ){
already = 1;
}else{
if(unique_words[counter] == current[i]){
document_word_matrix(n,counter) += 1;
already = 1;
}
counter +=1;
}
}
}
}
return document_word_matrix;
}