Skip to content

Commit

Permalink
fix convert num
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgitpr committed Oct 29, 2023
1 parent 9981c92 commit 3238798
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
19 changes: 7 additions & 12 deletions src/libs/ikg2p/zhg2p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ namespace IKg2p {
}

// get all chinese characters and positions in the list
void ZhG2pPrivate::zhPosition(const QStringList &input, QStringList &res, QList<int> &positions) const {
void ZhG2pPrivate::zhPosition(const QStringList &input, QStringList &res, QList<int> &positions,
bool covertNum) const {
for (int i = 0; i < input.size(); i++) {
if (word_dict.find(input.at(i)) != word_dict.end() || trans_dict.find(input.at(i)) != trans_dict.end() ||
numMap.find(input.at(i)) != numMap.end()) {
if (word_dict.find(input.at(i)) != word_dict.end() || trans_dict.find(input.at(i)) != trans_dict.end()) {
res.append(input.mid(i, 1));
positions.append(i);
} else if (covertNum && numMap.find(input.at(i)) != numMap.end()) {
res.append(numMap[input.at(i)]);
positions.append(i);
}
}
}
Expand All @@ -103,22 +106,14 @@ namespace IKg2p {
QStringList inputList;
QList<int> inputPos;
// get char&pos in dict
d->zhPosition(input, inputList, inputPos);
d->zhPosition(input, inputList, inputPos, covertNum);
QStringList result;
int cursor = 0;
while (cursor < inputList.size()) {
// get char
const QString &raw_current_char = inputList.at(cursor);
QString current_char;
current_char = d->tradToSim(raw_current_char);
// covert num
if (covertNum) {
if (numMap.contains(current_char)) {
result.append(d->getDefaultPinyin(numMap[current_char]));
cursor++;
continue;
}
}

// not in dict
if (d->word_dict.find(current_char) == d->word_dict.end()) {
Expand Down
3 changes: 1 addition & 2 deletions src/libs/ikg2p/zhg2p_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ namespace IKg2p {
bool isPolyphonic(const QString &text) const;
QString tradToSim(const QString &text) const;
QString getDefaultPinyin(const QString &text) const;
void zhPosition(const QStringList &input, QStringList &res, QList<int> &positions) const;

void zhPosition(const QStringList &input, QStringList &res, QList<int> &positions, bool covertNum) const;
};

}
Expand Down

0 comments on commit 3238798

Please sign in to comment.