activities/text/Evaluator. ComplexEvaluator

ComplexEvaluator acts like BasicEvaluator, but providing feedback about
the location of mistakes on the user's answer.

Constructor

new ComplexEvaluator(className)

ComplexEvaluator constructor

Parameters:
NameTypeDescription
classNamestring

The class name of this evaluator.

Extends

Members

PUNCTUATION :string

String containing all the characters considered as punctuation marks (currently ".,;:")

Type:
  • string

checkAccents :boolean

Whether accented letters must be considered equivalent or not.

Type:
  • boolean

checkDoubleSpaces :boolean

Whether to check or not the extra spaces added between words.

Type:
  • boolean

checkPunctuation :boolean

Whether to check or not dots, commas and other punctuation marks when comparing texts.

Type:
  • boolean

checkScope :number

When an eror is detected in the analyzed expression, this variable indicates the number of
characters the checking pointer will be moved forward and back looking for a coincident
expression.

For example, comparing the answer "one lardzy dog" with the correct answer "one lazy dog"
will detect an error at position 6 (an "r" instead of "z"). If checkSteps is set to 2 or
greater, the "zy dog" expression at position 8 will be found and evaluated as valid, while
a value of 1 or less will not found any coincident expression beyond the error position, thus
evaluating all the remaining sentence as erroneous.

Type:
  • number

checkSteps :number

Number of times to repeat the evaluation process if an error is found, eliminating in each
cycle the extra characters that caused the error.

Type:
  • number

checkcase :boolean

Whether uppercase and lowercase expressions must be considered equivalent or not.

Type:
  • boolean

className :string

The type of evaluator.

Type:
  • string

collator :external:Collator

The Intl.Collator object used to compare strings, when available.

detail :boolean

Whether to detail or not the location of errors found on the analyzed text.

Type:
  • boolean

initiated :boolean

Whether this evaluator has been initialized or not.

Type:
  • boolean

Methods

checkText(text, match) → {boolean}

Checks the given text against a set of valid matches

Parameters:
NameTypeDescription
textstring

The text to be checked

matchstring | Array.<string>

The valid expression or expressions with which to compare.

Returns:
  • true if the checked expression is valid, false otherwise.
Type: 
boolean

compareSegment(src, ls, ok, lok, attr, iterate) → {boolean}

Compares two segments of text.
This function should make recursive calls.

Parameters:
NameTypeDescription
srcstring

Text to be compared

lsnumber

Offset in src where to start the comparison

okstring

Text to match against.

loknumber

Offset in ok where to start the comparison.

attrArray.<number>

Array of integers that will be filled with information about the
validity or error of each character in src.

iterateboolean

When true, the segment will be iterated looking for other
coincident fragments.

Returns:
  • true if the comparison was valid.
Type: 
boolean

countFlagsOk(flags) → {number}

Counts the number of flags on the provided array that are zero.

Parameters:
NameTypeDescription
flagsArray.<number>
Returns:
Type: 
number

evalText(text, match) → {Array.<number>}

Evaluates the given text against a set of valid matches, returning an array of flags useful
to indicate where the mistakes are located.

Parameters:
NameTypeDescription
textstring

The text to be checked

matchstring | Array.<string>

The valid expression or expressions with which to compare.

Returns:
  • An array of flags (one number for character) indicating whether each
    position is erroneous or ok.
Type: 
Array.<number>

getAttributes() → {object}

Gets a object with the basic attributes needed to rebuild this instance excluding functions,
parent references, constants and also attributes retaining the default value.
The resulting object is commonly usued to serialize elements in JSON format.

Returns:
  • The resulting object, with minimal attrributes
Type: 
object

getClearedText(src, skipped) → {string}

Removes double spaces and erroneous characters from a given text expression.

Parameters:
NameTypeDescription
srcstring

The text to be processed.

skippedArray.<boolean>

An array of boolean indicating which characters should be removed
from the string.

Returns:
Type: 
string

isOk(flags) → {boolean}

Checks if the given array of flags (usually returned by evalText) can be considered as a
valid or erroneous answer.

Parameters:
NameTypeDescription
flagsArray.<number>
Returns:
  • true when there is at least one flag and all flags are 0 (meaning no error).
Type: 
boolean

setProperties($xml)

Loads the object settings from a specific JQuery XML element

Parameters:
NameTypeDescription
$xmlexternal:jQuery

The jQuery XML element to parse