Created
July 23, 2015 10:30
-
-
Save christopherlovell/7459147f2c8ff611ddaf to your computer and use it in GitHub Desktop.
Hidden Rcpp functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To make a function written in Rcpp hidden, add the following 'name; attribute to the export header line with a period prefix | |
// [[Rcpp::export(name=".ngram_generator")]] | |
std::vector<std::string> ngram_generator(std::string sentence, unsigned int n){ | |
std::istringstream iss(sentence); | |
std::vector<std::string> tokens; | |
std::vector<std::string> bigrams; | |
std::string str; | |
copy(std::istream_iterator<std::string>(iss), | |
std::istream_iterator<std::string>(), | |
back_inserter(tokens)); | |
for (unsigned int i = n; i <= tokens.size(); ++i){ | |
str = tokens[i - n]; | |
for (unsigned int j = i - n + 1; j < i; j++){ str = str + ' ' + tokens[j]; } | |
bigrams.push_back(str); | |
} | |
return(bigrams); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment