mmir.grammar.PositionUtils
Utilities for handling position information in pre-/post-processing
functions before executing grammars/NLU functions.
The position information is meant to trac the input-words' positions, so
that the returned grammar/NLU etc. results can be mapped to the input-string
again, e.g. so that it is possible to map
~ "match for token at [3, 8]" -> "sub-string [8,16] in input-string"
Example
var posUtil = mmir.require('mmirf/positionUtils');
posUtil.createWordPosPreProc(someFunction, aGrammarConverterInstance);
...
Methods
-
staticmmir.grammar.PositionUtils.createPosPreProc(preprocFunc, ctx){function}
-
HELPER create pre-processing function that handles string|Positions argument
Name Type Description preprocFuncfunction the preprocessing function ctxany context for executing the preprocessing function Returns:
Type Description function wrapper-function for preprocFuncthat handlesPositionsinput arguments -
staticmmir.grammar.PositionUtils.createWordPosPreProc(wordPreprocFunc, ctx, splitRegExp){function}
-
HELPER create pre-processing function that handles string|Positions argument where the pre-processing function handles single "words": input string is split by whitespaces, and then processed word by word; the position information is automatically generated
Name Type Description wordPreprocFuncfunction the preprocessing function that handles single words ctxany context for executing the preprocessing function splitRegExpRegExp optional regular expression for splitting (~ "tokenizing") words DEFAULT: /\s+/g
Returns:
Type Description function wrapper-function for wordPreprocFuncthat handlesPositionsinput arguments and tracks position-modifications forwordPreprocFunc -
staticmmir.grammar.PositionUtils.recalcPos(sourcePos, targetPos)
-
HELPER re-calculate the positions in
targetPosaccording tosourcePos: i.e. re-calculate the positions intargetPosso, as ifsourcePoshad not been applied. NOTE positions are changed "in-place" in targetPosName Type Description sourcePosArray.<Pos> the positions that should be used for re-calculation (e.g. from pre-processig step i-1) targetPosArray.<Pos> the positions that should be changed/adjusted (e.g. from pre-processig step i) -
staticmmir.grammar.PositionUtils.recalcProcPos(pos)
-
HELPER re-calculate the positions for 1-n steps of the pre-processing chain, so that positions at step i do refer to the positions of the input-string instead of the pre-processed string from step i-1 NOTE positions are changed "in-place"!
Name Type Description posPositionsInfo the positions information as processed by the mmir.grammar.GrammarConverter#preprocfunction