Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions common/ostream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ namespace acommon {
return *this;
}

OStream & operator << (int i) {printf("%d", i); return *this; }
OStream & operator << (unsigned i) {printf("%u", i); return *this;}
OStream & operator << (long int i) {printf("%ld", i); return *this; }
OStream & operator << (long unsigned i) {printf("%lu", i); return *this;}
OStream & operator << (long long int i) {printf("%lld", i); return *this; }
OStream & operator << (long long unsigned i) {printf("%llu", i); return *this;}

OStream & operator << (ParmStr in) {
write(in);
return *this;
Expand Down
7 changes: 4 additions & 3 deletions common/string_pair.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
#ifndef ASPELL_STRING_PAIR__HPP
#define ASPELL_STRING_PAIR__HPP


namespace acommon {


struct StringPair {
const char * first;
const char * second;
Expand All @@ -19,7 +17,10 @@ struct StringPair {
StringPair() : first(""), second("") {}
};


}

#ifdef __clang__
#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
#endif

#endif /* ASPELL_STRING_PAIR__HPP */
18 changes: 10 additions & 8 deletions modules/filter/markdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,31 +554,31 @@ struct HtmlTag : MultilineInline {
switch (state) {
// note: this switch is being used as a computed goto to make
// restoring state straightforward without restructuring the code
case Between:
case Between:
if (asc_isalpha(*itr) || *itr == '_' || *itr == ':') {
itr.inc();
while (asc_isalpha(*itr) || asc_isdigit(*itr)
|| *itr == '_' || *itr == ':' || *itr == '.' || *itr == '-')
itr.inc();
case AfterName:
case AfterName:
itr.eat_space();
if (itr.eol()) return AfterName;
if (*itr != '=') return Invalid;
itr.inc();
case AfterEq:
case AfterEq:
itr.eat_space();
if (itr.eol()) return AfterEq;
if (*itr == '\'') {
itr.inc();
case InSingleQ:
case InSingleQ:
while (!itr.eol() && *itr != '\'')
itr.inc();
if (itr.eol()) return InSingleQ;
if (*itr != '\'') return Invalid;
itr.inc();
} else if (*itr == '"') {
itr.inc();
case InDoubleQ:
case InDoubleQ:
while (!itr.eol() && *itr != '"')
itr.inc();
if (itr.eol()) return InDoubleQ;
Expand All @@ -594,12 +594,14 @@ struct HtmlTag : MultilineInline {
}
return Between;
}
case BeforeClose:
case BeforeClose:
return BeforeClose;
case Valid: case Invalid:
default: //case Valid: case Invalid:
// should not happen
abort();
break;
}
// should not be here
abort();
}
};

Expand Down
2 changes: 1 addition & 1 deletion modules/speller/default/editdist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace aspeller {
int a_size = a0.size() + 1;
int b_size = b0.size() + 1;
VARARRAY(short, e_d, a_size * b_size);
ShortMatrix e(a_size,b_size,e_d);
Matrix<short> e(a_size,b_size,e_d);
e(0, 0) = 0;
for (int j = 1; j != b_size; ++j)
e(0, j) = e(0, j-1) + w.del1;
Expand Down
15 changes: 8 additions & 7 deletions modules/speller/default/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@

namespace aspeller {

class ShortMatrix {
template <typename T>
class Matrix {
int x_size;
int y_size;
short * data;
T * data;
public:
void init(int sx, int sy, short * d) {x_size = sx; y_size = sy; data = d;}
ShortMatrix() {}
ShortMatrix(int sx, int sy, short * d) {init(sx,sy,d);}
short operator() (int x, int y) const {return data[x + y*x_size];}
short & operator() (int x, int y) {return data[x + y*x_size];}
void init(int sx, int sy, T * d) {x_size = sx; y_size = sy; data = d;}
Matrix() {}
Matrix(int sx, int sy, T * d) {init(sx,sy,d);}
T operator() (int x, int y) const {return data[x + y*x_size];}
T & operator() (int x, int y) {return data[x + y*x_size];}
};

}
Expand Down
22 changes: 19 additions & 3 deletions modules/speller/default/suggest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ namespace {
ObjStack buffer;
ObjStack temp_buffer;

String str_buffer;

static const bool do_count = true;
static const bool dont_count = false;

Expand Down Expand Up @@ -303,6 +305,7 @@ namespace {
return (word_weight*word_score
+ soundslike_weight*soundslike_score)/100;
}
int nudge_score(ParmStr orig_norm, int score, ParmStr normalized, ParmStr word);
int skip_first_couple(NearMisses::iterator & i) {
int k = 0;
InsensitiveCompare cmp(lang);
Expand Down Expand Up @@ -1263,12 +1266,12 @@ namespace {
adj_threshold = 0;
unsigned int j;

CharVector orig_norm, word;
Vector<NormalizedChar> orig_norm, word;
orig_norm.resize(original.word.size() + 1);
for (j = 0; j != original.word.size(); ++j)
orig_norm[j] = parms->ti->to_normalized(original.word[j]);
orig_norm[j] = 0;
ParmString orig(orig_norm.data(), j);
NormalizedString orig_word_norm(orig_norm.data(), j);
word.resize(max_word_length + 1);

for (i = scored_near_misses.begin();
Expand All @@ -1283,10 +1286,12 @@ namespace {
for (j = 0; (i->word)[j] != 0; ++j)
word[j] = parms->ti->to_normalized((i->word)[j]);
word[j] = 0;
int new_score = typo_edit_distance(ParmString(word.data(), j), orig, *parms->ti);
NormalizedString word_norm(word.data(), j);
int new_score = typo_edit_distance(word_norm, orig_word_norm, *parms->ti);
// if a repl. table was used we don't want to increase the score
if (!i->repl_table || new_score < i->word_score)
i->word_score = new_score;
i->word_score = nudge_score(orig_word_norm.str(), i->word_score, word_norm.str(), i->word);
i->adj_score = adj_wighted_average(i->soundslike_score, i->word_score, parms->ti->max);
}
if (i->adj_score > adj_threshold)
Expand All @@ -1308,6 +1313,17 @@ namespace {
}
}

int Working::nudge_score(ParmStr orig_norm, int score, ParmStr normalized, ParmStr word) {
int base_score = edit_distance(orig_norm, normalized, parms->edit_distance_weights);
const char * fixed_word = lang->fix_case(original.case_pattern, word, str_buffer);
int new_score = edit_distance(original.word, fixed_word, parms->edit_distance_weights);
//CERR.printf("%s %s %d >? %d\n", original.word.c_str(), fixed_word, new_score, base_score);
if (new_score > base_score)
return score + parms->ti->case_mismatch;
else
return score;
}

void Suggestions::transfer(NearMissesFinal & near_misses_final) {
# ifdef DEBUG_SUGGEST
COUT << "\n" << "\n"
Expand Down
Loading