A few optimizations.
This commit is contained in:
parent
3ae1979f26
commit
6be2d372f2
@ -174,22 +174,14 @@ bool is_fully_capitalized_word(char *word) {
|
||||
return true;
|
||||
}
|
||||
|
||||
sl *get_capitalized_words(char *content) {
|
||||
sl *get_capitalized_words(sl *all_words) {
|
||||
sl *capitalized_words = sln();
|
||||
sl *sentences = get_sentences(content);
|
||||
for (uint j = 0; j < sentences->count; j++) {
|
||||
char *sentence = sentences->strings[j];
|
||||
sl *all_words = get_words(sentence);
|
||||
|
||||
// Always skip the first word since sentences start with
|
||||
for (uint i = 0; i < all_words->count; i++) {
|
||||
if (is_fully_capitalized_word(all_words->strings[i])) {
|
||||
rstring_list_add(capitalized_words, all_words->strings[i]);
|
||||
}
|
||||
}
|
||||
slf(all_words);
|
||||
}
|
||||
slf(sentences);
|
||||
|
||||
return capitalized_words;
|
||||
}
|
||||
|
||||
@ -251,16 +243,13 @@ bool containswordi(sl *words, char *word) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sl *get_forbidden_words(char *content) {
|
||||
sl *words = get_words(content);
|
||||
sl *get_forbidden_words(sl *words) {
|
||||
sl *found = sln();
|
||||
for (int j = 0; forbidden_words[j] != NULL; j++) {
|
||||
if (containswordi(words, forbidden_words[j])) {
|
||||
rstring_list_add(found, forbidden_words[j]);
|
||||
}
|
||||
}
|
||||
|
||||
slf(words);
|
||||
return found;
|
||||
}
|
||||
unsigned int total = 0;
|
||||
@ -278,8 +267,18 @@ void analyze(FILE *f) {
|
||||
|
||||
free(clean_data);
|
||||
|
||||
sl *words = get_words(data);
|
||||
|
||||
// All words
|
||||
printf("Words: %llu\n", words->count);
|
||||
if(show_words)
|
||||
sld(words);
|
||||
sbuf = slds(words);
|
||||
stra(all, sbuf);
|
||||
free(sbuf);
|
||||
|
||||
// All capitalized words
|
||||
sl *capitalized_words = get_capitalized_words(data);
|
||||
sl *capitalized_words = get_capitalized_words(words);
|
||||
ulonglong capitalized_words_count = capitalized_words->count;
|
||||
printf("Capitalized words: %llu\n", capitalized_words_count);
|
||||
if(show_capitalized)
|
||||
@ -298,15 +297,7 @@ void analyze(FILE *f) {
|
||||
stra(all, sbuf);
|
||||
free(sbuf);
|
||||
|
||||
sl *words = get_words(data);
|
||||
|
||||
// All words
|
||||
printf("Words: %llu\n", words->count);
|
||||
if(show_words)
|
||||
sld(words);
|
||||
sbuf = slds(words);
|
||||
stra(all, sbuf);
|
||||
free(sbuf);
|
||||
|
||||
|
||||
// Numbers
|
||||
sl *numbers = get_numbers(data);
|
||||
@ -318,7 +309,7 @@ void analyze(FILE *f) {
|
||||
free(sbuf);
|
||||
|
||||
// Forbidden words
|
||||
sl *fw = get_forbidden_words(data);
|
||||
sl *fw = get_forbidden_words(words);
|
||||
printf("Forbidden words: %llu\n", fw->count);
|
||||
if(show_forbidden_words)
|
||||
sld(fw);
|
||||
|
Loading…
Reference in New Issue
Block a user