Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
danemadsen committed Jul 31, 2024
1 parent 5ba306a commit 4742389
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 10 additions & 8 deletions src/cleaners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

std::vector<std::string> split_into_threes(const std::string& str) {
std::vector<std::string> parts;
int length = str.length();

// Process the string from the end
for (int i = length; i > 0; i -= 3) {
for (int i = str.length(); i > 0; i -= 3) {
if (i < 3) {
parts.push_back(str.substr(0, i));
} else {
Expand Down Expand Up @@ -100,10 +99,11 @@ std::string teens_to_word(int teens) {
}

std::vector<std::string> hundreds_to_words(int hundreds) {
const int hundreds_digit = hundreds / 100;
const int tens_digit = (hundreds % 100) / 10;
const int ones_digit = hundreds % 10;

std::vector<std::string> result;
int hundreds_digit = hundreds / 100;
int tens_digit = (hundreds % 100) / 10;
int ones_digit = hundreds % 10;

if (hundreds_digit > 0) {
result.push_back(number_to_word(hundreds_digit));
Expand All @@ -129,9 +129,7 @@ std::vector<std::string> hundreds_to_words(int hundreds) {

namespace DeepPhonemizer {
std::vector<std::string> numbers_to_words(const std::string& text) {
std::vector<std::string> result;
std::vector<std::string> parts = split_into_threes(text);
std::vector<std::string> suffixes = {
const std::vector<std::string> suffixes = {
"thousand",
"million",
"billion",
Expand All @@ -145,6 +143,10 @@ namespace DeepPhonemizer {
"decillion"
};

const std::vector<std::string> parts = split_into_threes(text);

std::vector<std::string> result;

for (int i = 0; i < parts.size(); i++) {
int number = std::stoi(parts[i]);
std::vector<std::string> words = hundreds_to_words(number);
Expand Down
2 changes: 0 additions & 2 deletions src/phonemizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,6 @@ namespace DeepPhonemizer {
}

std::vector<std::string> Session::g2p_internal(const std::string& text) {
std::cout << "<" << text << ">" << std::endl;

// Check if the input text is longer than one character
std::string key_text = text;
std::transform(key_text.begin(), key_text.end(), key_text.begin(), ::tolower);
Expand Down

0 comments on commit 4742389

Please sign in to comment.