Class: PositionUtils

PositionUtils

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"
See:
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
preprocFunc function the preprocessing function
ctx any context for executing the preprocessing function
Returns:
Type Description
function wrapper-function for preprocFunc that handles Positions input 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
wordPreprocFunc function the preprocessing function that handles single words
ctx any context for executing the preprocessing function
splitRegExp RegExp optional regular expression for splitting (~ "tokenizing") words DEFAULT:
/\s+/g
Returns:
Type Description
function wrapper-function for wordPreprocFunc that handles Positions input arguments and tracks position-modifications for wordPreprocFunc

staticmmir.grammar.PositionUtils.recalcPos(sourcePos, targetPos)

HELPER re-calculate the positions in targetPos according to sourcePos: i.e. re-calculate the positions in targetPos so, as if sourcePos had not been applied. NOTE positions are changed "in-place" in targetPos
Name Type Description
sourcePos Array.<Pos> the positions that should be used for re-calculation (e.g. from pre-processig step i-1)
targetPos Array.<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
pos PositionsInfo the positions information as processed by the mmir.grammar.GrammarConverter#preproc function