Skip to content

Commit

Permalink
src/dict/dictionary: modify term sorting algorithm
Browse files Browse the repository at this point in the history
Modify term sorting to priorize first terms that have a longer close
body. Terms with longer cloze bodies have matched more text and may
represent a more accruate match in most cases. Next check for expression
size if the close is the same. This prioritizes expressions like
すみません which may have its own definition, but also deconjugations to
another valid term. Then deconjugations with more steps are priortized
as they may reperesent more accruate terms. Finally score is used if all
else fails.
  • Loading branch information
ripose-jp committed Jun 2, 2024
1 parent fb58f2a commit 906acb5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/dict/dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,15 @@ void Dictionary::sortTerms(SharedTermList &terms) const
{
return lhs->clozeBody.size() > rhs->clozeBody.size();
}
bool lhsIsConjugated = lhs->conjugationExplanation.size() > 0;
bool rhsIsConjugated = rhs->conjugationExplanation.size() > 0;
if (lhsIsConjugated != rhsIsConjugated)
if (lhs->expression.size() != rhs->expression.size())
{
return lhsIsConjugated;
return lhs->expression.size() > rhs->expression.size();
}
if (lhs->conjugationExplanation.size() !=
rhs->conjugationExplanation.size())
{
return lhs->conjugationExplanation.size() >
rhs->conjugationExplanation.size();
}
return lhs->score > rhs->score;
}
Expand Down

0 comments on commit 906acb5

Please sign in to comment.