Last active
October 21, 2020 14:50
-
-
Save hosseinzoda/2f9aa9b506f7c0421ca7ec118cd4b8cd to your computer and use it in GitHub Desktop.
How to change prediction of dynamic nodes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
There are two functions in main.js for letter or word predition, You can modify it with _tree_dynamic_nodes_module_map variable | |
*/ | |
// html/js/main.js L2063 | |
var _tree_dynamic_nodes_module_map = { | |
'trees-switcher': { | |
render: _trees_switcher_dynamic_nodes, | |
}, | |
'spell-word-prediction': { | |
render: _word_prediction_dynamic_nodes, | |
}, | |
'spell-letter-prediction': { | |
render: _letter_prediction_dynamic_nodes, | |
}, | |
}; | |
/* | |
(_word_prediction_dynamic_nodes, _letter_prediction_dynamic_nodes) | |
These two functions are what renders the dynamic nodes of these predictions. | |
*/ | |
/* | |
Both functions can are retreiving current context of pasco with the following snippet. | |
{ | |
var txt = _get_current_spell_word(), | |
max_nodes = anode.meta['max-nodes'] || 3, | |
start_predicting_after_n_chars = parseInt(anode.meta['predict-after-n-chars']); | |
if (!isNaN(nchars) && txt.length < start_predicting_after_n_chars) { | |
return Promise.resolve({ nodes: [] }); | |
} | |
} | |
*/ | |
/* | |
The render function receive the dyn node as an input and should return a promise of replacements dynamic nodes. | |
Like this. | |
*/ | |
async function _word_prediction_dynamic_nodes (anode) { | |
var txt = _get_current_spell_word(), | |
max_nodes = anode.meta['max-nodes'] || 3, | |
nchars = parseInt(anode.meta['predict-after-n-chars']); | |
if (!isNaN(nchars) && txt.length < nchars) { | |
return { nodes: [] } | |
} | |
return { | |
nodes: (await request_for_predictions(txt)) | |
.map((item) => ({ | |
text: item.value, | |
meta: { | |
'spell-word': item.value, | |
'spell-finish': anode.meta['spell-finish'], | |
} | |
})) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment