Zonble: KeyHandler // Prevents the user override model to store symbols.
This commit is contained in:
parent
fa0cd101da
commit
91dcc44c95
|
@ -201,9 +201,14 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
||||||
{
|
{
|
||||||
size_t cursorIndex = [self _actualCandidateCursorIndex];
|
size_t cursorIndex = [self _actualCandidateCursorIndex];
|
||||||
string stringValue = [value UTF8String];
|
string stringValue = [value UTF8String];
|
||||||
_builder->grid().fixNodeSelectedCandidate(cursorIndex, stringValue);
|
NodeAnchor selectedNode = _builder->grid().fixNodeSelectedCandidate(cursorIndex, stringValue);
|
||||||
if (!Preferences.useSCPCTypingMode) { // 不要針對逐字選字模式啟用臨時半衰記憶模型。
|
if (!Preferences.useSCPCTypingMode) { // 不要針對逐字選字模式啟用臨時半衰記憶模型。
|
||||||
_userOverrideModel->observe(_walkedNodes, cursorIndex, stringValue, [[NSDate date] timeIntervalSince1970]);
|
// If the length of the readings and the characters do not match,
|
||||||
|
// it often means it is a special symbol and it should not be stored
|
||||||
|
// in the user override model.
|
||||||
|
if (selectedNode.spanningLength == [value count]) {
|
||||||
|
_userOverrideModel->observe(_walkedNodes, cursorIndex, stringValue, [[NSDate date] timeIntervalSince1970]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[self _walk];
|
[self _walk];
|
||||||
|
|
||||||
|
|
|
@ -40,11 +40,11 @@ namespace Taiyan {
|
||||||
vector<NodeAnchor> nodesEndingAt(size_t inLocation);
|
vector<NodeAnchor> nodesEndingAt(size_t inLocation);
|
||||||
vector<NodeAnchor> nodesCrossingOrEndingAt(size_t inLocation);
|
vector<NodeAnchor> nodesCrossingOrEndingAt(size_t inLocation);
|
||||||
|
|
||||||
// "Freeze" the node with the unigram that represents the selected canditate value.
|
// "Freeze" the node with the unigram that represents the selected candidate value.
|
||||||
// After this, the node that contains the unigram will always be evaluated to that
|
// After this, the node that contains the unigram will always be evaluated to that
|
||||||
// unigram, while all other overlapping nodes will be reset to their initial state
|
// unigram, while all other overlapping nodes will be reset to their initial state
|
||||||
// (that is, if any of those nodes were "frozen" or fixed, they will be unfrozen.)
|
// (that is, if any of those nodes were "frozen" or fixed, they will be unfrozen.)
|
||||||
void fixNodeSelectedCandidate(size_t location, const string& value);
|
NodeAnchor fixNodeSelectedCandidate(size_t location, const string& value);
|
||||||
|
|
||||||
// Similar to fixNodeSelectedCandidate, but instead of "freezing" the node, only
|
// Similar to fixNodeSelectedCandidate, but instead of "freezing" the node, only
|
||||||
// boost the unigram that represents the value with an overriding score. This
|
// boost the unigram that represents the value with an overriding score. This
|
||||||
|
@ -64,7 +64,7 @@ namespace Taiyan {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Grid::insertNode(const Node& inNode, size_t inLocation, size_t inSpanningLength)
|
inline void Grid::insertNode(const Node& inNode, size_t inLocation, size_t inSpanningLength)
|
||||||
{
|
{
|
||||||
if (inLocation >= m_spans.size()) {
|
if (inLocation >= m_spans.size()) {
|
||||||
size_t diff = inLocation - m_spans.size() + 1;
|
size_t diff = inLocation - m_spans.size() + 1;
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ namespace Taiyan {
|
||||||
|
|
||||||
if (i + span.maximumLength() >= inLocation) {
|
if (i + span.maximumLength() >= inLocation) {
|
||||||
|
|
||||||
for (size_t j = 1, m = span.maximumLength(); j <= m ; j++) {
|
for (size_t j = 1, m = span.maximumLength(); j <= m ; j++) {
|
||||||
|
|
||||||
if (i + j < inLocation) {
|
if (i + j < inLocation) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -180,9 +180,10 @@ namespace Taiyan {
|
||||||
}
|
}
|
||||||
|
|
||||||
// For nodes found at the location, fix their currently-selected candidate using the supplied string value.
|
// For nodes found at the location, fix their currently-selected candidate using the supplied string value.
|
||||||
inline void Grid::fixNodeSelectedCandidate(size_t location, const string& value)
|
inline NodeAnchor Grid::fixNodeSelectedCandidate(size_t location, const string& value)
|
||||||
{
|
{
|
||||||
vector<NodeAnchor> nodes = nodesCrossingOrEndingAt(location);
|
vector<NodeAnchor> nodes = nodesCrossingOrEndingAt(location);
|
||||||
|
NodeAnchor node;
|
||||||
for (auto nodeAnchor : nodes) {
|
for (auto nodeAnchor : nodes) {
|
||||||
auto candidates = nodeAnchor.node->candidates();
|
auto candidates = nodeAnchor.node->candidates();
|
||||||
|
|
||||||
|
@ -192,10 +193,12 @@ namespace Taiyan {
|
||||||
for (size_t i = 0, c = candidates.size(); i < c; ++i) {
|
for (size_t i = 0, c = candidates.size(); i < c; ++i) {
|
||||||
if (candidates[i].value == value) {
|
if (candidates[i].value == value) {
|
||||||
const_cast<Node*>(nodeAnchor.node)->selectCandidateAtIndex(i);
|
const_cast<Node*>(nodeAnchor.node)->selectCandidateAtIndex(i);
|
||||||
break;
|
node = nodeAnchor;
|
||||||
|
break;;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Grid::overrideNodeScoreForSelectedCandidate(size_t location, const string& value, float overridingScore)
|
inline void Grid::overrideNodeScoreForSelectedCandidate(size_t location, const string& value, float overridingScore)
|
||||||
|
@ -254,7 +257,7 @@ namespace Taiyan {
|
||||||
sst << "EOS;" << endl;
|
sst << "EOS;" << endl;
|
||||||
sst << "}";
|
sst << "}";
|
||||||
return sst.str();
|
return sst.str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ namespace Taiyan {
|
||||||
|
|
||||||
const string& key() const;
|
const string& key() const;
|
||||||
double score() const;
|
double score() const;
|
||||||
|
// double scoreForCandidate(string &candidate) const; // Prevents the override model to remember symbols with scode -X or lower.
|
||||||
const KeyValuePair currentKeyValue() const;
|
const KeyValuePair currentKeyValue() const;
|
||||||
double highestUnigramScore() const;
|
double highestUnigramScore() const;
|
||||||
|
|
||||||
|
@ -190,6 +191,17 @@ namespace Taiyan {
|
||||||
return m_score;
|
return m_score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prevents the override model to remember symbols with scode -X or lower.
|
||||||
|
// inline double Node::scoreForCandidate(string &candidate) const
|
||||||
|
// {
|
||||||
|
// for (auto unigram : m_unigrams) {
|
||||||
|
// if (unigram.keyValue.value == candidate) {
|
||||||
|
// return unigram.score;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return 0.0;
|
||||||
|
// }
|
||||||
|
|
||||||
inline double Node::highestUnigramScore() const {
|
inline double Node::highestUnigramScore() const {
|
||||||
if (m_unigrams.empty()) {
|
if (m_unigrams.empty()) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
|
Loading…
Reference in New Issue